phpize.js.in 7.4 KB

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