blob: 01c9a27029932955ec8885df80da61936779a6a9 [file] [log] [blame]
Igor Zlatkovicac97f6e2002-03-24 21:00:26 +00001/* Configure script for libxml, specific for Windows with Scripting Host.
2 *
3 * This script will configure the libxml build process and create necessary files.
4 * Run it with an 'help', or an invalid option and it will tell you what options
5 * it accepts.
6 *
7 * March 2002, Igor Zlatkovic <igor@stud.fh-frankfurt.de>
8 */
9
10/* The source directory, relative to the one where this file resides. */
11var srcDirXml = "..";
12var srcDirUtils = "..";
13/* The directory where we put the binaries after compilation. */
14var binDir = "binaries";
15/* Base name of what we are building. */
16var baseName = "libxml2";
17/* Configure file which contains the version and the output file where
18 we can store our build configuration. */
19var configFile = srcDirXml + "\\configure.in";
20var versionFile = ".\\configure.txt";
21/* Input and output files regarding the libxml features. The second
22 output file is there for the compatibility reasons, otherwise it
23 is identical to the first. */
24var optsFileIn = srcDirXml + "\\include\\libxml\\xmlversion.h.in";
25var optsFile = srcDirXml + "\\include\\libxml\\xmlversion.h";
26var optsFile2 = srcDirXml + "\\include\\libxml\\xmlwin32version.h";
27/* Version strings for the binary distribution. Will be filled later
28 in the code. */
29var verMajor;
30var verMinor;
31var verMicro;
32/* Libxml features. */
33var withTrio = false;
34var withThreads = false;
35var withFtp = true;
36var withHttp = true;
37var withHtml = true;
38var withC14n = true;
39var withCatalog = true;
40var withDocb = true;
41var withXpath = true;
42var withXptr = true;
43var withXinclude = true;
44var withIconv = true;
45var withDebug = true;
46var withMemDebug = false;
47/* Win32 build options. */
48var buildDebug = 0;
49var buildStatic = 0;
50var buildPrefix = ".";
51var buildBinPrefix = "$(PREFIX)\\bin";
52var buildIncPrefix = "$(PREFIX)\\include";
53var buildLibPrefix = "$(PREFIX)\\lib";
54var buildSoPrefix = "$(PREFIX)\\lib";
55var buildInclude = ".";
56var buildLib = ".";
57/* Local stuff */
58var error = 0;
59
60/* Helper function, transforms the option variable into the 'Enabled'
61 or 'Disabled' string. */
62function boolToStr(opt)
63{
64 if (opt == false)
65 return "Disabled";
66 else if (opt == true)
67 return "Enabled";
68 error = 1;
69 return "Undefined";
70}
71
72/* Helper function, transforms the argument string into a boolean
73 value. */
74function strToBool(opt)
75{
76 if (opt == 0 || opt == "no")
77 return false;
78 else if (opt == 1 || opt == "yes")
79 return true;
80 error = 1;
81 return false;
82}
83
84/* Displays the details about how to use this script. */
85function usage()
86{
87 var txt;
88 txt = "Usage:\n";
89 txt += " cscript " + WScript.ScriptName + " <options>\n";
90 txt += " cscript " + WScript.ScriptName + " help\n\n";
91 txt += "Options can be specified in the form <option>=<value>, where the value is\n";
92 txt += "either 'yes' or 'no'.\n\n";
93 txt += "XML processor options, default value given in parentheses:\n\n";
94 txt += " trio: Enable TRIO string manipulator (" + (withTrio? "yes" : "no") + ")\n";
95 txt += " threads: Enable thread safety (" + (withThreads? "yes" : "no") + ") \n";
96 txt += " ftp: Enable FTP client (" + (withFtp? "yes" : "no") + ")\n";
97 txt += " http: Enable HTTP client (" + (withHttp? "yes" : "no") + ")\n";
98 txt += " html: Enable HTML processor (" + (withHtml? "yes" : "no") + ")\n";
99 txt += " c14n: Enable C14N support (" + (withC14n? "yes" : "no") + ")\n";
100 txt += " catalog: Enable catalog support (" + (withCatalog? "yes" : "no") + ")\n";
101 txt += " docb: Enable DocBook support (" + (withDocb? "yes" : "no") + ")\n";
102 txt += " xpath: Enable XPath support (" + (withXpath? "yes" : "no") + ")\n";
103 txt += " xptr: Enable XPointer support (" + (withXptr? "yes" : "no") + ")\n";
104 txt += " xinclude: Enable XInclude support (" + (withXinclude? "yes" : "no") + ")\n";
105 txt += " iconv: Enable ICONV support (" + (withIconv? "yes" : "no") + ")\n";
106 txt += " xml_debug: Enable XML debbugging module (" + (withDebug? "yes" : "no") + ")\n";
107 txt += " mem_debug: Enable memory debugger (" + (withMemDebug? "yes" : "no") + ")\n";
108 txt += "\nWin32 build options, default value given in parentheses:\n\n";
109 txt += " debug: Build unoptimised debug executables (" + (buildDebug? "yes" : "no") + ")\n";
110 txt += " static: Link xmllint statically to libxml2 (" + (buildStatic? "yes" : "no") + ")\n";
111 txt += " prefix: Base directory for the installation (" + buildPrefix + ")\n";
112 txt += " bindir: Directory where xmllint and friends should be installed\n";
113 txt += " (" + buildBinPrefix + ")\n";
114 txt += " incdir: Directory where headers should be installed\n";
115 txt += " (" + buildIncPrefix + ")\n";
116 txt += " libdir: Directory where static and import libraries should be\n";
117 txt += " installed (" + buildLibPrefix + ")\n";
118 txt += " sodir: Directory where shared libraries should be installed\n";
119 txt += " (" + buildSoPrefix + ")\n";
120 txt += " include: Additional search path for the compiler, particularily\n";
121 txt += " where iconv headers can be found (" + buildInclude + ")\n";
122 txt += " lib: Additional search path for the linker, particularily\n";
123 txt += " where iconv library can be found (" + buildLib + ")\n";
124 WScript.Echo(txt);
125}
126
127/* Discovers the version we are working with by reading the apropriate
128 configuration file. Despite its name, this also writes the configuration
129 file included by our makefile. */
130function discoverVersion()
131{
132 var fso, cf, vf, ln, s;
133 fso = new ActiveXObject("Scripting.FileSystemObject");
134 cf = fso.OpenTextFile(configFile, 1);
135 vf = fso.CreateTextFile(versionFile, true);
136 vf.WriteLine("# " + versionFile);
137 vf.WriteLine("# This file is generated automatically by " + WScript.ScriptName + ".");
138 vf.WriteBlankLines(1);
139 while (cf.AtEndOfStream != true) {
140 ln = cf.ReadLine();
141 s = new String(ln);
142 if (s.search(/^LIBXML_MAJOR_VERSION/) != -1) {
143 vf.WriteLine(s);
144 verMajor = s.substring(s.indexOf("=") + 1, s.length)
145 } else if(s.search(/^LIBXML_MINOR_VERSION/) != -1) {
146 vf.WriteLine(s);
147 verMinor = s.substring(s.indexOf("=") + 1, s.length)
148 } else if(s.search(/^LIBXML_MICRO_VERSION/) != -1) {
149 vf.WriteLine(s);
150 verMicro = s.substring(s.indexOf("=") + 1, s.length)
151 }
152 }
153 cf.Close();
154 vf.WriteLine("XML_SRCDIR=" + srcDirXml);
155 vf.WriteLine("UTILS_SRCDIR=" + srcDirUtils);
156 vf.WriteLine("BINDIR=" + binDir);
157 vf.WriteLine("WITH_TRIO=" + (withTrio? "1" : "0"));
158 vf.WriteLine("WITH_THREADS=" + (withThreads? "1" : "0"));
159 vf.WriteLine("WITH_FTP=" + (withFtp? "1" : "0"));
160 vf.WriteLine("WITH_HTTP=" + (withHttp? "1" : "0"));
161 vf.WriteLine("WITH_HTML=" + (withHtml? "1" : "0"));
162 vf.WriteLine("WITH_C14N=" + (withC14n? "1" : "0"));
163 vf.WriteLine("WITH_CATALOG=" + (withCatalog? "1" : "0"));
164 vf.WriteLine("WITH_DOCB=" + (withDocb? "1" : "0"));
165 vf.WriteLine("WITH_XPATH=" + (withXpath? "1" : "0"));
166 vf.WriteLine("WITH_XPTR=" + (withXptr? "1" : "0"));
167 vf.WriteLine("WITH_XINCLUDE=" + (withXinclude? "1" : "0"));
168 vf.WriteLine("WITH_ICONV=" + (withIconv? "1" : "0"));
169 vf.WriteLine("WITH_DEBUG=" + (withDebug? "1" : "0"));
170 vf.WriteLine("WITH_MEM_DEBUG=" + (withMemDebug? "1" : "0"));
171 vf.WriteLine("DEBUG=" + (buildDebug? "1" : "0"));
172 vf.WriteLine("STATIC=" + (buildStatic? "1" : "0"));
173 vf.WriteLine("PREFIX=" + buildPrefix);
174 vf.WriteLine("BINPREFIX=" + buildBinPrefix);
175 vf.WriteLine("INCPREFIX=" + buildIncPrefix);
176 vf.WriteLine("LIBPREFIX=" + buildLibPrefix);
177 vf.WriteLine("SOPREFIX=" + buildSoPrefix);
178 vf.WriteLine("INCLUDE=$(INCLUDE);" + buildInclude);
179 vf.WriteLine("LIB=$(LIB);" + buildLib);
180 vf.Close();
181}
182
183/* Configures libxml. This one will generate xmlversion.h from xmlversion.h.in
184 taking what the user passed on the command line into account. */
185function configureLibxml()
186{
187 var fso, ofi, of, ln, s;
188 fso = new ActiveXObject("Scripting.FileSystemObject");
189 ofi = fso.OpenTextFile(optsFileIn, 1);
190 of = fso.CreateTextFile(optsFile, true);
191 while (ofi.AtEndOfStream != true) {
192 ln = ofi.ReadLine();
193 s = new String(ln);
194 if (s.search(/\@VERSION\@/) != -1) {
195 of.WriteLine(s.replace(/\@VERSION\@/,
196 verMajor + "." + verMinor + "." + verMicro));
197 } else if (s.search(/\@LIBXML_VERSION_NUMBER\@/) != -1) {
198 of.WriteLine(s.replace(/\@LIBXML_VERSION_NUMBER\@/,
199 verMajor*10000 + verMinor*100 + verMicro*1));
200 } else if (s.search(/\@WITH_TRIO\@/) != -1) {
201 of.WriteLine(s.replace(/\@WITH_TRIO\@/, withTrio? "1" : "0"));
202 } else if (s.search(/\@WITH_THREADS\@/) != -1) {
203 of.WriteLine(s.replace(/\@WITH_THREADS\@/, withThreads? "1" : "0"));
204 } else if (s.search(/\@WITH_FTP\@/) != -1) {
205 of.WriteLine(s.replace(/\@WITH_FTP\@/, withFtp? "1" : "0"));
206 } else if (s.search(/\@WITH_HTTP\@/) != -1) {
207 of.WriteLine(s.replace(/\@WITH_HTTP\@/, withHttp? "1" : "0"));
208 } else if (s.search(/\@WITH_HTML\@/) != -1) {
209 of.WriteLine(s.replace(/\@WITH_HTML\@/, withHtml? "1" : "0"));
210 } else if (s.search(/\@WITH_C14N\@/) != -1) {
211 of.WriteLine(s.replace(/\@WITH_C14N\@/, withC14n? "1" : "0"));
212 } else if (s.search(/\@WITH_CATALOG\@/) != -1) {
213 of.WriteLine(s.replace(/\@WITH_CATALOG\@/, withCatalog? "1" : "0"));
214 } else if (s.search(/\@WITH_DOCB\@/) != -1) {
215 of.WriteLine(s.replace(/\@WITH_DOCB\@/, withDocb? "1" : "0"));
216 } else if (s.search(/\@WITH_XPATH\@/) != -1) {
217 of.WriteLine(s.replace(/\@WITH_XPATH\@/, withXpath? "1" : "0"));
218 } else if (s.search(/\@WITH_XPTR\@/) != -1) {
219 of.WriteLine(s.replace(/\@WITH_XPTR\@/, withXptr? "1" : "0"));
220 } else if (s.search(/\@WITH_XINCLUDE\@/) != -1) {
221 of.WriteLine(s.replace(/\@WITH_XINCLUDE\@/, withXinclude? "1" : "0"));
222 } else if (s.search(/\@WITH_ICONV\@/) != -1) {
223 of.WriteLine(s.replace(/\@WITH_ICONV\@/, withIconv? "1" : "0"));
224 } else if (s.search(/\@WITH_DEBUG\@/) != -1) {
225 of.WriteLine(s.replace(/\@WITH_DEBUG\@/, withDebug? "1" : "0"));
226 } else if (s.search(/\@WITH_MEM_DEBUG\@/) != -1) {
227 of.WriteLine(s.replace(/\@WITH_MEM_DEBUG\@/, withMemDebug? "1" : "0"));
228 } else
229 of.WriteLine(ln);
230 }
231 ofi.Close();
232 of.Close();
233 fso.CopyFile(optsFile, optsFile2, true);
234}
235
236/* Creates the readme file for the binary distribution of 'bname', for the
237 version 'ver' in the file 'file'. This one is called from the Makefile when
238 generating a binary distribution. The parameters are passed by make. */
239function genReadme(bname, ver, file)
240{
241 var fso, f;
242 fso = new ActiveXObject("Scripting.FileSystemObject");
243 f = fso.CreateTextFile(file, true);
244 f.WriteLine(" " + bname + " " + ver);
245 f.WriteLine(" --------------");
246 f.WriteBlankLines(1);
247 f.WriteLine(" This is " + bname + ", version " + ver + ", binary package for the native Win32/IA32");
248 f.WriteLine("platform.");
249 f.WriteBlankLines(1);
250 f.WriteLine(" The directory named 'include' contains the header files. Place its");
251 f.WriteLine("contents somewhere where it can be found by the compiler.");
252 f.WriteLine(" The directory which answers to the name 'lib' contains the static and");
253 f.WriteLine("dynamic libraries. Place them somewhere where they can be found by the");
254 f.WriteLine("linker. The files whose names end with '_a.lib' are aimed for static");
255 f.WriteLine("linking, the other files are lib/dll pairs.");
256 f.WriteLine(" The directory called 'util' contains various programs which count as a");
257 f.WriteLine("part of " + bname + ".");
258 f.WriteBlankLines(1);
259 f.WriteLine(" If there is something you cannot keep for yourself, such as a problem,");
260 f.WriteLine("a cheer of joy, a comment or a suggestion, feel free to contact me using");
261 f.WriteLine("the address below.");
262 f.WriteBlankLines(1);
263 f.WriteLine(" Igor Zlatkovic (igor@stud.fh-frankfurt.de)");
264 f.Close();
265}
266
267/*
268 * main(),
269 * Execution begins here.
270 */
271
272// Parse the command-line arguments.
273for (i = 0; (i < WScript.Arguments.length) && (error == 0); i++) {
274 var arg, opt;
275 arg = WScript.Arguments(i);
276 opt = arg.substring(0, arg.indexOf("="));
277 if (opt.length == 0)
278 opt = arg.substring(0, arg.indexOf(":"));
279 if (opt.length > 0) {
280 if (opt == "trio")
281 withTrio = strToBool(arg.substring(opt.length + 1, arg.length));
282 else if (opt == "threads")
283 withThreads = strToBool(arg.substring(opt.length + 1, arg.length));
284 else if (opt == "ftp")
285 withFtp = strToBool(arg.substring(opt.length + 1, arg.length));
286 else if (opt == "http")
287 withHttp = strToBool(arg.substring(opt.length + 1, arg.length));
288 else if (opt == "html")
289 withHtml = strToBool(arg.substring(opt.length + 1, arg.length));
Igor Zlatkovic9425ce22002-04-10 21:57:11 +0000290 else if (opt == "c14n")
291 withC14n = strToBool(arg.substring(opt.length + 1, arg.length));
Igor Zlatkovicac97f6e2002-03-24 21:00:26 +0000292 else if (opt == "catalog")
293 withCatalog = strToBool(arg.substring(opt.length + 1, arg.length));
294 else if (opt == "docb")
295 withDocb = strToBool(arg.substring(opt.length + 1, arg.length));
296 else if (opt == "xpath")
297 withXpath = strToBool(arg.substring(opt.length + 1, arg.length));
298 else if (opt == "xptr")
299 withXptr = strToBool(arg.substring(opt.length + 1, arg.length));
300 else if (opt == "xinclude")
301 withXinclude = strToBool(arg.substring(opt.length + 1, arg.length));
302 else if (opt == "iconv")
303 withIconv = strToBool(arg.substring(opt.length + 1, arg.length));
304 else if (opt == "xml_debug")
305 withDebug = strToBool(arg.substring(opt.length + 1, arg.length));
306 else if (opt == "mem_debug")
307 withMemDebug = strToBool(arg.substring(opt.length + 1, arg.length));
308 else if (opt == "debug")
309 buildDebug = strToBool(arg.substring(opt.length + 1, arg.length));
310 else if (opt == "static")
311 buildStatic = strToBool(arg.substring(opt.length + 1, arg.length));
312 else if (opt == "prefix")
313 buildPrefix = arg.substring(opt.length + 1, arg.length);
314 else if (opt == "incdir")
315 buildIncPrefix = arg.substring(opt.length + 1, arg.length);
316 else if (opt == "bindir")
317 buildBinPrefix = arg.substring(opt.length + 1, arg.length);
318 else if (opt == "libdir")
319 buildLibPrefix = arg.substring(opt.length + 1, arg.length);
320 else if (opt == "sodir")
321 buildSoPrefix = arg.substring(opt.length + 1, arg.length);
322 else if (opt == "incdir")
323 buildIncPrefix = arg.substring(opt.length + 1, arg.length);
324 else if (opt == "include")
325 buildInclude = arg.substring(opt.length + 1, arg.length);
326 else if (opt == "lib")
327 buildLib = arg.substring(opt.length + 1, arg.length);
328 else
329 error = 1;
330 } else if (i == 0) {
331 if (arg == "genreadme") {
332 // This command comes from the Makefile and will not be checked
333 // for errors, because Makefile will always supply right the parameters.
334 genReadme(WScript.Arguments(1), WScript.Arguments(2), WScript.Arguments(3));
335 WScript.Quit(0);
336 } else if (arg == "help") {
337 usage();
338 WScript.Quit(0);
339 }
340 } else
341 error = 1;
342}
343
344// If we fail here, it is because the user supplied an unrecognised argument.
345if (error != 0) {
346 usage();
347 WScript.Quit(error);
348}
349
350// Discover the version.
351discoverVersion();
352if (error != 0) {
353 WScript.Echo("Version discovery failed, aborting.");
354 WScript.Quit(error);
355}
356WScript.Echo(baseName + " version: " + verMajor + "." + verMinor + "." + verMicro);
357
358// Configure libxml.
359configureLibxml();
360if (error != 0) {
361 WScript.Echo("Configuration failed, aborting.");
362 WScript.Quit(error);
363}
364
365// Create the makefile.
366var fso = new ActiveXObject("Scripting.FileSystemObject");
367fso.CopyFile(".\\Makefile.msvc", ".\\Makefile", true);
368WScript.Echo("Created Makefile.");
369
370// Display the final configuration.
371var txtOut = "\nXML processor configuration\n";
372txtOut += "---------------------------\n";
373txtOut += " Trio: " + boolToStr(withTrio) + "\n";
374txtOut += " Thread safety: " + boolToStr(withThreads) + "\n";
375txtOut += " FTP client: " + boolToStr(withFtp) + "\n";
376txtOut += " HTTP client: " + boolToStr(withHttp) + "\n";
377txtOut += " HTML processor: " + boolToStr(withHtml) + "\n";
378txtOut += " C14N support: " + boolToStr(withC14n) + "\n";
379txtOut += " Catalog support: " + boolToStr(withCatalog) + "\n";
380txtOut += " DocBook support: " + boolToStr(withDocb) + "\n";
381txtOut += " XPath support: " + boolToStr(withXpath) + "\n";
382txtOut += " XPointer support: " + boolToStr(withXptr) + "\n";
383txtOut += " XInclude support: " + boolToStr(withXinclude) + "\n";
384txtOut += " ICONV support: " + boolToStr(withIconv) + "\n";
385txtOut += " Debugging module: " + boolToStr(withDebug) + "\n";
386txtOut += " Memory debugging: " + boolToStr(withMemDebug) + "\n";
387txtOut += "\n";
388txtOut += "Win32 build configuration\n";
389txtOut += "-------------------------\n";
390txtOut += " Debug symbols: " + boolToStr(buildDebug) + "\n";
391txtOut += " Static xmllint: " + boolToStr(buildStatic) + "\n";
392txtOut += " Install prefix: " + buildPrefix + "\n";
393txtOut += " Put tools in: " + buildBinPrefix + "\n";
394txtOut += " Put headers in: " + buildIncPrefix + "\n";
395txtOut += "Put static libs in: " + buildLibPrefix + "\n";
396txtOut += "Put shared libs in: " + buildSoPrefix + "\n";
397txtOut += " Include path: " + buildInclude + "\n";
398txtOut += " Lib path: " + buildLib + "\n";
399WScript.Echo(txtOut);
400
401// Done.