--- /dev/null
+/*\r
+ +----------------------------------------------------------------------+\r
+ | PHP Version 5 |\r
+ +----------------------------------------------------------------------+\r
+ | Copyright (c) 1997-2008 The PHP Group |\r
+ +----------------------------------------------------------------------+\r
+ | This source file is subject to version 3.01 of the PHP license, |\r
+ | that is bundled with this package in the file LICENSE, and is |\r
+ | available through the world-wide-web at the following url: |\r
+ | http://www.php.net/license/3_01.txt |\r
+ | If you did not receive a copy of the PHP license and are unable to |\r
+ | obtain it through the world-wide-web, please send a note to |\r
+ | license@php.net so we can mail you a copy immediately. |\r
+ +----------------------------------------------------------------------+\r
+ | Author: Pierre Joye <pierre1@php.net> |\r
+ +----------------------------------------------------------------------+\r
+*/\r
+\r
+/* $Id$ */\r
+// This generates a configure script for win32 build\r
+\r
+var STDOUT = WScript.StdOut;\r
+\r
+var FSO = WScript.CreateObject("Scripting.FileSystemObject");\r
+var C = FSO.CreateTextFile("configure.js", true);\r
+var B = FSO.CreateTextFile("configure.bat", true);\r
+var DSP = false;\r
+re = /\\script/i;\r
+var PHP_DIR=FSO.GetParentFolderName(WScript.ScriptFullName).replace(re,"");\r
+\r
+var modules = "";\r
+var MODULES = WScript.CreateObject("Scripting.Dictionary");\r
+var module_dirs = new Array();\r
+\r
+function ERROR(msg)\r
+{\r
+ STDERR.WriteLine("ERROR: " + msg);\r
+ WScript.Quit(3);\r
+}\r
+\r
+function file_get_contents(filename)\r
+{\r
+ var F = FSO.OpenTextFile(filename, 1);\r
+ var t = F.ReadAll();\r
+ F.Close();\r
+ return t;\r
+}\r
+\r
+function Module_Item(module_name, config_path, dir_line, deps, content)\r
+{\r
+ this.module_name = module_name;\r
+ this.config_path = config_path;\r
+ this.dir_line = dir_line;\r
+ this.deps = deps;\r
+ this.content = content;\r
+}\r
+\r
+function get_module_dep(contents)\r
+{\r
+ var re_dep_line = new RegExp("ADD_EXTENSION_DEP\\([^,]*\\s*,\\s*['\"]([^'\"]+)['\"].*\\)", "gm");\r
+ var calls = contents.match(re_dep_line);\r
+ var deps = new Array();\r
+ if (calls != null) {\r
+ for (i = 0; i < calls.length; i++) {\r
+ // now we need the extension name out of this thing\r
+ if (calls[i].match(re_dep_line)) {\r
+ deps[deps.length] = RegExp.$1;\r
+\r
+ }\r
+ }\r
+ }\r
+ return deps;\r
+}\r
+\r
+function find_config_w32(dirname)\r
+{\r
+ if (!FSO.FolderExists(dirname)) {\r
+ return;\r
+ }\r
+\r
+ var f = FSO.GetFolder(dirname);\r
+ var fc = new Enumerator(f.SubFolders);\r
+ var c, i, ok, n;\r
+ var item = null;\r
+\r
+ c = dirname + "\\config.w32";\r
+ if (FSO.FileExists(c)) {\r
+ var dir_line = "configure_module_dirname = condense_path(FSO.GetParentFolderName('"\r
+ + c.replace(new RegExp('(["\\\\])', "g"), '\\$1') + "'));\r\n";\r
+ var contents = file_get_contents(c);\r
+\r
+ deps = get_module_dep(contents);\r
+\r
+ item = new Module_Item(n, c, dir_line, deps, contents);\r
+ MODULES.Add(n, item);\r
+ }\r
+\r
+ for (; !fc.atEnd(); fc.moveNext()) {\r
+ /* check if we already picked up a module with the same dirname;\r
+ * if we have, don't include it here */\r
+ n = FSO.GetFileName(fc.item());\r
+ if (n == '.svn' || n == 'tests' || n == '.git') {\r
+ continue;\r
+ }\r
+\r
+ c = FSO.BuildPath(fc.item(), "config.w32");\r
+ if (FSO.FileExists(c)) {\r
+ var dir_line = "configure_module_dirname = condense_path(FSO.GetParentFolderName('"\r
+ + c.replace(new RegExp('(["\\\\])', "g"), '\\$1') + "'));\r\n";\r
+ var contents = file_get_contents(c);\r
+\r
+ deps = get_module_dep(contents);\r
+\r
+ item = new Module_Item(n, c, dir_line, deps, contents);\r
+ MODULES.Add(n, item);\r
+ }\r
+ }\r
+}\r
+\r
+function emit_module(item)\r
+{\r
+ return item.dir_line + item.content;\r
+}\r
+\r
+function emit_dep_modules(module_names)\r
+{\r
+ var i, mod_name, j;\r
+ var output = "";\r
+ var item = null;\r
+\r
+ for (i in module_names) {\r
+ mod_name = module_names[i];\r
+\r
+ if (MODULES.Exists(mod_name)) {\r
+ item = MODULES.Item(mod_name);\r
+ MODULES.Remove(mod_name);\r
+ if (item.deps.length) {\r
+ output += emit_dep_modules(item.deps);\r
+ }\r
+ output += emit_module(item);\r
+ }\r
+ }\r
+\r
+ return output;\r
+}\r
+\r
+function gen_modules()\r
+{\r
+ var module_names = (new VBArray(MODULES.Keys())).toArray();\r
+ var i, mod_name, j;\r
+ var item;\r
+ var output = "";\r
+\r
+ // first, look for modules with empty deps; emit those first\r
+ for (i in module_names) {\r
+ STDOUT.WriteLine("module ... " + module_names);\r
+ mod_name = module_names[i];\r
+ item = MODULES.Item(mod_name);\r
+ if (item.deps.length == 0) {\r
+ MODULES.Remove(mod_name);\r
+ output += emit_module(item);\r
+ }\r
+ }\r
+\r
+ // now we are left with modules that have dependencies on other modules\r
+ module_names = (new VBArray(MODULES.Keys())).toArray();\r
+ output += emit_dep_modules(module_names);\r
+\r
+ return output;\r
+}\r
+\r
+// Process buildconf arguments\r
+function buildconf_process_args()\r
+{\r
+ args = WScript.Arguments;\r
+\r
+ for (i = 0; i < args.length; i++) {\r
+ arg = args(i);\r
+ // If it is --foo=bar, split on the equals sign\r
+ arg = arg.split("=", 2);\r
+ argname = arg[0];\r
+ if (arg.length > 1) {\r
+ argval = arg[1];\r
+ } else {\r
+ argval = null;\r
+ }\r
+\r
+ if (argname == '--clean' && argval != null) {\r
+ STDOUT.WriteLine("Cleaning...");\r
+ return 0;\r
+ }\r
+\r
+ if (argname == '--help') {\r
+ STDOUT.WriteLine("Usage: phpize [--clean|--help|--version|-v]");\r
+ return 0;\r
+ }\r
+ return 1;\r
+ }\r
+}\r
+\r
+if (buildconf_process_args() == 0) {\r
+ WScript.Quit(3);\r
+}\r
+STDOUT.WriteLine("Rebuilding configure.js");\r
+STDOUT.WriteLine(PHP_DIR);\r
+\r
+// Write the head of the configure script\r
+C.WriteLine("/* This file automatically generated from script/confutils.js */");\r
+C.WriteLine("var MODE_PHPIZE = true;");\r
+C.WriteLine("var PHP_DIR = " + '"' + PHP_DIR.replace(new RegExp('(["\\\\])', "g"), '\\$1') + '"');\r
+\r
+C.Write(file_get_contents(PHP_DIR + "/script/confutils.js"));\r
+C.Write(file_get_contents(PHP_DIR + "/script/config.phpize.js"));\r
+\r
+// If project files were requested, pull in the code to generate them\r
+if (DSP == true) {\r
+ C.WriteLine('PHP_DSP="yes"');\r
+ C.WriteBlankLines(1);\r
+ C.Write(file_get_contents(PHP_DIR + "win32/build/projectgen.js"));\r
+} else {\r
+ C.WriteLine('PHP_DSP="no"');\r
+ C.WriteBlankLines(1);\r
+}\r
+\r
+// Pull in code from sapi and extensions\r
+modules = file_get_contents(PHP_DIR + "/script/config.w32.phpize.in");\r
+\r
+C.WriteLine("ARG_ENABLE('debug', 'Compile with debugging symbols', \"no\");");\r
+find_config_w32(".");\r
+\r
+// Now generate contents of module based on MODULES, chasing dependencies\r
+// to ensure that dependent modules are emitted first\r
+modules += gen_modules();\r
+\r
+// Look for ARG_ENABLE or ARG_WITH calls\r
+re = new RegExp("(ARG_(ENABLE|WITH)\([^;]+\);)", "gm");\r
+calls = modules.match(re);\r
+for (i = 0; i < calls.length; i++) {\r
+ item = calls[i];\r
+ C.WriteLine("try {");\r
+ C.WriteLine(item);\r
+ C.WriteLine("} catch (e) {");\r
+ C.WriteLine('\tSTDOUT.WriteLine("problem: " + e);');\r
+ C.WriteLine("}");\r
+}\r
+\r
+C.WriteBlankLines(1);\r
+C.WriteLine("conf_process_args();");\r
+C.WriteBlankLines(1);\r
+\r
+C.Write(file_get_contents(PHP_DIR + "/script/config.w32.phpize.in"));\r
+\r
+// Comment out the calls from their original positions\r
+modules = modules.replace(re, "/* $1 */");\r
+C.Write(modules);\r
+\r
+\r
+C.WriteBlankLines(1);\r
+C.Write(file_get_contents(PHP_DIR + "\\script\\configure.tail"));\r
+\r
+B.WriteLine("@echo off");\r
+B.WriteLine("cscript /nologo configure.js %*");\r