File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / win32 / build / projectgen.js
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:48:06 2012 UTC (13 years, 1 month ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, v5_3_10, HEAD
php

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>