Annotation of embedaddon/php/win32/build/buildconf.js, revision 1.1
1.1 ! misho 1: /*
! 2: +----------------------------------------------------------------------+
! 3: | PHP Version 5 |
! 4: +----------------------------------------------------------------------+
! 5: | Copyright (c) 1997-2008 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: Wez Furlong <wez@thebrainroom.com> |
! 16: +----------------------------------------------------------------------+
! 17: */
! 18:
! 19: /* $Id: buildconf.js,v 1.13.2.2.2.1.2.5 2009-01-02 12:18:21 kalle Exp $ */
! 20: // This generates a configure script for win32 build
! 21:
! 22: WScript.StdOut.WriteLine("Rebuilding configure.js");
! 23: var FSO = WScript.CreateObject("Scripting.FileSystemObject");
! 24: var C = FSO.CreateTextFile("configure.js", true);
! 25: var B = FSO.CreateTextFile("configure.bat", true);
! 26: var DSP = false;
! 27:
! 28: var modules = "";
! 29: var MODULES = WScript.CreateObject("Scripting.Dictionary");
! 30: var module_dirs = new Array();
! 31:
! 32: function file_get_contents(filename)
! 33: {
! 34: var F = FSO.OpenTextFile(filename, 1);
! 35: var t = F.ReadAll();
! 36: F.Close();
! 37: return t;
! 38: }
! 39:
! 40: function Module_Item(module_name, config_path, dir_line, deps, content)
! 41: {
! 42: this.module_name = module_name;
! 43: this.config_path = config_path;
! 44: this.dir_line = dir_line;
! 45: this.deps = deps;
! 46: this.content = content;
! 47: }
! 48:
! 49: function find_config_w32(dirname)
! 50: {
! 51: if (!FSO.FolderExists(dirname)) {
! 52: return;
! 53: }
! 54:
! 55: var f = FSO.GetFolder(dirname);
! 56: var fc = new Enumerator(f.SubFolders);
! 57: var c, i, ok, n;
! 58: var item = null;
! 59: var re_dep_line = new RegExp("ADD_EXTENSION_DEP\\([^,]*\\s*,\\s*['\"]([^'\"]+)['\"].*\\)", "gm");
! 60:
! 61: for (; !fc.atEnd(); fc.moveNext())
! 62: {
! 63: ok = true;
! 64: /* check if we already picked up a module with the same dirname;
! 65: * if we have, don't include it here */
! 66: n = FSO.GetFileName(fc.item());
! 67:
! 68: if (n == '.svn' || n == 'tests')
! 69: continue;
! 70:
! 71: // WScript.StdOut.WriteLine("checking " + dirname + "/" + n);
! 72: if (MODULES.Exists(n)) {
! 73: WScript.StdOut.WriteLine("Skipping " + dirname + "/" + n + " -- already have a module with that name");
! 74: continue;
! 75: }
! 76:
! 77: c = FSO.BuildPath(fc.item(), "config.w32");
! 78: if (FSO.FileExists(c)) {
! 79: // WScript.StdOut.WriteLine(c);
! 80:
! 81: var dir_line = "configure_module_dirname = condense_path(FSO.GetParentFolderName('"
! 82: + c.replace(new RegExp('(["\\\\])', "g"), '\\$1') + "'));\r\n";
! 83: var contents = file_get_contents(c);
! 84: var deps = new Array();
! 85:
! 86: // parse out any deps from the file
! 87: var calls = contents.match(re_dep_line);
! 88: if (calls != null) {
! 89: for (i = 0; i < calls.length; i++) {
! 90: // now we need the extension name out of this thing
! 91: if (calls[i].match(re_dep_line)) {
! 92: // WScript.StdOut.WriteLine("n depends on " + RegExp.$1);
! 93: deps[deps.length] = RegExp.$1;
! 94:
! 95: }
! 96: }
! 97: }
! 98:
! 99: item = new Module_Item(n, c, dir_line, deps, contents);
! 100: MODULES.Add(n, item);
! 101: }
! 102: }
! 103: }
! 104:
! 105: // Emit core modules array. This is used by a snapshot
! 106: // build to override a default "yes" value so that external
! 107: // modules don't break the build by becoming statically compiled
! 108: function emit_core_module_list()
! 109: {
! 110: var module_names = (new VBArray(MODULES.Keys())).toArray();
! 111: var i, mod_name, j;
! 112: var item;
! 113: var output = "";
! 114:
! 115: C.WriteLine("core_module_list = new Array(");
! 116:
! 117: // first, look for modules with empty deps; emit those first
! 118: for (i in module_names) {
! 119: mod_name = module_names[i];
! 120: C.WriteLine("\"" + mod_name.replace(/_/g, "-") + "\",");
! 121: }
! 122:
! 123: C.WriteLine("false // dummy");
! 124:
! 125: C.WriteLine(");");
! 126: }
! 127:
! 128:
! 129: function emit_module(item)
! 130: {
! 131: return item.dir_line + item.content;
! 132: }
! 133:
! 134: function emit_dep_modules(module_names)
! 135: {
! 136: var i, mod_name, j;
! 137: var output = "";
! 138: var item = null;
! 139:
! 140: for (i in module_names) {
! 141: mod_name = module_names[i];
! 142:
! 143: if (MODULES.Exists(mod_name)) {
! 144: item = MODULES.Item(mod_name);
! 145: MODULES.Remove(mod_name);
! 146: if (item.deps.length) {
! 147: output += emit_dep_modules(item.deps);
! 148: }
! 149: output += emit_module(item);
! 150: }
! 151: }
! 152:
! 153: return output;
! 154: }
! 155:
! 156: function gen_modules()
! 157: {
! 158: var module_names = (new VBArray(MODULES.Keys())).toArray();
! 159: var i, mod_name, j;
! 160: var item;
! 161: var output = "";
! 162:
! 163: // first, look for modules with empty deps; emit those first
! 164: for (i in module_names) {
! 165: mod_name = module_names[i];
! 166: item = MODULES.Item(mod_name);
! 167: if (item.deps.length == 0) {
! 168: MODULES.Remove(mod_name);
! 169: output += emit_module(item);
! 170: }
! 171: }
! 172:
! 173: // now we are left with modules that have dependencies on other modules
! 174: module_names = (new VBArray(MODULES.Keys())).toArray();
! 175: output += emit_dep_modules(module_names);
! 176:
! 177: return output;
! 178: }
! 179:
! 180: // Process buildconf arguments
! 181: function buildconf_process_args()
! 182: {
! 183: args = WScript.Arguments;
! 184:
! 185: for (i = 0; i < args.length; i++) {
! 186: arg = args(i);
! 187: // If it is --foo=bar, split on the equals sign
! 188: arg = arg.split("=", 2);
! 189: argname = arg[0];
! 190: if (arg.length > 1) {
! 191: argval = arg[1];
! 192: } else {
! 193: argval = null;
! 194: }
! 195:
! 196: if (argname == '--add-modules-dir' && argval != null) {
! 197: WScript.StdOut.WriteLine("Adding " + argval + " to the module search path");
! 198: module_dirs[module_dirs.length] = argval;
! 199: }
! 200:
! 201: if (argname == '--add-project-files') {
! 202: WScript.StdOut.WriteLine("Adding dsp templates into the mix");
! 203: DSP = true;
! 204: }
! 205: }
! 206: }
! 207:
! 208: buildconf_process_args();
! 209:
! 210: // Write the head of the configure script
! 211: C.WriteLine("/* This file automatically generated from win32/build/confutils.js */");
! 212: C.WriteLine("MODE_PHPIZE=false;");
! 213: C.Write(file_get_contents("win32/build/confutils.js"));
! 214:
! 215: // If project files were requested, pull in the code to generate them
! 216: if (DSP == true) {
! 217: C.WriteLine('PHP_DSP="yes"');
! 218: C.WriteBlankLines(1);
! 219: C.Write(file_get_contents("win32/build/projectgen.js"));
! 220: } else {
! 221: C.WriteLine('PHP_DSP="no"');
! 222: C.WriteBlankLines(1);
! 223: }
! 224:
! 225: // Pull in code from sapi and extensions
! 226: modules = file_get_contents("win32/build/config.w32");
! 227:
! 228: // Pick up confs from TSRM and Zend if present
! 229: find_config_w32(".");
! 230: find_config_w32("sapi");
! 231: find_config_w32("ext");
! 232: emit_core_module_list();
! 233:
! 234: // If we have not specified any module dirs let's add some defaults
! 235: if (module_dirs.length == 0) {
! 236: find_config_w32("pecl");
! 237: find_config_w32("..\\pecl");
! 238: find_config_w32("pecl\\rpc");
! 239: find_config_w32("..\\pecl\\rpc");
! 240: } else {
! 241: for (i = 0; i < module_dirs.length; i++) {
! 242: find_config_w32(module_dirs[i]);
! 243: }
! 244: }
! 245:
! 246: // Now generate contents of module based on MODULES, chasing dependencies
! 247: // to ensure that dependent modules are emitted first
! 248: modules += gen_modules();
! 249:
! 250: // Look for ARG_ENABLE or ARG_WITH calls
! 251: re = new RegExp("(ARG_(ENABLE|WITH)\([^;]+\);)", "gm");
! 252: calls = modules.match(re);
! 253: for (i = 0; i < calls.length; i++) {
! 254: item = calls[i];
! 255: C.WriteLine("try {");
! 256: C.WriteLine(item);
! 257: C.WriteLine("} catch (e) {");
! 258: C.WriteLine('\tSTDOUT.WriteLine("problem: " + e);');
! 259: C.WriteLine("}");
! 260: }
! 261:
! 262: C.WriteBlankLines(1);
! 263: C.WriteLine("conf_process_args();");
! 264: C.WriteBlankLines(1);
! 265:
! 266: // Comment out the calls from their original positions
! 267: modules = modules.replace(re, "/* $1 */");
! 268: C.Write(modules);
! 269:
! 270: C.WriteBlankLines(1);
! 271: C.Write(file_get_contents("win32/build/configure.tail"));
! 272:
! 273: B.WriteLine("@echo off");
! 274: B.WriteLine("cscript /nologo configure.js %*");
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>