1 /* Configure script for modbus.dll, specific for Windows with Scripting Host.
3 * Inspired by configure.js from libxml2
5 * oldfaber < oldfaber _at_ gmail _dot_ com >
9 /* The source directory, relative to the one where this file resides. */
11 /* Base name of what we are building. */
12 var baseName = "modbus";
13 /* Configure file template and output file */
14 var configFile = srcDir + "\\..\\configure.ac";
15 /* Input and output files for the modbus-version.h include */
17 /* Version strings for the binary distribution. Will be filled later in the code. */
21 /* modbus features. */
23 /* Win32 build options. NOT used yet */
24 var compiler = "msvc";
30 /* Displays the details about how to use this script. */
35 txt += " cscript " + WScript.ScriptName + " <options>\n";
36 txt += " cscript " + WScript.ScriptName + " help\n\n";
38 "Options can be specified in the form <option>=<value>, where the value is\n";
39 txt += "either 'yes' or 'no', if not stated otherwise.\n\n";
41 "\nModbus library configure options, default value given in parentheses:\n\n";
43 " dry-run: Run configure without creating files (" +
44 (dryRun ? "yes" : "no") +
46 txt += "\nWin32 build options, default value given in parentheses:\n\n";
47 txt += " compiler: Compiler to be used [msvc|mingw] (" + compiler + ")\n";
51 /* read the version from the configuration file */
52 function readVersion() {
54 fso = new ActiveXObject("Scripting.FileSystemObject");
55 cf = fso.OpenTextFile(configFile, 1);
56 while (cf.AtEndOfStream !== true) {
59 if (s.search(/^m4_define\(\[libmodbus_version_major/) != -1) {
60 verMajor = s.substr(s.indexOf(",") + 3, 1);
61 } else if (s.search(/^m4_define\(\[libmodbus_version_minor/) != -1) {
62 verMinor = s.substr(s.indexOf(",") + 3, 1);
63 } else if (s.search(/^m4_define\(\[libmodbus_version_micro/) != -1) {
64 verMicro = s.substr(s.indexOf(",") + 3, 1);
70 /* create the versioned file */
71 function createVersionedFile(newfile, unversioned) {
72 var fso, ofi, of, ln, s;
73 fso = new ActiveXObject("Scripting.FileSystemObject");
74 ofi = fso.OpenTextFile(unversioned, 1);
76 of = fso.CreateTextFile(newfile, true);
78 while (ofi.AtEndOfStream !== true) {
81 if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MAJOR\@/) != -1) {
82 of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MAJOR\@/, verMajor));
83 } else if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MINOR\@/) != -1) {
84 of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MINOR\@/, verMinor));
85 } else if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MICRO\@/) != -1) {
86 of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MICRO\@/, verMicro));
87 } else if (!dryRun && s.search(/\@LIBMODBUS_VERSION\@/) != -1) {
90 /\@LIBMODBUS_VERSION\@/,
91 verMajor + "." + verMinor + "." + verMicro
108 * Execution begins here.
111 // Parse the command-line arguments.
112 for (i = 0; i < WScript.Arguments.length && error === 0; i++) {
114 arg = WScript.Arguments(i);
115 opt = arg.substring(0, arg.indexOf("="));
116 if (opt.length > 0) {
117 if (opt == "dry-run") {
118 var str = arg.substring(opt.length + 1, arg.length);
119 if (opt == 1 || opt == "yes") {
122 } else if (opt == "compiler") {
123 compiler = arg.substring(opt.length + 1, arg.length);
127 } else if (i === 0) {
137 // If we fail here, it is because the user supplied an unrecognised argument.
143 // Read the the version.
146 WScript.Echo("Version discovery failed, aborting.");
150 newfile = srcDir + "\\modbus-version.h";
151 createVersionedFile(newfile, srcDir + "\\modbus-version.h.in");
153 WScript.Echo("Creation of " + newfile + " failed, aborting.");
156 WScript.Echo(newfile + " created.");
158 newfile = "modbus.dll.manifest";
159 createVersionedFile(newfile, "modbus.dll.manifest.in");
161 WScript.Echo("Creation of " + newfile + " failed, aborting.");
164 WScript.Echo(newfile + " created.");
166 newfile = "config.h";
167 createVersionedFile(newfile, "config.h.win32");
169 WScript.Echo("Creation of " + newfile + " failed, aborting.");
172 WScript.Echo(newfile + " created.");
174 WScript.Echo("\nLibmodbus configuration completed\n");