|
@@ -1,5 +1,5 @@
|
|
/* Configure script for modbus.dll, specific for Windows with Scripting Host.
|
|
/* Configure script for modbus.dll, specific for Windows with Scripting Host.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* Inspired by configure.js from libxml2
|
|
* Inspired by configure.js from libxml2
|
|
*
|
|
*
|
|
* oldfaber < oldfaber _at_ gmail _dot_ com >
|
|
* oldfaber < oldfaber _at_ gmail _dot_ com >
|
|
@@ -19,44 +19,25 @@ var verMajor;
|
|
var verMinor;
|
|
var verMinor;
|
|
var verMicro;
|
|
var verMicro;
|
|
/* modbus features. */
|
|
/* modbus features. */
|
|
-var testRun = false;
|
|
|
|
|
|
+var dryRun = false;
|
|
/* Win32 build options. NOT used yet */
|
|
/* Win32 build options. NOT used yet */
|
|
var compiler = "msvc";
|
|
var compiler = "msvc";
|
|
/* Local stuff */
|
|
/* Local stuff */
|
|
var error = 0;
|
|
var error = 0;
|
|
-
|
|
|
|
-/* Helper function, transforms the option variable into the 'Enabled'
|
|
|
|
- or 'Disabled' string. */
|
|
|
|
-function boolToStr(opt) {
|
|
|
|
- if (opt == false)
|
|
|
|
- return "no";
|
|
|
|
- else if (opt == true)
|
|
|
|
- return "yes";
|
|
|
|
- error = 1;
|
|
|
|
- return "*** undefined ***";
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/* Helper function, transforms the argument string into a boolean
|
|
|
|
- value. */
|
|
|
|
-function strToBool(opt) {
|
|
|
|
- if (opt == 0 || opt == "no")
|
|
|
|
- return false;
|
|
|
|
- else if (opt == 1 || opt == "yes")
|
|
|
|
- return true;
|
|
|
|
- error = 1;
|
|
|
|
- return false;
|
|
|
|
-}
|
|
|
|
|
|
+/* Filename */
|
|
|
|
+var newFile;
|
|
|
|
|
|
/* Displays the details about how to use this script. */
|
|
/* Displays the details about how to use this script. */
|
|
function usage() {
|
|
function usage() {
|
|
var txt;
|
|
var txt;
|
|
|
|
+
|
|
txt = "Usage:\n";
|
|
txt = "Usage:\n";
|
|
txt += " cscript " + WScript.ScriptName + " <options>\n";
|
|
txt += " cscript " + WScript.ScriptName + " <options>\n";
|
|
txt += " cscript " + WScript.ScriptName + " help\n\n";
|
|
txt += " cscript " + WScript.ScriptName + " help\n\n";
|
|
txt += "Options can be specified in the form <option>=<value>, where the value is\n";
|
|
txt += "Options can be specified in the form <option>=<value>, where the value is\n";
|
|
txt += "either 'yes' or 'no', if not stated otherwise.\n\n";
|
|
txt += "either 'yes' or 'no', if not stated otherwise.\n\n";
|
|
txt += "\nModbus library configure options, default value given in parentheses:\n\n";
|
|
txt += "\nModbus library configure options, default value given in parentheses:\n\n";
|
|
- txt += " dry-run: Run configure without creating files (" + (testRun? "yes" : "no") + ")\n";
|
|
|
|
|
|
+ txt += " dry-run: Run configure without creating files (" + (dryRun ? "yes" : "no") + ")\n";
|
|
txt += "\nWin32 build options, default value given in parentheses:\n\n";
|
|
txt += "\nWin32 build options, default value given in parentheses:\n\n";
|
|
txt += " compiler: Compiler to be used [msvc|mingw] (" + compiler + ")\n";
|
|
txt += " compiler: Compiler to be used [msvc|mingw] (" + compiler + ")\n";
|
|
WScript.Echo(txt);
|
|
WScript.Echo(txt);
|
|
@@ -67,15 +48,15 @@ function readVersion() {
|
|
var fso, cf, ln, s;
|
|
var fso, cf, ln, s;
|
|
fso = new ActiveXObject("Scripting.FileSystemObject");
|
|
fso = new ActiveXObject("Scripting.FileSystemObject");
|
|
cf = fso.OpenTextFile(configFile, 1);
|
|
cf = fso.OpenTextFile(configFile, 1);
|
|
- while (cf.AtEndOfStream != true) {
|
|
|
|
|
|
+ while (cf.AtEndOfStream !== true) {
|
|
ln = cf.ReadLine();
|
|
ln = cf.ReadLine();
|
|
s = new String(ln);
|
|
s = new String(ln);
|
|
if (s.search(/^m4_define\(\[libmodbus_version_major/) != -1) {
|
|
if (s.search(/^m4_define\(\[libmodbus_version_major/) != -1) {
|
|
- verMajor = s.substr(s.indexOf(",") + 3, 1)
|
|
|
|
|
|
+ verMajor = s.substr(s.indexOf(",") + 3, 1);
|
|
} else if (s.search(/^m4_define\(\[libmodbus_version_minor/) != -1) {
|
|
} else if (s.search(/^m4_define\(\[libmodbus_version_minor/) != -1) {
|
|
- verMinor = s.substr(s.indexOf(",") + 3, 1)
|
|
|
|
|
|
+ verMinor = s.substr(s.indexOf(",") + 3, 1);
|
|
} else if (s.search(/^m4_define\(\[libmodbus_version_micro/) != -1) {
|
|
} else if (s.search(/^m4_define\(\[libmodbus_version_micro/) != -1) {
|
|
- verMicro = s.substr(s.indexOf(",") + 3, 1)
|
|
|
|
|
|
+ verMicro = s.substr(s.indexOf(",") + 3, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
cf.Close();
|
|
cf.Close();
|
|
@@ -86,28 +67,30 @@ function createVersionedFile(newfile, unversioned) {
|
|
var fso, ofi, of, ln, s;
|
|
var fso, ofi, of, ln, s;
|
|
fso = new ActiveXObject("Scripting.FileSystemObject");
|
|
fso = new ActiveXObject("Scripting.FileSystemObject");
|
|
ofi = fso.OpenTextFile(unversioned, 1);
|
|
ofi = fso.OpenTextFile(unversioned, 1);
|
|
- if (!testRun) {
|
|
|
|
|
|
+ if (!dryRun) {
|
|
of = fso.CreateTextFile(newfile, true);
|
|
of = fso.CreateTextFile(newfile, true);
|
|
}
|
|
}
|
|
- while (ofi.AtEndOfStream != true) {
|
|
|
|
|
|
+ while (ofi.AtEndOfStream !== true) {
|
|
ln = ofi.ReadLine();
|
|
ln = ofi.ReadLine();
|
|
s = new String(ln);
|
|
s = new String(ln);
|
|
- if (!testRun && s.search(/\@LIBMODBUS_VERSION_MAJOR\@/) != -1) {
|
|
|
|
|
|
+ if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MAJOR\@/) != -1) {
|
|
of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MAJOR\@/, verMajor));
|
|
of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MAJOR\@/, verMajor));
|
|
- } else if (!testRun && s.search(/\@LIBMODBUS_VERSION_MINOR\@/) != -1) {
|
|
|
|
|
|
+ } else if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MINOR\@/) != -1) {
|
|
of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MINOR\@/, verMinor));
|
|
of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MINOR\@/, verMinor));
|
|
- } else if (!testRun && s.search(/\@LIBMODBUS_VERSION_MICRO\@/) != -1) {
|
|
|
|
|
|
+ } else if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MICRO\@/) != -1) {
|
|
of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MICRO\@/, verMicro));
|
|
of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MICRO\@/, verMicro));
|
|
- } else if (!testRun && s.search(/\@LIBMODBUS_VERSION\@/) != -1) {
|
|
|
|
- of.WriteLine(s.replace(/\@LIBMODBUS_VERSION\@/, verMajor+"."+verMinor+"."+verMicro));
|
|
|
|
|
|
+ } else if (!dryRun && s.search(/\@LIBMODBUS_VERSION\@/) != -1) {
|
|
|
|
+ of.WriteLine(s.replace(/\@LIBMODBUS_VERSION\@/, verMajor + "." + verMinor + "." + verMicro));
|
|
} else {
|
|
} else {
|
|
- if (!testRun)
|
|
|
|
|
|
+ if (!dryRun) {
|
|
of.WriteLine(ln);
|
|
of.WriteLine(ln);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ofi.Close();
|
|
ofi.Close();
|
|
- if (!testRun)
|
|
|
|
|
|
+ if (!dryRun) {
|
|
of.Close();
|
|
of.Close();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -117,18 +100,22 @@ function createVersionedFile(newfile, unversioned) {
|
|
*/
|
|
*/
|
|
|
|
|
|
// Parse the command-line arguments.
|
|
// Parse the command-line arguments.
|
|
-for (i = 0; (i < WScript.Arguments.length) && (error == 0); i++) {
|
|
|
|
|
|
+for (i = 0; (i < WScript.Arguments.length) && (error === 0); i++) {
|
|
var arg, opt;
|
|
var arg, opt;
|
|
arg = WScript.Arguments(i);
|
|
arg = WScript.Arguments(i);
|
|
opt = arg.substring(0, arg.indexOf("="));
|
|
opt = arg.substring(0, arg.indexOf("="));
|
|
if (opt.length > 0) {
|
|
if (opt.length > 0) {
|
|
- if (opt == "dry-run")
|
|
|
|
- testRun = strToBool(arg.substring(opt.length + 1, arg.length));
|
|
|
|
- else if (opt == "compiler")
|
|
|
|
|
|
+ if (opt == "dry-run") {
|
|
|
|
+ var str = arg.substring(opt.length + 1, arg.length);
|
|
|
|
+ if (opt == 1 || opt == "yes") {
|
|
|
|
+ dryRun = true;
|
|
|
|
+ }
|
|
|
|
+ } else if (opt == "compiler") {
|
|
compiler = arg.substring(opt.length + 1, arg.length);
|
|
compiler = arg.substring(opt.length + 1, arg.length);
|
|
- else
|
|
|
|
|
|
+ } else {
|
|
error = 1;
|
|
error = 1;
|
|
- } else if (i == 0) {
|
|
|
|
|
|
+ }
|
|
|
|
+ } else if (i === 0) {
|
|
if (arg == "help") {
|
|
if (arg == "help") {
|
|
usage();
|
|
usage();
|
|
WScript.Quit(0);
|
|
WScript.Quit(0);
|
|
@@ -140,44 +127,37 @@ for (i = 0; (i < WScript.Arguments.length) && (error == 0); i++) {
|
|
|
|
|
|
|
|
|
|
// If we fail here, it is because the user supplied an unrecognised argument.
|
|
// If we fail here, it is because the user supplied an unrecognised argument.
|
|
-if (error != 0) {
|
|
|
|
|
|
+if (error !== 0) {
|
|
usage();
|
|
usage();
|
|
WScript.Quit(error);
|
|
WScript.Quit(error);
|
|
}
|
|
}
|
|
|
|
|
|
// Read the the version.
|
|
// Read the the version.
|
|
readVersion();
|
|
readVersion();
|
|
-if (error != 0) {
|
|
|
|
|
|
+if (error !== 0) {
|
|
WScript.Echo("Version discovery failed, aborting.");
|
|
WScript.Echo("Version discovery failed, aborting.");
|
|
WScript.Quit(error);
|
|
WScript.Quit(error);
|
|
}
|
|
}
|
|
|
|
|
|
-var outVerString = baseName + " version: " + verMajor + "." + verMinor + "." + verMicro;
|
|
|
|
-// WScript.Echo(outVerString);
|
|
|
|
-
|
|
|
|
-newfile = srcDir + "\\modbus-version.h"
|
|
|
|
|
|
+newfile = srcDir + "\\modbus-version.h";
|
|
createVersionedFile(newfile, srcDir + "\\modbus-version.h.in");
|
|
createVersionedFile(newfile, srcDir + "\\modbus-version.h.in");
|
|
-if (error != 0) {
|
|
|
|
|
|
+if (error !== 0) {
|
|
WScript.Echo("Creation of " + newfile + " failed, aborting.");
|
|
WScript.Echo("Creation of " + newfile + " failed, aborting.");
|
|
WScript.Quit(error);
|
|
WScript.Quit(error);
|
|
}
|
|
}
|
|
|
|
|
|
-newfile = "modbus.dll.manifest"
|
|
|
|
|
|
+newfile = "modbus.dll.manifest";
|
|
createVersionedFile(newfile, "modbus.dll.manifest.in");
|
|
createVersionedFile(newfile, "modbus.dll.manifest.in");
|
|
-if (error != 0) {
|
|
|
|
|
|
+if (error !== 0) {
|
|
WScript.Echo("Creation of " + newfile + " failed, aborting.");
|
|
WScript.Echo("Creation of " + newfile + " failed, aborting.");
|
|
WScript.Quit(error);
|
|
WScript.Quit(error);
|
|
}
|
|
}
|
|
|
|
|
|
-newfile = "config.h"
|
|
|
|
|
|
+newfile = "config.h";
|
|
createVersionedFile(newfile, "config.h.win32");
|
|
createVersionedFile(newfile, "config.h.win32");
|
|
-if (error != 0) {
|
|
|
|
|
|
+if (error !== 0) {
|
|
WScript.Echo("Creation of " + newfile + " failed, aborting.");
|
|
WScript.Echo("Creation of " + newfile + " failed, aborting.");
|
|
WScript.Quit(error);
|
|
WScript.Quit(error);
|
|
}
|
|
}
|
|
|
|
|
|
-// Display the final configuration.
|
|
|
|
-var txtOut = "\nLibmodbus configuration completed\n";
|
|
|
|
-WScript.Echo(txtOut);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+WScript.Echo("\nLibmodbus configuration completed\n");
|