buildconf.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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: Wez Furlong <wez@thebrainroom.com> |
  16. +----------------------------------------------------------------------+
  17. */
  18. // This generates a configure script for win32 build
  19. WScript.StdOut.WriteLine("Rebuilding configure.js");
  20. var FSO = WScript.CreateObject("Scripting.FileSystemObject");
  21. var C = FSO.CreateTextFile("configure.js", true);
  22. var B = FSO.CreateTextFile("configure.bat", true);
  23. var modules = "";
  24. var MODULES = WScript.CreateObject("Scripting.Dictionary");
  25. var module_dirs = new Array();
  26. function file_get_contents(filename)
  27. {
  28. var F = FSO.OpenTextFile(filename, 1);
  29. var t = F.ReadAll();
  30. F.Close();
  31. return t;
  32. }
  33. function Module_Item(module_name, config_path, dir_line, deps, content)
  34. {
  35. this.module_name = module_name;
  36. this.config_path = config_path;
  37. this.dir_line = dir_line;
  38. this.deps = deps;
  39. this.content = content;
  40. }
  41. function find_config_w32(dirname)
  42. {
  43. if (!FSO.FolderExists(dirname)) {
  44. return;
  45. }
  46. var f = FSO.GetFolder(dirname);
  47. var fc = new Enumerator(f.SubFolders);
  48. var c, i, ok, n;
  49. var item = null;
  50. var re_dep_line = new RegExp("ADD_EXTENSION_DEP\\([^,]*\\s*,\\s*['\"]([^'\"]+)['\"].*\\)", "gm");
  51. for (; !fc.atEnd(); fc.moveNext())
  52. {
  53. ok = true;
  54. /* check if we already picked up a module with the same dirname;
  55. * if we have, don't include it here */
  56. n = FSO.GetFileName(fc.item());
  57. if (n == '.svn' || n == 'tests')
  58. continue;
  59. // WScript.StdOut.WriteLine("checking " + dirname + "/" + n);
  60. if (MODULES.Exists(n)) {
  61. WScript.StdOut.WriteLine("Skipping " + dirname + "/" + n + " -- already have a module with that name");
  62. continue;
  63. }
  64. c = FSO.BuildPath(fc.item(), "config.w32");
  65. if (FSO.FileExists(c)) {
  66. // WScript.StdOut.WriteLine(c);
  67. var dir_line = "configure_module_dirname = condense_path(FSO.GetParentFolderName('"
  68. + c.replace(new RegExp('(["\\\\])', "g"), '\\$1') + "'));\r\n";
  69. var contents = file_get_contents(c);
  70. var deps = new Array();
  71. // parse out any deps from the file
  72. var calls = contents.match(re_dep_line);
  73. if (calls != null) {
  74. for (i = 0; i < calls.length; i++) {
  75. // now we need the extension name out of this thing
  76. if (calls[i].match(re_dep_line)) {
  77. // WScript.StdOut.WriteLine("n depends on " + RegExp.$1);
  78. deps[deps.length] = RegExp.$1;
  79. }
  80. }
  81. }
  82. item = new Module_Item(n, c, dir_line, deps, contents);
  83. MODULES.Add(n, item);
  84. }
  85. }
  86. }
  87. // Emit core modules array. This is used by a snapshot
  88. // build to override a default "yes" value so that external
  89. // modules don't break the build by becoming statically compiled
  90. function emit_core_module_list()
  91. {
  92. var module_names = (new VBArray(MODULES.Keys())).toArray();
  93. var i, mod_name, j;
  94. var item;
  95. var output = "";
  96. C.WriteLine("core_module_list = new Array(");
  97. // first, look for modules with empty deps; emit those first
  98. for (i in module_names) {
  99. mod_name = module_names[i];
  100. C.WriteLine("\"" + mod_name.replace(/_/g, "-") + "\",");
  101. }
  102. C.WriteLine("false // dummy");
  103. C.WriteLine(");");
  104. }
  105. function emit_module(item)
  106. {
  107. return item.dir_line + item.content;
  108. }
  109. function emit_dep_modules(module_names)
  110. {
  111. var i, mod_name, j;
  112. var output = "";
  113. var item = null;
  114. for (i in module_names) {
  115. mod_name = module_names[i];
  116. if (MODULES.Exists(mod_name)) {
  117. item = MODULES.Item(mod_name);
  118. MODULES.Remove(mod_name);
  119. if (item.deps.length) {
  120. output += emit_dep_modules(item.deps);
  121. }
  122. output += emit_module(item);
  123. }
  124. }
  125. return output;
  126. }
  127. function gen_modules()
  128. {
  129. var module_names = (new VBArray(MODULES.Keys())).toArray();
  130. var i, mod_name, j;
  131. var item;
  132. var output = "";
  133. // first, look for modules with empty deps; emit those first
  134. for (i in 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 == '--add-modules-dir' && argval != null) {
  162. WScript.StdOut.WriteLine("Adding " + argval + " to the module search path");
  163. module_dirs[module_dirs.length] = argval;
  164. }
  165. }
  166. }
  167. buildconf_process_args();
  168. // Write the head of the configure script
  169. C.WriteLine("/* This file automatically generated from win32/build/confutils.js */");
  170. C.WriteLine("MODE_PHPIZE=false;");
  171. C.Write(file_get_contents("win32/build/confutils.js"));
  172. // Pull in code from sapi and extensions
  173. modules = file_get_contents("win32/build/config.w32");
  174. // Pick up confs from TSRM and Zend if present
  175. find_config_w32(".");
  176. find_config_w32("sapi");
  177. find_config_w32("ext");
  178. emit_core_module_list();
  179. // If we have not specified any module dirs let's add some defaults
  180. if (module_dirs.length == 0) {
  181. find_config_w32("pecl");
  182. find_config_w32("..\\pecl");
  183. find_config_w32("pecl\\rpc");
  184. find_config_w32("..\\pecl\\rpc");
  185. } else {
  186. for (i = 0; i < module_dirs.length; i++) {
  187. find_config_w32(module_dirs[i]);
  188. }
  189. }
  190. // Now generate contents of module based on MODULES, chasing dependencies
  191. // to ensure that dependent modules are emitted first
  192. modules += gen_modules();
  193. // Look for ARG_ENABLE or ARG_WITH calls
  194. re = new RegExp("(ARG_(ENABLE|WITH)\([^;]+\);)", "gm");
  195. calls = modules.match(re);
  196. for (i = 0; i < calls.length; i++) {
  197. item = calls[i];
  198. C.WriteLine("try {");
  199. C.WriteLine(item);
  200. C.WriteLine("} catch (e) {");
  201. C.WriteLine('\tSTDOUT.WriteLine("problem: " + e);');
  202. C.WriteLine("}");
  203. }
  204. C.WriteBlankLines(1);
  205. C.WriteLine("check_binary_tools_sdk();");
  206. C.WriteBlankLines(1);
  207. C.WriteLine("STDOUT.WriteLine(\"PHP Version: \" + PHP_VERSION_STRING);");
  208. C.WriteLine("STDOUT.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("win32/build/configure.tail"));
  216. B.WriteLine("@echo off");
  217. B.WriteLine("cscript /nologo /e:jscript configure.js %*");