phpize.js.in 7.7 KB

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