Commit 173991115932e219cb3a94fd77970bbfe1a33845

Authored by Stéphane Raimbault
1 parent aa84a0e0

Display created files in configure.js

Showing 1 changed file with 99 additions and 88 deletions
src/win32/configure.js
... ... @@ -29,135 +29,146 @@ var newFile;
29 29  
30 30 /* Displays the details about how to use this script. */
31 31 function usage() {
32   - var txt;
  32 + var txt;
33 33  
34   - txt = "Usage:\n";
35   - txt += " cscript " + WScript.ScriptName + " <options>\n";
36   - txt += " cscript " + WScript.ScriptName + " help\n\n";
37   - txt += "Options can be specified in the form <option>=<value>, where the value is\n";
38   - txt += "either 'yes' or 'no', if not stated otherwise.\n\n";
39   - txt += "\nModbus library configure options, default value given in parentheses:\n\n";
40   - txt += " dry-run: Run configure without creating files (" + (dryRun ? "yes" : "no") + ")\n";
41   - txt += "\nWin32 build options, default value given in parentheses:\n\n";
42   - txt += " compiler: Compiler to be used [msvc|mingw] (" + compiler + ")\n";
43   - WScript.Echo(txt);
  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);
44 49 }
45 50  
46 51 /* read the version from the configuration file */
47 52 function readVersion() {
48   - var fso, cf, ln, s;
49   - fso = new ActiveXObject("Scripting.FileSystemObject");
50   - cf = fso.OpenTextFile(configFile, 1);
51   - while (cf.AtEndOfStream !== true) {
52   - ln = cf.ReadLine();
53   - s = new String(ln);
54   - if (s.search(/^m4_define\(\[libmodbus_version_major/) != -1) {
55   - verMajor = s.substr(s.indexOf(",") + 3, 1);
56   - } else if (s.search(/^m4_define\(\[libmodbus_version_minor/) != -1) {
57   - verMinor = s.substr(s.indexOf(",") + 3, 1);
58   - } else if (s.search(/^m4_define\(\[libmodbus_version_micro/) != -1) {
59   - verMicro = s.substr(s.indexOf(",") + 3, 1);
60   - }
61   - }
62   - cf.Close();
  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 + verMicro = s.substr(s.indexOf(",") + 3, 1);
  65 + }
  66 + }
  67 + cf.Close();
63 68 }
64 69  
65 70 /* create the versioned file */
66 71 function createVersionedFile(newfile, unversioned) {
67   - var fso, ofi, of, ln, s;
68   - fso = new ActiveXObject("Scripting.FileSystemObject");
69   - ofi = fso.OpenTextFile(unversioned, 1);
70   - if (!dryRun) {
71   - of = fso.CreateTextFile(newfile, true);
72   - }
73   - while (ofi.AtEndOfStream !== true) {
74   - ln = ofi.ReadLine();
75   - s = new String(ln);
76   - if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MAJOR\@/) != -1) {
77   - of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MAJOR\@/, verMajor));
78   - } else if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MINOR\@/) != -1) {
79   - of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MINOR\@/, verMinor));
80   - } else if (!dryRun && s.search(/\@LIBMODBUS_VERSION_MICRO\@/) != -1) {
81   - of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MICRO\@/, verMicro));
82   - } else if (!dryRun && s.search(/\@LIBMODBUS_VERSION\@/) != -1) {
83   - of.WriteLine(s.replace(/\@LIBMODBUS_VERSION\@/, verMajor + "." + verMinor + "." + verMicro));
84   - } else {
85   - if (!dryRun) {
86   - of.WriteLine(ln);
87   - }
88   - }
89   - }
90   - ofi.Close();
91   - if (!dryRun) {
92   - of.Close();
93   - }
  72 + var fso, ofi, of, ln, s;
  73 + fso = new ActiveXObject("Scripting.FileSystemObject");
  74 + ofi = fso.OpenTextFile(unversioned, 1);
  75 + if (!dryRun) {
  76 + of = fso.CreateTextFile(newfile, true);
  77 + }
  78 + while (ofi.AtEndOfStream !== true) {
  79 + ln = ofi.ReadLine();
  80 + s = new String(ln);
  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) {
  88 + of.WriteLine(
  89 + s.replace(
  90 + /\@LIBMODBUS_VERSION\@/,
  91 + verMajor + "." + verMinor + "." + verMicro
  92 + )
  93 + );
  94 + } else {
  95 + if (!dryRun) {
  96 + of.WriteLine(ln);
  97 + }
  98 + }
  99 + }
  100 + ofi.Close();
  101 + if (!dryRun) {
  102 + of.Close();
  103 + }
