Commit a30eab37817694f3f4df86b838e009e492835404

Authored by Stéphane Raimbault
1 parent bb3ea92b

Cleanup on configure.js (w/o any tests...)

src/win32/README.win32
1 Intro 1 Intro
2 ----- 2 -----
3 3
4 -  
5 -This directory contains the project file for Visual Studio 2008 to build 4 +This directory contains the project file for Visual Studio 2008 to build
6 modbus.dll and the import library modbus.lib. 5 modbus.dll and the import library modbus.lib.
7 6
8 -  
9 -The project file searches for D:/include/msvc_std to find stdint.h.  
10 -See ../../README.md  
11 - 7 +The project file looks for D:/include/msvc_std to find stdint.h.
  8 +See ../../README.md file.
12 9
13 config.h and ../modbus-version.h are generated using configure.js. 10 config.h and ../modbus-version.h are generated using configure.js.
14 -Run 11 +
  12 +Run
15 cscript configure.js 13 cscript configure.js
16 -or 14 +or
17 wscript configure.js 15 wscript configure.js
18 -or double click configure.js to generate these files. 16 +or
  17 + double click configure.js to generate these files.
19 18
src/win32/configure.js
1 /* Configure script for modbus.dll, specific for Windows with Scripting Host. 1 /* Configure script for modbus.dll, specific for Windows with Scripting Host.
2 - * 2 + *
3 * Inspired by configure.js from libxml2 3 * Inspired by configure.js from libxml2
4 * 4 *
5 * oldfaber < oldfaber _at_ gmail _dot_ com > 5 * oldfaber < oldfaber _at_ gmail _dot_ com >
@@ -19,44 +19,25 @@ var verMajor; @@ -19,44 +19,25 @@ var verMajor;
19 var verMinor; 19 var verMinor;
20 var verMicro; 20 var verMicro;
21 /* modbus features. */ 21 /* modbus features. */
22 -var testRun = false; 22 +var dryRun = false;
23 /* Win32 build options. NOT used yet */ 23 /* Win32 build options. NOT used yet */
24 var compiler = "msvc"; 24 var compiler = "msvc";
25 /* Local stuff */ 25 /* Local stuff */
26 var error = 0; 26 var error = 0;
27 -  
28 -/* Helper function, transforms the option variable into the 'Enabled'  
29 - or 'Disabled' string. */  
30 -function boolToStr(opt) {  
31 - if (opt == false)  
32 - return "no";  
33 - else if (opt == true)  
34 - return "yes";  
35 - error = 1;  
36 - return "*** undefined ***";  
37 -}  
38 -  
39 -/* Helper function, transforms the argument string into a boolean  
40 - value. */  
41 -function strToBool(opt) {  
42 - if (opt == 0 || opt == "no")  
43 - return false;  
44 - else if (opt == 1 || opt == "yes")  
45 - return true;  
46 - error = 1;  
47 - return false;  
48 -} 27 +/* Filename */
  28 +var newFile;
