Annotation of embedaddon/php/win32/build/confutils.js, revision 1.1.1.1

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

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