xref: /PHP-5.5/win32/build/config.w32 (revision 7477f5b3)
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 ');
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
184
185if (VCVERS >= 1700) {
186	DEFINE("LDFLAGS", "/nologo ");
187} else {
188	DEFINE("LDFLAGS", "/nologo /version:" +
189			PHP_VERSION + "." + PHP_MINOR_VERSION + "." + PHP_RELEASE_VERSION);
190}
191
192// General DLL link flags
193DEFINE("DLL_LDFLAGS", "/dll ");
194
195// PHP DLL link flags
196DEFINE("PHP_LDFLAGS", "$(DLL_LDFLAGS)");
197
198// General libs
199// urlmon.lib ole32.lib oleaut32.lib uuid.lib gdi32.lib winspool.lib comdlg32.lib
200DEFINE("LIBS", "kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib Dnsapi.lib");
201
202// Set some debug/release specific options
203if (PHP_DEBUG == "yes") {
204	ADD_FLAG("CFLAGS", "/LDd /MDd /W3 /Gm /Od /D _DEBUG /D ZEND_DEBUG=1 " +
205		(X64?"/Zi":"/ZI"));
206	ADD_FLAG("LDFLAGS", "/debug");
207	// Avoid problems when linking to release libraries that use the release
208	// version of the libc
209	ADD_FLAG("PHP_LDFLAGS", "/nodefaultlib:msvcrt");
210} else {
211	// Generate external debug files when --enable-debug-pack is specified
212	if (PHP_DEBUG_PACK == "yes") {
213		ADD_FLAG("CFLAGS", "/Zi");
214		ADD_FLAG("LDFLAGS", "/incremental:no /debug /opt:ref,icf");
215	}
216	// Equivalent to Release_TSInline build -> best optimization
217	ADD_FLAG("CFLAGS", "/LD /MD /W3 /Ox /D NDebug /D NDEBUG /D ZEND_WIN32_FORCE_INLINE /GF /D ZEND_DEBUG=0");
218
219	// if you have VS.Net /GS hardens the binary against buffer overruns
220	// ADD_FLAG("CFLAGS", "/GS");
221}
222
223if (PHP_ZTS == "yes") {
224	ADD_FLAG("CFLAGS", "/D ZTS=1");
225	ADD_FLAG("ZTS", "1");
226} else {
227	ADD_FLAG("ZTS", "0");
228}
229
230DEFINE("PHP_ZTS_ARCHIVE_POSTFIX", PHP_ZTS == "yes" ? '' : "-nts");
231
232
233// we want msvcrt in the PHP DLL
234ADD_FLAG("PHP_LDFLAGS", "/nodefaultlib:libcmt");
235
236// set up the build dir and DLL name
237if (PHP_DEBUG == "yes" && PHP_ZTS == "yes") {
238	DEFINE("BUILD_DIR", PHP_OBJECT_OUT_DIR + "Debug_TS");
239	DEFINE("PHPDLL", "php" + PHP_VERSION + "ts_debug.dll");
240	DEFINE("PHPLIB", "php" + PHP_VERSION + "ts_debug.lib");
241} else if (PHP_DEBUG == "yes" && PHP_ZTS == "no") {
242	DEFINE("BUILD_DIR", PHP_OBJECT_OUT_DIR + "Debug");
243	DEFINE("PHPDLL", "php" + PHP_VERSION + "_debug.dll");
244	DEFINE("PHPLIB", "php" + PHP_VERSION + "_debug.lib");
245} else if (PHP_DEBUG == "no" && PHP_ZTS == "yes") {
246	DEFINE("BUILD_DIR", PHP_OBJECT_OUT_DIR + "Release_TS");
247	DEFINE("PHPDLL", "php" + PHP_VERSION + "ts.dll");
248	DEFINE("PHPLIB", "php" + PHP_VERSION + "ts.lib");
249} else if (PHP_DEBUG == "no" && PHP_ZTS == "no") {
250	DEFINE("BUILD_DIR", PHP_OBJECT_OUT_DIR + "Release");
251	DEFINE("PHPDLL", "php" + PHP_VERSION + ".dll");
252	DEFINE("PHPLIB", "php" + PHP_VERSION + ".lib");
253}
254
255// CFLAGS, LDFLAGS and BUILD_DIR are defined
256// Add compiler and link flags if PGO options are selected
257if (PHP_DEBUG != "yes" && PHP_PGI == "yes") {
258	ADD_FLAG("STATIC_EXT_CFLAGS", "/GL /O2");
259	DEFINE("PGOPGD_DIR", "$(BUILD_DIR)");
260}
261else if (PHP_DEBUG != "yes" && PHP_PGO != "no") {
262	ADD_FLAG("STATIC_EXT_CFLAGS", "/GL /O2");
263	DEFINE("PGOPGD_DIR", ((PHP_PGO.length == 0 || PHP_PGO == "yes") ? "$(BUILD_DIR)" : PHP_PGO));
264}
265
266// Find the php_build dir - it contains headers and libraries
267// that we need
268ARG_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');
269
270if (PHP_PHP_BUILD == 'no') {
271	if (FSO.FolderExists("..\\deps")) {
272		PHP_PHP_BUILD = "..\\deps";
273	} else {
274		if (FSO.FolderExists("..\\php_build")) {
275			PHP_PHP_BUILD = "..\\php_build";
276		} else {
277			if (X64) {
278				if (FSO.FolderExists("..\\win64build")) {
279					PHP_PHP_BUILD = "..\\win64build";
280				} else if (FSO.FolderExists("..\\php-win64-dev\\php_build")) {
281					PHP_PHP_BUILD = "..\\php-win64-dev\\php_build";
282				}
283			} else {
284				if (FSO.FolderExists("..\\win32build")) {
285					PHP_PHP_BUILD = "..\\win32build";
286				} else if (FSO.FolderExists("..\\php-win32-dev\\php_build")) {
287					PHP_PHP_BUILD = "..\\php-win32-dev\\php_build";
288				}
289			}
290		}
291	}
292	PHP_PHP_BUILD = FSO.GetAbsolutePathName(PHP_PHP_BUILD);
293}
294DEFINE("PHP_BUILD", PHP_PHP_BUILD);
295
296ARG_WITH('extra-includes', 'Extra include path to use when building everything', '');
297ARG_WITH('extra-libs', 'Extra library path to use when linking everything', '');
298
299var php_usual_include_suspects = PHP_PHP_BUILD+"\\include";
300var php_usual_lib_suspects = PHP_PHP_BUILD+"\\lib";
301
302ADD_FLAG("CFLAGS", '/I "' + php_usual_include_suspects + '" ');
303ADD_FLAG("LDFLAGS", '/libpath:"' + php_usual_lib_suspects + '" ');
304
305// Poke around for some headers
306function probe_basic_headers()
307{
308	var p;
309
310	if (PHP_PHP_BUILD != "no") {
311		php_usual_include_suspects += ";" + PHP_PHP_BUILD + "\\include";
312		php_usual_lib_suspects += ";" + PHP_PHP_BUILD + "\\lib";
313	}
314}
315
316function add_extra_dirs()
317{
318	var path, i, f;
319
320	if (PHP_EXTRA_INCLUDES.length) {
321		path = PHP_EXTRA_INCLUDES.split(';');
322		for (i = 0; i < path.length; i++) {
323			f = FSO.GetAbsolutePathName(path[i]);
324			if (FSO.FolderExists(f)) {
325				ADD_FLAG("CFLAGS", '/I "' + f + '" ');
326			}
327		}
328	}
329	if (PHP_EXTRA_LIBS.length) {
330		path = PHP_EXTRA_LIBS.split(';');
331		for (i = 0; i < path.length; i++) {
332			f = FSO.GetAbsolutePathName(path[i]);
333			if (FSO.FolderExists(f)) {
334				if (VCVERS <= 1200 && f.indexOf(" ") >= 0) {
335					ADD_FLAG("LDFLAGS", '/libpath:"\\"' + f + '\\"" ');
336				} else {
337					ADD_FLAG("LDFLAGS", '/libpath:"' + f + '" ');
338				}
339			}
340		}
341	}
342
343}
344
345probe_basic_headers();
346add_extra_dirs();
347
348//DEFINE("PHP_BUILD", PHP_PHP_BUILD);
349
350STDOUT.WriteBlankLines(1);
351STDOUT.WriteLine("Build dir: " + get_define('BUILD_DIR'));
352STDOUT.WriteLine("PHP Core:  " + get_define('PHPDLL') + " and " + get_define('PHPLIB'));
353
354ADD_SOURCES("Zend", "zend_language_parser.c zend_language_scanner.c \
355	zend_ini_parser.c zend_ini_scanner.c zend_alloc.c zend_compile.c \
356	zend_constants.c zend_dynamic_array.c zend_exceptions.c \
357	zend_execute_API.c zend_highlight.c \
358	zend_llist.c zend_vm_opcodes.c zend_opcode.c zend_operators.c zend_ptr_stack.c \
359	zend_stack.c zend_variables.c zend.c zend_API.c zend_extensions.c \
360	zend_hash.c zend_list.c zend_indent.c zend_builtin_functions.c \
361	zend_sprintf.c zend_ini.c zend_qsort.c zend_multibyte.c zend_ts_hash.c \
362	zend_stream.c zend_iterators.c zend_interfaces.c zend_objects.c \
363	zend_object_handlers.c zend_objects_API.c \
364	zend_default_classes.c zend_execute.c zend_strtod.c zend_gc.c zend_closures.c \
365	zend_float.c zend_string.c zend_generators.c");
366
367if (VCVERS == 1200) {
368	AC_DEFINE('ZEND_DVAL_TO_LVAL_CAST_OK', 1);
369}
370
371ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \
372	php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
373	strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \
374	php_open_temporary_file.c output.c internal_functions.c php_sprintf.c");
375ADD_SOURCES("win32", "inet.c fnmatch.c sockets.c");
376
377// Newer versions have it
378if (VCVERS <= 1300) {
379	ADD_SOURCES("win32", "strtoi64.c");
380}
381if (VCVERS >= 1400) {
382	AC_DEFINE('HAVE_STRNLEN', 1);
383}
384
385ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c plain_wrapper.c \
386	userspace.c transports.c xp_socket.c mmap.c glob_wrapper.c");
387
388ADD_SOURCES("win32", "glob.c readdir.c \
389	registry.c select.c sendmail.c time.c winutil.c wsyslog.c globals.c");
390
391PHP_INSTALL_HEADERS("", "Zend/ TSRM/ main/ main/streams/ win32/");
392
393STDOUT.WriteBlankLines(1);
394
395
396/* Can we build with IPv6 support? */
397ARG_ENABLE("ipv6", "Disable IPv6 support (default is turn it on if available)", "yes");
398
399var main_network_has_ipv6 = 0;
400if (PHP_IPV6 == "yes") {
401	main_network_has_ipv6 = CHECK_HEADER_ADD_INCLUDE("wspiapi.h", "CFLAGS") ? 1 : 0;
402}
403if (main_network_has_ipv6) {
404	STDOUT.WriteLine("Enabling IPv6 support");
405}
406AC_DEFINE('HAVE_GETADDRINFO', main_network_has_ipv6);
407AC_DEFINE('HAVE_GAI_STRERROR', main_network_has_ipv6);
408AC_DEFINE('HAVE_IPV6', main_network_has_ipv6);
409
410/* this allows up to 256 sockets to be select()ed in a single
411 * call to select(), instead of the usual 64 */
412ARG_ENABLE('fd-setsize', "Set maximum number of sockets for select(2)", "256");
413ADD_FLAG("CFLAGS", "/D FD_SETSIZE=" + parseInt(PHP_FD_SETSIZE));
414
415AC_DEFINE('HAVE_USLEEP', 1);
416AC_DEFINE('HAVE_STRCOLL', 1);
417
418/* For snapshot builders, where can we find the additional
419 * files that make up the snapshot template? */
420ARG_WITH("snapshot-template", "Path to snapshot builder template dir", "no");
421
422if (PHP_SNAPSHOT_TEMPLATE == "no") {
423	/* default is as a sibling of the php_build dir */
424	if (FSO.FolderExists(PHP_PHP_BUILD + "\\template")) {
425		PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\template");
426	} else if (FSO.FolderExists(PHP_PHP_BUILD + "\\..\\template")) {
427		PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\..\\template");
428	}
429}
430
431DEFINE('SNAPSHOT_TEMPLATE', PHP_SNAPSHOT_TEMPLATE);
432
433if (PHP_DSP != "no") {
434	if (FSO.FolderExists("tmp")) {
435		FSO.DeleteFolder("tmp");
436	}
437	FSO.CreateFolder("tmp");
438}
439
440ARG_ENABLE("security-flags", "Disable the compiler security flags", "yes");
441if (PHP_SECURITY_FLAGS == "yes") {
442	ADD_FLAG("LDFLAGS", "/NXCOMPAT /DYNAMICBASE ");
443}
444
445ARG_ENABLE("static-analyze", "Enable the VC compiler static analyze", "no");
446if (PHP_STATIC_ANALYZE == "yes") {
447	ADD_FLAG("CFLAGS", " /analyze ");
448	ADD_FLAG("CFLAGS", " /wd6308 ");
449}
450