| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
var srcDir = ".."; |
| 11 |
|
| 12 |
var baseName = "modbus"; |
| 13 |
|
| 14 |
var configFile = srcDir + "\\..\\configure.ac"; |
| 15 |
|
| 16 |
var newfile; |
| 17 |
|
| 18 |
var verMajor; |
| 19 |
var verMinor; |
| 20 |
var verMicro; |
| 21 |
|
| 22 |
var dryRun = false; |
| 23 |
|
| 24 |
var compiler = "msvc"; |
| 25 |
|
| 26 |
var error = 0; |
| 27 |
|
| 28 |
var newFile; |
| 29 |
|
| 30 |
|
| 31 |
function usage() { |
| 32 |
var txt; |
| 33 |
|
| 34 |
txt = "Usage:\n"; |
| 35 |
txt += " cscript " + WScript.ScriptName + " <options>\n"; |
| 36 |
txt += " cscript " + WScript.ScriptName + " help\n\n"; |
| 37 |
txt += |
| 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"; |
| 40 |
txt += |
| 41 |
"\nModbus library configure options, default value given in parentheses:\n\n"; |
| 42 |
txt += |
| 43 |
" dry-run: Run configure without creating files (" + |
| 44 |
(dryRun ? "yes" : "no") + |
| 45 |
")\n"; |
| 46 |
txt += "\nWin32 build options, default value given in parentheses:\n\n"; |
| 47 |
txt += " compiler: Compiler to be used [msvc|mingw] (" + compiler + ")\n"; |
| 48 |
WScript.Echo(txt); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
function readVersion() { |
| 53 |
var fso, cf, ln, s; |
| 54 |
fso = new ActiveXObject("Scripting.FileSystemObject"); |
| 55 |
cf = fso.OpenTextFile(configFile, 1); |
| 56 |
while (cf.AtEndOfStream !== true) { |
| 57 |
ln = cf.ReadLine(); |
| 58 |
s = new String(ln); |
| 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); |
| 67 |
} |
| 68 |
} |
| 69 |
cf.Close(); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
function createVersionedFile(newfile, unversioned) { |
| 74 |
var fso, ofi, of, ln, s; |
| 75 |
fso = new ActiveXObject("Scripting.FileSystemObject"); |
| 76 |
ofi = fso.OpenTextFile(unversioned, 1); |
| 77 |
if (!dryRun) { |
| 78 |
of = fso.CreateTextFile(newfile, true); |
| 79 |
} |
| 80 |
while (ofi.AtEndOfStream !== true) { |
| 81 |
ln = ofi.ReadLine(); |
| 82 |
s = new String(ln); |
| 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) { |
| 90 |
of.WriteLine( |
| 91 |
s.replace( |
| 92 |
/\@LIBMODBUS_VERSION\@/, |
| 93 |
verMajor + "." + verMinor + "." + verMicro |
| 94 |
) |
| 95 |
); |
| 96 |
} else { |
| 97 |
if (!dryRun) { |
| 98 |
of.WriteLine(ln); |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
ofi.Close(); |
| 103 |
if (!dryRun) { |
| 104 |
of.Close(); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
for (i = 0; i < WScript.Arguments.length && error === 0; i++) { |
| 115 |
var arg, opt; |
| 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") { |
| 122 |
dryRun = true; |
| 123 |
} |
| 124 |
} else if (opt == "compiler") { |
| 125 |
compiler = arg.substring(opt.length + 1, arg.length); |
| 126 |
} else { |
| 127 |
error = 1; |
| 128 |
} |
| 129 |
} else if (i === 0) { |
| 130 |
if (arg == "help") { |
| 131 |
usage(); |
| 132 |
WScript.Quit(0); |
| 133 |
} |
| 134 |
} else { |
| 135 |
error = 1; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
if (error !== 0) { |
| 141 |
usage(); |
| 142 |
WScript.Quit(error); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
readVersion(); |
| 147 |
if (error !== 0) { |
| 148 |
WScript.Echo("Version discovery failed, aborting."); |
| 149 |
WScript.Quit(error); |
| 150 |
} |
| 151 |
|
| 152 |
newfile = srcDir + "\\modbus-version.h"; |
| 153 |
createVersionedFile(newfile, srcDir + "\\modbus-version.h.in"); |
| 154 |
if (error !== 0) { |
| 155 |
WScript.Echo("Creation of " + newfile + " failed, aborting."); |
| 156 |
WScript.Quit(error); |
| 157 |
} |
| 158 |
WScript.Echo(newfile + " created."); |
| 159 |
|
| 160 |
newfile = "modbus.dll.manifest"; |
| 161 |
createVersionedFile(newfile, "modbus.dll.manifest.in"); |
| 162 |
if (error !== 0) { |
| 163 |
WScript.Echo("Creation of " + newfile + " failed, aborting."); |
| 164 |
WScript.Quit(error); |
| 165 |
} |
| 166 |
WScript.Echo(newfile + " created."); |
| 167 |
|
| 168 |
newfile = "config.h"; |
| 169 |
createVersionedFile(newfile, "config.h.win32"); |
| 170 |
if (error !== 0) { |
| 171 |
WScript.Echo("Creation of " + newfile + " failed, aborting."); |
| 172 |
WScript.Quit(error); |
| 173 |
} |
| 174 |
WScript.Echo(newfile + " created."); |
| 175 |
|
| 176 |
WScript.Echo("\nLibmodbus configuration completed\n"); |