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