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