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 str_start_idx
= s
.indexOf(",") + 3;
65 num_str_length
= s
.length
- str_start_idx
- 2;
66 verMicro
= s
.substr(str_start_idx
, num_str_length
);
72 /* create the versioned file */
73 function createVersionedFile(newfile
, unversioned
) {
74 var fso
, ofi
, of, ln
, s
;
75 fso
= new ActiveXObject("Scripting.FileSystemObject");
76 ofi
= fso
.OpenTextFile(unversioned
, 1);
78 of = fso
.CreateTextFile(newfile
, true);
80 while (ofi
.AtEndOfStream
!== true) {
83 if (!dryRun
&& s
.search(/\@LIBMODBUS_VERSION_MAJOR\@/) != -1) {
84 of.WriteLine(s
.replace(/\@LIBMODBUS_VERSION_MAJOR\@/, verMajor
));
85 } else if (!dryRun
&& s
.search(/\@LIBMODBUS_VERSION_MINOR\@/) != -1) {
86 of.WriteLine(s
.replace(/\@LIBMODBUS_VERSION_MINOR\@/, verMinor
));
87 } else if (!dryRun
&& s
.search(/\@LIBMODBUS_VERSION_MICRO\@/) != -1) {
88 of.WriteLine(s
.replace(/\@LIBMODBUS_VERSION_MICRO\@/, verMicro
));
89 } else if (!dryRun
&& s
.search(/\@LIBMODBUS_VERSION\@/) != -1) {
92 /\@LIBMODBUS_VERSION\@/,
93 verMajor
+ "." + verMinor
+ "." + verMicro
110 * Execution begins here.
113 // Parse the command-line arguments.
114 for (i
= 0; i
< WScript
.Arguments
.length
&& error
=== 0; i
++) {
116 arg
= WScript
.Arguments(i
);
117 opt
= arg
.substring(0, arg
.indexOf("="));
118 if (opt
.length
> 0) {
119 if (opt
== "dry-run") {
120 var str
= arg
.substring(opt
.length
+ 1, arg
.length
);
121 if (opt
== 1 || opt
== "yes") {
124 } else if (opt
== "compiler") {
125 compiler
= arg
.substring(opt
.length
+ 1, arg
.length
);
129 } else if (i
=== 0) {
139 // If we fail here, it is because the user supplied an unrecognised argument.
145 // Read the the version.
148 WScript
.Echo("Version discovery failed, aborting.");
152 newfile
= srcDir
+ "\\modbus-version.h";
153 createVersionedFile(newfile
, srcDir
+ "\\modbus-version.h.in");
155 WScript
.Echo("Creation of " + newfile
+ " failed, aborting.");
158 WScript
.Echo(newfile
+ " created.");
160 newfile
= "modbus.dll.manifest";
161 createVersionedFile(newfile
, "modbus.dll.manifest.in");
163 WScript
.Echo("Creation of " + newfile
+ " failed, aborting.");
166 WScript
.Echo(newfile
+ " created.");
168 newfile
= "config.h";
169 createVersionedFile(newfile
, "config.h.win32");
171 WScript
.Echo("Creation of " + newfile
+ " failed, aborting.");
174 WScript
.Echo(newfile
+ " created.");
176 WScript
.Echo("\nLibmodbus configuration completed\n");