xref: /PHP-5.4/win32/build/config.w32 (revision 6612e1ba)
1// vim:ft=javascript
2// $Id$
3// "Master" config file; think of it as a configure.in
4// equivalent.
5
6ARG_WITH('cygwin', 'Path to cygwin utilities on your system', '\\cygwin');
7PHP_CL = PATH_PROG('cl', null, 'PHP_CL');
8if (!PHP_CL) {
9	ERROR("MS C++ compiler is required");
10}
11
12/* For the record here: */
13// 1200 is VC6
14// 1300 is vs.net 2002
15// 1310 is vs.net 2003
16// 1400 is vs.net 2005
17// 1500 is vs.net 2008
18// 1600 is vs.net 2010
19// Which version of the compiler do we have?
20VCVERS = probe_binary(PHP_CL).substr(0, 5).replace('.', '');
21STDOUT.WriteLine("  Detected compiler " + VC_VERSIONS[VCVERS]);
22
23if (VCVERS < 1500) {
24	ERROR("Unsupported MS C++ Compiler, VC9 (2008) minimum is required");
25}
26
27AC_DEFINE('COMPILER', VC_VERSIONS[VCVERS], "Detected compiler version");
28DEFINE("PHP_COMPILER_SHORT", VC_VERSIONS_SHORT[VCVERS]);
29AC_DEFINE('PHP_COMPILER_ID', VC_VERSIONS_SHORT[VCVERS], "Compiler compatibility ID");
30
31// do we use x64 or 80x86 version of compiler?
32X64 = probe_binary(PHP_CL, 64, null, 'PHP_CL');
33if (X64) {
34	STDOUT.WriteLine("  Detected 64-bit compiler");
35} else {
36	STDOUT.WriteLine("  Detected 32-bit compiler");
37}
38AC_DEFINE('ARCHITECTURE', X64 ? 'x64' : 'x86', "Detected compiler architecture");
39DEFINE("PHP_ARCHITECTURE", X64 ? 'x64' : 'x86');
40
41// cygwin now ships with link.exe.  Avoid searching the cygwin path
42// for this, as we want the MS linker, not the fileutil
43PATH_PROG('link', WshShell.Environment("Process").Item("PATH"));
44PATH_PROG('nmake');
45
46// we don't want to define LIB, as that will override the default library path
47// that is set in that env var
48PATH_PROG('lib', null, 'MAKE_LIB');
49if (!PATH_PROG('bison')) {
50	ERROR('bison is required')
51}
52
53// There's a minimum requirement for re2c..
54MINRE2C = "0.13.4";
55
56RE2C = PATH_PROG('re2c');
57if (RE2C) {
58	var intvers, intmin;
59	var pattern = /\./g;
60
61	RE2CVERS = probe_binary(RE2C, "version");
62	STDOUT.WriteLine('  Detected re2c version ' + RE2CVERS);
63
64	intvers = RE2CVERS.replace(pattern, '') - 0;
65	intmin = MINRE2C.replace(pattern, '') - 0;
66
67	if (intvers < intmin) {
68		STDOUT.WriteLine('WARNING: The minimum RE2C version requirement is ' + MINRE2C);
69		STDOUT.WriteLine('Parsers will not be generated. Upgrade your copy at http://sf.net/projects/re2c');
70		DEFINE('RE2C', '');
71	} else {
72		DEFINE('RE2C_FLAGS', '');
73	}
74} else {
75	STDOUT.WriteLine('Parsers will not be regenerated');
76}
77PATH_PROG('zip');
78PATH_PROG('lemon');
79
80// avoid picking up midnight commander from cygwin
81PATH_PROG('mc', WshShell.Environment("Process").Item("PATH"));
82
83// Try locating manifest tool
84if (VCVERS > 1200) {
85	PATH_PROG('mt', WshShell.Environment("Process").Item("PATH"));
86}
87
88// stick objects somewhere outside of the source tree
89ARG_ENABLE('object-out-dir', 'Alternate location for binary objects during build', '');
90if (PHP_OBJECT_OUT_DIR.length) {
91	PHP_OBJECT_OUT_DIR = FSO.GetAbsolutePathName(PHP_OBJECT_OUT_DIR);
92	if (!FSO.FolderExists(PHP_OBJECT_OUT_DIR)) {
93		ERROR('you chosen output directory ' + PHP_OBJECT_OUT_DIR + ' does not exist');
94	}
95	PHP_OBJECT_OUT_DIR += '\\';
96} else if (X64) {
97	if (!FSO.FolderExists("x64")) {
98		FSO.CreateFolder("x64");
99	}
100	PHP_OBJECT_OUT_DIR = 'x64\\';
101}
102
103ARG_ENABLE('debug', 'Compile with debugging symbols', "no");
104ARG_ENABLE('debug-pack', 'Release binaries with external debug symbols (--enable-debug must not be specified)', 'no');
105if (PHP_DEBUG == "yes" && PHP_DEBUG_PACK == "yes") {
106	ERROR("Use of both --enable-debug and --enable-debug-pack not allowed.");
107}
108
109ARG_ENABLE('pgi', 'Generate PGO instrumented binaries', 'no');
110ARG_WITH('pgo', 'Compile optimized binaries using training data from folder', 'no');
111if (PHP_PGI == "yes" || PHP_PGO != "no") {
112	PGOMGR = PATH_PROG('pgomgr', WshShell.Environment("Process").Item("PATH"));
113	if (!PGOMGR) {
114		ERROR("--enable-pgi and --with-pgo options can only be used if PGO capable compiler is present.");
115	}
116	if (PHP_PGI == "yes" && PHP_PGO != "no") {
117		ERROR("Use of both --enable-pgi and --with-pgo not allowed.");
118	}
119}
120
121ARG_ENABLE('zts', 'Thread safety', 'yes');
122// Configures the hard-coded installation dir
123ARG_WITH('prefix', 'where PHP will be installed', '');
124if (PHP_PREFIX == '') {
125	PHP_PREFIX = "C:\\php";
126	if (PHP_DEBUG == "yes")
127		PHP_PREFIX += "\\debug";
128}
129DEFINE('PHP_PREFIX', PHP_PREFIX);
130
131DEFINE("BASE_INCLUDES", "/I . /I main /I Zend /I TSRM /I ext ");
132
133// CFLAGS for building the PHP dll
134DEFINE("CFLAGS_PHP", "/D _USRDLL /D PHP5DLLTS_EXPORTS /D PHP_EXPORTS \
135/D LIBZEND_EXPORTS /D TSRM_EXPORTS /D SAPI_EXPORTS /D WINVER=0x500");
136
137DEFINE('CFLAGS_PHP_OBJ', '$(CFLAGS_PHP) $(STATIC_EXT_CFLAGS)');
138
139// General CFLAGS for building objects
140DEFINE("CFLAGS", "/nologo /FD $(BASE_INCLUDES) /D _WINDOWS \
141/D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _MBCS /W3 ");
142
143if (VCVERS < 1400) {
144	// Enable automatic precompiled headers
145	ADD_FLAG('CFLAGS', ' /YX ');
146
147	if (PHP_DEBUG == "yes") {
148		// Set some debug/release specific options
149		ADD_FLAG('CFLAGS', ' /GZ ');
150	}
151}
152
153if (VCVERS >= 1400) {
154	// fun stuff: MS deprecated ANSI stdio and similar functions
155	// disable annoying warnings.  In addition, time_t defaults
156	// to 64-bit.  Ask for 32-bit.
157	if (X64) {
158		ADD_FLAG('CFLAGS', ' /wd4996 /Wp64 ');
159	} else {
160		ADD_FLAG('CFLAGS', ' /wd4996 /D_USE_32BIT_TIME_T=1 ');
161	}
162
163	if (PHP_DEBUG == "yes") {
164		// Set some debug/release specific options
165		ADD_FLAG('CFLAGS', ' /RTC1 ');
166	}
167}
168
169ARG_WITH('mp', 'Tell VC9+ use up to [n,auto,disable] processes for compilation', 'auto');
170if (VCVERS >= 1500 && PHP_MP != 'disable') {
171		// no from disable-all
172		if(PHP_MP == 'auto' || PHP_MP == 'no') {
173			 ADD_FLAG('CFLAGS', ' /MP ');
174		} else {
175			if(parseInt(PHP_MP) != 0) {
176				ADD_FLAG('CFLAGS', ' /MP'+ PHP_MP +' ');
177			} else {
178				STDOUT.WriteLine('WARNING: Invalid argument for MP: ' + PHP_MP);
179			}
180		}
181}
182
183// General link flags
184DEFINE("LDFLAGS", "/nologo /version:" +
185	PHP_VERSION + "." + PHP_MINOR_VERSION + "." + PHP_RELEASE_VERSION);
186
187// General DLL link flags
188DEFINE("DLL_LDFLAGS", "/dll ");
189
190// PHP DLL link flags
191DEFINE("PHP_LDFLAGS", "$(DLL_LDFLAGS)");
192
193// General libs
194// urlmon.lib ole32.lib oleaut32.lib uuid.lib gdi32.lib winspool.lib comdlg32.lib
195DEFINE("LIBS", "kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib Dnsapi.lib");
196
197// Set some debug/release specific options
198if (PHP_DEBUG == "yes") {
199	ADD_FLAG("CFLAGS", "/LDd /MDd /W3 /Gm /Od /D _DEBUG /D ZEND_DEBUG=1 " +
200		(X64?"/Zi":"/ZI"));
201	ADD_FLAG("LDFLAGS", "/debug");
202	// Avoid problems when linking to release libraries that use the release
203	// version of the libc
204	ADD_FLAG("PHP_LDFLAGS", "/nodefaultlib:msvcrt");
205} else {
206	// Generate external debug files when --enable-debug-pack is specified
207	if (PHP_DEBUG_PACK == "yes") {
208		ADD_FLAG("CFLAGS", "/Zi");
209		ADD_FLAG("LDFLAGS", "/incremental:no /debug /opt:ref,icf");
210	}
211	// Equivalent to Release_TSInline build -> best optimization
212	ADD_FLAG("CFLAGS", "/LD /MD /W3 /Ox /D NDebug /D NDEBUG /D ZEND_WIN32_FORCE_INLINE /GF /D ZEND_DEBUG=0");
213
214	// if you have VS.Net /GS hardens the binary against buffer overruns
215	// ADD_FLAG("CFLAGS", "/GS");
216}
217
218if (PHP_ZTS == "yes") {
219	ADD_FLAG("CFLAGS", "/D ZTS=1");
220	ADD_FLAG("ZTS", "1");
221} else {
222	ADD_FLAG("ZTS", "0");
223}
224
225DEFINE("PHP_ZTS_ARCHIVE_POSTFIX", PHP_ZTS == "yes" ? '' : "-nts");
226
227
228// we want msvcrt in the PHP DLL
229ADD_FLAG("PHP_LDFLAGS", "/nodefaultlib:libcmt");
230
231// set up the build dir and DLL name
232if (PHP_DEBUG == "yes" && PHP_ZTS == "yes") {
233	DEFINE("BUILD_DIR", PHP_OBJECT_OUT_DIR + "Debug_TS");
234	DEFINE("PHPDLL", "php" + PHP_VERSION + "ts_debug.dll");
235	DEFINE("PHPLIB", "php" + PHP_VERSION + "ts_debug.lib");
236} else if (PHP_DEBUG == "yes" && PHP_ZTS == "no") {
237	DEFINE("BUILD_DIR", PHP_OBJECT_OUT_DIR + "Debug");
238	DEFINE("PHPDLL", "php" + PHP_VERSION + "_debug.dll");
239	DEFINE("PHPLIB", "php" + PHP_VERSION + "_debug.lib");
240} else if (PHP_DEBUG == "no" && PHP_ZTS == "yes") {
241	DEFINE("BUILD_DIR", PHP_OBJECT_OUT_DIR + "Release_TS");
242	DEFINE("PHPDLL", "php" + PHP_VERSION + "ts.dll");
243	DEFINE("PHPLIB", "php" + PHP_VERSION + "ts.lib");
244} else if (PHP_DEBUG == "no" && PHP_ZTS == "no") {
245	DEFINE("BUILD_DIR", PHP_OBJECT_OUT_DIR + "Release");
246	DEFINE("PHPDLL", "php" + PHP_VERSION + ".dll");
247	DEFINE("PHPLIB", "php" + PHP_VERSION + ".lib");
248}
249
250// CFLAGS, LDFLAGS and BUILD_DIR are defined
251// Add compiler and link flags if PGO options are selected
252if (PHP_DEBUG != "yes" && PHP_PGI == "yes") {
253	ADD_FLAG('DLL_LDFLAGS', "/LTCG:PGINSTRUMENT");
254	ADD_FLAG("STATIC_EXT_CFLAGS", "/GL /O2");
255	DEFINE("PGOPGD_DIR", "$(BUILD_DIR)");
256}
257else if (PHP_DEBUG != "yes" && PHP_PGO != "no") {
258	ADD_FLAG('DLL_LDFLAGS', "/LTCG:PGUPDATE");
259	ADD_FLAG("STATIC_EXT_CFLAGS", "/GL /O2");
260	DEFINE("PGOPGD_DIR", ((PHP_PGO.length == 0 || PHP_PGO == "yes") ? "$(BUILD_DIR)" : PHP_PGO));
261}
262
263// Find the php_build dir - it contains headers and libraries
264// that we need
265ARG_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');
266
267if (PHP_PHP_BUILD == 'no') {
268	if (FSO.FolderExists("..\\deps")) {
269		PHP_PHP_BUILD = "..\\deps";
270	} else {
271		if (FSO.FolderExists("..\\php_build")) {
272			PHP_PHP_BUILD = "..\\php_build";
273		} else {
274			if (X64) {
275				if (FSO.FolderExists("..\\win64build")) {
276					PHP_PHP_BUILD = "..\\win64build";
277				} else if (FSO.FolderExists("..\\php-win64-dev\\php_build")) {
278					PHP_PHP_BUILD = "..\\php-win64-dev\\php_build";
279				}
280			} else {
281				if (FSO.FolderExists("..\\win32build")) {
282					PHP_PHP_BUILD = "..\\win32build";
283				} else if (FSO.FolderExists("..\\php-win32-dev\\php_build")) {
284					PHP_PHP_BUILD = "..\\php-win32-dev\\php_build";
285				}
286			}
287		}
288	}
289	PHP_PHP_BUILD = FSO.GetAbsolutePathName(PHP_PHP_BUILD);
290}
291DEFINE("PHP_BUILD", PHP_PHP_BUILD);
292
293ARG_WITH('extra-includes', 'Extra include path to use when building everything', '');
294ARG_WITH('extra-libs', 'Extra library path to use when linking everything', '');
295
296var php_usual_include_suspects = PHP_PHP_BUILD+"\\include";
297var php_usual_lib_suspects = PHP_PHP_BUILD+"\\lib";
298
299ADD_FLAG("CFLAGS", '/I "' + php_usual_include_suspects + '" ');
300ADD_FLAG("LDFLAGS", '/libpath:"' + php_usual_lib_suspects + '" ');
301
302// Poke around for some headers
303function probe_basic_headers()
304{
305	var p;
306
307	if (PHP_PHP_BUILD != "no") {
308		php_usual_include_suspects += ";" + PHP_PHP_BUILD + "\\include";
309		php_usual_lib_suspects += ";" + PHP_PHP_BUILD + "\\lib";
310	}
311}
312
313function add_extra_dirs()
314{
315	var path, i, f;
316
317	if (PHP_EXTRA_INCLUDES.length) {
318		path = PHP_EXTRA_INCLUDES.split(';');
319		for (i = 0; i < path.length; i++) {
320			f = FSO.GetAbsolutePathName(path[i]);
321			if (FSO.FolderExists(f)) {
322				ADD_FLAG("CFLAGS", '/I "' + f + '" ');
323			}
324		}
325	}
326	if (PHP_EXTRA_LIBS.length) {
327		path = PHP_EXTRA_LIBS.split(';');
328		for (i = 0; i < path.length; i++) {
329			f = FSO.GetAbsolutePathName(path[i]);
330			if (FSO.FolderExists(f)) {
331				if (VCVERS <= 1200 && f.indexOf(" ") >= 0) {
332					ADD_FLAG("LDFLAGS", '/libpath:"\\"' + f + '\\"" ');
333				} else {
334					ADD_FLAG("LDFLAGS", '/libpath:"' + f + '" ');
335				}
336			}
337		}
338	}
339
340}
341
342probe_basic_headers();
343add_extra_dirs();
344
345//DEFINE("PHP_BUILD", PHP_PHP_BUILD);
346
347STDOUT.WriteBlankLines(1);
348STDOUT.WriteLine("Build dir: " + get_define('BUILD_DIR'));
349STDOUT.WriteLine("PHP Core:  " + get_define('PHPDLL') + " and " + get_define('PHPLIB'));
350
351ADD_SOURCES("Zend", "zend_language_parser.c zend_language_scanner.c \
352	zend_ini_parser.c zend_ini_scanner.c zend_alloc.c zend_compile.c \
353	zend_constants.c zend_dynamic_array.c zend_exceptions.c \
354	zend_execute_API.c zend_highlight.c \
355	zend_llist.c zend_vm_opcodes.c zend_opcode.c zend_operators.c zend_ptr_stack.c \
356	zend_stack.c zend_variables.c zend.c zend_API.c zend_extensions.c \
357	zend_hash.c zend_list.c zend_indent.c zend_builtin_functions.c \
358	zend_sprintf.c zend_ini.c zend_qsort.c zend_multibyte.c zend_ts_hash.c \
359	zend_stream.c zend_iterators.c zend_interfaces.c zend_objects.c \
360	zend_object_handlers.c zend_objects_API.c \
361	zend_default_classes.c zend_execute.c zend_strtod.c zend_gc.c zend_closures.c \
362	zend_float.c zend_string.c");
363
364if (VCVERS == 1200) {
365	AC_DEFINE('ZEND_DVAL_TO_LVAL_CAST_OK', 1);
366}
367
368ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \
369	php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
370	strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \
371	php_open_temporary_file.c php_logos.c output.c internal_functions.c php_sprintf.c");
372ADD_SOURCES("win32", "inet.c fnmatch.c sockets.c");
373
374// Newer versions have it
375if (VCVERS <= 1300) {
376	ADD_SOURCES("win32", "strtoi64.c");
377}
378if (VCVERS >= 1400) {
379	AC_DEFINE('HAVE_STRNLEN', 1);
380}
381
382ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c plain_wrapper.c \
383	userspace.c transports.c xp_socket.c mmap.c glob_wrapper.c");
384
385ADD_SOURCES("win32", "glob.c readdir.c \
386	registry.c select.c sendmail.c time.c winutil.c wsyslog.c globals.c");
387
388PHP_INSTALL_HEADERS("", "Zend/ TSRM/ main/ main/streams/ win32/");
389
390STDOUT.WriteBlankLines(1);
391
392
393/* Can we build with IPv6 support? */
394ARG_ENABLE("ipv6", "Disable IPv6 support (default is turn it on if available)", "yes");
395
396var main_network_has_ipv6 = 0;
397if (PHP_IPV6 == "yes") {
398	main_network_has_ipv6 = CHECK_HEADER_ADD_INCLUDE("wspiapi.h", "CFLAGS") ? 1 : 0;
399}
400if (main_network_has_ipv6) {
401	STDOUT.WriteLine("Enabling IPv6 support");
402}
403AC_DEFINE('HAVE_GETADDRINFO', main_network_has_ipv6);
404AC_DEFINE('HAVE_GAI_STRERROR', main_network_has_ipv6);
405AC_DEFINE('HAVE_IPV6', main_network_has_ipv6);
406
407/* this allows up to 256 sockets to be select()ed in a single
408 * call to select(), instead of the usual 64 */
409ARG_ENABLE('fd-setsize', "Set maximum number of sockets for select(2)", "256");
410ADD_FLAG("CFLAGS", "/D FD_SETSIZE=" + parseInt(PHP_FD_SETSIZE));
411
412AC_DEFINE('HAVE_USLEEP', 1);
413AC_DEFINE('HAVE_STRCOLL', 1);
414
415/* For snapshot builders, where can we find the additional
416 * files that make up the snapshot template? */
417ARG_WITH("snapshot-template", "Path to snapshot builder template dir", "no");
418
419if (PHP_SNAPSHOT_TEMPLATE == "no") {
420	/* default is as a sibling of the php_build dir */
421	if (FSO.FolderExists(PHP_PHP_BUILD + "\\template")) {
422		PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\template");
423	} else if (FSO.FolderExists(PHP_PHP_BUILD + "\\..\\template")) {
424		PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\..\\template");
425	}
426}
427
428DEFINE('SNAPSHOT_TEMPLATE', PHP_SNAPSHOT_TEMPLATE);
429
430if (PHP_DSP != "no") {
431	if (FSO.FolderExists("tmp")) {
432		FSO.DeleteFolder("tmp");
433	}
434	FSO.CreateFolder("tmp");
435}
436
437ARG_ENABLE("security-flags", "Disable the compiler security flags", "yes");
438if (PHP_SECURITY_FLAGS == "yes") {
439	ADD_FLAG("LDFLAGS", "/NXCOMPAT /DYNAMICBASE ");
440}
441
442ARG_ENABLE("static-analyze", "Enable the VC compiler static analyze", "no");
443if (PHP_STATIC_ANALYZE == "yes") {
444	ADD_FLAG("CFLAGS", " /analyze ");
445	ADD_FLAG("CFLAGS", " /wd6308 ");
446}
447