confutils.js 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322
  1. // Utils for configure script
  2. /*
  3. +----------------------------------------------------------------------+
  4. | PHP Version 5 |
  5. +----------------------------------------------------------------------+
  6. | Copyright (c) 1997-2008 The PHP Group |
  7. +----------------------------------------------------------------------+
  8. | This source file is subject to version 3.01 of the PHP license, |
  9. | that is bundled with this package in the file LICENSE, and is |
  10. | available through the world-wide-web at the following url: |
  11. | http://www.php.net/license/3_01.txt |
  12. | If you did not receive a copy of the PHP license and are unable to |
  13. | obtain it through the world-wide-web, please send a note to |
  14. | license@php.net so we can mail you a copy immediately. |
  15. +----------------------------------------------------------------------+
  16. | Author: Wez Furlong <wez@thebrainroom.com> |
  17. +----------------------------------------------------------------------+
  18. */
  19. // $Id: confutils.js,v 1.60.2.1.2.8.2.33 2009-05-29 07:43:07 kalle Exp $
  20. var STDOUT = WScript.StdOut;
  21. var STDERR = WScript.StdErr;
  22. var WshShell = WScript.CreateObject("WScript.Shell");
  23. var FSO = WScript.CreateObject("Scripting.FileSystemObject");
  24. var MFO = null;
  25. var SYSTEM_DRIVE = WshShell.Environment("Process").Item("SystemDrive");
  26. var PROGRAM_FILES = WshShell.Environment("Process").Item("ProgramFiles");
  27. var PROGRAM_FILESx86 = WshShell.Environment("Process").Item("ProgramFiles(x86)");
  28. var VCINSTALLDIR = WshShell.Environment("Process").Item("VCINSTALLDIR");
  29. var DSP_FLAGS = new Array();
  30. var PHP_SRC_DIR=FSO.GetParentFolderName(WScript.ScriptFullName);
  31. /* Store the enabled extensions (summary + QA check) */
  32. var extensions_enabled = new Array();
  33. /* Store the SAPI enabled (summary + QA check) */
  34. var sapi_enabled = new Array();
  35. /* Store the headers to install */
  36. var headers_install = new Array();
  37. /* Mapping CL version > human readable name */
  38. var VC_VERSIONS = new Array();
  39. VC_VERSIONS[1200] = 'MSVC6 (Visual C++ 6.0)';
  40. VC_VERSIONS[1300] = 'MSVC7 (Visual C++ 2002)';
  41. VC_VERSIONS[1310] = 'MSVC7.1 (Visual C++ 2003)';
  42. VC_VERSIONS[1400] = 'MSVC8 (Visual C++ 2005)';
  43. VC_VERSIONS[1500] = 'MSVC9 (Visual C++ 2008)';
  44. VC_VERSIONS[1600] = 'MSVC10 (Visual C++ 2010)';
  45. VC_VERSIONS[1700] = 'MSVC11 (Visual C++ 2012)';
  46. VC_VERSIONS[1800] = 'MSVC12 (Visual C++ 2013)';
  47. var VC_VERSIONS_SHORT = new Array();
  48. VC_VERSIONS_SHORT[1200] = 'VC6';
  49. VC_VERSIONS_SHORT[1300] = 'VC7';
  50. VC_VERSIONS_SHORT[1310] = 'VC7.1';
  51. VC_VERSIONS_SHORT[1400] = 'VC8';
  52. VC_VERSIONS_SHORT[1500] = 'VC9';
  53. VC_VERSIONS_SHORT[1600] = 'VC10';
  54. VC_VERSIONS_SHORT[1700] = 'VC11';
  55. VC_VERSIONS_SHORT[1800] = 'VC12';
  56. if (PROGRAM_FILES == null) {
  57. PROGRAM_FILES = "C:\\Program Files";
  58. }
  59. if (MODE_PHPIZE) {
  60. if (!FSO.FileExists("config.w32")) {
  61. STDERR.WriteLine("Must be run from the root of the extension source");
  62. WScript.Quit(10);
  63. }
  64. } else {
  65. if (!FSO.FileExists("README.GIT-RULES")) {
  66. STDERR.WriteLine("Must be run from the root of the php source");
  67. WScript.Quit(10);
  68. }
  69. }
  70. var CWD = WshShell.CurrentDirectory;
  71. if (typeof(CWD) == "undefined") {
  72. CWD = FSO.GetParentFolderName(FSO.GetAbsolutePathName("README.GIT-RULES"));
  73. }
  74. /* defaults; we pick up the precise versions from configure.in */
  75. var PHP_VERSION = 5;
  76. var PHP_MINOR_VERSION = 0;
  77. var PHP_RELEASE_VERSION = 0;
  78. var PHP_EXTRA_VERSION = "";
  79. var PHP_VERSION_STRING = "5.0.0";
  80. function get_version_numbers()
  81. {
  82. var cin = file_get_contents("configure.in");
  83. if (cin.match(new RegExp("PHP_MAJOR_VERSION=(\\d+)"))) {
  84. PHP_VERSION = RegExp.$1;
  85. }
  86. if (cin.match(new RegExp("PHP_MINOR_VERSION=(\\d+)"))) {
  87. PHP_MINOR_VERSION = RegExp.$1;
  88. }
  89. if (cin.match(new RegExp("PHP_RELEASE_VERSION=(\\d+)"))) {
  90. PHP_RELEASE_VERSION = RegExp.$1;
  91. }
  92. PHP_VERSION_STRING = PHP_VERSION + "." + PHP_MINOR_VERSION + "." + PHP_RELEASE_VERSION;
  93. if (cin.match(new RegExp("PHP_EXTRA_VERSION=\"([^\"]+)\""))) {
  94. PHP_EXTRA_VERSION = RegExp.$1;
  95. if (PHP_EXTRA_VERSION.length) {
  96. PHP_VERSION_STRING += PHP_EXTRA_VERSION;
  97. }
  98. }
  99. DEFINE('PHP_VERSION_STRING', PHP_VERSION_STRING);
  100. }
  101. configure_args = new Array();
  102. configure_subst = WScript.CreateObject("Scripting.Dictionary");
  103. configure_hdr = WScript.CreateObject("Scripting.Dictionary");
  104. build_dirs = new Array();
  105. extension_include_code = "";
  106. extension_module_ptrs = "";
  107. if (!MODE_PHPIZE) {
  108. get_version_numbers();
  109. }
  110. /* execute a command and return the output as a string */
  111. function execute(command_line)
  112. {
  113. var e = WshShell.Exec(command_line);
  114. var ret = "";
  115. ret = e.StdOut.ReadAll();
  116. //STDOUT.WriteLine("command " + command_line);
  117. //STDOUT.WriteLine(ret);
  118. return ret;
  119. }
  120. function probe_binary(EXE, what)
  121. {
  122. // tricky escapes to get stderr redirection to work
  123. var command = 'cmd /c ""' + EXE;
  124. if (what == "version") {
  125. command = command + '" -v"';
  126. }
  127. var version = execute(command + '" 2>&1"');
  128. if (what == "64") {
  129. if (version.match(/x64/)) {
  130. return 1;
  131. }
  132. } else {
  133. if (version.match(/(\d+\.\d+(\.\d+)?(\.\d+)?)/)) {
  134. return RegExp.$1;
  135. }
  136. }
  137. return 0;
  138. }
  139. function condense_path(path)
  140. {
  141. path = FSO.GetAbsolutePathName(path);
  142. if (path.substr(0, CWD.length).toLowerCase()
  143. == CWD.toLowerCase() &&
  144. (path.charCodeAt(CWD.length) == 92 || path.charCodeAt(CWD.length) == 47)) {
  145. return path.substr(CWD.length + 1);
  146. }
  147. var a = CWD.split("\\");
  148. var b = path.split("\\");
  149. var i, j;
  150. for (i = 0; i < b.length; i++) {
  151. if (a[i].toLowerCase() == b[i].toLowerCase())
  152. continue;
  153. if (i > 0) {
  154. /* first difference found */
  155. path = "";
  156. for (j = 0; j < a.length - i; j++) {
  157. path += "..\\";
  158. }
  159. for (j = i; j < b.length; j++) {
  160. path += b[j];
  161. if (j < b.length - 1)
  162. path += "\\";
  163. }
  164. return path;
  165. }
  166. /* on a different drive */
  167. break;
  168. }
  169. return path;
  170. }
  171. function ConfigureArg(type, optname, helptext, defval)
  172. {
  173. var opptype = type == "enable" ? "disable" : "without";
  174. if (defval == "yes" || defval == "yes,shared") {
  175. this.arg = "--" + opptype + "-" + optname;
  176. this.imparg = "--" + type + "-" + optname;
  177. } else {
  178. this.arg = "--" + type + "-" + optname;
  179. this.imparg = "--" + opptype + "-" + optname;
  180. }
  181. this.optname = optname;
  182. this.helptext = helptext;
  183. this.defval = defval;
  184. this.symval = optname.toUpperCase().replace(new RegExp("-", "g"), "_");
  185. this.seen = false;
  186. this.argval = defval;
  187. }
  188. function ARG_WITH(optname, helptext, defval)
  189. {
  190. configure_args[configure_args.length] = new ConfigureArg("with", optname, helptext, defval);
  191. }
  192. function ARG_ENABLE(optname, helptext, defval)
  193. {
  194. configure_args[configure_args.length] = new ConfigureArg("enable", optname, helptext, defval);
  195. }
  196. function analyze_arg(argval)
  197. {
  198. var ret = new Array();
  199. var shared = false;
  200. if (argval == "shared") {
  201. shared = true;
  202. argval = "yes";
  203. } else if (argval == null) {
  204. /* nothing */
  205. } else if (arg_match = argval.match(new RegExp("^shared,(.*)"))) {
  206. shared = true;
  207. argval = arg_match[1];
  208. } else if (arg_match = argval.match(new RegExp("^(.*),shared$"))) {
  209. shared = true;
  210. argval = arg_match[1];
  211. }
  212. ret[0] = shared;
  213. ret[1] = argval;
  214. return ret;
  215. }
  216. function word_wrap_and_indent(indent, text, line_suffix, indent_char)
  217. {
  218. if (text == null) {
  219. return "";
  220. }
  221. var words = text.split(new RegExp("\\s+", "g"));
  222. var i = 0;
  223. var ret_text = "";
  224. var this_line = "";
  225. var t;
  226. var space = "";
  227. var lines = 0;
  228. if (line_suffix == null) {
  229. line_suffix = "";
  230. }
  231. if (indent_char == null) {
  232. indent_char = " ";
  233. }
  234. for (i = 0; i < indent; i++) {
  235. space += indent_char;
  236. }
  237. for (i = 0; i < words.length; i++) {
  238. if (this_line.length) {
  239. t = this_line + " " + words[i];
  240. } else {
  241. t = words[i];
  242. }
  243. if (t.length + indent > 78) {
  244. if (lines++) {
  245. ret_text += space;
  246. }
  247. ret_text += this_line + line_suffix + "\r\n";
  248. this_line = "";
  249. }
  250. if (this_line.length) {
  251. this_line += " " + words[i];
  252. } else {
  253. this_line = words[i];
  254. }
  255. }
  256. if (this_line.length) {
  257. if (lines)
  258. ret_text += space;
  259. ret_text += this_line;
  260. }
  261. return ret_text;
  262. }
  263. function conf_process_args()
  264. {
  265. var i, j;
  266. var configure_help_mode = false;
  267. var analyzed = false;
  268. var nice = "cscript /nologo configure.js ";
  269. var disable_all = false;
  270. args = WScript.Arguments;
  271. for (i = 0; i < args.length; i++) {
  272. arg = args(i);
  273. nice += ' "' + arg + '"';
  274. if (arg == "--help") {
  275. configure_help_mode = true;
  276. break;
  277. }
  278. if (arg == "--disable-all") {
  279. disable_all = true;
  280. continue;
  281. }
  282. // If it is --foo=bar, split on the equals sign
  283. arg = arg.split("=", 2);
  284. argname = arg[0];
  285. if (arg.length > 1) {
  286. argval = arg[1];
  287. } else {
  288. argval = null;
  289. }
  290. // Find the arg
  291. found = false;
  292. for (j = 0; j < configure_args.length; j++) {
  293. if (argname == configure_args[j].imparg || argname == configure_args[j].arg) {
  294. found = true;
  295. arg = configure_args[j];
  296. arg.seen = true;
  297. analyzed = analyze_arg(argval);
  298. /* Force shared when called after phpize */
  299. if (MODE_PHPIZE) {
  300. shared = "shared";
  301. } else {
  302. shared = analyzed[0];
  303. }
  304. argval = analyzed[1];
  305. if (argname == arg.imparg) {
  306. /* we matched the implicit, or default arg */
  307. if (argval == null) {
  308. argval = arg.defval;
  309. }
  310. } else {
  311. /* we matched the non-default arg */
  312. if (argval == null) {
  313. argval = arg.defval == "no" ? "yes" : "no";
  314. }
  315. }
  316. arg.argval = argval;
  317. eval("PHP_" + arg.symval + " = argval;");
  318. eval("PHP_" + arg.symval + "_SHARED = shared;");
  319. break;
  320. }
  321. }
  322. if (!found) {
  323. STDERR.WriteLine("Unknown option " + argname + "; please try configure.js --help for a list of valid options");
  324. WScript.Quit(2);
  325. }
  326. }
  327. if (configure_help_mode) {
  328. STDOUT.WriteLine(word_wrap_and_indent(0,
  329. "Options that enable extensions and SAPI will accept \
  330. 'yes' or 'no' as a parameter. They also accept 'shared' \
  331. as a synonym for 'yes' and request a shared build of that \
  332. module. Not all modules can be built as shared modules; \
  333. configure will display [shared] after the module name if \
  334. can be built that way. \
  335. "
  336. ));
  337. STDOUT.WriteBlankLines(1);
  338. // Measure width to pretty-print the output
  339. max_width = 0;
  340. for (i = 0; i < configure_args.length; i++) {
  341. arg = configure_args[i];
  342. if (arg.arg.length > max_width)
  343. max_width = arg.arg.length;
  344. }
  345. for (i = 0; i < configure_args.length; i++) {
  346. arg = configure_args[i];
  347. n = max_width - arg.arg.length;
  348. pad = " ";
  349. for (j = 0; j < n; j++) {
  350. pad += " ";
  351. }
  352. STDOUT.WriteLine(" " + arg.arg + pad + word_wrap_and_indent(max_width + 5, arg.helptext));
  353. }
  354. WScript.Quit(1);
  355. }
  356. var snapshot_build_exclusions = new Array(
  357. 'debug', 'crt-debug', 'lzf-better-compression',
  358. 'php-build', 'snapshot-template', 'ereg',
  359. 'pcre-regex', 'fastcgi', 'force-cgi-redirect',
  360. 'path-info-check', 'zts', 'ipv6', 'memory-limit',
  361. 'zend-multibyte', 'fd-setsize', 'memory-manager',
  362. 't1lib', 'pgi', 'pgo'
  363. );
  364. var force;
  365. // Now set any defaults we might have missed out earlier
  366. for (i = 0; i < configure_args.length; i++) {
  367. arg = configure_args[i];
  368. if (arg.seen)
  369. continue;
  370. analyzed = analyze_arg(arg.defval);
  371. shared = analyzed[0];
  372. argval = analyzed[1];
  373. // Don't trust a default "yes" answer for a non-core module
  374. // in a snapshot build
  375. if (PHP_SNAPSHOT_BUILD != "no" && argval == "yes" && !shared) {
  376. force = true;
  377. for (j = 0; j < snapshot_build_exclusions.length; j++) {
  378. if (snapshot_build_exclusions[j] == arg.optname) {
  379. force = false;
  380. break;
  381. }
  382. }
  383. if (force) {
  384. /* now check if it is a core module */
  385. force = false;
  386. for (j = 0; j < core_module_list.length; j++) {
  387. if (core_module_list[j] == arg.optname) {
  388. force = true;
  389. break;
  390. }
  391. }
  392. if (!force) {
  393. STDOUT.WriteLine("snapshot: forcing " + arg.arg + " shared");
  394. shared = true;
  395. }
  396. }
  397. }
  398. if (PHP_SNAPSHOT_BUILD != "no" && argval == "no") {
  399. force = true;
  400. for (j = 0; j < snapshot_build_exclusions.length; j++) {
  401. if (snapshot_build_exclusions[j] == arg.optname) {
  402. force = false;
  403. break;
  404. }
  405. }
  406. if (force) {
  407. STDOUT.WriteLine("snapshot: forcing " + arg.optname + " on");
  408. argval = "yes";
  409. shared = true;
  410. }
  411. }
  412. if (disable_all) {
  413. force = true;
  414. for (j = 0; j < snapshot_build_exclusions.length; j++) {
  415. if (snapshot_build_exclusions[j] == arg.optname) {
  416. force = false;
  417. break;
  418. }
  419. }
  420. if (force) {
  421. if (arg.defval == '') {
  422. argval = '';
  423. } else {
  424. argval = "no";
  425. }
  426. shared = false;
  427. }
  428. }
  429. eval("PHP_" + arg.symval + " = argval;");
  430. eval("PHP_" + arg.symval + "_SHARED = shared;");
  431. }
  432. MFO = FSO.CreateTextFile("Makefile.objects", true);
  433. STDOUT.WriteLine("Saving configure options to config.nice.bat");
  434. var nicefile = FSO.CreateTextFile("config.nice.bat", true);
  435. nicefile.WriteLine(nice + " %*");
  436. nicefile.Close();
  437. AC_DEFINE('CONFIGURE_COMMAND', nice, "Configure line");
  438. }
  439. function DEFINE(name, value)
  440. {
  441. if (configure_subst.Exists(name)) {
  442. configure_subst.Remove(name);
  443. }
  444. configure_subst.Add(name, value);
  445. }
  446. // Searches a set of paths for a file;
  447. // returns the dir in which the file was found,
  448. // true if it was found in the default env path,
  449. // or false if it was not found at all.
  450. // env_name is the optional name of an env var
  451. // specifying the default path to search
  452. function search_paths(thing_to_find, explicit_path, env_name)
  453. {
  454. var i, found = false, place = false, file, env;
  455. STDOUT.Write("Checking for " + thing_to_find + " ... ");
  456. thing_to_find = thing_to_find.replace(new RegExp("/", "g"), "\\");
  457. if (explicit_path != null) {
  458. if (typeof(explicit_path) == "string") {
  459. explicit_path = explicit_path.split(";");
  460. }
  461. for (i = 0; i < explicit_path.length; i++) {
  462. file = glob(explicit_path[i] + "\\" + thing_to_find);
  463. if (file) {
  464. found = true;
  465. place = file[0];
  466. place = place.substr(0, place.length - thing_to_find.length - 1);
  467. break;
  468. }
  469. }
  470. }
  471. if (!found && env_name != null) {
  472. env = WshShell.Environment("Process").Item(env_name);
  473. env = env.split(";");
  474. for (i = 0; i < env.length; i++) {
  475. file = glob(env[i] + "\\" + thing_to_find);
  476. if (file) {
  477. found = true;
  478. place = true;
  479. break;
  480. }
  481. }
  482. }
  483. if (found && place == true) {
  484. STDOUT.WriteLine(" <in default path>");
  485. } else if (found) {
  486. STDOUT.WriteLine(" " + place);
  487. } else {
  488. STDOUT.WriteLine(" <not found>");
  489. }
  490. return place;
  491. }
  492. function PATH_PROG(progname, additional_paths, symbol)
  493. {
  494. var exe;
  495. var place;
  496. var cyg_path = PHP_CYGWIN + "\\bin;" + PHP_CYGWIN + "\\usr\\local\\bin";
  497. var php_build_bin_path = PHP_PHP_BUILD + "\\bin"
  498. exe = progname + ".exe";
  499. if (additional_paths == null) {
  500. additional_paths = cyg_path;
  501. } else {
  502. additional_paths += ";" + cyg_path;
  503. }
  504. additional_paths = additional_paths + ";" + php_build_bin_path;
  505. place = search_paths(exe, additional_paths, "PATH");
  506. if (place == true) {
  507. place = exe;
  508. } else if (place != false) {
  509. place = place + "\\" + exe;
  510. }
  511. if (place) {
  512. if (symbol == null) {
  513. symbol = progname.toUpperCase();
  514. }
  515. DEFINE(symbol, place);
  516. }
  517. return place;
  518. }
  519. function find_pattern_in_path(pattern, path)
  520. {
  521. if (path == null) {
  522. return false;
  523. }
  524. var dirs = path.split(';');
  525. var i;
  526. var items;
  527. for (i = 0; i < dirs.length; i++) {
  528. items = glob(dirs[i] + "\\" + pattern);
  529. if (items) {
  530. return condense_path(items[0]);
  531. }
  532. }
  533. return false;
  534. }
  535. function CHECK_LIB(libnames, target, path_to_check, common_name)
  536. {
  537. STDOUT.Write("Checking for library " + libnames + " ... ");
  538. if (common_name == null && target != null) {
  539. common_name = target;
  540. }
  541. if (path_to_check == null) {
  542. path_to_check = "";
  543. }
  544. // if they specified a common name for the package that contains
  545. // the library, tag some useful defaults on to the end of the
  546. // path to be searched
  547. if (common_name != null) {
  548. path_to_check += ";" + PHP_PHP_BUILD + "\\" + common_name + "*";
  549. path_to_check += ";" + PHP_PHP_BUILD + "\\lib\\" + common_name + "*";
  550. path_to_check += ";..\\" + common_name + "*";
  551. }
  552. // Determine target for build flags
  553. if (target == null) {
  554. target = "";
  555. } else {
  556. target = "_" + target.toUpperCase();
  557. }
  558. // Expand path to include general dirs
  559. path_to_check += ";" + php_usual_lib_suspects;
  560. // It is common practice to put libs under one of these dir names
  561. var subdirs = new Array(PHP_DEBUG == "yes" ? "Debug" : (PHP_DEBUG_PACK == "yes"?"Release_Dbg":"Release"), "lib", "libs", "libexec");
  562. // libnames can be ; separated list of accepted library names
  563. libnames = libnames.split(';');
  564. // for debug builds, lib may have _debug appended, we want that first
  565. if (PHP_DEBUG == "yes") {
  566. var length = libnames.length;
  567. for (var i = 0; i < length; i++) {
  568. var name = new String(libnames[i]);
  569. rExp = /.lib$/i;
  570. name = name.replace(rExp,"_debug.lib");
  571. libnames.unshift(name);
  572. }
  573. }
  574. var i, j, k, libname;
  575. var location = false;
  576. var path = path_to_check.split(';');
  577. for (i = 0; i < libnames.length; i++) {
  578. libname = libnames[i];
  579. for (k = 0; k < path.length; k++) {
  580. location = glob(path[k] + "\\" + libname);
  581. if (location) {
  582. location = location[0];
  583. break;
  584. }
  585. for (j = 0; j < subdirs.length; j++) {
  586. location = glob(path[k] + "\\" + subdirs[j] + "\\" + libname);
  587. if (location) {
  588. location = location[0];
  589. break;
  590. }
  591. }
  592. if (location)
  593. break;
  594. }
  595. if (location) {
  596. location = condense_path(location);
  597. var libdir = FSO.GetParentFolderName(location);
  598. libname = FSO.GetFileName(location);
  599. ADD_FLAG("LDFLAGS" + target, '/libpath:"' + libdir + '" ');
  600. ADD_FLAG("LIBS" + target, libname);
  601. STDOUT.WriteLine(location);
  602. return location;
  603. }
  604. // Check in their standard lib path
  605. location = find_pattern_in_path(libname, WshShell.Environment("Process").Item("LIB"));
  606. if (location) {
  607. location = condense_path(location);
  608. libname = FSO.GetFileName(location);
  609. ADD_FLAG("LIBS" + target, libname);
  610. STDOUT.WriteLine("<in LIB path> " + libname);
  611. return location;
  612. }
  613. // Check in their general extra libs path
  614. location = find_pattern_in_path(libname, PHP_EXTRA_LIBS);
  615. if (location) {
  616. location = condense_path(location);
  617. libname = FSO.GetFileName(location);
  618. ADD_FLAG("LIBS" + target, libname);
  619. STDOUT.WriteLine("<in extra libs path>");
  620. return location;
  621. }
  622. }
  623. STDOUT.WriteLine("<not found>");
  624. return false;
  625. }
  626. function OLD_CHECK_LIB(libnames, target, path_to_check)
  627. {
  628. if (target == null) {
  629. target = "";
  630. } else {
  631. target = "_" + target.toUpperCase();
  632. }
  633. if (path_to_check == null) {
  634. path_to_check = php_usual_lib_suspects;
  635. } else {
  636. path_to_check += ";" + php_usual_lib_suspects;
  637. }
  638. var have = 0;
  639. var p;
  640. var i;
  641. var libname;
  642. var subdir = PHP_DEBUG == "yes" ? "Debug" : (PHP_DEBUG_PACK == "yes"?"Release_Dbg":"Release");
  643. libnames = libnames.split(';');
  644. for (i = 0; i < libnames.length; i++) {
  645. libname = libnames[i];
  646. p = search_paths(libname, path_to_check, "LIB");
  647. if (!p) {
  648. p = search_paths(subdir + "\\" + libname, path_to_check, "LIB");
  649. if (p) {
  650. p += "\\" + subdir;
  651. }
  652. }
  653. if (typeof(p) == "string") {
  654. ADD_FLAG("LDFLAGS" + target, '/libpath:"' + p + '" ');
  655. ADD_FLAG("LIBS" + target, libname);
  656. have = 1;
  657. } else if (p == true) {
  658. ADD_FLAG("LIBS" + target, libname);
  659. have = 1;
  660. } else {
  661. /* not found in the defaults or the explicit paths,
  662. * so check the general extra libs; if we find
  663. * it here, no need to add another /libpath: for it as we
  664. * already have it covered, but we need to add the lib
  665. * to LIBS_XXX */
  666. if (false != search_paths(libname, PHP_EXTRA_LIBS, null)) {
  667. ADD_FLAG("LIBS" + target, libname);
  668. have = 1;
  669. }
  670. }
  671. if (have) {
  672. break;
  673. }
  674. }
  675. // AC_DEFINE("HAVE_" + header_name.toUpperCase().replace(new RegExp("/\\\\-\.", "g"), "_"), have);
  676. return have;
  677. }
  678. function CHECK_FUNC_IN_HEADER(header_name, func_name, path_to_check, add_to_flag)
  679. {
  680. var c = false;
  681. var sym;
  682. STDOUT.Write("Checking for " + func_name + " in " + header_name + " ... ");
  683. c = GREP_HEADER(header_name, func_name, path_to_check);
  684. sym = func_name.toUpperCase();
  685. sym = sym.replace(new RegExp("[\\\\/\.-]", "g"), "_");
  686. if (typeof(add_to_flag) == "undefined") {
  687. AC_DEFINE("HAVE_" + sym, c ? 1 : 0);
  688. } else {
  689. ADD_FLAG(add_to_flag, "/DHAVE_" + sym + "=" + (c ? "1" : "0"));
  690. }
  691. if (c) {
  692. STDOUT.WriteLine("OK");
  693. return c;
  694. }
  695. STDOUT.WriteLine("No");
  696. return false;
  697. }
  698. function GREP_HEADER(header_name, regex, path_to_check)
  699. {
  700. var c = false;
  701. if (FSO.FileExists(path_to_check + "\\" + header_name)) {
  702. c = file_get_contents(path_to_check + "\\" + header_name);
  703. }
  704. if (!c) {
  705. /* look in the include path */
  706. var p = search_paths(header_name, path_to_check, "INCLUDE");
  707. if (typeof(p) == "string") {
  708. c = file_get_contents(p);
  709. } else if (p == false) {
  710. p = search_paths(header_name, PHP_EXTRA_INCLUDES, null);
  711. if (typeof(p) == "string") {
  712. c = file_get_contents(p);
  713. }
  714. }
  715. if (!c) {
  716. return false;
  717. }
  718. }
  719. if (typeof(regex) == "string") {
  720. regex = new RegExp(regex);
  721. }
  722. if (c.match(regex)) {
  723. /* caller can now use RegExp.$1 etc. to get at patterns */
  724. return true;
  725. }
  726. return false;
  727. }
  728. function CHECK_HEADER_ADD_INCLUDE(header_name, flag_name, path_to_check, use_env, add_dir_part, add_to_flag_only)
  729. {
  730. var dir_part_to_add = "";
  731. if (use_env == null) {
  732. use_env = true;
  733. }
  734. // if true, add the dir part of the header_name to the include path
  735. if (add_dir_part == null) {
  736. add_dir_part = false;
  737. } else if (add_dir_part) {
  738. var basename = FSO.GetFileName(header_name);
  739. dir_part_to_add = "\\" + header_name.substr(0, header_name.length - basename.length - 1);
  740. }
  741. if (path_to_check == null) {
  742. path_to_check = php_usual_include_suspects;
  743. } else {
  744. path_to_check += ";" + php_usual_include_suspects;
  745. }
  746. var p = search_paths(header_name, path_to_check, use_env ? "INCLUDE" : null);
  747. var have = 0;
  748. var sym;
  749. if (typeof(p) == "string") {
  750. ADD_FLAG(flag_name, '/I "' + p + dir_part_to_add + '" ');
  751. } else if (p == false) {
  752. /* not found in the defaults or the explicit paths,
  753. * so check the general extra includes; if we find
  754. * it here, no need to add another /I for it as we
  755. * already have it covered, unless we are adding
  756. * the dir part.... */
  757. p = search_paths(header_name, PHP_EXTRA_INCLUDES, null);
  758. if (typeof(p) == "string" && add_dir_part) {
  759. ADD_FLAG(flag_name, '/I "' + p + dir_part_to_add + '" ');
  760. }
  761. }
  762. have = p ? 1 : 0
  763. sym = header_name.toUpperCase();
  764. sym = sym.replace(new RegExp("[\\\\/\.-]", "g"), "_");
  765. if (typeof(add_to_flag_only) == "undefined" &&
  766. flag_name.match(new RegExp("^CFLAGS_(.*)$"))) {
  767. add_to_flag_only = true;
  768. }
  769. if (typeof(add_to_flag_only) != "undefined") {
  770. ADD_FLAG(flag_name, "/DHAVE_" + sym + "=" + have);
  771. } else {
  772. AC_DEFINE("HAVE_" + sym, have, "have the " + header_name + " header file");
  773. }
  774. return p;
  775. }
  776. function generate_version_info_manifest(makefiletarget)
  777. {
  778. var manifest_name = makefiletarget + ".manifest";
  779. if (MODE_PHPIZE) {
  780. MFO.WriteLine("$(BUILD_DIR)\\" + manifest_name + ": " + PHP_DIR + "\\build\\default.manifest");
  781. MFO.WriteLine("\t@copy " + PHP_DIR + "\\build\\default.manifest $(BUILD_DIR)\\" + makefiletarget + ".manifest");
  782. } else {
  783. MFO.WriteLine("$(BUILD_DIR)\\" + manifest_name + ": win32\\build\\default.manifest");
  784. MFO.WriteLine("\t@copy $(PHP_SRC_DIR)\\win32\\build\\default.manifest $(BUILD_DIR)\\" + makefiletarget + ".manifest");
  785. }
  786. return manifest_name;
  787. }
  788. /* emits rule to generate version info for a SAPI
  789. * or extension. Returns the name of the .res file
  790. * that will be generated */
  791. function generate_version_info_resource(makefiletarget, basename, creditspath, sapi)
  792. {
  793. var resname = makefiletarget + ".res";
  794. var res_desc = makefiletarget;
  795. var res_prod_name = "PHP " + makefiletarget;
  796. var credits;
  797. var thanks = "";
  798. var logo = "";
  799. var debug = "";
  800. var project_url = "http://www.php.net";
  801. var project_header = creditspath + "/php_" + basename + ".h";
  802. var versioning = "";
  803. if (sapi) {
  804. var internal_name = basename.toUpperCase() + " SAPI";
  805. } else {
  806. var internal_name = basename.toUpperCase() + " extension";
  807. }
  808. if (FSO.FileExists(creditspath + '/CREDITS')) {
  809. credits = FSO.OpenTextFile(creditspath + '/CREDITS', 1);
  810. res_desc = credits.ReadLine();
  811. try {
  812. thanks = credits.ReadLine();
  813. } catch (e) {
  814. thanks = null;
  815. }
  816. if (thanks == null) {
  817. thanks = "";
  818. } else {
  819. thanks = "Thanks to " + thanks;
  820. }
  821. credits.Close();
  822. }
  823. if (creditspath.match(new RegExp("pecl"))) {
  824. /* PECL project url - this will eventually work correctly for all */
  825. project_url = "http://pecl.php.net/" + basename;
  826. /* keep independent versioning PECL-specific for now */
  827. if (FSO.FileExists(project_header)) {
  828. if (header = FSO.OpenTextFile(project_header, 1)) {
  829. contents = header.ReadAll();
  830. /* allowed: x.x.x[a|b|-alpha|-beta][RCx][-dev] */
  831. if (contents.match(new RegExp('PHP_' + basename.toUpperCase() + '_VERSION(\\s+)"((\\d+\.\\d+(\.\\d+)?)((a|b)(\\d)?|\-[a-z]{3,5})?(RC\\d+)?(\-dev)?)'))) {
  832. project_version = RegExp.$2;
  833. file_version = RegExp.$3.split('.');
  834. if (!file_version[2]) {
  835. file_version[2] = 0;
  836. }
  837. versioning = '\\"" /d EXT_FILE_VERSION=' + file_version[0] + ',' + file_version[1] + ',' + file_version[2] + ' /d EXT_VERSION="\\"' + project_version;
  838. }
  839. header.Close();
  840. }
  841. }
  842. }
  843. if (makefiletarget.match(new RegExp("\\.exe$"))) {
  844. logo = " /d WANT_LOGO ";
  845. }
  846. if (PHP_DEBUG != "no") {
  847. debug = " /d _DEBUG";
  848. }
  849. /**
  850. * Use user supplied template.rc if it exists
  851. */
  852. if (FSO.FileExists(creditspath + '\\template.rc')) {
  853. MFO.WriteLine("$(BUILD_DIR)\\" + resname + ": " + creditspath + "\\template.rc");
  854. MFO.WriteLine("\t$(RC) /fo $(BUILD_DIR)\\" + resname + logo + debug +
  855. ' /d FILE_DESCRIPTION="\\"' + res_desc + '\\"" /d FILE_NAME="\\"' +
  856. makefiletarget + '\\"" /d PRODUCT_NAME="\\"' + res_prod_name +
  857. versioning + '\\"" /d THANKS_GUYS="\\"' + thanks + '\\"" ' +
  858. creditspath + '\\template.rc');
  859. return resname;
  860. }
  861. if (MODE_PHPIZE) {
  862. MFO.WriteLine("$(BUILD_DIR)\\" + resname + ": $(PHP_DIR)\\build\\template.rc");
  863. MFO.WriteLine("\t$(RC) /I $(PHP_DIR)/include /n /fo $(BUILD_DIR)\\" + resname + logo + debug +
  864. ' /d FILE_DESCRIPTION="\\"' + res_desc + '\\"" /d FILE_NAME="\\"'
  865. + makefiletarget + '\\"" /d URL="\\"' + project_url +
  866. '\\"" /d INTERNAL_NAME="\\"' + internal_name + versioning +
  867. '\\"" /d THANKS_GUYS="\\"' + thanks + '\\"" $(PHP_DIR)\\build\\template.rc');
  868. } else {
  869. MFO.WriteLine("$(BUILD_DIR)\\" + resname + ": win32\\build\\template.rc");
  870. MFO.WriteLine("\t$(RC) /n /fo $(BUILD_DIR)\\" + resname + logo + debug +
  871. ' /d FILE_DESCRIPTION="\\"' + res_desc + '\\"" /d FILE_NAME="\\"'
  872. + makefiletarget + '\\"" /d URL="\\"' + project_url +
  873. '\\"" /d INTERNAL_NAME="\\"' + internal_name + versioning +
  874. '\\"" /d THANKS_GUYS="\\"' + thanks + '\\"" win32\\build\\template.rc');
  875. }
  876. MFO.WriteBlankLines(1);
  877. return resname;
  878. }
  879. /* Check if PGO is enabled for given module. To disable PGO for a particular module,
  880. define a global variable by the following name scheme before SAPI() or EXTENSION() call
  881. var PHP_MYMODULE_PGO = false; */
  882. function is_pgo_desired(mod)
  883. {
  884. var varname = "PHP_" + mod.toUpperCase() + "_PGO";
  885. /* XXX enable PGO in phpize mode */
  886. if (MODE_PHPIZE) {
  887. return false;
  888. }
  889. /* don't disable if there's no mention of the varname */
  890. if (eval("typeof " + varname + " == 'undefined'")) {
  891. return true;
  892. }
  893. return eval("!!" + varname);
  894. }
  895. function SAPI(sapiname, file_list, makefiletarget, cflags, obj_dir)
  896. {
  897. var SAPI = sapiname.toUpperCase();
  898. var ldflags;
  899. var resname;
  900. var ld;
  901. var manifest;
  902. if (typeof(obj_dir) == "undefined") {
  903. sapiname_for_printing = configure_module_dirname;
  904. } else {
  905. sapiname_for_printing = configure_module_dirname + " (via " + obj_dir + ")";
  906. }
  907. STDOUT.WriteLine("Enabling SAPI " + sapiname_for_printing);
  908. MFO.WriteBlankLines(1);
  909. MFO.WriteLine("# objects for SAPI " + sapiname);
  910. MFO.WriteBlankLines(1);
  911. if (cflags) {
  912. ADD_FLAG('CFLAGS_' + SAPI, cflags);
  913. }
  914. ADD_SOURCES(configure_module_dirname, file_list, sapiname, obj_dir);
  915. MFO.WriteBlankLines(1);
  916. MFO.WriteLine("# SAPI " + sapiname);
  917. MFO.WriteBlankLines(1);
  918. /* generate a .res file containing version information */
  919. resname = generate_version_info_resource(makefiletarget, sapiname, configure_module_dirname, true);
  920. manifest_name = generate_version_info_manifest(makefiletarget);
  921. MFO.WriteLine(makefiletarget + ": $(BUILD_DIR)\\" + makefiletarget);
  922. MFO.WriteLine("\t@echo SAPI " + sapiname_for_printing + " build complete");
  923. if (MODE_PHPIZE) {
  924. MFO.WriteLine("$(BUILD_DIR)\\" + makefiletarget + ": $(DEPS_" + SAPI + ") $(" + SAPI + "_GLOBAL_OBJS) $(PHPLIB) $(BUILD_DIR)\\" + resname + " $(BUILD_DIR)\\" + manifest_name);
  925. } else {
  926. MFO.WriteLine("$(BUILD_DIR)\\" + makefiletarget + ": $(DEPS_" + SAPI + ") $(" + SAPI + "_GLOBAL_OBJS) $(BUILD_DIR)\\$(PHPLIB) $(BUILD_DIR)\\" + resname + " $(BUILD_DIR)\\" + manifest_name);
  927. }
  928. if (makefiletarget.match(new RegExp("\\.dll$"))) {
  929. ldflags = "/dll $(LDFLAGS)";
  930. manifest = "-@$(_VC_MANIFEST_EMBED_DLL)";
  931. } else if (makefiletarget.match(new RegExp("\\.lib$"))) {
  932. ldflags = "$(LDFLAGS)";
  933. ld = "$(MAKE_LIB)";
  934. } else {
  935. ldflags = "$(LDFLAGS)";
  936. manifest = "-@$(_VC_MANIFEST_EMBED_EXE)";
  937. }
  938. if(is_pgo_desired(sapiname) && (PHP_PGI == "yes" || PHP_PGO != "no")) {
  939. // Add compiler and link flags if PGO options are selected
  940. if (PHP_DEBUG != "yes" && PHP_PGI == "yes") {
  941. ADD_FLAG('CFLAGS_' + SAPI, "/GL /O2");
  942. ADD_FLAG('LDFLAGS_' + SAPI, "/LTCG:PGINSTRUMENT");
  943. }
  944. else if (PHP_DEBUG != "yes" && PHP_PGO != "no") {
  945. ADD_FLAG('CFLAGS_' + SAPI, "/GL /O2");
  946. ADD_FLAG('LDFLAGS_' + SAPI, "/LTCG:PGUPDATE");
  947. }
  948. ldflags += " /PGD:$(PGOPGD_DIR)\\" + makefiletarget.substring(0, makefiletarget.indexOf(".")) + ".pgd";
  949. }
  950. if (MODE_PHPIZE) {
  951. if (ld) {
  952. MFO.WriteLine("\t" + ld + " /nologo /out:$(BUILD_DIR)\\" + makefiletarget + " " + ldflags + " $(" + SAPI + "_GLOBAL_OBJS) $(PHPLIB) $(LDFLAGS_" + SAPI + ") $(LIBS_" + SAPI + ") $(BUILD_DIR)\\" + resname);
  953. } else {
  954. ld = "@$(CC)";
  955. MFO.WriteLine("\t" + ld + " /nologo " + " $(" + SAPI + "_GLOBAL_OBJS) $(PHPLIB) $(LIBS_" + SAPI + ") $(BUILD_DIR)\\" + resname + " /link /out:$(BUILD_DIR)\\" + makefiletarget + " " + ldflags + " $(LDFLAGS_" + SAPI + ")");
  956. }
  957. } else {
  958. if (ld) {
  959. MFO.WriteLine("\t" + ld + " /nologo /out:$(BUILD_DIR)\\" + makefiletarget + " " + ldflags + " $(" + SAPI + "_GLOBAL_OBJS) $(BUILD_DIR)\\$(PHPLIB) $(LDFLAGS_" + SAPI + ") $(LIBS_" + SAPI + ") $(BUILD_DIR)\\" + resname);
  960. } else {
  961. ld = "@$(CC)";
  962. MFO.WriteLine("\t" + ld + " /nologo " + " $(" + SAPI + "_GLOBAL_OBJS) $(BUILD_DIR)\\$(PHPLIB) $(LIBS_" + SAPI + ") $(BUILD_DIR)\\" + resname + " /link /out:$(BUILD_DIR)\\" + makefiletarget + " " + ldflags + " $(LDFLAGS_" + SAPI + ")");
  963. }
  964. }
  965. if (manifest) {
  966. MFO.WriteLine("\t" + manifest);
  967. }
  968. DEFINE('CFLAGS_' + SAPI + '_OBJ', '$(CFLAGS_' + SAPI + ')');
  969. if (configure_module_dirname.match("pecl")) {
  970. ADD_FLAG("PECL_TARGETS", makefiletarget);
  971. } else {
  972. ADD_FLAG("SAPI_TARGETS", makefiletarget);
  973. }
  974. if (PHP_DSP != "no") {
  975. generate_dsp_file(sapiname, configure_module_dirname, file_list, false);
  976. }
  977. MFO.WriteBlankLines(1);
  978. sapi_enabled[sapi_enabled.length] = [sapiname];
  979. }
  980. function ADD_DIST_FILE(filename)
  981. {
  982. if (configure_module_dirname.match("pecl")) {
  983. ADD_FLAG("PECL_EXTRA_DIST_FILES", filename);
  984. } else {
  985. ADD_FLAG("PHP_EXTRA_DIST_FILES", filename);
  986. }
  987. }
  988. function file_get_contents(filename)
  989. {
  990. var f, c;
  991. try {
  992. f = FSO.OpenTextFile(filename, 1);
  993. c = f.ReadAll();
  994. f.Close();
  995. return c;
  996. } catch (e) {
  997. STDOUT.WriteLine("Problem reading " + filename);
  998. return false;
  999. }
  1000. }
  1001. // Add a dependency on another extension, so that
  1002. // the dependencies are built before extname
  1003. function ADD_EXTENSION_DEP(extname, dependson, optional)
  1004. {
  1005. var EXT = extname.toUpperCase();
  1006. var DEP = dependson.toUpperCase();
  1007. var dep_present = false;
  1008. var dep_shared = false;
  1009. try {
  1010. dep_present = eval("PHP_" + DEP);
  1011. if (dep_present != "no") {
  1012. try {
  1013. dep_shared = eval("PHP_" + DEP + "_SHARED");
  1014. } catch (e) {
  1015. dep_shared = false;
  1016. }
  1017. }
  1018. } catch (e) {
  1019. dep_present = "no";
  1020. }
  1021. if (optional) {
  1022. if (dep_present == "no") {
  1023. MESSAGE("\t" + dependson + " not found: " + dependson + " support in " + extname + " disabled");
  1024. return false;
  1025. }
  1026. }
  1027. var ext_shared = eval("PHP_" + EXT + "_SHARED");
  1028. if (dep_shared) {
  1029. if (!ext_shared) {
  1030. if (optional) {
  1031. MESSAGE("\tstatic " + extname + " cannot depend on shared " + dependson + ": " + dependson + "support disabled");
  1032. return false;
  1033. }
  1034. ERROR("static " + extname + " cannot depend on shared " + dependson);
  1035. }
  1036. ADD_FLAG("LIBS_" + EXT, "php_" + dependson + ".lib");
  1037. if (MODE_PHPIZE) {
  1038. ADD_FLAG("LDFLAGS_" + EXT, "/libpath:$(BUILD_DIR_DEV)\\lib");
  1039. ADD_FLAG("DEPS_" + EXT, "$(BUILD_DIR_DEV)\\lib\\php_" + dependson + ".lib");
  1040. } else {
  1041. ADD_FLAG("LDFLAGS_" + EXT, "/libpath:$(BUILD_DIR)");
  1042. ADD_FLAG("DEPS_" + EXT, "$(BUILD_DIR)\\php_" + dependson + ".lib");
  1043. }
  1044. } else {
  1045. if (dep_present == "no") {
  1046. if (ext_shared) {
  1047. WARNING(extname + " cannot be built: missing dependency, " + dependson + " not found");
  1048. var dllname = ' php_' + extname + '.dll';
  1049. if (!REMOVE_TARGET(dllname, 'EXT_TARGETS')) {
  1050. REMOVE_TARGET(dllname, 'PECL_TARGETS');
  1051. }
  1052. return false;
  1053. }
  1054. ERROR("Cannot build " + extname + "; " + dependson + " not enabled");
  1055. return false;
  1056. }
  1057. } // dependency is statically built-in to PHP
  1058. return true;
  1059. }
  1060. var static_pgo_enabled = false;
  1061. function EXTENSION(extname, file_list, shared, cflags, dllname, obj_dir)
  1062. {
  1063. var objs = null;
  1064. var EXT = extname.toUpperCase();
  1065. var extname_for_printing;
  1066. var ldflags;
  1067. if (shared == null) {
  1068. eval("shared = PHP_" + EXT + "_SHARED;");
  1069. } else {
  1070. eval("PHP_" + EXT + "_SHARED = shared;");
  1071. }
  1072. if (cflags == null) {
  1073. cflags = "";
  1074. }
  1075. if (typeof(obj_dir) == "undefined") {
  1076. extname_for_printing = configure_module_dirname;
  1077. } else {
  1078. extname_for_printing = configure_module_dirname + " (via " + obj_dir + ")";
  1079. }
  1080. if (shared) {
  1081. STDOUT.WriteLine("Enabling extension " + extname_for_printing + " [shared]");
  1082. cflags = "/D COMPILE_DL_" + EXT + " /D " + EXT + "_EXPORTS=1 " + cflags;
  1083. ADD_FLAG("CFLAGS_PHP", "/D COMPILE_DL_" + EXT);
  1084. } else {
  1085. STDOUT.WriteLine("Enabling extension " + extname_for_printing);
  1086. }
  1087. MFO.WriteBlankLines(1);
  1088. MFO.WriteLine("# objects for EXT " + extname);
  1089. MFO.WriteBlankLines(1);
  1090. ADD_SOURCES(configure_module_dirname, file_list, extname, obj_dir);
  1091. MFO.WriteBlankLines(1);
  1092. if (shared) {
  1093. if (dllname == null) {
  1094. dllname = "php_" + extname + ".dll";
  1095. }
  1096. var libname = dllname.substring(0, dllname.length-4) + ".lib";
  1097. var resname = generate_version_info_resource(dllname, extname, configure_module_dirname, false);
  1098. var ld = "@$(CC)";
  1099. var manifest_name = generate_version_info_manifest(dllname);
  1100. ldflags = "";
  1101. if (is_pgo_desired(extname) && (PHP_PGI == "yes" || PHP_PGO != "no")) {
  1102. // Add compiler and link flags if PGO options are selected
  1103. if (PHP_DEBUG != "yes" && PHP_PGI == "yes") {
  1104. ADD_FLAG('LDFLAGS_' + EXT, "/LTCG:PGINSTRUMENT");
  1105. }
  1106. else if (PHP_DEBUG != "yes" && PHP_PGO != "no") {
  1107. ADD_FLAG('LDFLAGS_' + EXT, "/LTCG:PGUPDATE");
  1108. }
  1109. ADD_FLAG('CFLAGS_' + EXT, "/GL /O2");
  1110. ldflags = " /PGD:$(PGOPGD_DIR)\\" + dllname.substring(0, dllname.indexOf(".")) + ".pgd";
  1111. }
  1112. MFO.WriteLine("$(BUILD_DIR)\\" + libname + ": $(BUILD_DIR)\\" + dllname);
  1113. MFO.WriteBlankLines(1);
  1114. if (MODE_PHPIZE) {
  1115. MFO.WriteLine("$(BUILD_DIR)\\" + dllname + ": $(DEPS_" + EXT + ") $(" + EXT + "_GLOBAL_OBJS) $(PHPLIB) $(BUILD_DIR)\\" + resname + " $(BUILD_DIR)\\" + manifest_name);
  1116. MFO.WriteLine("\t" + ld + " $(" + EXT + "_GLOBAL_OBJS) $(PHPLIB) $(LIBS_" + EXT + ") $(LIBS) $(BUILD_DIR)\\" + resname + " /link /out:$(BUILD_DIR)\\" + dllname + " $(DLL_LDFLAGS) $(LDFLAGS) $(LDFLAGS_" + EXT + ")");
  1117. } else {
  1118. MFO.WriteLine("$(BUILD_DIR)\\" + dllname + ": $(DEPS_" + EXT + ") $(" + EXT + "_GLOBAL_OBJS) $(BUILD_DIR)\\$(PHPLIB) $(BUILD_DIR)\\" + resname + " $(BUILD_DIR)\\" + manifest_name);
  1119. MFO.WriteLine("\t" + ld + " $(" + EXT + "_GLOBAL_OBJS) $(BUILD_DIR)\\$(PHPLIB) $(LIBS_" + EXT + ") $(LIBS) $(BUILD_DIR)\\" + resname + " /link /out:$(BUILD_DIR)\\" + dllname + ldflags + " $(DLL_LDFLAGS) $(LDFLAGS) $(LDFLAGS_" + EXT + ")");
  1120. }
  1121. MFO.WriteLine("\t-@$(_VC_MANIFEST_EMBED_DLL)");
  1122. MFO.WriteBlankLines(1);
  1123. if (configure_module_dirname.match("pecl")) {
  1124. ADD_FLAG("PECL_TARGETS", dllname);
  1125. } else {
  1126. ADD_FLAG("EXT_TARGETS", dllname);
  1127. }
  1128. MFO.WriteLine(dllname + ": $(BUILD_DIR)\\" + dllname);
  1129. MFO.WriteLine("\t@echo EXT " + extname + " build complete");
  1130. MFO.WriteBlankLines(1);
  1131. DEFINE('CFLAGS_' + EXT + '_OBJ', '$(CFLAGS_' + EXT + ')');
  1132. } else {
  1133. ADD_FLAG("STATIC_EXT_OBJS", "$(" + EXT + "_GLOBAL_OBJS)");
  1134. ADD_FLAG("STATIC_EXT_LIBS", "$(LIBS_" + EXT + ")");
  1135. ADD_FLAG("STATIC_EXT_LDFLAGS", "$(LDFLAGS_" + EXT + ")");
  1136. ADD_FLAG("STATIC_EXT_CFLAGS", "$(CFLAGS_" + EXT + ")");
  1137. if (is_pgo_desired(extname) && (PHP_PGI == "yes" || PHP_PGO != "no")) {
  1138. if (!static_pgo_enabled) {
  1139. if (PHP_DEBUG != "yes" && PHP_PGI == "yes") {
  1140. ADD_FLAG('STATIC_EXT_LDFLAGS', "/LTCG:PGINSTRUMENT");
  1141. }
  1142. else if (PHP_DEBUG != "yes" && PHP_PGO != "no") {
  1143. ADD_FLAG('STATIC_EXT_LDFLAGS', "/LTCG:PGUPDATE");
  1144. }
  1145. ADD_FLAG("STATIC_EXT_CFLAGS", "/GL /O2");
  1146. static_pgo_enabled = true;
  1147. }
  1148. }
  1149. /* find the header that declares the module pointer,
  1150. * so we can include it in internal_functions.c */
  1151. var ext_dir = FSO.GetFolder(configure_module_dirname);
  1152. var fc = new Enumerator(ext_dir.Files);
  1153. var re = /\.h$/;
  1154. var s, c;
  1155. for (; !fc.atEnd(); fc.moveNext()) {
  1156. s = fc.item() + "";
  1157. if (s.match(re)) {
  1158. c = file_get_contents(s);
  1159. if (c.match("phpext_")) {
  1160. extension_include_code += '#include "' + configure_module_dirname + '/' + FSO.GetFileName(s) + '"\r\n';
  1161. }
  1162. }
  1163. }
  1164. extension_module_ptrs += '\tphpext_' + extname + '_ptr,\r\n';
  1165. DEFINE('CFLAGS_' + EXT + '_OBJ', '$(CFLAGS_PHP) $(CFLAGS_' + EXT + ')');
  1166. }
  1167. if (MODE_PHPIZE && FSO.FileExists(PHP_DIR + "/include/main/config.pickle.h")) {
  1168. cflags = "/FI main/config.pickle.h " + cflags;
  1169. }
  1170. ADD_FLAG("CFLAGS_" + EXT, cflags);
  1171. if (PHP_DSP != "no") {
  1172. generate_dsp_file(extname, configure_module_dirname, file_list, shared);
  1173. }
  1174. extensions_enabled[extensions_enabled.length] = [extname, shared ? 'shared' : 'static'];
  1175. }
  1176. function ADD_SOURCES(dir, file_list, target, obj_dir)
  1177. {
  1178. var i;
  1179. var tv;
  1180. var src, obj, sym, flags;
  1181. if (target == null) {
  1182. target = "php";
  1183. }
  1184. sym = target.toUpperCase() + "_GLOBAL_OBJS";
  1185. flags = "CFLAGS_" + target.toUpperCase() + '_OBJ';
  1186. if (configure_subst.Exists(sym)) {
  1187. tv = configure_subst.Item(sym);
  1188. } else {
  1189. tv = "";
  1190. }
  1191. file_list = file_list.split(new RegExp("\\s+"));
  1192. file_list.sort();
  1193. var re = new RegExp("\.[a-z0-9A-Z]+$");
  1194. dir = dir.replace(new RegExp("/", "g"), "\\");
  1195. var objs_line = "";
  1196. var srcs_line = "";
  1197. var sub_build = "$(BUILD_DIR)\\";
  1198. /* if module dir is not a child of the main source dir,
  1199. * we need to tweak it; we should have detected such a
  1200. * case in condense_path and rewritten the path to
  1201. * be relative.
  1202. * This probably breaks for non-sibling dirs, but that
  1203. * is not a problem as buildconf only checks for pecl
  1204. * as either a child or a sibling */
  1205. if (obj_dir == null) {
  1206. var build_dir = dir.replace(new RegExp("^..\\\\"), "");
  1207. var mangle_dir = build_dir.replace(new RegExp("[\\\\/.-]", "g"), "_");
  1208. var bd_flags_name = "CFLAGS_BD_" + mangle_dir.toUpperCase();
  1209. }
  1210. else {
  1211. var build_dir = obj_dir.replace(new RegExp("^..\\\\"), "");
  1212. var mangle_dir = build_dir.replace(new RegExp("[\\\\/.-]", "g"), "_");
  1213. var bd_flags_name = "CFLAGS_BD_" + mangle_dir.toUpperCase();
  1214. }
  1215. var dirs = build_dir.split("\\");
  1216. var i, d = "";
  1217. for (i = 0; i < dirs.length; i++) {
  1218. d += dirs[i];
  1219. build_dirs[build_dirs.length] = d;
  1220. d += "\\";
  1221. }
  1222. sub_build += d;
  1223. DEFINE(bd_flags_name, " /Fd" + sub_build + " /Fp" + sub_build + " /FR" + sub_build + " ");
  1224. for (i in file_list) {
  1225. src = file_list[i];
  1226. obj = src.replace(re, ".obj");
  1227. tv += " " + sub_build + obj;
  1228. if (!MODE_PHPIZE && PHP_ONE_SHOT == "yes") {
  1229. if (i > 0) {
  1230. objs_line += " " + sub_build + obj;
  1231. srcs_line += " " + dir + "\\" + src;
  1232. } else {
  1233. objs_line = sub_build + obj;
  1234. srcs_line = dir + "\\" + src;
  1235. }
  1236. } else {
  1237. MFO.WriteLine(sub_build + obj + ": " + dir + "\\" + src);
  1238. if (PHP_ANALYZER == "pvs") {
  1239. MFO.WriteLine("\t@\"$(PVS_STUDIO)\" --cl-params $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " --source-file " + dir + "\\" + src
  1240. + " --cfg PVS-Studio.conf --errors-off \"V122 V117 V111\" ");
  1241. }
  1242. MFO.WriteLine("\t@$(CC) $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " /Fo" + sub_build + obj);
  1243. }
  1244. }
  1245. if (!MODE_PHPIZE && PHP_ONE_SHOT == "yes") {
  1246. MFO.WriteLine(objs_line + ": " + srcs_line);
  1247. MFO.WriteLine("\t$(CC) $(" + flags + ") $(CFLAGS) /Fo" + sub_build + " $(" + bd_flags_name + ") /c " + srcs_line);
  1248. }
  1249. DEFINE(sym, tv);
  1250. }
  1251. function REMOVE_TARGET(dllname, flag)
  1252. {
  1253. var dllname = dllname.replace(/\s/g, "");
  1254. var EXT = dllname.replace(/php_(\S+)\.dll/, "$1").toUpperCase();
  1255. var php_flags = configure_subst.Item("CFLAGS_PHP");
  1256. if (configure_subst.Exists(flag)) {
  1257. var targets = configure_subst.Item(flag);
  1258. if (targets.match(dllname)) {
  1259. configure_subst.Remove(flag);
  1260. targets = targets.replace(dllname, "");
  1261. targets = targets.replace(/\s+/, " ");
  1262. targets = targets.replace(/\s$/, "");
  1263. configure_subst.Add(flag, targets);
  1264. configure_hdr.Add("HAVE_" + EXT, new Array(0, ""));
  1265. configure_subst.Item("CFLAGS_PHP") = php_flags.replace(" /D COMPILE_DL_" + EXT, "");
  1266. extensions_enabled.pop();
  1267. return true;
  1268. }
  1269. }
  1270. return false;
  1271. }
  1272. function generate_internal_functions()
  1273. {
  1274. var infile, outfile;
  1275. var indata;
  1276. STDOUT.WriteLine("Generating main/internal_functions.c");
  1277. infile = FSO.OpenTextFile("main/internal_functions.c.in", 1);
  1278. indata = infile.ReadAll();
  1279. infile.Close();
  1280. indata = indata.replace("@EXT_INCLUDE_CODE@", extension_include_code);
  1281. indata = indata.replace("@EXT_MODULE_PTRS@", extension_module_ptrs);
  1282. if (FSO.FileExists("main/internal_functions.c")) {
  1283. var origdata = file_get_contents("main/internal_functions.c");
  1284. if (origdata == indata) {
  1285. STDOUT.WriteLine("\t[content unchanged; skipping]");
  1286. return;
  1287. }
  1288. }
  1289. outfile = FSO.CreateTextFile("main/internal_functions.c", true);
  1290. outfile.Write(indata);
  1291. outfile.Close();
  1292. }
  1293. function output_as_table(header, ar_out)
  1294. {
  1295. var l = header.length;
  1296. var cols = 80;
  1297. var fixedlength = "";
  1298. var t = 0;
  1299. var i,j,k,m;
  1300. var out = "| ";
  1301. var min = new Array(l);
  1302. var max = new Array(l);
  1303. if (!!ar_out[0] && l != ar_out[0].length) {
  1304. STDOUT.WriteLine("Invalid header argument, can't output the table " + l + " " + ar_out[0].length );
  1305. return;
  1306. }
  1307. for (j=0; j < l; j++) {
  1308. var tmax, tmin;
  1309. /*Figure out the max length per column */
  1310. tmin = 0;
  1311. tmax = 0;
  1312. for (k = 0; k < ar_out.length; k++) {
  1313. var t = ar_out[k][j].length;
  1314. if (t > tmax) tmax = t;
  1315. else if (t < tmin) tmin = t;
  1316. }
  1317. if (tmax > header[j].length) {
  1318. max[j] = tmax;
  1319. } else {
  1320. max[j] = header[j].length;
  1321. }
  1322. if (tmin < header[j].length) {
  1323. min[j] = header[j].length;
  1324. }
  1325. }
  1326. sep = "";
  1327. k = 0;
  1328. for (i = 0; i < l; i++) {
  1329. k += max[i] + 3;
  1330. }
  1331. k++;
  1332. for (j=0; j < k; j++) {
  1333. sep += "-";
  1334. }
  1335. STDOUT.WriteLine(sep);
  1336. out = "|";
  1337. for (j=0; j < l; j++) {
  1338. out += " " + header[j];
  1339. for (var i = 0; i < (max[j] - header[j].length); i++){
  1340. out += " ";
  1341. }
  1342. out += " |";
  1343. }
  1344. STDOUT.WriteLine(out);
  1345. STDOUT.WriteLine(sep);
  1346. out = "|";
  1347. for (i=0; i < ar_out.length; i++) {
  1348. line = ar_out[i];
  1349. for (j=0; j < l; j++) {
  1350. out += " " + line[j];
  1351. for (var k = 0; k < (max[j] - line[j].length); k++){
  1352. out += " ";
  1353. }
  1354. out += " |";
  1355. }
  1356. STDOUT.WriteLine(out);
  1357. out = "|";
  1358. }
  1359. STDOUT.WriteLine(sep);
  1360. }
  1361. function write_summary()
  1362. {
  1363. var ar = new Array();
  1364. STDOUT.WriteBlankLines(2);
  1365. STDOUT.WriteLine("Enabled extensions:");
  1366. output_as_table(["Extension", "Mode"], extensions_enabled.sort());
  1367. STDOUT.WriteBlankLines(2);
  1368. if (!MODE_PHPIZE) {
  1369. STDOUT.WriteLine("Enabled SAPI:");
  1370. output_as_table(["Sapi Name"], sapi_enabled);
  1371. STDOUT.WriteBlankLines(2);
  1372. }
  1373. ar[0] = ['Build type', PHP_DEBUG == "yes" ? "Debug" : "Release"];
  1374. ar[1] = ['Thread Safety', PHP_ZTS == "yes" ? "Yes" : "No"];
  1375. ar[2] = ['Compiler', VC_VERSIONS[VCVERS]];
  1376. ar[3] = ['Architecture', X64 ? 'x64' : 'x86'];
  1377. if (PHP_PGO == "yes") {
  1378. ar[4] = ['Optimization', "PGO"];
  1379. } else if (PHP_PGI == "yes") {
  1380. ar[4] = ['Optimization', "PGI"];
  1381. } else {
  1382. ar[4] = ['Optimization', PHP_DEBUG == "yes" ? "disabled" : "PGO disabled"];
  1383. }
  1384. if (PHP_ANALYZER == "vs") {
  1385. ar[5] = ['Static analyzer', 'Visual Studio'];
  1386. } else if (PHP_ANALYZER == "pvs") {
  1387. ar[5] = ['Static analyzer', 'PVS-Studio'];
  1388. } else {
  1389. ar[5] = ['Static analyzer', 'disabled'];
  1390. }
  1391. output_as_table(["",""], ar);
  1392. STDOUT.WriteBlankLines(2);
  1393. }
  1394. function generate_files()
  1395. {
  1396. var i, dir, bd, last;
  1397. STDOUT.WriteBlankLines(1);
  1398. STDOUT.WriteLine("Creating build dirs...");
  1399. dir = get_define("BUILD_DIR");
  1400. build_dirs.sort();
  1401. last = null;
  1402. if (!FSO.FolderExists(dir)) {
  1403. FSO.CreateFolder(dir);
  1404. }
  1405. for (i = 0; i < build_dirs.length; i++) {
  1406. bd = FSO.BuildPath(dir, build_dirs[i]);
  1407. if (bd == last) {
  1408. continue;
  1409. }
  1410. last = bd;
  1411. build_dir = get_define('BUILD_DIR');
  1412. build_dir = build_dir.replace(new RegExp("\\\\", "g"), "\\\\");
  1413. if (build_dir.substr(build_dir.Length - 2, 2) != '\\\\') {
  1414. build_dir += '\\\\';
  1415. }
  1416. ADD_FLAG("BUILD_DIRS_SUB", bd.replace(new RegExp(build_dir), ''));
  1417. if (!FSO.FolderExists(bd)) {
  1418. FSO.CreateFolder(bd);
  1419. }
  1420. }
  1421. if (PHP_DSP != "no") {
  1422. generate_dsp_file("TSRM", "TSRM", null, false);
  1423. generate_dsp_file("Zend", "Zend", null, false);
  1424. generate_dsp_file("win32", "win32", null, false);
  1425. generate_dsp_file("main", "main", null, false);
  1426. generate_dsp_file("streams", "main\\streams", null, false);
  1427. copy_dsp_files();
  1428. }
  1429. STDOUT.WriteLine("Generating files...");
  1430. generate_makefile();
  1431. if (!MODE_PHPIZE) {
  1432. generate_internal_functions();
  1433. generate_config_h();
  1434. generate_phpize();
  1435. } else {
  1436. generate_config_pickle_h();
  1437. generate_ext_pickle();
  1438. }
  1439. STDOUT.WriteLine("Done.");
  1440. STDOUT.WriteBlankLines(1);
  1441. write_summary();
  1442. if (PHP_SNAPSHOT_BUILD != "no") {
  1443. STDOUT.WriteLine("Type 'nmake snap' to build a PHP snapshot");
  1444. } else {
  1445. STDOUT.WriteLine("Type 'nmake' to build PHP");
  1446. }
  1447. }
  1448. function generate_ext_pickle()
  1449. {
  1450. var content;
  1451. var DEPS = null;
  1452. var dest;
  1453. var deps_lines = new Array();
  1454. var build_var_name = function(name) {
  1455. return "PHP_" + name.toUpperCase();
  1456. }
  1457. STDOUT.WriteLine("Generating pickle deps");
  1458. dest = PHP_DIR + "/script/";
  1459. if (!FSO.FolderExists(dest)) {
  1460. FSO.CreateFolder(dest);
  1461. }
  1462. if (FSO.FileExists(dest + "/ext_pickle.js")) {
  1463. DEPS = FSO.OpenTextFile(dest + "/ext_pickle.js", 1);
  1464. while (!DEPS.AtEndOfStream) {
  1465. var ln = DEPS.ReadLine();
  1466. var found = false;
  1467. for (var i in extensions_enabled) {
  1468. var reg0 = new RegExp(build_var_name(extensions_enabled[i][0]) + "\s*=.+", "g");
  1469. var reg1 = new RegExp(build_var_name(extensions_enabled[i][0]) + "_SHARED" + "\s*=.+", "g");
  1470. if (ln.match(reg1) || ln.match(reg0)) {
  1471. found = true;
  1472. break;
  1473. }
  1474. }
  1475. if (!found) {
  1476. deps_lines.push(ln);
  1477. }
  1478. }
  1479. }
  1480. for (var i in extensions_enabled) {
  1481. deps_lines.push(build_var_name(extensions_enabled[i][0]) + "=true;");
  1482. deps_lines.push(build_var_name(extensions_enabled[i][0]) + "_SHARED=" + (extensions_enabled[i][1] == 'shared' ? 'true' : 'false') + ";");
  1483. }
  1484. if (!!DEPS) {
  1485. DEPS.Close();
  1486. DEPS = null;
  1487. }
  1488. /* Replace the ext_pickle.js with the new content */
  1489. DEPS = FSO.CreateTextFile(dest + "/ext_pickle.js", true);
  1490. for (var j in deps_lines) {
  1491. DEPS.WriteLine(deps_lines[j]);
  1492. }
  1493. DEPS.Close();
  1494. }
  1495. function generate_config_pickle_h()
  1496. {
  1497. var outfile = null;
  1498. var lines = new Array();
  1499. var keys = (new VBArray(configure_hdr.Keys())).toArray();
  1500. dest = PHP_DIR + "/include/main";
  1501. var ignore_key = function(key) {
  1502. var ignores = [ "CONFIGURE_COMMAND", "PHP_COMPILER_ID", "COMPILER", "ARCHITECTURE", "HAVE_STRNLEN", "PHP_DIR" ];
  1503. for (var k in ignores) {
  1504. if (ignores[k] == key) {
  1505. return true;
  1506. }
  1507. }
  1508. return false;
  1509. }
  1510. STDOUT.WriteLine("Generating main/config.pickle.h");
  1511. if (FSO.FileExists(dest + "/config.pickle.h")) {
  1512. outfile = FSO.OpenTextFile(dest + "/config.pickle.h", 1);
  1513. while (!outfile.AtEndOfStream) {
  1514. var found = false;
  1515. var ln = outfile.ReadLine();
  1516. for (var i in keys) {
  1517. var reg = new RegExp("#define[\s ]+" + keys[i] + "[\s ]*.*", "g");
  1518. if (ln.match(reg)) {
  1519. found = true;
  1520. break;
  1521. }
  1522. }
  1523. if (!found) {
  1524. lines.push(ln);
  1525. }
  1526. }
  1527. }
  1528. for (var i in keys) {
  1529. var item = configure_hdr.Item(keys[i]);
  1530. if (ignore_key(keys[i])) {
  1531. continue;
  1532. }
  1533. /* XXX fix comment handling */
  1534. /*if (!lines[j].match(/^#define.+/g)) {
  1535. continue;
  1536. }*/
  1537. lines.push("#define " + keys[i] + " " + item[0]);
  1538. }
  1539. if (outfile) {
  1540. outfile.Close();
  1541. outfile = null;
  1542. }
  1543. outfile = FSO.CreateTextFile(dest + "/config.pickle.h", true);
  1544. for (var k in lines) {
  1545. outfile.WriteLine(lines[k]);
  1546. }
  1547. outfile.Close();
  1548. }
  1549. function generate_config_h()
  1550. {
  1551. var infile, outfile;
  1552. var indata;
  1553. var prefix;
  1554. prefix = PHP_PREFIX.replace(new RegExp("\\\\", "g"), "\\\\");
  1555. STDOUT.WriteLine("Generating main/config.w32.h");
  1556. infile = FSO.OpenTextFile("win32/build/config.w32.h.in", 1);
  1557. indata = infile.ReadAll();
  1558. infile.Close();
  1559. outfile = FSO.CreateTextFile("main/config.w32.h", true);
  1560. indata = indata.replace(new RegExp("@PREFIX@", "g"), prefix);
  1561. outfile.Write(indata);
  1562. var keys = (new VBArray(configure_hdr.Keys())).toArray();
  1563. var i, j;
  1564. var item;
  1565. var pieces, stuff_to_crack, chunk;
  1566. outfile.WriteBlankLines(1);
  1567. outfile.WriteLine("/* values determined by configure.js */");
  1568. for (i in keys) {
  1569. item = configure_hdr.Item(keys[i]);
  1570. outfile.WriteBlankLines(1);
  1571. pieces = item[0];
  1572. if (item[1] != undefined) {
  1573. outfile.WriteLine("/* " + item[1] + " */");
  1574. }
  1575. if (typeof(pieces) == "string" && pieces.charCodeAt(0) == 34) {
  1576. /* quoted string have a maximal length of 2k under vc.
  1577. * solution is to crack them and let the compiler concat
  1578. * them implicitly */
  1579. stuff_to_crack = pieces;
  1580. pieces = "";
  1581. while (stuff_to_crack.length) {
  1582. j = 65;
  1583. while (stuff_to_crack.charCodeAt(j) != 32 && j < stuff_to_crack.length)
  1584. j++;
  1585. chunk = stuff_to_crack.substr(0, j);
  1586. pieces += chunk;
  1587. stuff_to_crack = stuff_to_crack.substr(chunk.length);
  1588. if (stuff_to_crack.length)
  1589. pieces += '" "';
  1590. }
  1591. }
  1592. outfile.WriteLine("#define " + keys[i] + " " + pieces);
  1593. }
  1594. outfile.Close();
  1595. }
  1596. function generate_phpize()
  1597. {
  1598. STDOUT.WriteLine("Generating phpize");
  1599. dest = get_define("BUILD_DIR") + '/devel';
  1600. if (!FSO.FolderExists(dest)) {
  1601. FSO.CreateFolder(dest);
  1602. }
  1603. var MF = FSO.CreateTextFile(dest + "/phpize.js", true);
  1604. var DEPS = FSO.CreateTextFile(dest + "/ext_deps.js", true);
  1605. prefix = get_define("PHP_PREFIX");
  1606. prefix = prefix.replace(new RegExp("/", "g"), "\\");
  1607. prefix = prefix.replace(new RegExp("\\\\", "g"), "\\\\");
  1608. MF.WriteLine("var PHP_PREFIX=" + '"' + prefix + '"');
  1609. MF.WriteLine("var PHP_ZTS=" + '"' + (PHP_ZTS.toLowerCase() == "yes" ? "Yes" : "No") + '"');
  1610. MF.WriteLine("var VC_VERSION=" + VCVERS);
  1611. MF.WriteLine("var PHP_VERSION=" + PHP_VERSION);
  1612. MF.WriteLine("var PHP_MINOR_VERSION=" + PHP_MINOR_VERSION);
  1613. MF.WriteLine("var PHP_RELEASE_VERSION=" + PHP_RELEASE_VERSION);
  1614. MF.WriteBlankLines(1);
  1615. MF.WriteLine("/* Genereted extensions list with mode (static/shared) */");
  1616. var count = extensions_enabled.length;
  1617. for (i in extensions_enabled) {
  1618. out = "PHP_" + extensions_enabled[i][0].toUpperCase() + "_SHARED=" + (extensions_enabled[i][1] == 'shared' ? 'true' : 'false') + ";";
  1619. DEPS.WriteLine("PHP_" + extensions_enabled[i][0].toUpperCase() + "=true;");
  1620. DEPS.WriteLine(out);
  1621. MF.WriteLine(out);
  1622. }
  1623. MF.WriteBlankLines(2);
  1624. MF.WriteLine("/* Genereted win32/build/phpize.js.in */");
  1625. MF.WriteBlankLines(1);
  1626. MF.Write(file_get_contents("win32/build/phpize.js.in"));
  1627. MF.Close();
  1628. DEPS.Close();
  1629. /* Generate flags file */
  1630. /* spit out variable definitions */
  1631. CJ = FSO.CreateTextFile(dest + "/config.phpize.js");
  1632. CJ.WriteLine("var PHP_ZTS =" + '"' + PHP_ZTS + '"');
  1633. CJ.WriteLine("var PHP_DLL_LIB =" + '"' + get_define('PHPLIB') + '"');
  1634. CJ.WriteLine("var PHP_DLL =" + '"' + get_define('PHPDLL') + '"');
  1635. /* The corresponding configure options aren't enabled through phpize,
  1636. thus these dummy declarations are required. */
  1637. CJ.WriteLine("var PHP_ANALYZER =" + '"no"');
  1638. CJ.WriteLine("var PHP_PGO =" + '"no"');
  1639. CJ.WriteLine("var PHP_PGI =" + '"no"');
  1640. CJ.WriteLine("var PHP_ALL_SHARED =" + '"no"');
  1641. CJ.WriteBlankLines(1);
  1642. CJ.Close();
  1643. }
  1644. function generate_makefile()
  1645. {
  1646. STDOUT.WriteLine("Generating Makefile");
  1647. var MF = FSO.CreateTextFile("Makefile", true);
  1648. MF.WriteLine("# Generated by configure.js");
  1649. /* spit out variable definitions */
  1650. var keys = (new VBArray(configure_subst.Keys())).toArray();
  1651. var i;
  1652. MF.WriteLine("PHP_SRC_DIR =" + PHP_SRC_DIR);
  1653. for (i in keys) {
  1654. // The trailing space is needed to prevent the trailing backslash
  1655. // that is part of the build dir flags (CFLAGS_BD_XXX) from being
  1656. // seen as a line continuation character
  1657. MF.WriteLine(keys[i] + "=" +
  1658. //word_wrap_and_indent(1, configure_subst.Item(keys[i]), ' \\', '\t') + " "
  1659. configure_subst.Item(keys[i]) + " "
  1660. );
  1661. MF.WriteBlankLines(1);
  1662. }
  1663. MF.WriteBlankLines(1);
  1664. if (MODE_PHPIZE) {
  1665. var TF = FSO.OpenTextFile(PHP_DIR + "/script/Makefile.phpize", 1);
  1666. } else {
  1667. var TF = FSO.OpenTextFile("win32/build/Makefile", 1);
  1668. }
  1669. MF.Write(TF.ReadAll());
  1670. MF.WriteLine("build-headers:");
  1671. MF.WriteLine(" @if not exist $(BUILD_DIR_DEV)\\include mkdir $(BUILD_DIR_DEV)\\include >nul");
  1672. MF.WriteLine(" @for %D in ($(INSTALL_HEADERS_DIR)) do @if not exist $(BUILD_DIR_DEV)\\include\\%D mkdir $(BUILD_DIR_DEV)\\include\\%D >nul");
  1673. for (i in headers_install) {
  1674. if (headers_install[i][2] != "") {
  1675. MF.WriteLine(" @if not exist $(BUILD_DIR_DEV)\\include\\" + headers_install[i][2] + " mkdir $(BUILD_DIR_DEV)\\include\\" +
  1676. headers_install[i][2] + ">nul");
  1677. MF.WriteLine(" @copy " + headers_install[i][0] + " " + "$(BUILD_DIR_DEV)\\include\\" + headers_install[i][2] + " /y >nul");
  1678. }
  1679. }
  1680. MF.WriteLine(" @for %D in ($(INSTALL_HEADERS_DIR)) do @copy %D*.h $(BUILD_DIR_DEV)\\include\\%D /y >nul");
  1681. if (MODE_PHPIZE) {
  1682. MF.WriteBlankLines(1);
  1683. MF.WriteLine("build-bins:");
  1684. for (var i in extensions_enabled) {
  1685. var lib = "php_" + extensions_enabled[i][0] + ".lib";
  1686. var dll = "php_" + extensions_enabled[i][0] + ".dll";
  1687. MF.WriteLine(" @copy $(BUILD_DIR)\\" + lib + " $(BUILD_DIR_DEV)\\lib");
  1688. MF.WriteLine(" @if not exist $(PHP_PREFIX) mkdir $(PHP_PREFIX) >nul");
  1689. MF.WriteLine(" @if not exist $(PHP_PREFIX)\\ext mkdir $(PHP_PREFIX)\\ext >nul");
  1690. MF.WriteLine(" @copy $(BUILD_DIR)\\" + dll + " $(PHP_PREFIX)\\ext");
  1691. }
  1692. } else {
  1693. MF.WriteBlankLines(1);
  1694. MF.WriteLine("build-ext-libs:");
  1695. MF.WriteLine(" @if not exist $(BUILD_DIR_DEV)\\lib mkdir $(BUILD_DIR_DEV)\\lib >nul");
  1696. for (var i in extensions_enabled) {
  1697. var lib;
  1698. lib = "php_" + extensions_enabled[i][0] + "*.lib";
  1699. if ('shared' == extensions_enabled[i][1]) {
  1700. MF.WriteLine(" @if exist $(BUILD_DIR)\\" + lib + " copy $(BUILD_DIR)\\" + lib + " $(BUILD_DIR_DEV)\\lib");
  1701. }
  1702. }
  1703. }
  1704. TF.Close();
  1705. MF.WriteBlankLines(2);
  1706. MFO.Close();
  1707. TF = FSO.OpenTextFile("Makefile.objects", 1);
  1708. if (!TF.AtEndOfStream) {
  1709. MF.Write(TF.ReadAll());
  1710. }
  1711. TF.Close();
  1712. MF.Close();
  1713. }
  1714. function ADD_FLAG(name, flags, target)
  1715. {
  1716. if (target != null) {
  1717. name = target.toUpperCase() + "_" + name;
  1718. }
  1719. if (configure_subst.Exists(name)) {
  1720. var curr_flags = configure_subst.Item(name);
  1721. if (curr_flags.indexOf(flags) >= 0) {
  1722. return;
  1723. }
  1724. flags = curr_flags + " " + flags;
  1725. configure_subst.Remove(name);
  1726. }
  1727. configure_subst.Add(name, flags);
  1728. if (PHP_DSP != "no") {
  1729. if (flags && (name.substr(name.length-3) != "PHP") && (name.substr(0, 7) == "CFLAGS_")) {
  1730. DSP_FLAGS[DSP_FLAGS.length] = new Array(name, flags);
  1731. }
  1732. }
  1733. }
  1734. function get_define(name)
  1735. {
  1736. if (configure_subst.Exists(name)) {
  1737. return configure_subst.Item(name);
  1738. }
  1739. return "";
  1740. }
  1741. // Add a .def to the core to export symbols
  1742. function ADD_DEF_FILE(name)
  1743. {
  1744. if (!configure_subst.Exists("PHPDEF")) {
  1745. DEFINE("PHPDEF", "$(BUILD_DIR)\\$(PHPDLL).def");
  1746. ADD_FLAG("PHP_LDFLAGS", "/def:$(PHPDEF)");
  1747. }
  1748. ADD_FLAG("PHP_DLL_DEF_SOURCES", name);
  1749. }
  1750. function AC_DEFINE(name, value, comment, quote)
  1751. {
  1752. if (quote == null) {
  1753. quote = true;
  1754. }
  1755. if (quote && typeof(value) == "string") {
  1756. value = '"' + value.replace(new RegExp('(["\\\\])', "g"), '\\$1') + '"';
  1757. } else if (value.length == 0) {
  1758. value = '""';
  1759. }
  1760. var item = new Array(value, comment);
  1761. if (configure_hdr.Exists(name)) {
  1762. var orig_item = configure_hdr.Item(name);
  1763. STDOUT.WriteLine("AC_DEFINE[" + name + "]=" + value + ": is already defined to " + orig_item[0]);
  1764. } else {
  1765. configure_hdr.Add(name, item);
  1766. }
  1767. }
  1768. function MESSAGE(msg)
  1769. {
  1770. STDOUT.WriteLine("" + msg);
  1771. }
  1772. function ERROR(msg)
  1773. {
  1774. STDERR.WriteLine("ERROR: " + msg);
  1775. WScript.Quit(3);
  1776. }
  1777. function WARNING(msg)
  1778. {
  1779. STDERR.WriteLine("WARNING: " + msg);
  1780. STDERR.WriteBlankLines(1);
  1781. }
  1782. function copy_and_subst(srcname, destname, subst_array)
  1783. {
  1784. if (!FSO.FileExists(srcname)) {
  1785. srcname = configure_module_dirname + "\\" + srcname;
  1786. destname = configure_module_dirname + "\\" + destname;
  1787. }
  1788. var content = file_get_contents(srcname);
  1789. var i;
  1790. for (i = 0; i < subst_array.length; i+=2) {
  1791. var re = subst_array[i];
  1792. var rep = subst_array[i+1];
  1793. content = content.replace(re, rep);
  1794. }
  1795. var f = FSO.CreateTextFile(destname, true);
  1796. f.Write(content);
  1797. f.Close();
  1798. }
  1799. // glob using simple filename wildcards
  1800. // returns an array of matches that are found
  1801. // in the filesystem
  1802. function glob(path_pattern)
  1803. {
  1804. var path_parts = path_pattern.replace(new RegExp("/", "g"), "\\").split("\\");
  1805. var p;
  1806. var base = "";
  1807. var is_pat_re = /\*/;
  1808. //STDOUT.WriteLine("glob: " + path_pattern);
  1809. if (FSO.FileExists(path_pattern)) {
  1810. return new Array(path_pattern);
  1811. }
  1812. // first, build as much as possible that doesn't have a pattern
  1813. for (p = 0; p < path_parts.length; p++) {
  1814. if (path_parts[p].match(is_pat_re))
  1815. break;
  1816. if (p)
  1817. base += "\\";
  1818. base += path_parts[p];
  1819. }
  1820. return _inner_glob(base, p, path_parts);
  1821. }
  1822. function _inner_glob(base, p, parts)
  1823. {
  1824. var pat = parts[p];
  1825. var full_name = base + "\\" + pat;
  1826. var re = null;
  1827. var items = null;
  1828. if (p == parts.length) {
  1829. return false;
  1830. }
  1831. //STDOUT.WriteLine("inner: base=" + base + " p=" + p + " pat=" + pat);
  1832. if (FSO.FileExists(full_name)) {
  1833. if (p < parts.length - 1) {
  1834. // we didn't reach the full extent of the pattern
  1835. return false;
  1836. }
  1837. return new Array(full_name);
  1838. }
  1839. if (FSO.FolderExists(full_name) && p == parts.length - 1) {
  1840. // we have reached the end of the pattern; no need to recurse
  1841. return new Array(full_name);
  1842. }
  1843. // Convert the pattern into a regexp
  1844. re = new RegExp("^" + pat.replace(/\./g, '\\.').replace(/\*/g, '.*').replace(/\?/g, '.') + "$", "i");
  1845. items = new Array();
  1846. if (!FSO.FolderExists(base)) {
  1847. return false;
  1848. }
  1849. var folder = FSO.GetFolder(base);
  1850. var fc = null;
  1851. var subitems = null;
  1852. var item_name = null;
  1853. var j;
  1854. fc = new Enumerator(folder.SubFolders);
  1855. for (; !fc.atEnd(); fc.moveNext()) {
  1856. item_name = FSO.GetFileName(fc.item());
  1857. if (item_name.match(re)) {
  1858. // got a match; if we are at the end of the pattern, just add these
  1859. // things to the items array
  1860. if (p == parts.length - 1) {
  1861. items[items.length] = fc.item();
  1862. } else {
  1863. // we should recurse and do more matches
  1864. subitems = _inner_glob(base + "\\" + item_name, p + 1, parts);
  1865. if (subitems) {
  1866. for (j = 0; j < subitems.length; j++) {
  1867. items[items.length] = subitems[j];
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. // if we are at the end of the pattern, we should match
  1874. // files too
  1875. if (p == parts.length - 1) {
  1876. fc = new Enumerator(folder.Files);
  1877. for (; !fc.atEnd(); fc.moveNext()) {
  1878. item_name = FSO.GetFileName(fc.item());
  1879. if (item_name.match(re)) {
  1880. items[items.length] = fc.item();
  1881. }
  1882. }
  1883. }
  1884. if (items.length == 0)
  1885. return false;
  1886. return items;
  1887. }
  1888. function PHP_INSTALL_HEADERS(dir, headers_list)
  1889. {
  1890. headers_list = headers_list.split(new RegExp("\\s+"));
  1891. headers_list.sort();
  1892. if (dir.length > 0 && dir.substr(dir.length - 1) != '/' && dir.substr(dir.length - 1) != '\\') {
  1893. dir += '/';
  1894. }
  1895. dir = dir.replace(new RegExp("/", "g"), "\\");
  1896. for (i in headers_list) {
  1897. found = false;
  1898. src = headers_list[i];
  1899. src = src.replace(new RegExp("/", "g"), "\\");
  1900. isdir = FSO.FolderExists(dir + src);
  1901. isfile = FSO.FileExists(dir + src);
  1902. if (isdir) {
  1903. if (src.length > 0 && src.substr(src.length - 1) != '/' && src.substr(src.length - 1) != '\\') {
  1904. src += '\\';
  1905. }
  1906. headers_install[headers_install.length] = [dir + src, 'dir',''];
  1907. ADD_FLAG("INSTALL_HEADERS_DIR", dir + src);
  1908. found = true;
  1909. } else if (isfile) {
  1910. dirname = FSO.GetParentFolderName(dir + src);
  1911. headers_install[headers_install.length] = [dir + src, 'file', dirname];
  1912. ADD_FLAG("INSTALL_HEADERS", dir + src);
  1913. found = true;
  1914. } else {
  1915. path = configure_module_dirname + "\\"+ src;
  1916. isdir = FSO.FolderExists(path);
  1917. isfile = FSO.FileExists(path);
  1918. if (isdir) {
  1919. if (src.length > 0 && src.substr(src.length - 1) != '/' && src.substr(src.length - 1) != '\\') {
  1920. src += '\\';
  1921. }
  1922. headers_install[headers_install.length] = [path, 'dir',''];
  1923. ADD_FLAG("INSTALL_HEADERS_DIR", path);
  1924. } else if (isfile) {
  1925. dirname = FSO.GetParentFolderName(path);
  1926. headers_install[headers_install.length] = [path, 'file', dir];
  1927. ADD_FLAG("INSTALL_HEADERS", dir + src);
  1928. found = true;
  1929. }
  1930. }
  1931. if (found == false) {
  1932. STDOUT.WriteLine(headers_list);
  1933. ERROR("Cannot find header " + dir + src);
  1934. }
  1935. }
  1936. }
  1937. // for snapshot builders, this option will attempt to enable everything
  1938. // and you can then build everything, ignoring fatal errors within a module
  1939. // by running "nmake snap"
  1940. PHP_SNAPSHOT_BUILD = "no";
  1941. if (!MODE_PHPIZE) {
  1942. ARG_ENABLE('snapshot-build', 'Build a snapshot; turns on everything it can and ignores build errors', 'no');
  1943. // one-shot build optimizes build by asking compiler to build
  1944. // several objects at once, reducing overhead of starting new
  1945. // compiler processes.
  1946. ARG_ENABLE('one-shot', 'Optimize for fast build - best for release and snapshot builders, not so hot for edit-and-rebuild hacking', 'no');
  1947. }