Git init
[external/xmlsec1.git] / win32 / configure.js
1 /* Configure script for xmlsec, specific for Windows with Scripting Host.
2  * 
3  * This script will configure the libxmlsec 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  *      Created for LibXML and LibXSLT
9  * April 2002, Aleksey Sanin <aleksey@aleksey.com>
10  *      Modified for XMLSec Libary
11  */
12
13 /* The source directory, relative to the one where this file resides. */
14 var baseDir = "..";
15 var srcDir = baseDir + "\\src";
16 var srcDirApps = baseDir + "\\apps";
17 /* The directory where we put the binaries after compilation. */
18 var binDir = "binaries";
19 /* Base name of what we are building. */
20 var baseName = "libxmlsec";
21
22 /* Configure file which contains the version and the output file where
23    we can store our build configuration. */
24 var configFile = baseDir + "\\configure.in";
25 var versionFile = ".\\configure.txt";
26
27 /* Input and output files regarding the lib(e)xml features. The second
28    output file is there for the compatibility reasons, otherwise it
29    is identical to the first. */
30 var optsFileIn = baseDir + "\\config.h.in";
31 var optsFile = baseDir + "\\config.h";
32
33 /* Version strings for the binary distribution. Will be filled later 
34    in the code. */
35 var verMajorXmlSec;
36 var verMinorXmlSec;
37 var verMicroXmlSec;
38
39 /* Libxmlsec features. */
40 var withCrypto = "openssl";
41 var withDefaultCrypto = "openssl";
42 var withOpenSSL = 0;
43 var withOpenSSLVersion = "";
44 var withNss = 0;
45 var withMSCrypto = 0;
46 var withLibXSLT = 1;
47 var withIconv = 1;
48 var withNT4 = 0;
49
50 /* Win32 build options. */
51 var buildDebug = 0;
52 var buildStatic = 1;
53 var buildWithDLSupport = 1;
54 var buildPrefix = ".";
55 var buildBinPrefix = "$(PREFIX)\\bin";
56 var buildIncPrefix = "$(PREFIX)\\include";
57 var buildLibPrefix = "$(PREFIX)\\lib";
58 var buildSoPrefix = "$(PREFIX)\\lib";
59 var buildInclude = ".";
60 var buildLib = ".";
61 /* Local stuff */
62 var error = 0;
63
64 /* Helper function, transforms the option variable into the 'Enabled'
65    or 'Disabled' string. */
66 function boolToStr(opt)
67 {
68         if (opt == false)
69                 return "Disabled";
70         else if (opt == true)
71                 return "Enabled";
72         error = 1;
73         return "Undefined";
74 }
75
76 /* Helper function, transforms the argument string into the boolean
77    value. */
78 function strToBool(opt)
79 {
80         if (opt == "0" || opt == "no")
81                 return false;
82         else if (opt == "1" || opt == "yes")
83                 return true;
84         error = 1;
85         return false;
86 }
87
88 /* Displays the details about how to use this script. */
89 function usage()
90 {
91         var txt;
92         txt = "Usage:\n";
93         txt += "  cscript " + WScript.ScriptName + " <options>\n";
94         txt += "  cscript " + WScript.ScriptName + " help\n\n";
95         txt += "Options can be specified in the form <option>=<value>, where the value is\n";
96         txt += "either 'yes' or 'no'.\n\n";
97         txt += "XmlSec Library options, default value given in parentheses:\n\n";
98         txt += "  crypto:     Crypto engines list, first is default: \"openssl\",\n";
99         txt += "              \"openssl=096\", \"openssl=097\", \"openssl=098\", \n";
100         txt += "              \"nss\", \"mscrypto\" (\"" + withCrypto + "\");\n"
101         txt += "  xslt:       LibXSLT is used (" + (withLibXSLT? "yes" : "no")  + ")\n";        
102         txt += "  iconv:      Use the iconv library (" + (withIconv? "yes" : "no")  + ")\n";    
103         txt += "  nt4:        Enable NT 4.0 support (" + (withNT4? "yes" : "no")  + ")\n";      
104         txt += "\nWin32 build options, default value given in parentheses:\n\n";
105         txt += "  debug:      Build unoptimised debug executables (" + (buildDebug? "yes" : "no")  + ")\n";
106         txt += "  static:     Link libxmlsec statically to xmlsec (" + (buildStatic? "yes" : "no")  + ")\n";
107         txt += "  with-dl:    Enable dynamic loading of xmlsec-crypto libraries (" + (buildWithDLSupport? "yes" : "no")  + ")\n";
108         txt += "  prefix:     Base directory for the installation (" + buildPrefix + ")\n";
109         txt += "  bindir:     Directory where xmlsec and friends should be installed\n";
110         txt += "              (" + buildBinPrefix + ")\n";
111         txt += "  incdir:     Directory where headers should be installed\n";
112         txt += "              (" + buildIncPrefix + ")\n";
113         txt += "  libdir:     Directory where static and import libraries should be\n";
114         txt += "              installed (" + buildLibPrefix + ")\n";
115         txt += "  sodir:      Directory where shared libraries should be installed\n"; 
116         txt += "              (" + buildSoPrefix + ")\n";
117         txt += "  include:    Additional search path for the compiler, particularily\n";
118         txt += "              where libxml headers can be found (" + buildInclude + ")\n";
119         txt += "  lib:        Additional search path for the linker, particularily\n";
120         txt += "              where libxml library can be found (" + buildLib + ")\n";
121         WScript.Echo(txt);
122 }
123
124 /* Discovers the version we are working with by reading the apropriate
125    configuration file. Despite its name, this also writes the configuration
126    file included by our makefile. */
127 function discoverVersion()
128 {
129         var fso, cf, vf, ln, s;
130
131         fso = new ActiveXObject("Scripting.FileSystemObject");
132         cf = fso.OpenTextFile(configFile, 1);
133         vf = fso.CreateTextFile(versionFile, true);
134         vf.WriteLine("# " + versionFile);
135         vf.WriteLine("# This file is generated automatically by " + WScript.ScriptName + ".");
136         vf.WriteBlankLines(1);
137         while (cf.AtEndOfStream != true) {
138                 ln = cf.ReadLine();
139                 s = new String(ln);
140                 if (s.search(/^XMLSEC_VERSION_MAJOR/) != -1) {
141                         WScript.Echo(verMajorXmlSec);
142                         vf.WriteLine(s);
143                         verMajorXmlSec = s.substring(s.indexOf("=") + 1, s.length)
144                 } else if(s.search(/^XMLSEC_VERSION_MINOR/) != -1) {
145                         vf.WriteLine(s);
146                         verMinorXmlSec = s.substring(s.indexOf("=") + 1, s.length)
147                 } else if(s.search(/^XMLSEC_VERSION_SUBMINOR/) != -1) {
148                         vf.WriteLine(s);
149                         verMicroXmlSec = s.substring(s.indexOf("=") + 1, s.length)
150                 }               
151         }
152         cf.Close();
153         vf.WriteLine("BASEDIR=" + baseDir);
154         vf.WriteLine("XMLSEC_SRCDIR=" + srcDir);
155         vf.WriteLine("APPS_SRCDIR=" + srcDirApps);
156         vf.WriteLine("BINDIR=" + binDir);
157         vf.WriteLine("WITH_CRYPTO=" + withCrypto);      
158         vf.WriteLine("WITH_DEFAULT_CRYPTO=" + withDefaultCrypto);       
159         vf.WriteLine("WITH_OPENSSL=" + withOpenSSL);    
160         vf.WriteLine("WITH_OPENSSL_VERSION=" + withOpenSSLVersion);     
161         vf.WriteLine("WITH_NSS=" + withNss);    
162         vf.WriteLine("WITH_MSCRYPTO=" + withMSCrypto);  
163         vf.WriteLine("WITH_LIBXSLT=" + (withLibXSLT ? "1" : "0"));
164         vf.WriteLine("WITH_ICONV=" + (withIconv ? "1" : "0"));
165         vf.WriteLine("WITH_NT4=" + (withNT4 ? "1" : "0"));
166         vf.WriteLine("DEBUG=" + (buildDebug? "1" : "0"));
167         vf.WriteLine("STATIC=" + (buildStatic? "1" : "0"));
168         vf.WriteLine("WITH_DL=" + (buildWithDLSupport ? "1" : "0"));
169         vf.WriteLine("PREFIX=" + buildPrefix);
170         vf.WriteLine("BINPREFIX=" + buildBinPrefix);
171         vf.WriteLine("INCPREFIX=" + buildIncPrefix);
172         vf.WriteLine("LIBPREFIX=" + buildLibPrefix);
173         vf.WriteLine("SOPREFIX=" + buildSoPrefix);
174         vf.WriteLine("INCLUDE=$(INCLUDE);" + buildInclude);
175         vf.WriteLine("LIB=$(LIB);" + buildLib);
176         vf.Close();
177 }
178
179 /* Configures xmlsec. This one will generate config.h from config.h.in
180    taking what the user passed on the command line into account. */
181 function configureXmlSec()
182 {
183         var fso, ofi, of, ln, s;
184         fso = new ActiveXObject("Scripting.FileSystemObject");
185         ofi = fso.OpenTextFile(optsFileIn, 1);
186         of = fso.CreateTextFile(optsFile, true);
187         while (ofi.AtEndOfStream != true) {
188                 ln = ofi.ReadLine();
189                 s = new String(ln);
190                 if (s.search(/\@VERSION\@/) != -1) {
191                         of.WriteLine(s.replace(/\@VERSION\@/, 
192                                 verMajorXmlSec + "." + verMinorXmlSec + "." + verMicroXmlSec));
193                 } else if (s.search(/\@XMLSECVERSION_NUMBER\@/) != -1) {
194                         of.WriteLine(s.replace(/\@XMLSECVERSION_NUMBER\@/, 
195                                 verMajorXmlSec*10000 + verMinorXmlSec*100 + verMicroXmlSec*1));
196                 } else
197                         of.WriteLine(ln);
198         }
199         ofi.Close();
200         of.Close();
201 }
202
203 /* Creates the readme file for the binary distribution of 'bname', for the
204    version 'ver' in the file 'file'. This one is called from the Makefile when
205    generating a binary distribution. The parameters are passed by make. */
206 function genReadme(bname, ver, file)
207 {
208         var fso, f;
209         fso = new ActiveXObject("Scripting.FileSystemObject");
210         f = fso.CreateTextFile(file, true);
211         f.WriteLine("  " + bname + " " + ver);
212         f.WriteLine("  --------------");
213         f.WriteBlankLines(1);
214         f.WriteLine("  This is " + bname + ", version " + ver + ", binary package for the native Win32/IA32");
215         f.WriteLine("platform.");
216         f.WriteBlankLines(1);
217         f.WriteLine("  The files in this package do not require any special installation");
218         f.WriteLine("steps. Extract the contents of the archive whereever you wish and");
219         f.WriteLine("make sure that your tools which use " + bname + " can find it.");
220         f.WriteBlankLines(1);
221         f.WriteLine("  For example, if you want to run the supplied utilities from the command");
222         f.WriteLine("line, you can, if you wish, add the 'bin' subdirectory to the PATH");
223         f.WriteLine("environment variable.");
224         f.WriteLine("  If you want to make programmes in C which use " + bname + ", you'll");
225         f.WriteLine("likely know how to use the contents of this package. If you don't, please");
226         f.WriteLine("refer to your compiler's documentation."); 
227         f.WriteBlankLines(1);
228         f.WriteLine("  If there is something you cannot keep for yourself, such as a problem,");
229         f.WriteLine("a cheer of joy, a comment or a suggestion, feel free to contact me using");
230         f.WriteLine("the address below.");
231         f.WriteBlankLines(1);
232         f.WriteLine("Igor Zlatkovic (igor@zlatkovic.com)");
233         f.Close();
234 }
235
236 /*
237  * main(),
238  * Execution begins here.
239  */
240
241 /* Parse the command-line arguments. */
242 for (i = 0; (i < WScript.Arguments.length) && (error == 0); i++) {
243         var arg, opt;
244         arg = WScript.Arguments(i);
245         opt = arg.substring(0, arg.indexOf("="));
246         if (opt.length == 0)
247                 opt = arg.substring(0, arg.indexOf(":"));
248         if (opt.length > 0) {
249                 if (opt == "crypto")
250                         withCrypto = arg.substring(opt.length + 1, arg.length);
251                 else if (opt == "xslt")
252                         withLibXSLT = strToBool(arg.substring(opt.length + 1, arg.length));
253                 else if (opt == "iconv")
254                         withIconv = strToBool(arg.substring(opt.length + 1, arg.length));
255                 else if (opt == "nt4")
256                         withNT4 = strToBool(arg.substring(opt.length + 1, arg.length));
257                 else if (opt == "debug")
258                         buildDebug = strToBool(arg.substring(opt.length + 1, arg.length));
259                 else if (opt == "static")
260                         buildStatic = strToBool(arg.substring(opt.length + 1, arg.length));
261                 else if (opt == "with-dl")
262                         buildWithDLSupport = strToBool(arg.substring(opt.length + 1, arg.length));
263                 else if (opt == "prefix")
264                         buildPrefix = arg.substring(opt.length + 1, arg.length);
265                 else if (opt == "incdir")
266                         buildIncPrefix = arg.substring(opt.length + 1, arg.length);
267                 else if (opt == "bindir")
268                         buildBinPrefix = arg.substring(opt.length + 1, arg.length);
269                 else if (opt == "libdir")
270                         buildLibPrefix = arg.substring(opt.length + 1, arg.length);
271                 else if (opt == "sodir")
272                         buildSoPrefix = arg.substring(opt.length + 1, arg.length);
273                 else if (opt == "incdir")
274                         buildIncPrefix = arg.substring(opt.length + 1, arg.length);
275                 else if (opt == "include")
276                         buildInclude = arg.substring(opt.length + 1, arg.length);
277                 else if (opt == "lib")
278                         buildLib = arg.substring(opt.length + 1, arg.length);
279                 else
280                         error = 1;
281         } else if (i == 0) {
282                 if (arg == "genreadme") {
283                         // This command comes from the Makefile and will not be checked
284                         // for errors, because Makefile will always supply right parameters.
285                         genReadme(WScript.Arguments(1), WScript.Arguments(2), WScript.Arguments(3));
286                         WScript.Quit(0);
287                 } else if (arg == "help") {
288                         usage();
289                         WScript.Quit(0);
290                 }
291         } else
292                 error = 1;
293 }
294 // If we have an error here, it is because the user supplied bad parameters.
295 if (error != 0) {
296         usage();
297         WScript.Quit(error);
298 }
299
300 // Discover crypto support
301 var crlist, j, curcrypto;
302 crlist = withCrypto.split(",");                 
303 withCrypto = "";
304 withDefaultCrypto = "";
305 for (j = 0; j < crlist.length; j++) {           
306         if (crlist[j] == "openssl") {
307                 curcrypto="openssl";
308                 withOpenSSL = 1;
309                 withOpenSSLVersion = "XMLSEC_OPENSSL_098"; /* default */
310         } else if (crlist[j] == "openssl=096") {
311                 curcrypto="openssl";
312                 withOpenSSL = 1;
313                 withOpenSSLVersion = "XMLSEC_OPENSSL_096";
314         } else if (crlist[j] == "openssl=097") {
315                 curcrypto="openssl";
316                 withOpenSSL = 1;
317                 withOpenSSLVersion = "XMLSEC_OPENSSL_097";
318         } else if (crlist[j] == "openssl=098") {
319                 curcrypto="openssl";
320                 withOpenSSL = 1;
321                 withOpenSSLVersion = "XMLSEC_OPENSSL_098";
322         } else if (crlist[j] == "nss") {
323                 curcrypto="nss";
324                 withNss = 1;
325         } else if (crlist[j] == "mscrypto") {
326                 curcrypto="mscrypto";
327                 withMSCrypto = 1;
328         } else {
329                 WScript.Echo("Unknown crypto engine \"" + crlist[j] + "\" is found. Aborting.");
330                 WScript.Quit(error);
331         }
332         if (j == 0) {
333                 withDefaultCrypto = curcrypto;
334                 withCrypto = curcrypto;
335         } else {
336                 withCrypto = withCrypto + " " + curcrypto;
337         }
338 }
339
340 // Discover the version.
341 discoverVersion();
342 if (error != 0) {
343         WScript.Echo("Version discovery failed, aborting.");
344         WScript.Quit(error);
345 }
346 WScript.Echo(baseName + " version: " + verMajorXmlSec + "." + verMinorXmlSec + "." + verMicroXmlSec);
347
348
349 // Configure libxmlsec.
350 configureXmlSec();
351 if (error != 0) {
352         WScript.Echo("Configuration failed, aborting.");
353         WScript.Quit(error);
354 }
355
356
357 // Create the Makefile.
358 var fso = new ActiveXObject("Scripting.FileSystemObject");
359 fso.CopyFile(".\\Makefile.msvc", ".\\Makefile", true);
360 WScript.Echo("Created Makefile.");
361
362 // Display the final configuration.
363 var txtOut = "\nXMLSEC configuration\n";
364 txtOut += "----------------------------\n";
365 txtOut += "         Use Crypto: " + withCrypto + "\n";
366 txtOut += " Use Default Crypto: " + withDefaultCrypto + "\n";
367 txtOut += "       Use OpenSSL: " + boolToStr(withOpenSSL) + "\n";
368 txtOut += "Use OpenSSL Version: " + boolToStr(withOpenSSLVersion) + "\n";
369 txtOut += "            Use NSS: " + boolToStr(withNss) + "\n";
370 txtOut += "       Use MSCrypto: " + boolToStr(withMSCrypto) + "\n";
371 txtOut += "        Use LibXSLT: " + boolToStr(withLibXSLT) + "\n";
372 txtOut += "          Use iconv: " + boolToStr(withIconv) + "\n";
373 txtOut += "     NT 4.0 support: " + boolToStr(withNT4) + "\n";
374 txtOut += "\n";
375 txtOut += "Win32 build configuration\n";
376 txtOut += "-------------------------\n";
377 txtOut += "     Debug symbols: " + boolToStr(buildDebug) + "\n";
378 txtOut += "     Static xmlsec: " + boolToStr(buildStatic) + "\n";
379 txtOut += "  Enable DL suport: " + boolToStr(buildWithDLSupport) + "\n";
380 txtOut += "    Install prefix: " + buildPrefix + "\n";
381 txtOut += "      Put tools in: " + buildBinPrefix + "\n";
382 txtOut += "    Put headers in: " + buildIncPrefix + "\n";
383 txtOut += "Put static libs in: " + buildLibPrefix + "\n";
384 txtOut += "Put shared libs in: " + buildSoPrefix + "\n";
385 txtOut += "      Include path: " + buildInclude + "\n";
386 txtOut += "          Lib path: " + buildLib + "\n";
387 WScript.Echo(txtOut);
388
389 // Done.