1// vim:ft=javascript 2// $Id$ 3// "Master" config file; think of it as a configure.ac 4// equivalent. 5 6ARG_WITH("toolset", "Toolset to use for the compilation, give: vs, clang, icc. " + 7 "The only recommended and supported toolset for production use " + 8 "is Visual Studio. Use others at your own risk.", "vs"); 9toolset_option_handle(); 10 11ARG_WITH('cygwin', 'Path to cygwin utilities on your system', '\\cygwin'); 12 13toolset_setup_compiler(); 14 15// do we use x64 or 80x86 version of compiler? 16X64 = toolset_is_64(); 17toolset_setup_arch(); 18 19toolset_setup_linker(); 20toolset_setup_project_tools(); 21 22// stick objects somewhere outside of the source tree 23ARG_ENABLE('object-out-dir', 'Alternate location for binary objects during build', ''); 24object_out_dir_option_handle(); 25 26ARG_ENABLE('debug', 'Compile with debugging symbols', "no"); 27ARG_ENABLE('debug-pack', 'Release binaries with external debug symbols (--enable-debug must not be specified)', 'no'); 28if (PHP_DEBUG == "yes" && PHP_DEBUG_PACK == "yes") { 29 ERROR("Use of both --enable-debug and --enable-debug-pack not allowed."); 30} 31 32if (PHP_DEBUG == "yes") { 33 ADD_FLAG("CFLAGS"," /Wall "); 34 ADD_FLAG("LDFLAGS", " /verbose "); 35} 36 37ARG_ENABLE('pgi', 'Generate PGO instrumented binaries', 'no'); 38ARG_WITH('pgo', 'Compile optimized binaries using training data from folder', 'no'); 39if (PHP_PGI == "yes" || PHP_PGO != "no") { 40 PGOMGR = PATH_PROG('pgomgr', WshShell.Environment("Process").Item("PATH")); 41 if (!PGOMGR) { 42 ERROR("--enable-pgi and --with-pgo options can only be used if PGO capable compiler is present."); 43 } 44 if (PHP_PGI == "yes" && PHP_PGO != "no") { 45 ERROR("Use of both --enable-pgi and --with-pgo not allowed."); 46 } 47} 48 49ARG_ENABLE('zts', 'Thread safety', 'yes'); 50// Configures the hard-coded installation dir 51ARG_WITH('prefix', 'where PHP will be installed', ''); 52if (PHP_PREFIX == '') { 53 PHP_PREFIX = "C:\\php"; 54 if (PHP_DEBUG == "yes") 55 PHP_PREFIX += "\\debug"; 56} 57DEFINE('PHP_PREFIX', PHP_PREFIX); 58 59DEFINE("BASE_INCLUDES", "/I . /I main /I Zend /I TSRM /I ext "); 60 61toolset_setup_common_cflags(); 62 63ARG_WITH('mp', 'Tell Visual Studio use up to [n,auto,disable] processes for compilation', 'auto'); 64var PHP_MP_DISABLED = true; 65if (VS_TOOLSET && PHP_MP != 'disable') { 66 if(PHP_DEBUG == 'yes') { 67 STDOUT.WriteLine('WARNING: Debug builds cannot be built using multi processing'); 68 } else { 69 // no from disable-all 70 if(PHP_MP == 'auto' || PHP_MP == 'no') { 71 ADD_FLAG('CFLAGS', ' /MP '); 72 PHP_MP_DISABLED = false; 73 } else { 74 if(parseInt(PHP_MP) != 0) { 75 ADD_FLAG('CFLAGS', ' /MP'+ PHP_MP +' '); 76 PHP_MP_DISABLED = false; 77 } else { 78 STDOUT.WriteLine('WARNING: Invalid argument for MP: ' + PHP_MP); 79 } 80 } 81 } 82} 83 84if (!PHP_MP_DISABLED) { 85 STDOUT.WriteLine('Enabling multi process build'); 86} 87 88// General link flags 89toolset_setup_common_ldlags(); 90 91// General libs 92toolset_setup_common_libs(); 93 94// Set some debug/release specific options 95toolset_setup_build_mode(); 96 97setup_zts_stuff(); 98 99// CFLAGS, LDFLAGS and BUILD_DIR are defined 100// Add compiler and link flags if PGO options are selected 101if (PHP_DEBUG != "yes" && PHP_PGI == "yes") { 102 ADD_FLAG("STATIC_EXT_CFLAGS", "/GL /O2"); 103 DEFINE("PGOPGD_DIR", "$(BUILD_DIR)"); 104} 105else if (PHP_DEBUG != "yes" && PHP_PGO != "no") { 106 ADD_FLAG("STATIC_EXT_CFLAGS", "/GL /O2"); 107 DEFINE("PGOPGD_DIR", ((PHP_PGO.length == 0 || PHP_PGO == "yes") ? "$(BUILD_DIR)" : PHP_PGO)); 108} 109 110// Find the php_build dir - it contains headers and libraries 111// that we need 112ARG_WITH('php-build', 'Path to where you extracted the development libraries (http://wiki.php.net/internals/windows/libs). Assumes that it is a sibling of this source dir (..\\deps) if not specified', 'no'); 113php_build_option_handle(); 114 115ARG_WITH('extra-includes', 'Extra include path to use when building everything', ''); 116ARG_WITH('extra-libs', 'Extra library path to use when linking everything', ''); 117 118var php_usual_include_suspects = PHP_PHP_BUILD+"\\include"; 119var php_usual_lib_suspects = PHP_PHP_BUILD+"\\lib"; 120 121ADD_FLAG("CFLAGS", '/I "' + php_usual_include_suspects + '" '); 122ADD_FLAG("LDFLAGS", '/libpath:"' + php_usual_lib_suspects + '" '); 123ADD_FLAG("ARFLAGS", '/nologo /libpath:"' + php_usual_lib_suspects + '" '); 124 125probe_basic_headers(); 126add_extra_dirs(); 127 128//DEFINE("PHP_BUILD", PHP_PHP_BUILD); 129 130ARG_WITH("analyzer", "Enable static analyzer. Pass vs for Visual Studio, clang for clang, cppcheck for Cppcheck, pvs for PVS-Studio", "no"); 131if (PHP_ANALYZER == "vs") { 132 ADD_FLAG("CFLAGS", " /analyze "); 133 ADD_FLAG("CFLAGS", " /wd6308 "); 134} else if (PHP_ANALYZER == "clang") { 135 var clang_cl = false; 136 137 if (FSO.FileExists(PROGRAM_FILES + "\\LLVM\\bin\\clang-cl.exe")) { 138 clang_cl = PROGRAM_FILES + "\\LLVM\\bin\\clang-cl.exe"; 139 } else if (FSO.FileExists(PROGRAM_FILESx86 + "\\LLVM\\bin\\clang-cl.exe")) { 140 clang_cl = PROGRAM_FILESx86 + "\\LLVM\\bin\\clang-cl.exe"; 141 } 142 143 if (!clang_cl) { 144 if (false == PATH_PROG('clang-cl', null, 'CLANG_CL')) { 145 WARNING("Couldn't find clang binaries, static analyze was disabled"); 146 PHP_ANALYZER = "no"; 147 } 148 } else { 149 DEFINE("CLANG_CL", clang_cl); 150 } 151} else if (PHP_ANALYZER == "cppcheck") { 152 153 var cppcheck = false; 154 155 if (FSO.FileExists(PROGRAM_FILES + "\\Cppcheck\\cppcheck.exe")) { 156 cppcheck = PROGRAM_FILES + "\\Cppcheck\\cppcheck.exe"; 157 } else if (FSO.FileExists(PROGRAM_FILESx86 + "\\Cppcheck\\cppcheck.exe")) { 158 cppcheck = PROGRAM_FILESx86 + "\\Cppcheck\\cppcheck.exe"; 159 } 160 if (!cppcheck) { 161 if (false == PATH_PROG('cppcheck', null, 'CPPCHECK')) { 162 WARNING("Couldn't find Cppcheck binaries, static analyze was disabled"); 163 PHP_ANALYZER = "no"; 164 } else { 165 cppcheck = get_define("CPPCHECK"); 166 } 167 } else { 168 DEFINE("CPPCHECK", cppcheck); 169 } 170 171 if (cppcheck) { 172 var _tmp = execute(cppcheck + " --version").split(/ /)[1]; 173 var cppcheck_ver = [ 174 parseInt(_tmp.split(".")[0]), 175 parseInt(_tmp.split(".")[1]), 176 ]; 177 if (cppcheck_ver[0] > 1 || cppcheck_ver[0] == 1 && cppcheck_ver[1] >= 77) { 178 var build_dir = get_define("BUILD_DIR"); 179 var cppcheck_build_dir = build_dir + "\\cppcheck_build"; 180 if (!FSO.FolderExists(cppcheck_build_dir)) { 181 FSO.CreateFolder(cppcheck_build_dir); 182 } 183 DEFINE("CPPCHECK_BUILD_DIR", cppcheck_build_dir); 184 } 185 } 186 187} else if (PHP_ANALYZER == "pvs") { 188 var pvs_studio = false; 189 190 if (FSO.FileExists(PROGRAM_FILES + "\\PVS-Studio\\x64\\PVS-Studio.exe")) { 191 pvs_studio = PROGRAM_FILES + "\\PVS-Studio\\x86\\PVS-Studio.exe"; 192 } else if (FSO.FileExists(PROGRAM_FILESx86 + "\\PVS-Studio\\x64\\PVS-Studio.exe")) { 193 pvs_studio = PROGRAM_FILESx86 + "\\PVS-Studio\\x64\\PVS-Studio.exe"; 194 } 195 196 if (!pvs_studio) { 197 WARNING("Couldn't find PVS-Studio binaries, static analyze was disabled"); 198 PHP_ANALYZER = "no"; 199 } else { 200 var pvscfg = FSO.CreateTextFile("PVS-Studio.conf", true); 201 DEFINE("PVS_STUDIO", pvs_studio); 202 203 pvscfg.WriteLine("exclude-path = " + VCINSTALLDIR); 204 if (FSO.FolderExists(PROGRAM_FILESx86 + "\\windows kits\\")) { 205 pvscfg.WriteLine("exclude-path = " + PROGRAM_FILESx86 + "\\windows kits\\"); 206 } else if (FSO.FolderExists(PROGRAM_FILES + "\\windows kits\\")) { 207 pvscfg.WriteLine("exclude-path = " + PROGRAM_FILES + "\\windows kits\\"); 208 } 209 pvscfg.WriteLine("vcinstalldir = " + VCINSTALLDIR); 210 pvscfg.WriteLine("platform = " + (X64 ? 'x64' : 'Win32')); 211 pvscfg.WriteLine("preprocessor = visualcpp"); 212 pvscfg.WriteLine("language = C"); 213 } 214} else { 215 PHP_ANALYZER = "no" 216} 217 218STDOUT.WriteBlankLines(1); 219STDOUT.WriteLine("Build dir: " + get_define('BUILD_DIR')); 220STDOUT.WriteLine("PHP Core: " + get_define('PHPDLL') + " and " + get_define('PHPLIB')); 221 222ADD_SOURCES("Zend", "zend_language_parser.c zend_language_scanner.c \ 223 zend_ini_parser.c zend_ini_scanner.c zend_alloc.c zend_compile.c \ 224 zend_constants.c zend_exceptions.c \ 225 zend_execute_API.c zend_highlight.c \ 226 zend_llist.c zend_vm_opcodes.c zend_opcode.c zend_operators.c zend_ptr_stack.c \ 227 zend_stack.c zend_variables.c zend.c zend_API.c zend_extensions.c \ 228 zend_hash.c zend_list.c zend_builtin_functions.c \ 229 zend_sprintf.c zend_ini.c zend_sort.c zend_multibyte.c zend_ts_hash.c \ 230 zend_stream.c zend_iterators.c zend_interfaces.c zend_objects.c \ 231 zend_object_handlers.c zend_objects_API.c \ 232 zend_default_classes.c zend_execute.c zend_strtod.c zend_gc.c zend_closures.c \ 233 zend_float.c zend_string.c zend_generators.c zend_virtual_cwd.c zend_ast.c \ 234 zend_inheritance.c zend_smart_str.c"); 235 236ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); 237 238/* XXX inspect this for other toolsets */ 239//AC_DEFINE('ZEND_DVAL_TO_LVAL_CAST_OK', 1); 240 241ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \ 242 php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \ 243 strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \ 244 php_open_temporary_file.c output.c internal_functions.c php_sprintf.c"); 245ADD_FLAG("CFLAGS_BD_MAIN", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); 246 247AC_DEFINE('HAVE_STRNLEN', 1); 248 249ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c plain_wrapper.c \ 250 userspace.c transports.c xp_socket.c mmap.c glob_wrapper.c"); 251ADD_FLAG("CFLAGS_BD_MAIN_STREAMS", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); 252 253ADD_SOURCES("win32", "dllmain.c glob.c readdir.c \ 254 registry.c select.c sendmail.c time.c winutil.c wsyslog.c globals.c \ 255 getrusage.c ftok.c ioutil.c codepage.c nice.c \ 256 inet.c fnmatch.c sockets.c console.c"); 257 258ADD_FLAG("CFLAGS_BD_WIN32", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); 259 260PHP_INSTALL_HEADERS("", "Zend/ TSRM/ main/ main/streams/ win32/"); 261 262STDOUT.WriteBlankLines(1); 263 264 265/* Can we build with IPv6 support? */ 266ARG_ENABLE("ipv6", "Disable IPv6 support (default is turn it on if available)", "yes"); 267 268var main_network_has_ipv6 = 0; 269if (PHP_IPV6 == "yes") { 270 main_network_has_ipv6 = CHECK_HEADER_ADD_INCLUDE("wspiapi.h", "CFLAGS") ? 1 : 0; 271} 272if (main_network_has_ipv6) { 273 STDOUT.WriteLine("Enabling IPv6 support"); 274} 275AC_DEFINE('HAVE_GETADDRINFO', main_network_has_ipv6); 276AC_DEFINE('HAVE_GAI_STRERROR', main_network_has_ipv6); 277AC_DEFINE('HAVE_IPV6', main_network_has_ipv6); 278 279/* this allows up to 256 sockets to be select()ed in a single 280 * call to select(), instead of the usual 64 */ 281ARG_ENABLE('fd-setsize', "Set maximum number of sockets for select(2)", "256"); 282ADD_FLAG("CFLAGS", "/D FD_SETSIZE=" + parseInt(PHP_FD_SETSIZE)); 283 284AC_DEFINE('HAVE_USLEEP', 1); 285AC_DEFINE('HAVE_STRCOLL', 1); 286 287/* For snapshot builders, where can we find the additional 288 * files that make up the snapshot template? */ 289ARG_WITH("snapshot-template", "Path to snapshot builder template dir", "no"); 290 291if (PHP_SNAPSHOT_TEMPLATE == "no") { 292 /* default is as a sibling of the php_build dir */ 293 if (FSO.FolderExists(PHP_PHP_BUILD + "\\template")) { 294 PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\template"); 295 } else if (FSO.FolderExists(PHP_PHP_BUILD + "\\..\\template")) { 296 PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\..\\template"); 297 } 298} 299 300DEFINE('SNAPSHOT_TEMPLATE', PHP_SNAPSHOT_TEMPLATE); 301 302ARG_ENABLE("security-flags", "Disable the compiler security flags", "yes"); 303if (PHP_SECURITY_FLAGS == "yes") { 304 ADD_FLAG("LDFLAGS", "/NXCOMPAT /DYNAMICBASE "); 305} 306 307if (CLANG_TOOLSET) { 308 ARG_WITH("uncritical-warn-choke", "Disable some uncritical warnings", "yes"); 309 if (PHP_UNCRITICAL_WARN_CHOKE != "no") { 310 ADD_FLAG("CFLAGS", "-Wno-ignored-attributes -Wno-deprecated-declarations -Wno-missing-braces \ 311 -Wno-logical-op-parentheses -Wno-msvc-include -Wno-invalid-source-encoding -Wno-unknown-pragmas \ 312 -Wno-unused-command-line-argument"); 313 } 314 315 ARG_ENABLE("sanitizer", "Enable address sanitizer extension", "no"); 316 if (PHP_SANITIZER == "yes") { 317 if (COMPILER_NUMERIC_VERSION < 500) { 318 ERROR("Clang at least 5.0.0 required for sanitation plugins"); 319 } 320 add_asan_opts("CFLAGS", "LIBS", "LDFLAGS"); 321 } 322} 323 324ARG_WITH("codegen-arch", "Architecture for code generation: ia32, sse, sse2, avx, avx2", "no"); 325toolset_setup_codegen_arch(); 326 327ARG_WITH("all-shared", "Force all the non obligatory extensions to be shared", "no"); 328 329// Config profiles (--with-config-profile=<name>) will save a certain config to php-src/config.<name>.bat 330// so that it can be executed like: cofig.<name> instead of a long list of parameters 331// 332// Note, nice as a name is disallowed and will generate a warning and skip saving 333ARG_WITH('config-profile', 'Name of the configuration profile to save this to in php-src/config.name.bat', 'no'); 334 335ARG_ENABLE("test-ini", "Enable automatic php.ini generation. The test.ini will be put \ 336 into the build dir and used to automatically load the shared extensions.", "yes"); 337 338ARG_WITH("test-ini-ext-exclude", "Comma separated list of shared extensions to \ 339 be excluded from the test.ini", "no"); 340