configure.js
5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* Configure script for modbus.dll, specific for Windows with Scripting Host.
*
* Inspired by configure.js from libxml2
*
* oldfaber < oldfaber _at_ gmail _dot_ com >
*
*/
/* The source directory, relative to the one where this file resides. */
var srcDir = "..";
/* Base name of what we are building. */
var baseName = "modbus";
/* Configure file template and output file */
var configFile = srcDir + "\\..\\configure.ac";
/* Input and output files for the modbus-version.h include */
var newfile;
/* Version strings for the binary distribution. Will be filled later in the code. */
var verMajor;
var verMinor;
var verMicro;
/* modbus features. */
var testRun = false;
/* Win32 build options. NOT used yet */
var compiler = "msvc";
/* Local stuff */
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;
}
/* Displays the details about how to use this script. */
function usage()
{
var txt;
txt = "Usage:\n";
txt += " cscript " + WScript.ScriptName + " <options>\n";
txt += " cscript " + WScript.ScriptName + " help\n\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 += "\nModbus library configure options, default value given in parentheses:\n\n";
txt += " test-run: Run configure without creating files (" + (testRun? "yes" : "no") + ")\n";
txt += "\nWin32 build options, default value given in parentheses:\n\n";
txt += " compiler: Compiler to be used [msvc|mingw|bcb] (" + compiler + ")\n";
WScript.Echo(txt);
}
/* read the version from the configuration file */
function readVersion()
{
var fso, cf, ln, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
cf = fso.OpenTextFile(configFile, 1);
while (cf.AtEndOfStream != true) {
ln = cf.ReadLine();
s = new String(ln);
if (s.search(/^m4_define\(\[libmodbus_version_major/) != -1) {
verMajor = s.substr(s.indexOf(",") + 3, 1)
} else if(s.search(/^m4_define\(\[libmodbus_version_minor/) != -1) {
verMinor = s.substr(s.indexOf(",") + 3, 1)
} else if(s.search(/^m4_define\(\[libmodbus_version_micro/) != -1) {
verMicro = s.substr(s.indexOf(",") + 3, 1)
}
}
cf.Close();
}
/* create the versioned file */
function createVersionedFile(newfile, unversioned)
{
var fso, ofi, of, ln, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
ofi = fso.OpenTextFile(unversioned, 1);
if (!testRun) {
of = fso.CreateTextFile(newfile, true);
}
while (ofi.AtEndOfStream != true) {
ln = ofi.ReadLine();
s = new String(ln);
if (!testRun && s.search(/\@LIBMODBUS_VERSION_MAJOR\@/) != -1) {
of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MAJOR\@/, verMajor));
} else if (!testRun && s.search(/\@LIBMODBUS_VERSION_MINOR\@/) != -1) {
of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MINOR\@/, verMinor));
} else if (!testRun && s.search(/\@LIBMODBUS_VERSION_MICRO\@/) != -1) {
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 (!testRun)
of.WriteLine(ln);
}
}
ofi.Close();
if (!testRun)
of.Close();
}
/*
* main(),
* Execution begins here.
*/
// Parse the command-line arguments.
for (i = 0; (i < WScript.Arguments.length) && (error == 0); i++) {
var arg, opt;
arg = WScript.Arguments(i);
opt = arg.substring(0, arg.indexOf("="));
if (opt.length == 0)
opt = arg.substring(0, arg.indexOf(":"));
if (opt.length > 0) {
if (opt == "dry-run")
testRun = strToBool(arg.substring(opt.length + 1, arg.length));
else if (opt == "compiler")
compiler = arg.substring(opt.length + 1, arg.length);
else
error = 1;
} else if (i == 0) {
if (arg == "help") {
usage();
WScript.Quit(0);
}
} else {
error = 1;
}
}
// If we fail here, it is because the user supplied an unrecognised argument.
if (error != 0) {
usage();
WScript.Quit(error);
}
// Read the the version.
readVersion();
if (error != 0) {
WScript.Echo("Version discovery failed, aborting.");
WScript.Quit(error);
}
var outVerString = baseName + " version: " + verMajor + "." + verMinor + "." + verMicro;
// WScript.Echo(outVerString);
newfile = srcDir + "\\modbus-version.h"
createVersionedFile(newfile, srcDir + "\\modbus-version.h.in");
if (error != 0) {
WScript.Echo("Creation of " + newfile + " failed, aborting.");
WScript.Quit(error);
}
newfile = "modbus.dll.manifest"
createVersionedFile(newfile, "modbus.dll.manifest.in");
if (error != 0) {
WScript.Echo("Creation of " + newfile + " failed, aborting.");
WScript.Quit(error);
}
newfile = "config.h"
createVersionedFile(newfile, "config.h.win32");
if (error != 0) {
WScript.Echo("Creation of " + newfile + " failed, aborting.");
WScript.Quit(error);
}
// Display the final configuration.
var txtOut = "\nLIBMODBUS configuration completed\n";
WScript.Echo(txtOut);