PageRenderTime 81ms CodeModel.GetById 31ms RepoModel.GetById 4ms app.codeStats 0ms

/win32/build/buildconf.js

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