# HG changeset patch
# User Chun-wei Fan <fanchunwei@src.gnome.org>
# Date 1646815546 -28800
#      Wed Mar 09 16:45:46 2022 +0800
# Node ID ae4cd162620c1a65830400c95d75d6aac024111f
# Parent  aa334823ebd6ee42e08a9b41eea557ba4fa04543
win32/configure.js: Support building Python bindings

Add the python=yes option so that one can build the Python bindings.  This will
configure python/setup.py, which one can use to build and package the bindings
via distutils.

diff --git a/win32/configure.js b/win32/configure.js
--- a/win32/configure.js
+++ b/win32/configure.js
@@ -48,6 +48,7 @@
 var withCrypto = true;
 var withModules = false;
 var withProfiler = true;
+var withPython = false;
 /* Win32 build options. */
 var dirSep = "\\";
 var compiler = "msvc";
@@ -108,6 +109,7 @@
 	txt += "  crypto:     Enable Crypto support (" + (withCrypto? "yes" : "no") + ")\n";
 	txt += "  modules:    Enable Module support (" + (withModules? "yes" : "no") + ")\n";
 	txt += "  profiler:   Enable Profiler support (" + (withProfiler? "yes" : "no") + ")\n";
+	txt += "  python:     Build Python bindings (" + (withPython? "yes" : "no")  + ")\n";
 	txt += "\nWin32 build options, default value given in parentheses:\n\n";
 	txt += "  compiler:   Compiler to be used [msvc|mingw] (" + compiler + ")\n";
 	txt += "  cruntime:   C-runtime compiler option (only msvc) (" + cruntime + ")\n";
@@ -181,6 +183,7 @@
 	vf.WriteLine("WITH_CRYPTO=" + (withCrypto? "1" : "0"));
 	vf.WriteLine("WITH_MODULES=" + (withModules? "1" : "0"));
 	vf.WriteLine("WITH_PROFILER=" + (withProfiler? "1" : "0"));
+	vf.WriteLine("WITH_PYTHON=" + (withPython? "1" : "0"));
 	vf.WriteLine("DEBUG=" + (buildDebug? "1" : "0"));
 	vf.WriteLine("STATIC=" + (buildStatic? "1" : "0"));
 	vf.WriteLine("PREFIX=" + buildPrefix);
@@ -270,6 +273,49 @@
 	of.Close();
 }
 
+/* Configures Python bindings. Otherwise identical to the above */
+function configureLibxsltPy()
+{
+	var pyOptsFileIn = baseDir + "\\python\\setup.py.in";
+	var pyOptsFile = baseDir + "\\python\\setup.py";
+	var fso, ofi, of, ln, s;
+	fso = new ActiveXObject("Scripting.FileSystemObject");
+	ofi = fso.OpenTextFile(pyOptsFileIn, 1);
+	of = fso.CreateTextFile(pyOptsFile, true);
+	while (ofi.AtEndOfStream != true) {
+		ln = ofi.ReadLine();
+		s = new String(ln);
+		if (s.search(/\@VERSION\@/) != -1) {
+			of.WriteLine(s.replace(/\@VERSION\@/, 
+				verMajorXslt + "." + verMinorXslt + "." + verMicroXslt));
+		} else if (s.search(/\@prefix\@/) != -1) {
+			of.WriteLine(s.replace(/\@prefix\@/, buildPrefix));
+		} else if (s.search(/\@LIBXSLT_VERSION_NUMBER\@/) != -1) {
+			of.WriteLine(s.replace(/\@LIBXSLT_VERSION_NUMBER\@/, 
+				verMajorXslt*10000 + verMinorXslt*100 + verMicroXslt*1));
+		} else if (s.search(/\@LIBXSLT_VERSION_EXTRA\@/) != -1) {
+			of.WriteLine(s.replace(/\@LIBXSLT_VERSION_EXTRA\@/, verCvs));
+		} else if (s.search(/\@WITH_TRIO\@/) != -1) {
+			of.WriteLine(s.replace(/\@WITH_TRIO\@/, withTrio? "1" : "0"));
+		} else if (s.search(/\@WITH_XSLT_DEBUG\@/) != -1) {
+			of.WriteLine(s.replace(/\@WITH_XSLT_DEBUG\@/, withXsltDebug? "1" : "0"));
+		} else if (s.search(/\@WITH_MEM_DEBUG\@/) != -1) {
+			of.WriteLine(s.replace(/\@WITH_MEM_DEBUG\@/, withMemDebug? "1" : "0"));
+		} else if (s.search(/\@WITH_DEBUGGER\@/) != -1) {
+			of.WriteLine(s.replace(/\@WITH_DEBUGGER\@/, withDebugger? "1" : "0"));
+		} else if (s.search(/\@WITH_MODULES\@/) != -1) {
+			of.WriteLine(s.replace(/\@WITH_MODULES\@/, withModules? "1" : "0"));
+		} else if (s.search(/\@WITH_PROFILER\@/) != -1) {
+			of.WriteLine(s.replace(/\@WITH_PROFILER\@/, withProfiler? "1" : "0"));
+		} else if (s.search(/\@LIBXSLT_DEFAULT_PLUGINS_PATH\@/) != -1) {
+			of.WriteLine(s.replace(/\@LIBXSLT_DEFAULT_PLUGINS_PATH\@/, "NULL"));
+		} else
+			of.WriteLine(ln);
+	}
+	ofi.Close();
+	of.Close();
+}
+
 /* Creates the readme file for the binary distribution of 'bname', for the
    version 'ver' in the file 'file'. This one is called from the Makefile when
    generating a binary distribution. The parameters are passed by make. */
@@ -336,6 +382,8 @@
 			withModules = strToBool(arg.substring(opt.length + 1, arg.length));
 		else if (opt == "profiler")
 			withProfiler = strToBool(arg.substring(opt.length + 1, arg.length));
+		else if (opt == "python")
+			withPython = strToBool(arg.substring(opt.length + 1, arg.length));
 		else if (opt == "compiler")
 			compiler = arg.substring(opt.length + 1, arg.length);
  		else if (opt == "cruntime")
@@ -432,6 +480,15 @@
 	WScript.Quit(error);
 }
 
+if (withPython == true) {
+	configureLibxsltPy();
+	if (error != 0) {
+		WScript.Echo("Configuration failed, aborting.");
+		WScript.Quit(error);
+	}
+
+}
+
 // Configure libexslt.
 configureExslt();
 if (error != 0) {
@@ -469,6 +526,7 @@
 txtOut += "            Crypto: " + boolToStr(withCrypto) + "\n";
 txtOut += "           Modules: " + boolToStr(withModules) + "\n";
 txtOut += "          Profiler: " + boolToStr(withProfiler) + "\n";
+txtOut += "   Python bindings: " + boolToStr(withPython) + "\n";
 txtOut += "\n";
 txtOut += "Win32 build configuration\n";
 txtOut += "-------------------------\n";