49 29
50 /* Displays the details about how to use this script. */ 30 /* Displays the details about how to use this script. */
51 function usage() { 31 function usage() {
52 var txt; 32 var txt;
  33 +
53 txt = "Usage:\n"; 34 txt = "Usage:\n";
54 txt += " cscript " + WScript.ScriptName + " <options>\n"; 35 txt += " cscript " + WScript.ScriptName + " <options>\n";
55 txt += " cscript " + WScript.ScriptName + " help\n\n"; 36 txt += " cscript " + WScript.ScriptName + " help\n\n";
56 txt += "Options can be specified in the form <option>=<value>, where the value is\n"; 37 txt += "Options can be specified in the form <option>=<value>, where the value is\n";
57 txt += "either 'yes' or 'no', if not stated otherwise.\n\n"; 38 txt += "either 'yes' or 'no', if not stated otherwise.\n\n";
58 txt += "\nModbus library configure options, default value given in parentheses:\n\n"; 39 txt += "\nModbus library configure options, default value given in parentheses:\n\n";
59 - txt += " dry-run: Run configure without creating files (" + (testRun? "yes" : "no") + ")\n"; 40 + txt += " dry-run: Run configure without creating files (" + (dryRun ? "yes" : "no") + ")\n";
60 txt += "\nWin32 build options, default value given in parentheses:\n\n"; 41 txt += "\nWin32 build options, default value given in parentheses:\n\n";
61 txt += " compiler: Compiler to be used [msvc|mingw] (" + compiler + ")\n"; 42 txt += " compiler: Compiler to be used [msvc|mingw] (" + compiler + ")\n";
62 WScript.Echo(txt); 43 WScript.Echo(txt);
@@ -67,15 +48,15 @@ function readVersion() { @@ -67,15 +48,15 @@ function readVersion() {
67 var fso, cf, ln, s; 48 var fso, cf, ln, s;
68 fso = new ActiveXObject("Scripting.FileSystemObject"); 49 fso = new ActiveXObject("Scripting.FileSystemObject");
69 cf = fso.OpenTextFile(configFile, 1); 50 cf = fso.OpenTextFile(configFile, 1);
70 - while (cf.AtEndOfStream != true) { 51 + while (cf.AtEndOfStream !== true) {
71 ln = cf.ReadLine(); 52 ln = cf.ReadLine();
72 s = new String(ln); 53 s = new String(ln);
73 if (s.search(/^m4_define\(\[libmodbus_version_major/) != -1) { 54 if (s.search(/^m4_define\(\[libmodbus_version_major/) != -1) {
74 - verMajor = s.substr(s.indexOf(",") + 3, 1) 55 + verMajor = s.substr(s.indexOf(",") + 3, 1);
75 } else if (s.search(/^m4_define\(\[libmodbus_version_minor/) != -1) { 56 } else if (s.search(/^m4_define\(\[libmodbus_version_minor/) != -1) {
76 - verMinor = s.substr(s.indexOf(",") + 3, 1) 57 + verMinor = s.substr(s.indexOf(",") + 3, 1);
77 } else if (s.search(/^m4_define\(\[libmodbus_version_micro/) != -1) { 58 } else if (s.search(/^m4_define\(\[libmodbus_version_micro/) != -1) {
78 - verMicro = s.substr(s.indexOf(",") + 3, 1) 59 + verMicro = s.substr(s.indexOf(",") + 3, 1);
79 } 60 }
80 } 61 }
81 cf.Close(); 62 cf.Close();
@@ -86,28 +67,30 @@ function createVersionedFile(newfile, unversioned) { @@ -86,28 +67,30 @@ function createVersionedFile(newfile, unversioned) {
86 var fso, ofi, of, ln, s; 67 var fso, ofi, of, ln, s;
87 fso = new ActiveXObject("Scripting.FileSystemObject"); 68 fso = new ActiveXObject("Scripting.FileSystemObject");
88 ofi = fso.OpenTextFile(unversioned, 1); 69 ofi = fso.OpenTextFile(unversioned, 1);
89 - if (!testRun) { 70 + if (!dryRun) {
90 of = fso.CreateTextFile(newfile, true); 71 of = fso.CreateTextFile(newfile, true);
91 } 72 }
92 - while (ofi.AtEndOfStream != true) { 73 + while (ofi.AtEndOfStream !== true) {
93 ln = ofi.ReadLine(); 74 ln = ofi.ReadLine();
94 s = new String(ln); 75 s = new String(ln);
95 - if (!testRun && s.search(/\@LIBMODBUS_VERSION_MAJOR\@/) != -1) { 76 + if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MAJOR\@/) != -1) {
96 of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MAJOR\@/, verMajor)); 77 of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MAJOR\@/, verMajor));
97 - } else if (!testRun && s.search(/\@LIBMODBUS_VERSION_MINOR\@/) != -1) { 78 + } else if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MINOR\@/) != -1) {
98 of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MINOR\@/, verMinor)); 79 of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MINOR\@/, verMinor));
99 - } else if (!testRun && s.search(/\@LIBMODBUS_VERSION_MICRO\@/) != -1) { 80 + } else if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MICRO\@/) != -1) {
100 of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MICRO\@/, verMicro)); 81 of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MICRO\@/, verMicro));
101 - } else if (!testRun && s.search(/\@LIBMODBUS_VERSION\@/) != -1) {  
102 - of.WriteLine(s.replace(/\@LIBMODBUS_VERSION\@/, verMajor+"."+verMinor+"."+verMicro)); 82 + } else if (!dryRun && s.search(/\@LIBMODBUS_VERSION\@/) != -1) {
  83 + of.WriteLine(s.replace(/\@LIBMODBUS_VERSION\@/, verMajor + "." + verMinor + "." + verMicro));
103 } else { 84 } else {
104 - if (!testRun) 85 + if (!dryRun) {
105 of.WriteLine(ln); 86 of.WriteLine(ln);
  87 + }
106 } 88 }
107 } 89 }
108 ofi.Close(); 90 ofi.Close();
109 - if (!testRun) 91 + if (!dryRun) {
110 of.Close(); 92 of.Close();
  93 + }
