xref: /PHP-7.4/win32/build/config.w32 (revision ea3afcba)
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	}
219} else {
220	PHP_ANALYZER = "no"
221}
222
223STDOUT.WriteBlankLines(1);
224STDOUT.WriteLine("Build dir: " + get_define('BUILD_DIR'));
225STDOUT.WriteLine("PHP Core:  " + get_define('PHPDLL') + " and " + get_define('PHPLIB'));
226
227ADD_SOURCES("Zend", "zend_language_parser.c zend_language_scanner.c \
228	zend_ini_parser.c zend_ini_scanner.c zend_alloc.c zend_compile.c \
229	zend_constants.c zend_exceptions.c \
230	zend_execute_API.c zend_highlight.c \
231	zend_llist.c zend_vm_opcodes.c zend_opcode.c zend_operators.c zend_ptr_stack.c \
232	zend_stack.c zend_variables.c zend.c zend_API.c zend_extensions.c \
233	zend_hash.c zend_list.c zend_builtin_functions.c \
234	zend_ini.c zend_sort.c zend_multibyte.c zend_ts_hash.c \
235	zend_stream.c zend_iterators.c zend_interfaces.c zend_objects.c \
236	zend_object_handlers.c zend_objects_API.c \
237	zend_default_classes.c zend_execute.c zend_strtod.c zend_gc.c zend_closures.c zend_weakrefs.c \
238	zend_float.c zend_string.c zend_generators.c zend_virtual_cwd.c zend_ast.c \
239	zend_inheritance.c zend_smart_str.c zend_cpuinfo.c");
240
241ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
242if (VS_TOOLSET && VCVERS >= 1914) {
243	ADD_FLAG("CFLAGS_BD_ZEND", "/d2FuncCache1");
244}
245
246/* XXX inspect this for other toolsets */
247//AC_DEFINE('ZEND_DVAL_TO_LVAL_CAST_OK', 1);
248
249ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \
250	php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
251	strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \
252	php_open_temporary_file.c output.c internal_functions.c \
253	php_syslog.c");
254ADD_FLAG("CFLAGS_BD_MAIN", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
255if (VS_TOOLSET && VCVERS >= 1914) {
256	ADD_FLAG("CFLAGS_BD_MAIN", "/d2FuncCache1");
257}
258
259AC_DEFINE('HAVE_STRNLEN', 1);
260
261ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c plain_wrapper.c \
262	userspace.c transports.c xp_socket.c mmap.c glob_wrapper.c");
263ADD_FLAG("CFLAGS_BD_MAIN_STREAMS", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
264if (VS_TOOLSET && VCVERS >= 1914) {
265	ADD_FLAG("CFLAGS_BD_MAIN_STREAMS", "/d2FuncCache1");
266}
267
268ADD_SOURCES("win32", "dllmain.c glob.c readdir.c \
269	registry.c select.c sendmail.c time.c winutil.c wsyslog.c globals.c \
270	getrusage.c ftok.c ioutil.c codepage.c nice.c \
271	inet.c fnmatch.c sockets.c console.c signal.c");
272
273ADD_FLAG("CFLAGS_BD_WIN32", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
274if (VS_TOOLSET && VCVERS >= 1914) {
275	ADD_FLAG("CFLAGS_BD_WIN32", "/d2FuncCache1");
276}
277
278PHP_INSTALL_HEADERS("", "Zend/ TSRM/ main/ main/streams/ win32/");
279
280STDOUT.WriteBlankLines(1);
281
282
283/* Can we build with IPv6 support? */
284ARG_ENABLE("ipv6", "Disable IPv6 support (default is turn it on if available)", "yes");
285
286var main_network_has_ipv6 = 0;
287if (PHP_IPV6 == "yes") {
288	main_network_has_ipv6 = CHECK_HEADER_ADD_INCLUDE("wspiapi.h", "CFLAGS") ? 1 : 0;
289}
290if (main_network_has_ipv6) {
291	STDOUT.WriteLine("Enabling IPv6 support");
292}
293AC_DEFINE('HAVE_GETADDRINFO', main_network_has_ipv6);
294AC_DEFINE('HAVE_GAI_STRERROR', main_network_has_ipv6);
295AC_DEFINE('HAVE_IPV6', main_network_has_ipv6);
296
297/* this allows up to 256 sockets to be select()ed in a single
298 * call to select(), instead of the usual 64 */
299ARG_ENABLE('fd-setsize', "Set maximum number of sockets for select(2)", "256");
300ADD_FLAG("CFLAGS", "/D FD_SETSIZE=" + parseInt(PHP_FD_SETSIZE));
301
302/* For snapshot builders, where can we find the additional
303 * files that make up the snapshot template? */
304ARG_WITH("snapshot-template", "Path to snapshot builder template dir", "no");
305
306if (PHP_SNAPSHOT_TEMPLATE == "no") {
307	/* default is as a sibling of the php_build dir */
308	if (FSO.FolderExists(PHP_PHP_BUILD + "\\template")) {
309		PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\template");
310	} else if (FSO.FolderExists(PHP_PHP_BUILD + "\\..\\template")) {
311		PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\..\\template");
312	}
313}
314
315DEFINE('SNAPSHOT_TEMPLATE', PHP_SNAPSHOT_TEMPLATE);
316
317ARG_ENABLE("security-flags", "Disable the compiler security flags", "yes");
318if (PHP_SECURITY_FLAGS == "yes") {
319	ADD_FLAG("LDFLAGS", "/NXCOMPAT /DYNAMICBASE ");
320}
321
322if (CLANG_TOOLSET) {
323	ARG_WITH("uncritical-warn-choke", "Disable some uncritical warnings", "yes");
324	if (PHP_UNCRITICAL_WARN_CHOKE != "no") {
325		ADD_FLAG("CFLAGS", "-Wno-ignored-attributes -Wno-deprecated-declarations -Wno-missing-braces " +
326		"-Wno-logical-op-parentheses -Wno-msvc-include -Wno-invalid-source-encoding -Wno-unknown-pragmas " +
327		"-Wno-unused-command-line-argument -Wno-unused-function -Wno-ignored-pragma-optimize");
328	}
329
330	ARG_ENABLE("sanitizer", "Enable ASan and UBSan extensions", "no");
331	if (PHP_SANITIZER == "yes") {
332		if (COMPILER_NUMERIC_VERSION < 500) {
333			ERROR("Clang at least 5.0.0 required for sanitation plugins");
334		}
335		add_asan_opts("CFLAGS", "LIBS", "LDFLAGS");
336	}
337}
338
339ARG_WITH("codegen-arch", "Architecture for code generation: ia32. Use --enable-native-intrinsics to enable SIMD optimizations.", "no");
340toolset_setup_codegen_arch();
341
342ARG_WITH("all-shared", "Force all the non obligatory extensions to be shared", "no");
343
344// Config profiles (--with-config-profile=<name>) will save a certain config to php-src/config.<name>.bat
345// so that it can be executed like: cofig.<name> instead of a long list of parameters
346//
347// Note, nice as a name is disallowed and will generate a warning and skip saving
348ARG_WITH('config-profile', 'Name of the configuration profile to save this to in php-src/config.name.bat', 'no');
349
350ARG_ENABLE("test-ini", "Enable automatic php.ini generation. The test.ini will be put \
351		into the build dir and used to automatically load the shared extensions.", "yes");
352
353ARG_WITH("test-ini-ext-exclude", "Comma separated list of shared extensions to \
354		be excluded from the test.ini", "no");
355
356ARG_ENABLE("native-intrinsics", "Comma separated list of intrinsic optimizations to enable. \
357	Available instruction set names are sse, sse2, sse3, ssse3, sse4.1, sse4.2, avx, avx2. \
358	SSE and SSE2 are enabled by default. The best instruction set specified will \
359	automatically enable all the older instruction sets. Note, that the produced binary \
360	might not work properly, if the chosen instruction sets are not available on the target \
361	processor.", "no");
362toolset_setup_intrinsic_cflags();
363