xref: /PHP-7.1/win32/build/config.w32 (revision 03f3b847)
1// vim:ft=javascript
2// $Id$
3// "Master" config file; think of it as a configure.in
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		// no from disable-all
67		if(PHP_MP == 'auto' || PHP_MP == 'no') {
68			 ADD_FLAG('CFLAGS', ' /MP ');
69			PHP_MP_DISABLED = false;
70		} else {
71			if(parseInt(PHP_MP) != 0) {
72				ADD_FLAG('CFLAGS', ' /MP'+ PHP_MP +' ');
73				PHP_MP_DISABLED = false;
74			} else {
75				STDOUT.WriteLine('WARNING: Invalid argument for MP: ' + PHP_MP);
76			}
77		}
78}
79
80if (!PHP_MP_DISABLED) {
81	STDOUT.WriteLine('Enabling multi process build');
82}
83
84// General link flags
85toolset_setup_common_ldlags();
86
87// General libs
88toolset_setup_common_libs();
89
90// Set some debug/release specific options
91toolset_setup_build_mode();
92
93setup_zts_stuff();
94
95// CFLAGS, LDFLAGS and BUILD_DIR are defined
96// Add compiler and link flags if PGO options are selected
97if (PHP_DEBUG != "yes" && PHP_PGI == "yes") {
98	ADD_FLAG("STATIC_EXT_CFLAGS", "/GL /O2");
99	DEFINE("PGOPGD_DIR", "$(BUILD_DIR)");
100}
101else if (PHP_DEBUG != "yes" && PHP_PGO != "no") {
102	ADD_FLAG("STATIC_EXT_CFLAGS", "/GL /O2");
103	DEFINE("PGOPGD_DIR", ((PHP_PGO.length == 0 || PHP_PGO == "yes") ? "$(BUILD_DIR)" : PHP_PGO));
104}
105
106// Find the php_build dir - it contains headers and libraries
107// that we need
108ARG_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');
109php_build_option_handle();
110
111ARG_WITH('extra-includes', 'Extra include path to use when building everything', '');
112ARG_WITH('extra-libs', 'Extra library path to use when linking everything', '');
113
114var php_usual_include_suspects = PHP_PHP_BUILD+"\\include";
115var php_usual_lib_suspects = PHP_PHP_BUILD+"\\lib";
116
117ADD_FLAG("CFLAGS", '/I "' + php_usual_include_suspects + '" ');
118ADD_FLAG("LDFLAGS", '/libpath:"' + php_usual_lib_suspects + '" ');
119ADD_FLAG("ARFLAGS", '/nologo /libpath:"' + php_usual_lib_suspects + '" ');
120
121probe_basic_headers();
122add_extra_dirs();
123
124//DEFINE("PHP_BUILD", PHP_PHP_BUILD);
125
126ARG_WITH("analyzer", "Enable static analyzer. Pass vs for Visual Studio, clang for clang, cppcheck for Cppcheck, pvs for PVS-Studio", "no");
127if (PHP_ANALYZER == "vs") {
128	ADD_FLAG("CFLAGS", " /analyze ");
129	ADD_FLAG("CFLAGS", " /wd6308 ");
130} else if (PHP_ANALYZER == "clang") {
131	var clang_cl = false;
132
133	if (FSO.FileExists(PROGRAM_FILES + "\\LLVM\\bin\\clang-cl.exe")) {
134		clang_cl = PROGRAM_FILES + "\\LLVM\\bin\\clang-cl.exe";
135	} else if (FSO.FileExists(PROGRAM_FILESx86 + "\\LLVM\\bin\\clang-cl.exe")) {
136		clang_cl = PROGRAM_FILESx86 + "\\LLVM\\bin\\clang-cl.exe";
137	}
138
139	if (!clang_cl) {
140		if (false == PATH_PROG('clang-cl', null, 'CLANG_CL')) {
141			WARNING("Couldn't find clang binaries, static analyze was disabled");
142			PHP_ANALYZER = "no";
143		}
144	} else {
145		DEFINE("CLANG_CL", clang_cl);
146	}
147} else if (PHP_ANALYZER == "cppcheck") {
148
149	var cppcheck = false;
150
151	if (FSO.FileExists(PROGRAM_FILES + "\\Cppcheck\\cppcheck.exe")) {
152		cppcheck = PROGRAM_FILES + "\\Cppcheck\\cppcheck.exe";
153	} else if (FSO.FileExists(PROGRAM_FILESx86 + "\\Cppcheck\\cppcheck.exe")) {
154		cppcheck = PROGRAM_FILESx86 + "\\Cppcheck\\cppcheck.exe";
155	}
156	if (!cppcheck) {
157		if (false == PATH_PROG('cppcheck', null, 'CPPCHECK')) {
158			WARNING("Couldn't find Cppcheck binaries, static analyze was disabled");
159			PHP_ANALYZER = "no";
160		} else {
161			cppcheck = get_define("CPPCHECK");
162		}
163	} else {
164		DEFINE("CPPCHECK", cppcheck);
165	}
166
167	if (cppcheck) {
168		var _tmp = execute(cppcheck + " --version").split(/ /)[1];
169		var cppcheck_ver = [
170			parseInt(_tmp.split(".")[0]),
171			parseInt(_tmp.split(".")[1]),
172		];
173		if (cppcheck_ver[0] > 1 || cppcheck_ver[0] == 1 && cppcheck_ver[1] >= 77) {
174			var build_dir = get_define("BUILD_DIR");
175			var cppcheck_build_dir = build_dir + "\\cppcheck_build";
176			if (!FSO.FolderExists(cppcheck_build_dir)) {
177				FSO.CreateFolder(cppcheck_build_dir);
178			}
179			DEFINE("CPPCHECK_BUILD_DIR", cppcheck_build_dir);
180		}
181	}
182
183} else if (PHP_ANALYZER == "pvs") {
184	var pvs_studio = false;
185
186	if (FSO.FileExists(PROGRAM_FILES + "\\PVS-Studio\\x64\\PVS-Studio.exe")) {
187		pvs_studio = PROGRAM_FILES + "\\PVS-Studio\\x86\\PVS-Studio.exe";
188	} else if (FSO.FileExists(PROGRAM_FILESx86 + "\\PVS-Studio\\x64\\PVS-Studio.exe")) {
189		pvs_studio = PROGRAM_FILESx86 + "\\PVS-Studio\\x64\\PVS-Studio.exe";
190	}
191
192	if (!pvs_studio) {
193		WARNING("Couldn't find PVS-Studio binaries, static analyze was disabled");
194		PHP_ANALYZER = "no";
195	} else {
196		var pvscfg = FSO.CreateTextFile("PVS-Studio.conf", true);
197		DEFINE("PVS_STUDIO", pvs_studio);
198
199		pvscfg.WriteLine("exclude-path = " + VCINSTALLDIR);
200		if (FSO.FolderExists(PROGRAM_FILESx86 + "\\windows kits\\")) {
201			pvscfg.WriteLine("exclude-path = " + PROGRAM_FILESx86 + "\\windows kits\\");
202		} else if (FSO.FolderExists(PROGRAM_FILES + "\\windows kits\\")) {
203			pvscfg.WriteLine("exclude-path = " + PROGRAM_FILES + "\\windows kits\\");
204		}
205		pvscfg.WriteLine("vcinstalldir = " + VCINSTALLDIR);
206		pvscfg.WriteLine("platform = " + (X64 ? 'x64' : 'Win32'));
207		pvscfg.WriteLine("preprocessor = visualcpp");
208		pvscfg.WriteLine("language = C");
209	}
210} else {
211	PHP_ANALYZER = "no"
212}
213
214STDOUT.WriteBlankLines(1);
215STDOUT.WriteLine("Build dir: " + get_define('BUILD_DIR'));
216STDOUT.WriteLine("PHP Core:  " + get_define('PHPDLL') + " and " + get_define('PHPLIB'));
217
218ADD_SOURCES("Zend", "zend_language_parser.c zend_language_scanner.c \
219	zend_ini_parser.c zend_ini_scanner.c zend_alloc.c zend_compile.c \
220	zend_constants.c zend_exceptions.c \
221	zend_execute_API.c zend_highlight.c \
222	zend_llist.c zend_vm_opcodes.c zend_opcode.c zend_operators.c zend_ptr_stack.c \
223	zend_stack.c zend_variables.c zend.c zend_API.c zend_extensions.c \
224	zend_hash.c zend_list.c zend_builtin_functions.c \
225	zend_sprintf.c zend_ini.c zend_sort.c zend_multibyte.c zend_ts_hash.c \
226	zend_stream.c zend_iterators.c zend_interfaces.c zend_objects.c \
227	zend_object_handlers.c zend_objects_API.c \
228	zend_default_classes.c zend_execute.c zend_strtod.c zend_gc.c zend_closures.c \
229	zend_float.c zend_string.c zend_generators.c zend_virtual_cwd.c zend_ast.c \
230	zend_inheritance.c zend_smart_str.c");
231
232ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
233
234/* XXX inspect this for other toolsets */
235//AC_DEFINE('ZEND_DVAL_TO_LVAL_CAST_OK', 1);
236
237ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \
238	php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
239	strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \
240	php_open_temporary_file.c output.c internal_functions.c php_sprintf.c");
241ADD_FLAG("CFLAGS_BD_MAIN", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
242ADD_SOURCES("win32", "inet.c fnmatch.c sockets.c");
243
244AC_DEFINE('HAVE_STRNLEN', 1);
245
246ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c plain_wrapper.c \
247	userspace.c transports.c xp_socket.c mmap.c glob_wrapper.c");
248ADD_FLAG("CFLAGS_BD_MAIN_STREAMS", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
249
250ADD_SOURCES("win32", "dllmain.c glob.c readdir.c \
251	registry.c select.c sendmail.c time.c winutil.c wsyslog.c globals.c \
252	getrusage.c ftok.c ioutil.c codepage.c");
253
254ADD_FLAG("CFLAGS_BD_WIN32", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
255
256PHP_INSTALL_HEADERS("", "Zend/ TSRM/ main/ main/streams/ win32/");
257
258STDOUT.WriteBlankLines(1);
259
260
261/* Can we build with IPv6 support? */
262ARG_ENABLE("ipv6", "Disable IPv6 support (default is turn it on if available)", "yes");
263
264var main_network_has_ipv6 = 0;
265if (PHP_IPV6 == "yes") {
266	main_network_has_ipv6 = CHECK_HEADER_ADD_INCLUDE("wspiapi.h", "CFLAGS") ? 1 : 0;
267}
268if (main_network_has_ipv6) {
269	STDOUT.WriteLine("Enabling IPv6 support");
270}
271AC_DEFINE('HAVE_GETADDRINFO', main_network_has_ipv6);
272AC_DEFINE('HAVE_GAI_STRERROR', main_network_has_ipv6);
273AC_DEFINE('HAVE_IPV6', main_network_has_ipv6);
274
275/* this allows up to 256 sockets to be select()ed in a single
276 * call to select(), instead of the usual 64 */
277ARG_ENABLE('fd-setsize', "Set maximum number of sockets for select(2)", "256");
278ADD_FLAG("CFLAGS", "/D FD_SETSIZE=" + parseInt(PHP_FD_SETSIZE));
279
280AC_DEFINE('HAVE_USLEEP', 1);
281AC_DEFINE('HAVE_STRCOLL', 1);
282
283/* For snapshot builders, where can we find the additional
284 * files that make up the snapshot template? */
285ARG_WITH("snapshot-template", "Path to snapshot builder template dir", "no");
286
287if (PHP_SNAPSHOT_TEMPLATE == "no") {
288	/* default is as a sibling of the php_build dir */
289	if (FSO.FolderExists(PHP_PHP_BUILD + "\\template")) {
290		PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\template");
291	} else if (FSO.FolderExists(PHP_PHP_BUILD + "\\..\\template")) {
292		PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\..\\template");
293	}
294}
295
296DEFINE('SNAPSHOT_TEMPLATE', PHP_SNAPSHOT_TEMPLATE);
297
298ARG_ENABLE("security-flags", "Disable the compiler security flags", "yes");
299if (PHP_SECURITY_FLAGS == "yes") {
300	ADD_FLAG("LDFLAGS", "/NXCOMPAT /DYNAMICBASE ");
301}
302
303if (CLANG_TOOLSET) {
304	ARG_WITH("uncritical-warn-choke", "Disable some uncritical warnings", "yes");
305	if (PHP_UNCRITICAL_WARN_CHOKE != "no") {
306		ADD_FLAG("CFLAGS", "-Wno-ignored-attributes -Wno-deprecated-declarations -Wno-missing-braces \
307		-Wno-logical-op-parentheses -Wno-msvc-include -Wno-invalid-source-encoding -Wno-unknown-pragmas");
308	}
309}
310
311ARG_WITH("codegen-arch", "Architecture for code generation: ia32, sse, sse2, avx, avx2", "no");
312toolset_setup_codegen_arch();
313
314ARG_WITH("all-shared", "Force all the non obligatory extensions to be shared", "no");
315
316ARG_ENABLE("test-ini", "Enable automatic php.ini generation. The test.ini will be put \
317		into the build dir and used to automatically load the shared extensions.", "yes");
318
319ARG_WITH("test-ini-ext-exclude", "Comma separated list of shared extensions to \
320		be excluded from the test.ini", "no");
321