phpize.js.in 7.5 KB

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