diff options
Diffstat (limited to 'win32/build/confutils.js')
-rw-r--r-- | win32/build/confutils.js | 251 |
1 files changed, 196 insertions, 55 deletions
diff --git a/win32/build/confutils.js b/win32/build/confutils.js index 12e89ca8c7..59f51f249e 100644 --- a/win32/build/confutils.js +++ b/win32/build/confutils.js @@ -39,12 +39,18 @@ var INTELVERS = -1; var COMPILER_NUMERIC_VERSION = -1; var COMPILER_NAME = "unknown"; var PHP_OBJECT_OUT_DIR = ""; +var PHP_CONFIG_PROFILE = "no"; +var PHP_SANITIZER = "no"; var PHP_TEST_INI_PATH = ""; var PHP_TEST_INI = ""; var PHP_TEST_INI_EXT_EXCLUDE = ""; -var WINVER = "0x0600"; /* Vista */ +var PHP_MAKEFILE_FRAGMENTS = PHP_SRC_DIR + "\\Makefile.fragments.w32"; + +/* Care also about NTDDI_VERSION and _WIN32_WINNT in config.w32.h.in + and manifest. */ +var WINVER = "0x0601"; /* 7/2008r2 */ // There's a minimum requirement for re2c.. var MINRE2C = "0.13.4"; @@ -60,12 +66,6 @@ var headers_install = new Array(); /* Mapping CL version > human readable name */ var VC_VERSIONS = new Array(); -VC_VERSIONS[1200] = 'MSVC6 (Visual C++ 6.0)'; -VC_VERSIONS[1300] = 'MSVC7 (Visual C++ 2002)'; -VC_VERSIONS[1310] = 'MSVC7.1 (Visual C++ 2003)'; -VC_VERSIONS[1400] = 'MSVC8 (Visual C++ 2005)'; -VC_VERSIONS[1500] = 'MSVC9 (Visual C++ 2008)'; -VC_VERSIONS[1600] = 'MSVC10 (Visual C++ 2010)'; VC_VERSIONS[1700] = 'MSVC11 (Visual C++ 2012)'; VC_VERSIONS[1800] = 'MSVC12 (Visual C++ 2013)'; VC_VERSIONS[1900] = 'MSVC14 (Visual C++ 2015)'; @@ -78,12 +78,6 @@ VC_VERSIONS[1915] = 'MSVC15 (Visual C++ 2017)'; VC_VERSIONS[1916] = 'MSVC15 (Visual C++ 2017)'; var VC_VERSIONS_SHORT = new Array(); -VC_VERSIONS_SHORT[1200] = 'VC6'; -VC_VERSIONS_SHORT[1300] = 'VC7'; -VC_VERSIONS_SHORT[1310] = 'VC7.1'; -VC_VERSIONS_SHORT[1400] = 'VC8'; -VC_VERSIONS_SHORT[1500] = 'VC9'; -VC_VERSIONS_SHORT[1600] = 'VC10'; VC_VERSIONS_SHORT[1700] = 'VC11'; VC_VERSIONS_SHORT[1800] = 'VC12'; VC_VERSIONS_SHORT[1900] = 'VC14'; @@ -117,17 +111,17 @@ if (typeof(CWD) == "undefined") { CWD = FSO.GetParentFolderName(FSO.GetAbsolutePathName("README.GIT-RULES")); } -/* defaults; we pick up the precise versions from configure.in */ +/* defaults; we pick up the precise versions from configure.ac */ var PHP_VERSION = 7; -var PHP_MINOR_VERSION = 1; +var PHP_MINOR_VERSION = 2; var PHP_RELEASE_VERSION = 0; var PHP_EXTRA_VERSION = ""; -var PHP_VERSION_STRING = "7.1.0"; +var PHP_VERSION_STRING = "7.2.0"; /* Get version numbers and DEFINE as a string */ function get_version_numbers() { - var cin = file_get_contents("configure.in"); + var cin = file_get_contents("configure.ac"); if (cin.match(new RegExp("PHP_MAJOR_VERSION=(\\d+)"))) { PHP_VERSION = RegExp.$1; @@ -356,6 +350,7 @@ function conf_process_args() for (i = 0; i < args.length; i++) { arg = args(i); nice += ' "' + arg + '"'; + if (arg == "--help") { configure_help_mode = true; break; @@ -463,7 +458,7 @@ can be built that way. \ 'pcre-regex', 'fastcgi', 'force-cgi-redirect', 'path-info-check', 'zts', 'ipv6', 'memory-limit', 'zend-multibyte', 'fd-setsize', 'memory-manager', - 't1lib', 'pgi', 'pgo', 'all-shared' + 'pgi', 'pgo', 'all-shared', 'config-profile' ); var force; @@ -544,10 +539,31 @@ can be built that way. \ MFO = FSO.CreateTextFile("Makefile.objects", true); - STDOUT.WriteLine("Saving configure options to config.nice.bat"); - var nicefile = FSO.CreateTextFile("config.nice.bat", true); - nicefile.WriteLine(nice + " %*"); - nicefile.Close(); + var profile = false; + + if (PHP_CONFIG_PROFILE != 'no') { + if (PHP_CONFIG_PROFILE.toLowerCase() == 'nice') { + WARNING('Config profile name cannot be named \'nice\''); + } else { + var config_profile = FSO.CreateTextFile('config.' + PHP_CONFIG_PROFILE + '.bat', true); + + config_profile.WriteLine('@echo off'); + config_profile.WriteLine(nice + ' %*'); + config_profile.Close(); + + profile = true; + } + } + + // Only generate an updated config.nice.bat file if a profile was not used + if (!profile) { + STDOUT.WriteLine("Saving configure options to config.nice.bat"); + + var nicefile = FSO.CreateTextFile("config.nice.bat", true); + nicefile.WriteLine('@echo off'); + nicefile.WriteLine(nice + " %*"); + nicefile.Close(); + } AC_DEFINE('CONFIGURE_COMMAND', nice, "Configure line"); } @@ -1013,7 +1029,7 @@ function CHECK_HEADER_ADD_INCLUDE(header_name, flag_name, path_to_check, use_env if (typeof(add_to_flag_only) != "undefined") { ADD_FLAG(flag_name, "/DHAVE_" + sym + "=" + have); - } else { + } else if (!configure_hdr.Exists('HAVE_' + sym)) { AC_DEFINE("HAVE_" + sym, have, "have the " + header_name + " header file"); } @@ -1197,10 +1213,11 @@ function SAPI(sapiname, file_list, makefiletarget, cflags, obj_dir) MFO.WriteLine("$(BUILD_DIR)\\" + makefiletarget + ": $(DEPS_" + SAPI + ") $(" + SAPI + "_GLOBAL_OBJS) $(BUILD_DIR)\\$(PHPLIB) $(BUILD_DIR)\\" + resname + " $(BUILD_DIR)\\" + manifest_name); } + var is_lib = makefiletarget.match(new RegExp("\\.lib$")); if (makefiletarget.match(new RegExp("\\.dll$"))) { ldflags = "/dll $(LDFLAGS)"; manifest = "-@$(_VC_MANIFEST_EMBED_DLL)"; - } else if (makefiletarget.match(new RegExp("\\.lib$"))) { + } else if (is_lib) { ldflags = "$(ARFLAGS)"; ld = "@$(MAKE_LIB)"; } else { @@ -1208,15 +1225,21 @@ function SAPI(sapiname, file_list, makefiletarget, cflags, obj_dir) manifest = "-@$(_VC_MANIFEST_EMBED_EXE)"; } + if (PHP_SANITIZER == "yes") { + if (CLANG_TOOLSET) { + add_asan_opts("CFLAGS_" + SAPI, "LIBS_" + SAPI, (is_lib ? "ARFLAGS_" : "LDFLAGS_") + SAPI); + } + } + if(is_pgo_desired(sapiname) && (PHP_PGI == "yes" || PHP_PGO != "no")) { // Add compiler and link flags if PGO options are selected if (PHP_DEBUG != "yes" && PHP_PGI == "yes") { ADD_FLAG('CFLAGS_' + SAPI, "/GL /O2"); - ADD_FLAG('LDFLAGS_' + SAPI, "/LTCG:PGINSTRUMENT"); + ADD_FLAG('LDFLAGS_' + SAPI, "/LTCG /GENPROFILE"); } else if (PHP_DEBUG != "yes" && PHP_PGO != "no") { ADD_FLAG('CFLAGS_' + SAPI, "/GL /O2"); - ADD_FLAG('LDFLAGS_' + SAPI, "/LTCG:PGUPDATE"); + ADD_FLAG('LDFLAGS_' + SAPI, "/LTCG /USEPROFILE"); } ldflags += " /PGD:$(PGOPGD_DIR)\\" + makefiletarget.substring(0, makefiletarget.indexOf(".")) + ".pgd"; @@ -1411,10 +1434,10 @@ function EXTENSION(extname, file_list, shared, cflags, dllname, obj_dir) if (is_pgo_desired(extname) && (PHP_PGI == "yes" || PHP_PGO != "no")) { // Add compiler and link flags if PGO options are selected if (PHP_DEBUG != "yes" && PHP_PGI == "yes") { - ADD_FLAG('LDFLAGS_' + EXT, "/LTCG:PGINSTRUMENT"); + ADD_FLAG('LDFLAGS_' + EXT, "/LTCG /GENPROFILE"); } else if (PHP_DEBUG != "yes" && PHP_PGO != "no") { - ADD_FLAG('LDFLAGS_' + EXT, "/LTCG:PGUPDATE"); + ADD_FLAG('LDFLAGS_' + EXT, "/LTCG /USEPROFILE"); } ADD_FLAG('CFLAGS_' + EXT, "/GL /O2"); @@ -1678,7 +1701,7 @@ function ADD_SOURCES(dir, file_list, target, obj_dir) MFO.WriteLine("\t@$(CC) $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " /Fo" + sub_build + d + obj); if ("clang" == PHP_ANALYZER) { - MFO.WriteLine("\t\"@$(CLANG_CL)\" " + analyzer_base_args + " $(" + flags + "_ANALYZER) $(CFLAGS_ANALYZER) $(" + bd_flags_name + "_ANALYZER) " + dir + "\\" + src); + MFO.WriteLine("\t@\"$(CLANG_CL)\" " + analyzer_base_args + " $(" + flags + "_ANALYZER) $(CFLAGS_ANALYZER) $(" + bd_flags_name + "_ANALYZER) " + dir + "\\" + src); } else if ("cppcheck" == PHP_ANALYZER) { MFO.WriteLine("\t\"@$(CPPCHECK)\" " + analyzer_base_args + " $(" + flags + "_ANALYZER) $(CFLAGS_ANALYZER) $(" + bd_flags_name + "_ANALYZER) " + analyzer_base_flags + " " + dir + "\\" + src); }else if (PHP_ANALYZER == "pvs") { @@ -2482,6 +2505,11 @@ function generate_makefile() } } } + if (PHP_SANITIZER == "yes") { + if (CLANG_TOOLSET) { + extra_path = extra_path + ";" + get_clang_lib_dir() + "\\windows"; + } + } MF.WriteLine("set-tmp-env:"); MF.WriteLine(" @set PATH=" + extra_path + ";$(PATH)"); @@ -2498,6 +2526,17 @@ function generate_makefile() MF.Write(TF.ReadAll()); } TF.Close(); + MF.WriteBlankLines(2); + + if (FSO.FileExists(PHP_MAKEFILE_FRAGMENTS)) { + TF = FSO.OpenTextFile(PHP_MAKEFILE_FRAGMENTS, 1); + if (!TF.AtEndOfStream) { + MF.Write(TF.ReadAll()); + } + TF.Close(); + MF.WriteBlankLines(2); + FSO.DeleteFile(PHP_MAKEFILE_FRAGMENTS, true); + } MF.Close(); } @@ -2773,11 +2812,6 @@ function PHP_INSTALL_HEADERS(dir, headers_list) PHP_SNAPSHOT_BUILD = "no"; if (!MODE_PHPIZE) { ARG_ENABLE('snapshot-build', 'Build a snapshot; turns on everything it can and ignores build errors', 'no'); - - // one-shot build optimizes build by asking compiler to build - // several objects at once, reducing overhead of starting new - // compiler processes. - ARG_ENABLE('one-shot', 'Optimize for fast build - best for release and snapshot builders, not so hot for edit-and-rebuild hacking', 'no'); } function toolset_option_handle() @@ -2822,8 +2856,9 @@ function toolset_setup_compiler() // 1600 is vs.net 2010 // 1700 is vs.net 2011 // 1800 is vs.net 2012 - // 1900 is vs.net 2014 - // Which version of the compiler do we have?12 + // 1900 is vs.net 2015 + // 1910 is vs.net 2017 + // Which version of the compiler do we have? VCVERS = COMPILER_NUMERIC_VERSION; if (VCVERS < 1700) { @@ -2872,8 +2907,9 @@ function toolset_setup_project_tools() ERROR('bison is required') } - /* TODO throw error, ignore for now for BC. */ - PATH_PROG('sed'); + if (!PATH_PROG('sed')) { + ERROR('sed is required') + } RE2C = PATH_PROG('re2c'); if (RE2C) { @@ -2891,14 +2927,10 @@ function toolset_setup_project_tools() var intmin = (nm[1]-0)*10000 + (nm[2]-0)*100 + (nm[3]-0); if (intvers < intmin) { - STDOUT.WriteLine('WARNING: The minimum RE2C version requirement is ' + MINRE2C); - STDOUT.WriteLine('Parsers will not be generated. Upgrade your copy at http://sf.net/projects/re2c'); - DEFINE('RE2C', ''); - } else { - DEFINE('RE2C_FLAGS', ''); + ERROR('The minimum RE2C version requirement is ' + MINRE2C); } } else { - STDOUT.WriteLine('Parsers will not be regenerated'); + ERROR('re2c is required') } PATH_PROG('zip'); PATH_PROG('lemon'); @@ -3060,8 +3092,9 @@ function toolset_setup_common_cflags() DEFINE('CFLAGS_PHP_OBJ', '$(CFLAGS_PHP) $(STATIC_EXT_CFLAGS)'); // General CFLAGS for building objects - DEFINE("CFLAGS", "/nologo $(BASE_INCLUDES) /D _WINDOWS \ - /D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _MBCS /W3"); + DEFINE("CFLAGS", "/nologo $(BASE_INCLUDES) /D _WINDOWS /D WINDOWS=1 \ + /D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _MBCS /W3 \ + /D _USE_MATH_DEFINES"); if (VS_TOOLSET) { ADD_FLAG("CFLAGS", " /FD "); @@ -3150,7 +3183,7 @@ function toolset_setup_common_ldlags() function toolset_setup_common_libs() { // urlmon.lib ole32.lib oleaut32.lib uuid.lib gdi32.lib winspool.lib comdlg32.lib - DEFINE("LIBS", "kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib Dnsapi.lib psapi.lib"); + DEFINE("LIBS", "kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib Dnsapi.lib psapi.lib bcrypt.lib"); } function toolset_setup_build_mode() @@ -3181,7 +3214,7 @@ function object_out_dir_option_handle() if (PHP_OBJECT_OUT_DIR.length) { PHP_OBJECT_OUT_DIR = FSO.GetAbsolutePathName(PHP_OBJECT_OUT_DIR); if (!FSO.FolderExists(PHP_OBJECT_OUT_DIR)) { - ERROR('you chosen output directory ' + PHP_OBJECT_OUT_DIR + ' does not exist'); + ERROR('chosen output directory ' + PHP_OBJECT_OUT_DIR + ' does not exist'); } PHP_OBJECT_OUT_DIR += '\\'; } else { @@ -3320,25 +3353,133 @@ function force_all_shared() return !!PHP_ALL_SHARED && "yes" == PHP_ALL_SHARED; } +function ADD_MAKEFILE_FRAGMENT(src_file) +{ + var fn_in; + + if ("undefined" == typeof(src_file)) { + fn_in = configure_module_dirname + "\\Makefile.frag.w32"; + } else { + fn_in = src_file; + } + + if (FSO.FileExists(fn_in)) { + var h_in, h_out; + var create_out_fl = !FSO.FileExists(PHP_MAKEFILE_FRAGMENTS); + var open_flags = create_out_fl ? 2 : 8; + + h_in = FSO.OpenTextFile(fn_in, 1); + h_out = FSO.OpenTextFile(PHP_MAKEFILE_FRAGMENTS, open_flags, create_out_fl); + + if (!h_in.AtEndOfStream) { + h_out.Write(h_in.ReadAll()); + h_out.WriteBlankLines(1); + } + + h_in.Close(); + h_out.Close(); + } +} + function SETUP_OPENSSL(target, path_to_check, common_name, use_env, add_dir_part, add_to_flag_only) { var ret = 0; var cflags_var = "CFLAGS_" + target.toUpperCase(); - if (CHECK_LIB("ssleay32.lib", target, path_to_check, common_name) && - CHECK_LIB("libeay32.lib", target, path_to_check, common_name) && - CHECK_LIB("crypt32.lib", target, path_to_check, common_name) && - CHECK_HEADER_ADD_INCLUDE("openssl/ssl.h", cflags_var, path_to_check, use_env, add_dir_part, add_to_flag_only)) { - /* Openssl 1.0.x and lower */ - return 1; - } else if (CHECK_LIB("libcrypto.lib", target, path_to_check) && + if (CHECK_LIB("libcrypto.lib", target, path_to_check) && CHECK_LIB("libssl.lib", target, path_to_check) && CHECK_LIB("crypt32.lib", target, path_to_check, common_name) && CHECK_HEADER_ADD_INCLUDE("openssl/ssl.h", cflags_var, path_to_check, use_env, add_dir_part, add_to_flag_only)) { /* Openssl 1.1.x */ return 2; + } else if (CHECK_LIB("ssleay32.lib", target, path_to_check, common_name) && + CHECK_LIB("libeay32.lib", target, path_to_check, common_name) && + CHECK_LIB("crypt32.lib", target, path_to_check, common_name) && + CHECK_HEADER_ADD_INCLUDE("openssl/ssl.h", cflags_var, path_to_check, use_env, add_dir_part, add_to_flag_only)) { + /* Openssl 1.0.x and lower */ + return 1; } return ret; } +function check_binary_tools_sdk() +{ + var BIN_TOOLS_SDK_VER_MAJOR = 0; + var BIN_TOOLS_SDK_VER_MINOR = 0; + var BIN_TOOLS_SDK_VER_PATCH = 0; + + var out = execute("cmd /c phpsdk_version"); + + if (out.match(/PHP SDK (\d+)\.(\d+)\.(\d+).*/)) { + BIN_TOOLS_SDK_VER_MAJOR = parseInt(RegExp.$1); + BIN_TOOLS_SDK_VER_MINOR = parseInt(RegExp.$2); + BIN_TOOLS_SDK_VER_PATCH = parseInt(RegExp.$3); + } + + /* Basic test, extend by need. */ + if (BIN_TOOLS_SDK_VER_MAJOR < 2) { + ERROR("Incompatible binary tools version. Please consult\r\nhttps://wiki.php.net/internals/windows/stepbystepbuild_sdk_2"); + } +} + +function get_clang_lib_dir() +{ + var ret = null; + var ver = null; + + if (COMPILER_NAME.match(/clang version ([\d\.]+) \((.*)\)/)) { + ver = RegExp.$1; + } else { + ERROR("Faled to determine clang lib path"); + } + + if (X64) { + ret = PROGRAM_FILES + "\\LLVM\\lib\\clang\\" + ver + "\\lib"; + if (!FSO.FolderExists(ret)) { + ret = null; + } + } else { + ret = PROGRAM_FILESx86 + "\\LLVM\\lib\\clang\\" + ver + "\\lib"; + if (!FSO.FolderExists(ret)) { + ret = PROGRAM_FILES + "\\LLVM\\lib\\clang\\" + ver + "\\lib"; + if (!FSO.FolderExists(ret)) { + ret = null; + } + } + } + + if (null == ret) { + ERROR("Invalid clang lib path encountered"); + } + + return ret; +} + +function add_asan_opts(cflags_name, libs_name, ldflags_name) +{ + + var ver = null; + + if (COMPILER_NAME.match(/clang version ([\d\.]+) \((.*)\)/)) { + ver = RegExp.$1; + } else { + ERROR("Faled to determine clang lib path"); + } + + if (!!cflags_name) { + ADD_FLAG(cflags_name, "-fsanitize=address"); + } + if (!!libs_name) { + if (X64) { + ADD_FLAG(libs_name, "clang_rt.asan_dynamic-x86_64.lib clang_rt.asan_dynamic_runtime_thunk-x86_64.lib"); + } else { + ADD_FLAG(libs_name, "clang_rt.asan_dynamic-i386.lib clang_rt.asan_dynamic_runtime_thunk-i386.lib"); + } + } + + if (!!ldflags_name) { + ADD_FLAG(ldflags_name, "/libpath:\"" + get_clang_lib_dir() + "\\windows\""); + } +} + |