94 104 }
95 105  
96   -
97 106 /*
98 107 * main(),
99 108 * Execution begins here.
100 109 */
101 110  
102 111 // Parse the command-line arguments.
103   -for (i = 0; (i < WScript.Arguments.length) && (error === 0); i++) {
104   - var arg, opt;
105   - arg = WScript.Arguments(i);
106   - opt = arg.substring(0, arg.indexOf("="));
107   - if (opt.length > 0) {
108   - if (opt == "dry-run") {
109   - var str = arg.substring(opt.length + 1, arg.length);
110   - if (opt == 1 || opt == "yes") {
111   - dryRun = true;
112   - }
113   - } else if (opt == "compiler") {
114   - compiler = arg.substring(opt.length + 1, arg.length);
115   - } else {
116   - error = 1;
117   - }
118   - } else if (i === 0) {
119   - if (arg == "help") {
120   - usage();
121   - WScript.Quit(0);
122   - }
123   - } else {
124   - error = 1;
125   - }
  112 +for (i = 0; i < WScript.Arguments.length && error === 0; i++) {
  113 + var arg, opt;
  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") {
  120 + dryRun = true;
  121 + }
  122 + } else if (opt == "compiler") {
  123 + compiler = arg.substring(opt.length + 1, arg.length);
  124 + } else {
  125 + error = 1;
  126 + }
  127 + } else if (i === 0) {
  128 + if (arg == "help") {
  129 + usage();
  130 + WScript.Quit(0);
  131 + }
  132 + } else {
  133 + error = 1;
  134 + }
126 135 }
127 136  
128   -
129 137 // If we fail here, it is because the user supplied an unrecognised argument.
130 138 if (error !== 0) {
131   - usage();
132   - WScript.Quit(error);
  139 + usage();
  140 + WScript.Quit(error);
133 141 }
134 142  
135 143 // Read the the version.
136 144 readVersion();
137 145 if (error !== 0) {
138   - WScript.Echo("Version discovery failed, aborting.");
139   - WScript.Quit(error);
  146 + WScript.Echo("Version discovery failed, aborting.");
  147 + WScript.Quit(error);
140 148 }
141 149  
142 150 newfile = srcDir + "\\modbus-version.h";
143 151 createVersionedFile(newfile, srcDir + "\\modbus-version.h.in");
144 152 if (error !== 0) {
145   - WScript.Echo("Creation of " + newfile + " failed, aborting.");
146   - WScript.Quit(error);
  153 + WScript.Echo("Creation of " + newfile + " failed, aborting.");
  154 + WScript.Quit(error);
147 155 }
  156 +WScript.Echo(newfile + " created.");
148 157  
149 158 newfile = "modbus.dll.manifest";
150 159 createVersionedFile(newfile, "modbus.dll.manifest.in");
151 160 if (error !== 0) {
152   - WScript.Echo("Creation of " + newfile + " failed, aborting.");
153   - WScript.Quit(error);
  161 + WScript.Echo("Creation of " + newfile + " failed, aborting.");
  162 + WScript.Quit(error);
154 163 }
  164 +WScript.Echo(newfile + " created.");
155 165  
156 166 newfile = "config.h";
157 167 createVersionedFile(newfile, "config.h.win32");
158 168 if (error !== 0) {
159   - WScript.Echo("Creation of " + newfile + " failed, aborting.");
160   - WScript.Quit(error);
  169 + WScript.Echo("Creation of " + newfile + " failed, aborting.");
  170 + WScript.Quit(error);
161 171 }
  172 +WScript.Echo(newfile + " created.");
162 173  
163 174 WScript.Echo("\nLibmodbus configuration completed\n");
... ...