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