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