1/* 2 +----------------------------------------------------------------------+ 3 | PHP Version 7 | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) The PHP Group | 6 +----------------------------------------------------------------------+ 7 | This source file is subject to version 3.01 of the PHP license, | 8 | that is bundled with this package in the file LICENSE, and is | 9 | available through the world-wide-web at the following url: | 10 | http://www.php.net/license/3_01.txt | 11 | If you did not receive a copy of the PHP license and are unable to | 12 | obtain it through the world-wide-web, please send a note to | 13 | license@php.net so we can mail you a copy immediately. | 14 +----------------------------------------------------------------------+ 15 | Author: Pierre Joye <pierre1@php.net> | 16 +----------------------------------------------------------------------+ 17*/ 18 19// This generates a configure script for win32 build 20 21var STDOUT = WScript.StdOut; 22 23var FSO = WScript.CreateObject("Scripting.FileSystemObject"); 24var C = FSO.CreateTextFile("configure.js", true); 25var B = FSO.CreateTextFile("configure.bat", true); 26re = /\\script/i; 27var PHP_DIR=FSO.GetParentFolderName(WScript.ScriptFullName).replace(re,""); 28 29var modules = ""; 30var MODULES = WScript.CreateObject("Scripting.Dictionary"); 31var module_dirs = new Array(); 32 33function ERROR(msg) 34{ 35 STDERR.WriteLine("ERROR: " + msg); 36 WScript.Quit(3); 37} 38 39function file_get_contents(filename) 40{ 41 var t = ""; 42 var F = FSO.OpenTextFile(filename, 1); 43 44 if (!F.AtEndOfStream) { 45 t = F.ReadAll(); 46 F.Close(); 47 } 48 return t; 49} 50 51function Module_Item(module_name, config_path, dir_line, deps, content) 52{ 53 this.module_name = module_name; 54 this.config_path = config_path; 55 this.dir_line = dir_line; 56 this.deps = deps; 57 this.content = content; 58} 59 60function get_module_dep(contents) 61{ 62 var re_dep_line = new RegExp("ADD_EXTENSION_DEP\\([^,]*\\s*,\\s*['\"]([^'\"]+)['\"].*\\)", "gm"); 63 var calls = contents.match(re_dep_line); 64 var deps = new Array(); 65 if (calls != null) { 66 for (i = 0; i < calls.length; i++) { 67 // now we need the extension name out of this thing 68 if (calls[i].match(re_dep_line)) { 69 deps[deps.length] = RegExp.$1; 70 71 } 72 } 73 } 74 return deps; 75} 76 77function find_config_w32(dirname) 78{ 79 if (!FSO.FolderExists(dirname)) { 80 return; 81 } 82 83 var f = FSO.GetFolder(dirname); 84 var fc = new Enumerator(f.SubFolders); 85 var c, i, ok, n; 86 var item = null; 87 88 c = dirname + "\\config.w32"; 89 if (FSO.FileExists(c)) { 90 var dir_line = "configure_module_dirname = condense_path(FSO.GetParentFolderName('" 91 + c.replace(new RegExp('(["\\\\])', "g"), '\\$1') + "'));\r\n"; 92 var contents = file_get_contents(c); 93 94 deps = get_module_dep(contents); 95 96 item = new Module_Item(n, c, dir_line, deps, contents); 97 MODULES.Add(n, item); 98 } 99 100 for (; !fc.atEnd(); fc.moveNext()) { 101 /* check if we already picked up a module with the same dirname; 102 * if we have, don't include it here */ 103 n = FSO.GetFileName(fc.item()); 104 if (n == '.svn' || n == 'tests' || n == '.git') { 105 continue; 106 } 107 108 c = FSO.BuildPath(fc.item(), "config.w32"); 109 if (FSO.FileExists(c)) { 110 var dir_line = "configure_module_dirname = condense_path(FSO.GetParentFolderName('" 111 + c.replace(new RegExp('(["\\\\])', "g"), '\\$1') + "'));\r\n"; 112 var contents = file_get_contents(c); 113 114 deps = get_module_dep(contents); 115 116 item = new Module_Item(n, c, dir_line, deps, contents); 117 MODULES.Add(n, item); 118 } 119 } 120} 121 122function emit_module(item) 123{ 124 return item.dir_line + item.content; 125} 126 127function emit_dep_modules(module_names) 128{ 129 var i, mod_name, j; 130 var output = ""; 131 var item = null; 132 133 for (i in module_names) { 134 mod_name = module_names[i]; 135 136 if (MODULES.Exists(mod_name)) { 137 item = MODULES.Item(mod_name); 138 MODULES.Remove(mod_name); 139 if (item.deps.length) { 140 output += emit_dep_modules(item.deps); 141 } 142 output += emit_module(item); 143 } 144 } 145 146 return output; 147} 148 149function gen_modules() 150{ 151 var module_names = (new VBArray(MODULES.Keys())).toArray(); 152 var i, mod_name, j; 153 var item; 154 var output = ""; 155 156 // first, look for modules with empty deps; emit those first 157 for (i in module_names) { 158 STDOUT.WriteLine("module ... " + module_names); 159 mod_name = module_names[i]; 160 item = MODULES.Item(mod_name); 161 if (item.deps.length == 0) { 162 MODULES.Remove(mod_name); 163 output += emit_module(item); 164 } 165 } 166 167 // now we are left with modules that have dependencies on other modules 168 module_names = (new VBArray(MODULES.Keys())).toArray(); 169 output += emit_dep_modules(module_names); 170 171 return output; 172} 173 174// Process buildconf arguments 175function buildconf_process_args() 176{ 177 args = WScript.Arguments; 178 179 for (i = 0; i < args.length; i++) { 180 arg = args(i); 181 // If it is --foo=bar, split on the equals sign 182 arg = arg.split("=", 2); 183 argname = arg[0]; 184 if (arg.length > 1) { 185 argval = arg[1]; 186 } else { 187 argval = null; 188 } 189 190 if (argname == '--clean' && argval != null) { 191 STDOUT.WriteLine("Cleaning..."); 192 return 0; 193 } 194 195 if (argname == '--help') { 196 STDOUT.WriteLine("Usage: phpize [--clean|--help|--version|-v]"); 197 return 0; 198 } 199 return 1; 200 } 201} 202 203if (buildconf_process_args() == 0) { 204 WScript.Quit(3); 205} 206STDOUT.WriteLine("Rebuilding configure.js"); 207STDOUT.WriteLine(PHP_DIR); 208 209// Write the head of the configure script 210C.WriteLine("/* This file automatically generated from script/confutils.js */"); 211C.WriteLine("var MODE_PHPIZE = true;"); 212C.WriteLine("var PHP_DIR = " + '"' + PHP_DIR.replace(new RegExp('(["\\\\])', "g"), '\\$1') + '"'); 213C.WriteLine("var PHP_PREFIX = " + '"' + PHP_PREFIX.replace(new RegExp('(["\\\\])', "g"), '\\$1') + '"'); 214 215/* XXX this needs to be implemented for the phpize mode yet, a quick fix just to disable it for now */ 216C.WriteLine("var PHP_ANALYZER = 'disabled';"); 217C.WriteLine("var PHP_PGO = 'no';"); 218C.WriteLine("var PHP_PGI = 'no';"); 219 220C.WriteLine("var PHP_VERSION=" + PHP_VERSION); 221C.WriteLine("var PHP_MINOR_VERSION=" + PHP_MINOR_VERSION); 222C.WriteLine("var PHP_RELEASE_VERSION=" + PHP_RELEASE_VERSION); 223C.WriteLine("var PHP_EXTRA_VERSION=\"" + PHP_EXTRA_VERSION + "\""); 224C.WriteLine("var PHP_VERSION_STRING=\"" + PHP_VERSION_STRING + "\""); 225 226C.Write(file_get_contents(PHP_DIR + "//script//ext_deps.js")); 227if (FSO.FileExists(PHP_DIR + "/script/ext_pickle.js")) { 228 C.Write(file_get_contents(PHP_DIR + "//script//ext_pickle.js")); 229} 230 231C.Write(file_get_contents(PHP_DIR + "/script/confutils.js")); 232C.Write(file_get_contents(PHP_DIR + "/script/config.phpize.js")); 233 234// Pull in code for the base detection 235modules = file_get_contents(PHP_DIR + "/script/config.w32.phpize.in"); 236 237C.WriteLine("ARG_ENABLE('debug', 'Compile with debugging symbols', PHP_DEBUG);"); 238find_config_w32("."); 239 240// Now generate contents of module based on MODULES, chasing dependencies 241// to ensure that dependent modules are emitted first 242modules += gen_modules(); 243 244// Look for ARG_ENABLE or ARG_WITH calls 245re = new RegExp("(ARG_(ENABLE|WITH)\([^;]+\);)", "gm"); 246calls = modules.match(re); 247for (i = 0; i < calls.length; i++) { 248 item = calls[i]; 249 C.WriteLine("try {"); 250 C.WriteLine(item); 251 C.WriteLine("} catch (e) {"); 252 C.WriteLine('\tSTDOUT.WriteLine("problem: " + e);'); 253 C.WriteLine("}"); 254} 255 256C.WriteBlankLines(1); 257C.WriteLine("conf_process_args();"); 258C.WriteBlankLines(1); 259 260// Comment out the calls from their original positions 261modules = modules.replace(re, "/* $1 */"); 262C.Write(modules); 263 264 265C.WriteBlankLines(1); 266C.Write(file_get_contents(PHP_DIR + "\\script\\configure.tail")); 267 268B.WriteLine("@echo off"); 269B.WriteLine("cscript /nologo /e:jscript configure.js %*"); 270 271FSO.CopyFile(PHP_DIR + "\\script\\run-tests.php", "run-tests.php", true); 272