xref: /PHP-7.0/win32/build/config.w32 (revision 5b04a218)
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
126STDOUT.WriteBlankLines(1);
127STDOUT.WriteLine("Build dir: " + get_define('BUILD_DIR'));
128STDOUT.WriteLine("PHP Core:  " + get_define('PHPDLL') + " and " + get_define('PHPLIB'));
129
130ADD_SOURCES("Zend", "zend_language_parser.c zend_language_scanner.c \
131	zend_ini_parser.c zend_ini_scanner.c zend_alloc.c zend_compile.c \
132	zend_constants.c zend_exceptions.c \
133	zend_execute_API.c zend_highlight.c \
134	zend_llist.c zend_vm_opcodes.c zend_opcode.c zend_operators.c zend_ptr_stack.c \
135	zend_stack.c zend_variables.c zend.c zend_API.c zend_extensions.c \
136	zend_hash.c zend_list.c zend_builtin_functions.c \
137	zend_sprintf.c zend_ini.c zend_sort.c zend_multibyte.c zend_ts_hash.c \
138	zend_stream.c zend_iterators.c zend_interfaces.c zend_objects.c \
139	zend_object_handlers.c zend_objects_API.c \
140	zend_default_classes.c zend_execute.c zend_strtod.c zend_gc.c zend_closures.c \
141	zend_float.c zend_string.c zend_generators.c zend_virtual_cwd.c zend_ast.c \
142	zend_inheritance.c zend_smart_str.c");
143
144ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
145
146/* XXX inspect this for other toolsets */
147//AC_DEFINE('ZEND_DVAL_TO_LVAL_CAST_OK', 1);
148
149ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \
150	php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
151	strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \
152	php_open_temporary_file.c output.c internal_functions.c php_sprintf.c");
153ADD_FLAG("CFLAGS_BD_MAIN", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
154ADD_SOURCES("win32", "inet.c fnmatch.c sockets.c");
155
156AC_DEFINE('HAVE_STRNLEN', 1);
157
158ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c plain_wrapper.c \
159	userspace.c transports.c xp_socket.c mmap.c glob_wrapper.c");
160ADD_FLAG("CFLAGS_BD_MAIN_STREAMS", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
161
162ADD_SOURCES("win32", "dllmain.c glob.c readdir.c \
163	registry.c select.c sendmail.c time.c winutil.c wsyslog.c globals.c getrusage.c");
164
165ADD_FLAG("CFLAGS_BD_WIN32", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
166
167PHP_INSTALL_HEADERS("", "Zend/ TSRM/ main/ main/streams/ win32/");
168
169STDOUT.WriteBlankLines(1);
170
171
172/* Can we build with IPv6 support? */
173ARG_ENABLE("ipv6", "Disable IPv6 support (default is turn it on if available)", "yes");
174
175var main_network_has_ipv6 = 0;
176if (PHP_IPV6 == "yes") {
177	main_network_has_ipv6 = CHECK_HEADER_ADD_INCLUDE("wspiapi.h", "CFLAGS") ? 1 : 0;
178}
179if (main_network_has_ipv6) {
180	STDOUT.WriteLine("Enabling IPv6 support");
181}
182AC_DEFINE('HAVE_GETADDRINFO', main_network_has_ipv6);
183AC_DEFINE('HAVE_GAI_STRERROR', main_network_has_ipv6);
184AC_DEFINE('HAVE_IPV6', main_network_has_ipv6);
185
186/* this allows up to 256 sockets to be select()ed in a single
187 * call to select(), instead of the usual 64 */
188ARG_ENABLE('fd-setsize', "Set maximum number of sockets for select(2)", "256");
189ADD_FLAG("CFLAGS", "/D FD_SETSIZE=" + parseInt(PHP_FD_SETSIZE));
190
191AC_DEFINE('HAVE_USLEEP', 1);
192AC_DEFINE('HAVE_STRCOLL', 1);
193
194/* For snapshot builders, where can we find the additional
195 * files that make up the snapshot template? */
196ARG_WITH("snapshot-template", "Path to snapshot builder template dir", "no");
197
198if (PHP_SNAPSHOT_TEMPLATE == "no") {
199	/* default is as a sibling of the php_build dir */
200	if (FSO.FolderExists(PHP_PHP_BUILD + "\\template")) {
201		PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\template");
202	} else if (FSO.FolderExists(PHP_PHP_BUILD + "\\..\\template")) {
203		PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\..\\template");
204	}
205}
206
207DEFINE('SNAPSHOT_TEMPLATE', PHP_SNAPSHOT_TEMPLATE);
208
209ARG_ENABLE("security-flags", "Disable the compiler security flags", "yes");
210if (PHP_SECURITY_FLAGS == "yes") {
211	ADD_FLAG("LDFLAGS", "/NXCOMPAT /DYNAMICBASE ");
212}
213
214/* XXX add and implement clang keyword for clang analyzer */
215ARG_WITH("analyzer", "Enable static analyzer. Pass vs for Visual Studio, pvs for PVS-Studio", "no");
216if (PHP_ANALYZER == "vs") {
217	ADD_FLAG("CFLAGS", " /analyze ");
218	ADD_FLAG("CFLAGS", " /wd6308 ");
219} else if (PHP_ANALYZER == "pvs") {
220	var pvs_studio = false;
221
222	if (FSO.FileExists(PROGRAM_FILES + "\\PVS-Studio\\x64\\PVS-Studio.exe")) {
223		pvs_studio = PROGRAM_FILES + "\\PVS-Studio\\x86\\PVS-Studio.exe";
224	} else if (FSO.FileExists(PROGRAM_FILESx86 + "\\PVS-Studio\\x64\\PVS-Studio.exe")) {
225		pvs_studio = PROGRAM_FILESx86 + "\\PVS-Studio\\x64\\PVS-Studio.exe";
226	}
227
228	if (!pvs_studio) {
229		WARNING("Couldn't find PVS-Studio binaries, static analyze was disabled");
230		PHP_ANALYZER = "no";
231	} else {
232		var pvscfg = FSO.CreateTextFile("PVS-Studio.conf", true);
233		DEFINE("PVS_STUDIO", pvs_studio);
234
235		pvscfg.WriteLine("exclude-path = " + VCINSTALLDIR);
236		if (FSO.FolderExists(PROGRAM_FILESx86 + "\\windows kits\\")) {
237			pvscfg.WriteLine("exclude-path = " + PROGRAM_FILESx86 + "\\windows kits\\");
238		} else if (FSO.FolderExists(PROGRAM_FILES + "\\windows kits\\")) {
239			pvscfg.WriteLine("exclude-path = " + PROGRAM_FILES + "\\windows kits\\");
240		}
241		pvscfg.WriteLine("vcinstalldir = " + VCINSTALLDIR);
242		pvscfg.WriteLine("platform = " + (X64 ? 'x64' : 'Win32'));
243		pvscfg.WriteLine("preprocessor = visualcpp");
244		pvscfg.WriteLine("language = C");
245	}
246} else {
247	PHP_ANALYZER = "no"
248}
249
250if (CLANG_TOOLSET) {
251	ARG_WITH("uncritical-warn-choke", "Disable some uncritical warnings", "yes");
252	if (PHP_UNCRITICAL_WARN_CHOKE != "no") {
253		ADD_FLAG("CFLAGS", "-Wno-ignored-attributes -Wno-deprecated-declarations -Wno-missing-braces \
254		-Wno-logical-op-parentheses -Wno-msvc-include -Wno-invalid-source-encoding -Wno-unknown-pragmas");
255	}
256}
257
258ARG_WITH("codegen-arch", "Architecture for code generation: ia32, sse, sse2, avx, avx2", "no");
259toolset_setup_codegen_arch();
260
261ARG_WITH("all-shared", "Force all the non obligatory extensions to be shared", "no");
262
263ARG_ENABLE("test-ini", "Enable automatic php.ini generation. The test.ini will be put \
264		into the build dir and used to automatically load the shared extensions.", "yes");
265
266ARG_WITH("test-ini-ext-exclude", "Comma separated list of shared extensions to \
267		be excluded from the test.ini", "no");
268
269