111 } 94 }
112 95
113 96
@@ -117,18 +100,22 @@ function createVersionedFile(newfile, unversioned) { @@ -117,18 +100,22 @@ function createVersionedFile(newfile, unversioned) {
117 */ 100 */
118 101
119 // Parse the command-line arguments. 102 // Parse the command-line arguments.
120 -for (i = 0; (i < WScript.Arguments.length) && (error == 0); i++) { 103 +for (i = 0; (i < WScript.Arguments.length) && (error === 0); i++) {
121 var arg, opt; 104 var arg, opt;
122 arg = WScript.Arguments(i); 105 arg = WScript.Arguments(i);
123 opt = arg.substring(0, arg.indexOf("=")); 106 opt = arg.substring(0, arg.indexOf("="));
124 if (opt.length > 0) { 107 if (opt.length > 0) {
125 - if (opt == "dry-run")  
126 - testRun = strToBool(arg.substring(opt.length + 1, arg.length));  
127 - else if (opt == "compiler") 108 + if (opt == "dry-run") {
  109 + var str = arg.substring(opt.length + 1, arg.length);
  110 + if (opt == 1 || opt == "yes") {
  111 + dryRun = true;
  112 + }
  113 + } else if (opt == "compiler") {
128 compiler = arg.substring(opt.length + 1, arg.length); 114 compiler = arg.substring(opt.length + 1, arg.length);
129 - else 115 + } else {
130 error = 1; 116 error = 1;
131 - } else if (i == 0) { 117 + }
  118 + } else if (i === 0) {
132 if (arg == "help") { 119 if (arg == "help") {
133 usage(); 120 usage();
134 WScript.Quit(0); 121 WScript.Quit(0);
@@ -140,44 +127,37 @@ for (i = 0; (i &lt; WScript.Arguments.length) &amp;&amp; (error == 0); i++) { @@ -140,44 +127,37 @@ for (i = 0; (i &lt; WScript.Arguments.length) &amp;&amp; (error == 0); i++) {
140 127
141 128
142 // If we fail here, it is because the user supplied an unrecognised argument. 129 // If we fail here, it is because the user supplied an unrecognised argument.
143 -if (error != 0) { 130 +if (error !== 0) {
144 usage(); 131 usage();
145 WScript.Quit(error); 132 WScript.Quit(error);
146 } 133 }
147 134
148 // Read the the version. 135 // Read the the version.
149 readVersion(); 136 readVersion();
150 -if (error != 0) { 137 +if (error !== 0) {
151 WScript.Echo("Version discovery failed, aborting."); 138 WScript.Echo("Version discovery failed, aborting.");
152 WScript.Quit(error); 139 WScript.Quit(error);
153 } 140 }
154 141
155 -var outVerString = baseName + " version: " + verMajor + "." + verMinor + "." + verMicro;  
156 -// WScript.Echo(outVerString);  
157 -  
158 -newfile = srcDir + "\\modbus-version.h" 142 +newfile = srcDir + "\\modbus-version.h";
159 createVersionedFile(newfile, srcDir + "\\modbus-version.h.in"); 143 createVersionedFile(newfile, srcDir + "\\modbus-version.h.in");
160 -if (error != 0) { 144 +if (error !== 0) {
161 WScript.Echo("Creation of " + newfile + " failed, aborting."); 145 WScript.Echo("Creation of " + newfile + " failed, aborting.");
162 WScript.Quit(error); 146 WScript.Quit(error);
163 } 147 }
164 148
165 -newfile = "modbus.dll.manifest" 149 +newfile = "modbus.dll.manifest";
166 createVersionedFile(newfile, "modbus.dll.manifest.in"); 150 createVersionedFile(newfile, "modbus.dll.manifest.in");
167 -if (error != 0) { 151 +if (error !== 0) {
168 WScript.Echo("Creation of " + newfile + " failed, aborting."); 152 WScript.Echo("Creation of " + newfile + " failed, aborting.");
169 WScript.Quit(error); 153 WScript.Quit(error);
170 } 154 }
171 155
172 -newfile = "config.h" 156 +newfile = "config.h";
173 createVersionedFile(newfile, "config.h.win32"); 157 createVersionedFile(newfile, "config.h.win32");
174 -if (error != 0) { 158 +if (error !== 0) {
175 WScript.Echo("Creation of " + newfile + " failed, aborting."); 159 WScript.Echo("Creation of " + newfile + " failed, aborting.");
176 WScript.Quit(error); 160 WScript.Quit(error);
177 } 161 }
178 162
179 -// Display the final configuration.  
180 -var txtOut = "\nLibmodbus configuration completed\n";  
181 -WScript.Echo(txtOut);  
182 -  
183 - 163 +WScript.Echo("\nLibmodbus configuration completed\n");