projectgen.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /* check for duplicate entries */
  2. function check_duplicates(local, core)
  3. {
  4. if (!local) {
  5. return core;
  6. }
  7. arr = local.split(" ");
  8. for(i = 0; i < arr.length; i++) {
  9. if (core.match(arr[i])) {
  10. continue;
  11. }
  12. core += " " + arr[i];
  13. }
  14. return core;
  15. }
  16. /* read .dsp source blocks */
  17. function read_src_files(ext, tmpl, path)
  18. {
  19. sources = file_get_contents("tmp\\src\\" + ext + ".sources.tmp");
  20. sources = (path ? sources.replace(/\.\//g, path) : sources);
  21. tmpl = tmpl.replace("SOURCEFILES", sources);
  22. FSO.DeleteFile("tmp\\src\\" + ext + ".sources.tmp");
  23. headers = file_get_contents("tmp\\src\\" + ext + ".headers.tmp");
  24. headers = (path ? headers.replace(/\.\//g, path) : headers);
  25. tmpl = tmpl.replace("HEADERFILES", headers);
  26. FSO.DeleteFile("tmp\\src\\" + ext + ".headers.tmp");
  27. return tmpl;
  28. }
  29. /* write a .dsp source block */
  30. function write_src_file(fname, path, intpath, arr)
  31. {
  32. FSO.FolderExists("tmp\\src") ? "" : FSO.CreateFolder("tmp\\src");
  33. var src = FSO.CreateTextFile("tmp\\src\\" + fname, true);
  34. var out = get_define("BUILD_DIR");
  35. var libpath = "";
  36. for (i = 0; i < arr.length; i++) {
  37. if (arr[i].length > 1) {
  38. if (arr[i].match('alloca.c') ||
  39. arr[i].match(/internal_functions_(nw|win32)\.c/) ||
  40. arr[i].match(/flock\.(c|h)/) ||
  41. arr[i].match(/zend_static_allocator\.(c|h)/) ||
  42. arr[i].match(/zend_(ini|language)_scanner_defs\.h/)) {
  43. continue;
  44. }
  45. libpath = arr[i].substr(2, arr[i].lastIndexOf("\\") - 2);
  46. if (libpath) {
  47. libpath = "\\" + libpath;
  48. }
  49. src.WriteLine("# Begin Source File");
  50. src.WriteLine("SOURCE=" + arr[i]);
  51. src.WriteLine('# PROP Intermediate_Dir "' + intpath + out + '\\' + path + libpath + '"');
  52. src.WriteLine("# End Source File");
  53. src.WriteBlankLines(1);
  54. }
  55. }
  56. src.Close();
  57. return;
  58. }
  59. /* generate list of text files */
  60. function generate_text_filelist(ext, ext_dir)
  61. {
  62. var txtdir = FSO.GetFolder(ext_dir);
  63. block = '# Begin Group "Text Files"\r\n\# PROP Default_Filter ""\r\n\r\n';
  64. txt = new Enumerator(txtdir.Files);
  65. for (; !txt.atEnd(); txt.moveNext()) {
  66. fname = FSO.GetFileName(txt.item());
  67. munged = fname.replace(ext, ""); /* TSRM...! */
  68. if (munged.match(/[A-Z]{4}/)){
  69. block += "# Begin Source File\r\n";
  70. block += "SOURCE=./" + fname + "\r\n";
  71. block += "# End Source File\r\n\r\n";
  72. }
  73. }
  74. block += "# End Group\r\n";
  75. return block;
  76. }
  77. /* generate list of resource files */
  78. function generate_resource_filelist(ext, ext_dir)
  79. {
  80. var resdir = FSO.GetFolder(ext_dir);
  81. res = new Enumerator(resdir.Files);
  82. block = "";
  83. for (; !res.atEnd(); res.moveNext()) {
  84. fname = FSO.GetFileName(res.item());
  85. if (fname.match(/\.(ico|rc)/)) {
  86. block += "# Begin Source File\r\n";
  87. block += "SOURCE=./" + fname + "\r\n";
  88. block += "# End Source File\r\n\r\n";
  89. }
  90. }
  91. return block;
  92. }
  93. /* generate parser and scanner files for Zend */
  94. function generate_parsers_or_scanners(arr, type)
  95. {
  96. var filter = (type.match("Parsers") ? "y" : "l");
  97. ret = '# Begin Group "' + type + '"\r\n# PROP Default_Filter "' + filter + '"\r\n\r\n';
  98. for (i = 0; i < arr.length; i++) {
  99. fl = "zend_" + arr[i] + "_" + type.toLowerCase().substr(0, type.length - 1);
  100. ret += "# Begin Source File\r\n";
  101. ret += "SOURCE=.\\" + fl + "." + filter + "\r\n\r\n";
  102. ret += '# Begin Custom Build\r\n\r\n';
  103. if (type.match("Parsers")) {
  104. pre = (arr[i].match(/ini/) ? "ini_ " : "zend ");
  105. ret += fl + ".c " + fl + ".h: " + fl + ".y\r\n";
  106. ret += "\tbison --output=" + fl + ".c -v -d -p " + pre + fl + ".y\r\n\r\n";
  107. } else {
  108. ret += fl + ".c: " + fl + ".l\r\n";
  109. ret += "\tre2c --case-inverted -cbdFt " + fl + "_defs.h -o" + fl + ".c " + fl + ".l\r\n\r\n";
  110. }
  111. ret += "# End Custom Build\r\n";
  112. ret += "# End Source File\r\n";
  113. }
  114. ret += "# End Group\r\n\r\n";
  115. return ret;
  116. }
  117. /* generate .defs file for php5[ts].dll */
  118. function generate_php_defs()
  119. {
  120. var defs = get_define("PHP_DLL_DEF_SOURCES").split(" ");
  121. var bdir = get_define("BUILD_DIR") + "\\";
  122. var file = get_define("PHPLIB").replace("lib", "def");
  123. var path = "..\\" + bdir + file;
  124. var deps = "USERDEP__PHP5TS=";
  125. var cmds = "BuildCmds= \\\r\n";
  126. var cmd = '$(SOURCE) "$(INTDIR)" "$(OUTDIR)"\r\n\t$(BuildCmds)\r\n';
  127. for (i = 0; i < defs.length; i++) {
  128. deps += '"..\\' + defs[i] + '" ';
  129. cmds += "\ttype ..\\" + defs[i] + (i == 0 ? " > " : " >> ") + path + " \\\r\n";
  130. }
  131. ret = '# Begin Group "Defs Files"\r\n\r\n';
  132. ret += "# Begin Source File\r\nSOURCE=" + path + "\r\n\r\n";
  133. ret += deps.substr(0, deps.length-1) + "\r\n# Begin Custom Build - ";
  134. ret += "Generating $(InputPath)\r\nInputPath=" + path + "\r\n\r\n";
  135. ret += cmds + '\r\n\"' + path + '" : ' + cmd + "\r\n";
  136. ret += "# End Custom Build\r\n# End Source File\r\n\r\n";
  137. ret += "# End Group\r\n";
  138. return ret;
  139. }
  140. /* generate win32\wsyslog.h for php5[ts].dll */
  141. function generate_wsyslog()
  142. {
  143. var path = ".\\build\\wsyslog.mc\r\n\r\n";
  144. var intdir = "..\\" + get_define("BUILD_DIR");
  145. ret = "# Begin Source File\r\nSOURCE=" + path;
  146. ret += "# Begin Custom Build\r\nInputDir=.\\build\r\n";
  147. ret += "IntDir=" + intdir + "\r\nInputPath=" + path;
  148. ret += '"wsyslog.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"\r\n';
  149. ret += "\tmc -h $(InputDir)/.. -r $(InputDir) -x $(IntDir) $(InputPath)\r\n\r\n";
  150. ret += "# End Custom Build\r\n# End Source File\r\n";
  151. return ret;
  152. }
  153. /* generate ext\date\lib\timelib_config.h for php5[ts].dll */
  154. function generate_timelib_conf(headers)
  155. {
  156. var file = "timelib_config.h";
  157. var path = "..\\ext\\date\\lib\\timelib_config.h";
  158. var pos = headers.search(file);
  159. var entry = headers.slice(pos, pos + 64);
  160. replace = entry.replace(file, file + ".win32");
  161. replace += "\r\n\r\n# Begin Custom Build\r\nInputDir=..\\ext\\date\\lib\r\n";
  162. replace += "InputPath=" + path + ".win32\r\n\r\n";
  163. replace += '"' + path + '" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"\r\n';
  164. replace += "\tcopy $(InputPath) $(InputDir)\\" + file + "\r\n\r\n";
  165. replace += "# End Custom Build";
  166. headers = headers.replace(entry, replace);
  167. return headers;
  168. }
  169. /* generate php5[ts].dsp */
  170. function generate_core_dsp(core_headers, core_sources, headers, sources, cflags, ldflags, libs)
  171. {
  172. var ts = (PHP_ZTS != "no" ? "ts" : "");
  173. var extname = "php5" + ts;
  174. var tmpl = generate_dsp_file(extname, ".", false, false);
  175. cflags += get_define("CFLAGS_PHP").replace("/D _USRDLL", "");
  176. cflags = cflags.replace(/\/(I|D)(\S)/g, "/$1 $2");
  177. ldflags += get_define("LDFLAGS_PHP");
  178. libs += get_define("LIBS_PHP");
  179. tmpl = tmpl.replace(/LOCALCPP/, cflags.replace(/\"ext/g, '"../ext') + " /c");
  180. tmpl = tmpl.replace(/LOCALLIBS/, libs);
  181. tmpl = tmpl.replace(/LOCALLDFLAGS/, ldflags);
  182. tmpl = tmpl.replace(extname + ".dll", get_define("PHPDLL"));
  183. wsyslog = (core_headers.match("wsyslog.h") ? "" : generate_wsyslog(core_headers));
  184. core_sources = '# Begin Group "CORE"\r\n' + core_sources + "# End Group\r\n";
  185. tmpl = tmpl.replace(/CORESOURCES/, core_sources);
  186. core_headers = '# Begin Group "CORE "\r\n' + core_headers + "# End Group\r\n";
  187. tmpl = tmpl.replace(/COREHEADERS/, core_headers + wsyslog);
  188. headers = generate_timelib_conf(headers);
  189. tmpl = tmpl.replace(/SOURCEFILES/, sources);
  190. tmpl = tmpl.replace(/HEADERFILES/, headers);
  191. defs = generate_php_defs();
  192. tmpl = tmpl.replace(/DEFS/, defs);
  193. dsp = FSO.CreateTextFile("win32\\php5" + ts + ".dsp", true);
  194. STDOUT.WriteLine("\tGenerating win32\\php5" + ts + ".dsp");
  195. dsp.Write(tmpl);
  196. dsp.Close();
  197. return;
  198. }
  199. /* generate .dsw files */
  200. function generate_dsw_files(sblocks, mblocks)
  201. {
  202. var stmpl = file_get_contents("win32\\build\\template.dsw");
  203. var mtmpl = file_get_contents("win32\\build\\template.dsw");
  204. var ts = (PHP_ZTS != "no" ? "ts" : "");
  205. /* push all the sapi blocks to the same tag */
  206. stmpl = stmpl.replace("INSERT", sblocks);
  207. stmpl = (PHP_ZTS != "no" ? stmpl : stmpl.replace(/dllts/g, "dll"));
  208. sdsw = FSO.CreateTextFile("win32\\php5" + ts + ".dsw", true);
  209. STDOUT.WriteLine("\tGenerating win32\\php5" + ts + ".dsw");
  210. sdsw.Write(stmpl);
  211. sdsw.Close();
  212. /* same for shared modules - except that nothing else goes in here */
  213. garbage = mtmpl.slice(200, mtmpl.search("INSERT"));
  214. mtmpl = mtmpl.replace(garbage, "\r\n");
  215. mtmpl = mtmpl.replace("INSERT", mblocks);
  216. mtmpl = (PHP_ZTS != "no" ? mtmpl : mtmpl.replace(/dllts/g, "dll"));
  217. mdsw = FSO.CreateTextFile("win32\\php_modules.dsw", true);
  218. STDOUT.WriteLine("\tGenerating win32\\php_modules.dsw");
  219. mdsw.Write(mtmpl);
  220. mdsw.Close();
  221. return;
  222. }
  223. /* finalize .dsp files and copy to final destination */
  224. function copy_dsp_files()
  225. {
  226. var tmp = FSO.GetFolder("tmp");
  227. var CORE_HEADERS = "";
  228. var CORE_SOURCES = "";
  229. var EXT_HEADERS = "";
  230. var EXT_SOURCES = "";
  231. var EXT_CFLAGS = "";
  232. var EXT_LDFLAGS = "";
  233. var EXT_LIBS = "";
  234. var sblocks = ""; /* for sapis */
  235. var mblocks = ""; /* for modules */
  236. f = new Enumerator(tmp.Files);
  237. for (; !f.atEnd(); f.moveNext()) {
  238. /* retrieve the path */
  239. contents = file_get_contents(f.item());
  240. address = contents.slice(0, contents.indexOf("#"));
  241. contents = contents.slice(contents.indexOf("#")+1);
  242. shared = contents.slice(0, contents.indexOf("#"));
  243. contents = contents.slice(contents.indexOf("#"));
  244. /* pick up module name and path */
  245. path = address.slice(0, address.lastIndexOf("\\")+1);
  246. ext = address.slice(address.lastIndexOf("\\")+1, address.length-4);
  247. EXT = ext.toUpperCase();
  248. if (path.match(/(sapi|ext)/)) {
  249. rel = "..\\..\\";
  250. } else {
  251. rel = "..\\";
  252. }
  253. /* pick up local flags and libs */
  254. cflags = get_define("CFLAGS_" + EXT);
  255. cflags += (ext.match(/(TSRM|Zend)/) ? "/D TSRM_EXPORTS " : "");
  256. cflags += (ext.match(/Zend/) ? "/D LIBZEND_EXPORTS " : "");
  257. libs = get_define("LIBS_" + EXT);
  258. ldflags = get_define("LDFLAGS_" + EXT);
  259. ldflags = ldflags.replace(/(\.\.\\)/g, rel + "$1");
  260. contents = contents.replace(/LOCALCPP/, cflags + " /c");
  261. contents = contents.replace(/LOCALLIBS/, libs);
  262. contents = contents.replace(/LOCALLDFLAGS/, ldflags);
  263. if (ext.match("Zend")) {
  264. arr = new Array("ini", "language");
  265. parsers = generate_parsers_or_scanners(arr, "Parsers");
  266. scanners = generate_parsers_or_scanners(arr, "Scanners");
  267. contents = contents.replace(/DEFS/, parsers + scanners);
  268. }
  269. /* none of these are core... */
  270. contents = contents.replace(/\r\n(CORESOURCES|COREHEADERS|EXTSOURCES|EXTHEADERS|DEFS)\r\n/g, "");
  271. if (address.match("sapi")) {
  272. /* most sapis are .dlls, just not cgi, cli, embed */
  273. if (ext == "cli") {
  274. /* change of address: php.dsp */
  275. newext = "cli";
  276. address = "win32\\php.dsp";
  277. srcpath = "..\\" + path;
  278. contents = contents.replace(/cli\.exe/g, "php.exe");
  279. } else if (ext == "cgi") {
  280. /* change of address: php-cgi.dsp */
  281. newext = "cgi";
  282. address = "win32\\php-cgi.dsp";
  283. srcpath = "..\\" + path;
  284. contents = contents.replace(/cgi\.exe/g, "php-cgi.exe");
  285. } else {
  286. /* there's always one... most sapis just get a 'php5' prefix */
  287. newext = (ext.match(/apache2handler/) ? "php5apache2" : "php5" + ext);
  288. address = address.replace(ext + ".dsp", newext + ".dsp");
  289. srcpath = ".\\";
  290. oldext = new RegExp(('[^=\\\\]'+ext), "g");
  291. contents = contents.replace(oldext, newext);
  292. contents = contents.replace(ext + ".dll", newext + ".dll");
  293. contents = contents.replace("CFG=" + ext, "CFG=" + newext);
  294. }
  295. contents = read_src_files(ext, contents, (srcpath ? srcpath : false));
  296. dsp = FSO.CreateTextFile(address, true);
  297. STDOUT.WriteLine("\tGenerating " + address);
  298. dsp.Write(contents);
  299. dsp.Close();
  300. /* add all configured sapis to the list in php5ts.dsw */
  301. sblocks += file_get_contents("win32\\build\\block.template.dsw");
  302. sblocks = sblocks.replace("ADDRESS", address);
  303. sblocks = sblocks.replace("EXTNAME", newext);
  304. } else if (address.match("ext") && shared == "true") {
  305. /* independent modules with their own .dsp */
  306. contents = read_src_files(ext, contents, false);
  307. dsp = FSO.CreateTextFile(address, true);
  308. STDOUT.WriteLine("\tGenerating " + address);
  309. dsp.Write(contents);
  310. dsp.Close();
  311. mblocks += file_get_contents("win32\\build\\block.template.dsw");
  312. mblocks = mblocks.replace("ADDRESS", address);
  313. mblocks = mblocks.replace("EXTNAME", ext);
  314. } else if (ext.match(/(TSRM|Zend)/)) {
  315. contents = read_src_files(ext, contents, false);
  316. dsp = FSO.CreateTextFile(address, true);
  317. STDOUT.WriteLine("\tGenerating " + address);
  318. dsp.Write(contents);
  319. dsp.Close();
  320. } else {
  321. /* bound for php5[ts].dsp */
  322. cflags = get_define("CFLAGS_" + EXT);
  323. cflags = cflags ? cflags.replace(/-(I|D)/g, " /$1") : "";
  324. cflags = cflags? cflags.replace(/\/(I|D)\s+/g, "/$1") : "";
  325. cflags = cflags ? cflags.replace(/\/I(?!\")(\S+)/g, '/I"$1"') : "";
  326. EXT_CFLAGS = check_duplicates(cflags, EXT_CFLAGS);
  327. EXT_LDFLAGS = check_duplicates(ldflags, EXT_LDFLAGS);
  328. EXT_LIBS = check_duplicates(libs, EXT_LIBS);
  329. beginh = '# Begin Group "' + ext + ' "\r\n';
  330. begins = '# Begin Group "' + ext + '"\r\n';
  331. hdr = file_get_contents("tmp\\src\\" + ext + ".headers.tmp");
  332. hdr = hdr.replace(/\.\//g, "..\\" + path);
  333. hdr = hdr.replace(/\.\.\\\.\.\\/g, "..\\");
  334. src = file_get_contents("tmp\\src\\" + ext + ".sources.tmp");
  335. src = src.replace(/\.\//g, "..\\" + path);
  336. src = src.replace(/\.\.\\\.\.\\/g, "..\\");
  337. if (ext.match(/(main|standard|streams|win32)/)) {
  338. CORE_HEADERS += beginh + hdr + "# End Group\r\n";
  339. CORE_SOURCES += begins + src + "# End Group\r\n";
  340. } else {
  341. EXT_HEADERS += beginh + hdr + "# End Group\r\n";
  342. EXT_SOURCES += begins + src + "# End Group\r\n";
  343. }
  344. FSO.DeleteFile("tmp\\src\\" + ext + ".headers.tmp");
  345. FSO.DeleteFile("tmp\\src\\" + ext + ".sources.tmp");
  346. }
  347. FSO.DeleteFile(f.item());
  348. }
  349. generate_core_dsp(CORE_HEADERS, CORE_SOURCES, EXT_HEADERS, EXT_SOURCES, EXT_CFLAGS, EXT_LDFLAGS, EXT_LIBS);
  350. generate_dsw_files(sblocks, mblocks);
  351. /* goodnight vienna */
  352. FSO.DeleteFolder("tmp\\src");
  353. FSO.DeleteFolder("tmp");
  354. }
  355. /* generate source and header entries for .dsp files */
  356. function generate_dsp_filelist(ext, ext_dir, files, intpath)
  357. {
  358. var EXT = ext.toUpperCase();
  359. var tabs = new RegExp("[\t\r\n\'\"]", "gm");
  360. var ws = new RegExp("\\s+", "g");
  361. var dir = FSO.GetFolder(ext_dir);
  362. var configfile = FSO.BuildPath(ext_dir, "config.w32");
  363. var headers = "";
  364. var path = "";
  365. if (!files) {
  366. /* module either lacks a config.w32 or is core
  367. * either way, we know nothing about its sources
  368. */
  369. files = "";
  370. f = new Enumerator(dir.Files);
  371. for (; !f.atEnd(); f.moveNext()) {
  372. name = FSO.GetFileName(f.item());
  373. if (name.substr(name.length-2) == ".c") {
  374. files += " ./" + name;
  375. }
  376. }
  377. } else {
  378. files = files.replace(tabs, "");
  379. files = "./" + files.replace(/ /g, " ./");
  380. }
  381. DSP_SOURCES = files.split(" ");
  382. /* pick up headers (all modules) */
  383. f = new Enumerator(dir.Files);
  384. for (; !f.atEnd(); f.moveNext()) {
  385. name = FSO.GetFileName(f.item());
  386. if (name.substr(name.length-2) == ".h") {
  387. headers += " ./" + name;
  388. }
  389. }
  390. DSP_HEADERS = headers.split(" ");
  391. /* check for bundled library paths and sourcefiles */
  392. if (FSO.FileExists(configfile)) {
  393. config = file_get_contents(configfile);
  394. if (config.match("ADD_SOURCES")) {
  395. sources = new RegExp("ADD_SOURCES\\([^,]*\\s*,\\s*['\"]([^'\"]+)['\"].*\\)", "gm");
  396. arr = config.match(sources);
  397. line = arr[0].replace(tabs, "");
  398. line = line.replace(/ADD_SOURCES\((.+)\)/, "$1");
  399. newarr = line.split(',');
  400. orig_path = newarr[0].replace(/\//g, "\\");
  401. orig_path = orig_path.replace(/configure_module_dirname(\s?\+\s?)?/, ext_dir);
  402. path = orig_path.replace(ext_dir + '\\', "");
  403. if (path.length > 0 && path != ext_dir) {
  404. subdir = FSO.GetFolder(orig_path);
  405. lib = new Enumerator(subdir.Files);
  406. libheaders = "";
  407. for (; !lib.atEnd(); lib.moveNext()) {
  408. name = FSO.GetFileName(lib.item());
  409. if (name.substr(name.length-2) == ".h") {
  410. libheaders += " ./" + path + "\\" + name;
  411. }
  412. }
  413. DSP_HEADERS = DSP_HEADERS.concat(libheaders.split(" "));
  414. } else {
  415. path = "";
  416. }
  417. sources = newarr[1].replace(/\\/g, ""); /* continuation lines */
  418. sources = sources.replace(ws, " ");
  419. sources = sources.replace(/\s/g, (path ? " ./" + path + "\\" : " ./"));
  420. sources = check_duplicates(DSP_SOURCES.join(" "), sources);
  421. DSP_SOURCES = sources.split(" ");
  422. }
  423. }
  424. /* store the array contents in temp files for now */
  425. write_src_file(ext + ".headers.tmp", ext_dir, intpath, DSP_HEADERS);
  426. write_src_file(ext + ".sources.tmp", ext_dir, intpath, DSP_SOURCES);
  427. return;
  428. }
  429. /* entry point. Called from EXTENSION(), SAPI() and generate_files() (confutils.js) */
  430. function generate_dsp_file(ext, ext_dir, files, shared)
  431. {
  432. var dsp = FSO.CreateTextFile("tmp\\" + ext + ".dsp", true);
  433. var tmpl = file_get_contents("win32\\build\\template.dsp");
  434. var ts = (PHP_ZTS != "no" ? "ts" : "");
  435. var debug = (PHP_DEBUG != "no" ? " /debug" : "");
  436. var ld = (debug ? "/LDd" : "/LD");
  437. var status = (PHP_DEBUG == "no" ? 'Release' : 'Debug');
  438. var statusts = status + (ts ? "_" + ts.toUpperCase() : "");
  439. var baseflags = "";
  440. /* store the final path and value of shared in the tmp file */
  441. if (!ext.match("php5")) {
  442. tmpl = ext_dir + "\\" + ext + ".dsp#" + shared + tmpl;
  443. }
  444. tmpl = tmpl.replace(/extname/g, ext);
  445. tmpl = tmpl.replace(/Status_TS/g, statusts);
  446. if (debug) {
  447. tmpl = tmpl.replace(/Use_Debug_Libraries 0/g, "Use_Debug_Libraries 1");
  448. tmpl = tmpl.replace(/NDEBUG/g, "_DEBUG");
  449. }
  450. if (ext == "cli" || ext == "cgi") {
  451. tmpl = tmpl.replace(/Dynamic-Link Library/g, "Console Application");
  452. tmpl = tmpl.replace(/0x0102/, "0x0103");
  453. path = "..\\";
  454. type = ".exe";
  455. } else if (ext == "embed" || ext == "TSRM" || ext == "Zend") {
  456. tmpl = tmpl.replace(/Dynamic-Link/g, "Static");
  457. tmpl = tmpl.replace(/0x0102/, "0x0104");
  458. tmpl = tmpl.replace(/LINK32/g, "LIB32");
  459. tmpl = tmpl.replace("link.exe", "link.exe -lib");
  460. tmpl = tmpl.replace(/BASELIBS/g, "/nologo");
  461. tmpl = tmpl.replace(/\s(LOCALLIBS|BASELDFLAGS|LOCALLDFLAGS|OUTPATH)/g, "");
  462. path = "..\\";
  463. if (ext == "embed") {
  464. path += "..\\";
  465. }
  466. type = ".lib";
  467. } else if (ext.match("php5")) {
  468. path = "..\\";
  469. type = ".dll";
  470. } else {
  471. path = "..\\..\\";
  472. type = ".dll";
  473. }
  474. outpath = path + get_define("BUILD_DIR");
  475. tmpl = tmpl.replace(/OUTPUTDIR/g, outpath);
  476. /* populate the baseline CFLAGS and libs */
  477. cflags = get_define("CFLAGS").replace(/\s+/g, " ");
  478. cflags = cflags.replace('/I "..\\bindlib_w32" ', "");
  479. bcflags = (cflags.replace(/\/([A-Z])\s/g, "/$1")).split(" ");
  480. for (i= 0; i < bcflags.length; i++) {
  481. baseflags += (bcflags[i].match(/(PHP|ZEND|ZTS|BASE|FD|WINDOWS)/) ? "" : bcflags[i]);
  482. }
  483. baseflags = baseflags.replace(/\//g, " /");
  484. baseflags = baseflags.substr(1).replace(/(\/D)/g, "$1 ") + " /c";
  485. tmpl = tmpl.replace(/BASECPP/, (type == ".dll" ? baseflags : baseflags.replace(ld + " ", "")));
  486. tmpl = tmpl.replace(/BASELIBS/, "/nologo " + get_define("LIBS").replace(/\sresolv.lib/, ""));
  487. /* now populate the bases in the 'local' lines */
  488. incs = get_define("BASE_INCLUDES").replace(/\/I (\S+)/g, '/I "' + path + '$1"');
  489. incs = incs.replace('"' + path + '."', '".."');
  490. lcflags = cflags.replace(/\$\(BASE_INCLUDES\)/, incs + (type == ".exe" ? '/I "..\\sapi" ' : "") + '/I "' + path + '..\\bindlib_w32"');
  491. tmpl = tmpl.replace(/BASECPP/, (type == ".dll" ? lcflags : lcflags.replace(ld + " ", "")));
  492. tmpl = tmpl.replace(/BASELIBS/, "/nologo " + get_define("LIBS") + " " + (ext.match("php5") ? "" : get_define("PHPLIB")));
  493. ldflags = get_define("LDFLAGS").replace(/\s?(\/nologo|\/libpath:\S+)\s?/g, "");
  494. tmpl = tmpl.replace(/BASELDFLAGS/, ldflags + (type == ".dll" ? " " + get_define("DLL_LDFLAGS") : "") + (debug ? ' /nodefaultlib:"msvcrt"' : ""));
  495. out = '/out:"' + outpath + "\\" + ext + type + '"' + ' /libpath:"' + outpath + '"' + ' /libpath:"..\\' + path + 'bindlib_w32\\' + status + '"';
  496. tmpl = tmpl.replace(/OUTPATH/, out);
  497. txt = generate_text_filelist(ext, ext_dir);
  498. res = generate_resource_filelist(ext, ext_dir);
  499. tmpl = tmpl.replace(/TEXTFILES/, txt);
  500. tmpl = tmpl.replace(/RESOURCEFILES/, res);
  501. if (ext.match("php5")) {
  502. return tmpl;
  503. }
  504. /* generate source and header blocks for .dsp */
  505. generate_dsp_filelist(ext, ext_dir, files, path);
  506. dsp.Write(tmpl);
  507. dsp.Close();
  508. return;
  509. }