File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / win32 / build / confutils.js
Revision 1.1.1.4 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Sun Jun 15 20:04:03 2014 UTC (10 years, 9 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_29, HEAD
php 5.4.29

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

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