Commit a30eab37817694f3f4df86b838e009e492835404
1 parent
bb3ea92b
Cleanup on configure.js (w/o any tests...)
Showing
2 changed files
with
48 additions
and
69 deletions
src/win32/README.win32
| 1 | 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 | 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 | 10 | config.h and ../modbus-version.h are generated using configure.js. |
| 14 | -Run | |
| 11 | + | |
| 12 | +Run | |
| 15 | 13 | cscript configure.js |
| 16 | -or | |
| 14 | +or | |
| 17 | 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 | 1 | /* Configure script for modbus.dll, specific for Windows with Scripting Host. |
| 2 | - * | |
| 2 | + * | |
| 3 | 3 | * Inspired by configure.js from libxml2 |
| 4 | 4 | * |
| 5 | 5 | * oldfaber < oldfaber _at_ gmail _dot_ com > |
| ... | ... | @@ -19,44 +19,25 @@ var verMajor; |
| 19 | 19 | var verMinor; |
| 20 | 20 | var verMicro; |
| 21 | 21 | /* modbus features. */ |
| 22 | -var testRun = false; | |
| 22 | +var dryRun = false; | |
| 23 | 23 | /* Win32 build options. NOT used yet */ |
| 24 | 24 | var compiler = "msvc"; |
| 25 | 25 | /* Local stuff */ |
| 26 | 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 | 30 | /* Displays the details about how to use this script. */ |
| 51 | 31 | function usage() { |
| 52 | 32 | var txt; |
| 33 | + | |
| 53 | 34 | txt = "Usage:\n"; |
| 54 | 35 | txt += " cscript " + WScript.ScriptName + " <options>\n"; |
| 55 | 36 | txt += " cscript " + WScript.ScriptName + " help\n\n"; |
| 56 | 37 | txt += "Options can be specified in the form <option>=<value>, where the value is\n"; |
| 57 | 38 | txt += "either 'yes' or 'no', if not stated otherwise.\n\n"; |
| 58 | 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 | 41 | txt += "\nWin32 build options, default value given in parentheses:\n\n"; |
| 61 | 42 | txt += " compiler: Compiler to be used [msvc|mingw] (" + compiler + ")\n"; |
| 62 | 43 | WScript.Echo(txt); |
| ... | ... | @@ -67,15 +48,15 @@ function readVersion() { |
| 67 | 48 | var fso, cf, ln, s; |
| 68 | 49 | fso = new ActiveXObject("Scripting.FileSystemObject"); |
| 69 | 50 | cf = fso.OpenTextFile(configFile, 1); |
| 70 | - while (cf.AtEndOfStream != true) { | |
| 51 | + while (cf.AtEndOfStream !== true) { | |
| 71 | 52 | ln = cf.ReadLine(); |
| 72 | 53 | s = new String(ln); |
| 73 | 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 | 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 | 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 | 62 | cf.Close(); |
| ... | ... | @@ -86,28 +67,30 @@ function createVersionedFile(newfile, unversioned) { |
| 86 | 67 | var fso, ofi, of, ln, s; |
| 87 | 68 | fso = new ActiveXObject("Scripting.FileSystemObject"); |
| 88 | 69 | ofi = fso.OpenTextFile(unversioned, 1); |
| 89 | - if (!testRun) { | |
| 70 | + if (!dryRun) { | |
| 90 | 71 | of = fso.CreateTextFile(newfile, true); |
| 91 | 72 | } |
| 92 | - while (ofi.AtEndOfStream != true) { | |
| 73 | + while (ofi.AtEndOfStream !== true) { | |
| 93 | 74 | ln = ofi.ReadLine(); |
| 94 | 75 | s = new String(ln); |
| 95 | - if (!testRun && s.search(/\@LIBMODBUS_VERSION_MAJOR\@/) != -1) { | |
| 76 | + if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MAJOR\@/) != -1) { | |
| 96 | 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 | 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 | 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 | 84 | } else { |
| 104 | - if (!testRun) | |
| 85 | + if (!dryRun) { | |
| 105 | 86 | of.WriteLine(ln); |
| 87 | + } | |
| 106 | 88 | } |
| 107 | 89 | } |
| 108 | 90 | ofi.Close(); |
| 109 | - if (!testRun) | |
| 91 | + if (!dryRun) { | |
| 110 | 92 | of.Close(); |
| 93 | + } | |
| 111 | 94 | } |
| 112 | 95 | |
| 113 | 96 | |
| ... | ... | @@ -117,18 +100,22 @@ function createVersionedFile(newfile, unversioned) { |
| 117 | 100 | */ |
| 118 | 101 | |
| 119 | 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 | 104 | var arg, opt; |
| 122 | 105 | arg = WScript.Arguments(i); |
| 123 | 106 | opt = arg.substring(0, arg.indexOf("=")); |
| 124 | 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 | 114 | compiler = arg.substring(opt.length + 1, arg.length); |
| 129 | - else | |
| 115 | + } else { | |
| 130 | 116 | error = 1; |
| 131 | - } else if (i == 0) { | |
| 117 | + } | |
| 118 | + } else if (i === 0) { | |
| 132 | 119 | if (arg == "help") { |
| 133 | 120 | usage(); |
| 134 | 121 | WScript.Quit(0); |
| ... | ... | @@ -140,44 +127,37 @@ for (i = 0; (i < WScript.Arguments.length) && (error == 0); i++) { |
| 140 | 127 | |
| 141 | 128 | |
| 142 | 129 | // If we fail here, it is because the user supplied an unrecognised argument. |
| 143 | -if (error != 0) { | |
| 130 | +if (error !== 0) { | |
| 144 | 131 | usage(); |
| 145 | 132 | WScript.Quit(error); |
| 146 | 133 | } |
| 147 | 134 | |
| 148 | 135 | // Read the the version. |
| 149 | 136 | readVersion(); |
| 150 | -if (error != 0) { | |
| 137 | +if (error !== 0) { | |
| 151 | 138 | WScript.Echo("Version discovery failed, aborting."); |
| 152 | 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 | 143 | createVersionedFile(newfile, srcDir + "\\modbus-version.h.in"); |
| 160 | -if (error != 0) { | |
| 144 | +if (error !== 0) { | |
| 161 | 145 | WScript.Echo("Creation of " + newfile + " failed, aborting."); |
| 162 | 146 | WScript.Quit(error); |
| 163 | 147 | } |
| 164 | 148 | |
| 165 | -newfile = "modbus.dll.manifest" | |
| 149 | +newfile = "modbus.dll.manifest"; | |
| 166 | 150 | createVersionedFile(newfile, "modbus.dll.manifest.in"); |
| 167 | -if (error != 0) { | |
| 151 | +if (error !== 0) { | |
| 168 | 152 | WScript.Echo("Creation of " + newfile + " failed, aborting."); |
| 169 | 153 | WScript.Quit(error); |
| 170 | 154 | } |
| 171 | 155 | |
| 172 | -newfile = "config.h" | |
| 156 | +newfile = "config.h"; | |
| 173 | 157 | createVersionedFile(newfile, "config.h.win32"); |
| 174 | -if (error != 0) { | |
| 158 | +if (error !== 0) { | |
| 175 | 159 | WScript.Echo("Creation of " + newfile + " failed, aborting."); |
| 176 | 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"); | ... | ... |