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

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

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