xref: /PHP-5.5/win32/build/config.w32.phpize.in (revision 8044d068)
1// vim:ft=javascript
2// $Id: config.w32 306241 2010-12-11 22:18:10Z pajoye $
3// "Master" config file; think of it as a configure.in
4// equivalent.
5
6var PHP_CYGWIN="notset";
7PHP_CL = PATH_PROG('cl', null, 'PHP_CL');
8if (!PHP_CL) {
9	ERROR("MS C++ compiler is required");
10}
11/* For the record here: */
12// 1200 is VC6
13// 1300 is vs.net 2002
14// 1310 is vs.net 2003
15// 1400 is vs.net 2005
16// 1500 is vs.net 2008
17// 1600 is vs.net 2010
18// Which version of the compiler do we have?
19VCVERS = probe_binary(PHP_CL).substr(0, 5).replace('.', '');
20STDOUT.WriteLine("  Detected compiler " + VC_VERSIONS[VCVERS]);
21
22if (VCVERS < 1500) {
23	ERROR("Unsupported MS C++ Compiler, VC9 (2008) minimum is required");
24}
25
26AC_DEFINE('COMPILER', VC_VERSIONS[VCVERS], "Detected compiler version");
27DEFINE("PHP_COMPILER_SHORT", VC_VERSIONS_SHORT[VCVERS]);
28AC_DEFINE('PHP_COMPILER_ID', VC_VERSIONS_SHORT[VCVERS], "Compiler compatibility ID");
29
30// do we use x64 or 80x86 version of compiler?
31X64 = probe_binary(PHP_CL, 64, null, 'PHP_CL');
32if (X64) {
33	STDOUT.WriteLine("  Detected 64-bit compiler");
34} else {
35	STDOUT.WriteLine("  Detected 32-bit compiler");
36}
37AC_DEFINE('ARCHITECTURE', X64 ? 'x64' : 'x86', "Detected compiler architecture");
38DEFINE("PHP_ARCHITECTURE", X64 ? 'x64' : 'x86');
39
40// cygwin now ships with link.exe.  Avoid searching the cygwin path
41// for this, as we want the MS linker, not the fileutil
42PATH_PROG('link', WshShell.Environment("Process").Item("PATH"));
43PATH_PROG('nmake');
44
45// we don't want to define LIB, as that will override the default library path
46// that is set in that env var
47PATH_PROG('lib', null, 'MAKE_LIB');
48if (!PATH_PROG('bison')) {
49	ERROR('bison is required')
50}
51
52// There's a minimum requirement for re2c..
53MINRE2C = "0.13.4";
54
55RE2C = PATH_PROG('re2c');
56if (RE2C) {
57	var intvers, intmin;
58	var pattern = /\./g;
59
60	RE2CVERS = probe_binary(RE2C, "version");
61	STDOUT.WriteLine('  Detected re2c version ' + RE2CVERS);
62
63	intvers = RE2CVERS.replace(pattern, '') - 0;
64	intmin = MINRE2C.replace(pattern, '') - 0;
65
66	if (intvers < intmin) {
67		STDOUT.WriteLine('WARNING: The minimum RE2C version requirement is ' + MINRE2C);
68		STDOUT.WriteLine('Parsers will not be generated. Upgrade your copy at http://sf.net/projects/re2c');
69		DEFINE('RE2C', '');
70	} else {
71		DEFINE('RE2C_FLAGS', '');
72	}
73} else {
74	STDOUT.WriteLine('Parsers will not be regenerated');
75}
76PATH_PROG('zip');
77PATH_PROG('lemon');
78
79// avoid picking up midnight commander from cygwin
80PATH_PROG('mc', WshShell.Environment("Process").Item("PATH"));
81
82// Try locating manifest tool
83if (VCVERS > 1200) {
84	PATH_PROG('mt', WshShell.Environment("Process").Item("PATH"));
85}
86
87// stick objects somewhere outside of the source tree
88ARG_ENABLE('object-out-dir', 'Alternate location for binary objects during build', '');
89if (PHP_OBJECT_OUT_DIR.length) {
90	PHP_OBJECT_OUT_DIR = FSO.GetAbsolutePathName(PHP_OBJECT_OUT_DIR);
91	if (!FSO.FolderExists(PHP_OBJECT_OUT_DIR)) {
92		ERROR('you chosen output directory ' + PHP_OBJECT_OUT_DIR + ' does not exist');
93	}
94	PHP_OBJECT_OUT_DIR += '\\';
95} else if (X64) {
96	if (!FSO.FolderExists("x64")) {
97		FSO.CreateFolder("x64");
98	}
99	PHP_OBJECT_OUT_DIR = 'x64\\';
100}
101
102ARG_ENABLE('debug', 'Compile with debugging symbols', "no");
103ARG_ENABLE('debug-pack', 'Release binaries with external debug symbols (--enable-debug must not be specified)', 'no');
104if (PHP_DEBUG == "yes" && PHP_DEBUG_PACK == "yes") {
105	ERROR("Use of both --enable-debug and --enable-debug-pack not allowed.");
106}
107
108if (PHP_PREFIX == '') {
109	PHP_PREFIX = "C:\\php";
110	if (PHP_DEBUG == "yes")
111		PHP_PREFIX += "\\debug";
112}
113DEFINE('PHP_PREFIX', PHP_PREFIX);
114
115DEFINE("BASE_INCLUDES", "/I " + PHP_DIR + "/include /I " + PHP_DIR + "/include/main /I " + PHP_DIR + "/include/Zend /I " + PHP_DIR + "/include/TSRM /I " + PHP_DIR + "/include/ext ");
116
117// CFLAGS for building the PHP dll
118DEFINE("CFLAGS_PHP", "/D _USRDLL /D PHP5DLLTS_EXPORTS /D PHP_EXPORTS \
119/D LIBZEND_EXPORTS /D TSRM_EXPORTS /D SAPI_EXPORTS /D WINVER=0x500");
120
121DEFINE('CFLAGS_PHP_OBJ', '$(CFLAGS_PHP) $(STATIC_EXT_CFLAGS)');
122
123// General CFLAGS for building objects
124DEFINE("CFLAGS", "/nologo /FD $(BASE_INCLUDES) /D _WINDOWS \
125/D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _MBCS /W3 ");
126
127if (VCVERS < 1400) {
128	// Enable automatic precompiled headers
129	ADD_FLAG('CFLAGS', ' /YX ');
130
131	if (PHP_DEBUG == "yes") {
132		// Set some debug/release specific options
133		ADD_FLAG('CFLAGS', ' /GZ ');
134	}
135}
136
137if (VCVERS >= 1400) {
138	// fun stuff: MS deprecated ANSI stdio and similar functions
139	// disable annoying warnings.  In addition, time_t defaults
140	// to 64-bit.  Ask for 32-bit.
141	if (X64) {
142		ADD_FLAG('CFLAGS', ' /wd4996 ');
143	} else {
144		ADD_FLAG('CFLAGS', ' /wd4996 /D_USE_32BIT_TIME_T=1 ');
145	}
146
147	if (PHP_DEBUG == "yes") {
148		// Set some debug/release specific options
149		ADD_FLAG('CFLAGS', ' /RTC1 ');
150	}
151}
152
153ARG_WITH('prefix', 'PHP installation prefix', '');
154ARG_WITH('mp', 'Tell VC9+ use up to [n,auto,disable] processes for compilation', 'auto');
155if (VCVERS >= 1500 && PHP_MP != 'disable') {
156		// no from disable-all
157		if(PHP_MP == 'auto' || PHP_MP == 'no') {
158			 ADD_FLAG('CFLAGS', ' /MP ');
159		} else {
160			if(parseInt(PHP_MP) != 0) {
161				ADD_FLAG('CFLAGS', ' /MP'+ PHP_MP +' ');
162			} else {
163				STDOUT.WriteLine('WARNING: Invalid argument for MP: ' + PHP_MP);
164			}
165		}
166}
167
168/* For snapshot builders, where can we find the additional
169 * files that make up the snapshot template? */
170ARG_WITH("snapshot-template", "Path to snapshot builder template dir", "no");
171
172// General DLL link flags
173DEFINE("DLL_LDFLAGS", "/dll ");
174
175// PHP DLL link flags
176DEFINE("PHP_LDFLAGS", "$(DLL_LDFLAGS)");
177
178// General libs
179// urlmon.lib ole32.lib oleaut32.lib uuid.lib gdi32.lib winspool.lib comdlg32.lib
180DEFINE("LIBS", "kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib Dnsapi.lib");
181
182// Set some debug/release specific options
183if (PHP_DEBUG == "yes") {
184	ADD_FLAG("CFLAGS", "/LDd /MDd /W3 /Gm /Od /D _DEBUG /D ZEND_DEBUG=1 " +
185		(X64?"/Zi":"/ZI"));
186	ADD_FLAG("LDFLAGS", "/debug");
187	// Avoid problems when linking to release libraries that use the release
188	// version of the libc
189	ADD_FLAG("PHP_LDFLAGS", "/nodefaultlib:msvcrt");
190} else {
191	// Generate external debug files when --enable-debug-pack is specified
192	if (PHP_DEBUG_PACK == "yes") {
193		ADD_FLAG("CFLAGS", "/Zi");
194		ADD_FLAG("LDFLAGS", "/incremental:no /debug /opt:ref,icf");
195	}
196	// Equivalent to Release_TSInline build -> best optimization
197	ADD_FLAG("CFLAGS", "/LD /MD /W3 /Ox /D NDebug /D NDEBUG /D ZEND_WIN32_FORCE_INLINE /GF /D ZEND_DEBUG=0");
198
199	// if you have VS.Net /GS hardens the binary against buffer overruns
200	// ADD_FLAG("CFLAGS", "/GS");
201}
202
203if (PHP_ZTS == "yes") {
204	ADD_FLAG("CFLAGS", "/D ZTS=1");
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	if (!MODE_PHPIZE) {
217		DEFINE("PHPDLL", "php" + PHP_VERSION + "ts_debug.dll");
218		DEFINE("PHPLIB", "php" + PHP_VERSION + "ts_debug.lib");
219	}
220} else if (PHP_DEBUG == "yes" && PHP_ZTS == "no") {
221	DEFINE("BUILD_DIR", PHP_OBJECT_OUT_DIR + "Debug");
222	if (!MODE_PHPIZE) {
223		DEFINE("PHPDLL", "php" + PHP_VERSION + "_debug.dll");
224		DEFINE("PHPLIB", "php" + PHP_VERSION + "_debug.lib");
225	}
226} else if (PHP_DEBUG == "no" && PHP_ZTS == "yes") {
227	DEFINE("BUILD_DIR", PHP_OBJECT_OUT_DIR + "Release_TS");
228	if (!MODE_PHPIZE) {
229		DEFINE("PHPDLL", "php" + PHP_VERSION + "ts.dll");
230		DEFINE("PHPLIB", "php" + PHP_VERSION + "ts.lib");
231	}
232} else if (PHP_DEBUG == "no" && PHP_ZTS == "no") {
233	DEFINE("BUILD_DIR", PHP_OBJECT_OUT_DIR + "Release");
234	if (!MODE_PHPIZE) {
235		DEFINE("PHPDLL", "php" + PHP_VERSION + ".dll");
236		DEFINE("PHPLIB", "php" + PHP_VERSION + ".lib");
237	}
238}
239
240if (MODE_PHPIZE) {
241	DEFINE("PHPDLL", PHP_DLL);
242	DEFINE("PHPLIB", PHP_DLL_LIB);
243}
244
245// Find the php_build dir - it contains headers and libraries
246// that we need
247ARG_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');
248
249if (PHP_PHP_BUILD == 'no') {
250	if (FSO.FolderExists("..\\deps")) {
251		PHP_PHP_BUILD = "..\\deps";
252	} else {
253		if (FSO.FolderExists("..\\php_build")) {
254			PHP_PHP_BUILD = "..\\php_build";
255		} else {
256			if (X64) {
257				if (FSO.FolderExists("..\\win64build")) {
258					PHP_PHP_BUILD = "..\\win64build";
259				} else if (FSO.FolderExists("..\\php-win64-dev\\php_build")) {
260					PHP_PHP_BUILD = "..\\php-win64-dev\\php_build";
261				}
262			} else {
263				if (FSO.FolderExists("..\\win32build")) {
264					PHP_PHP_BUILD = "..\\win32build";
265				} else if (FSO.FolderExists("..\\php-win32-dev\\php_build")) {
266					PHP_PHP_BUILD = "..\\php-win32-dev\\php_build";
267				}
268			}
269		}
270	}
271	PHP_PHP_BUILD = FSO.GetAbsolutePathName(PHP_PHP_BUILD);
272}
273DEFINE("PHP_BUILD", PHP_PHP_BUILD);
274
275ARG_WITH('extra-includes', 'Extra include path to use when building everything', '');
276ARG_WITH('extra-libs', 'Extra library path to use when linking everything', '');
277
278var php_usual_include_suspects = PHP_PHP_BUILD+"\\include";
279var php_usual_lib_suspects = PHP_PHP_BUILD+"\\lib";
280
281ADD_FLAG("CFLAGS", '/I "' + php_usual_include_suspects + '" ');
282ADD_FLAG("LDFLAGS", '/libpath:"\\"' + php_usual_lib_suspects + '\\"" ');
283
284// Poke around for some headers
285function probe_basic_headers()
286{
287	var p;
288
289	if (PHP_PHP_BUILD != "no") {
290		php_usual_include_suspects += ";" + PHP_PHP_BUILD + "\\include";
291		php_usual_lib_suspects += ";" + PHP_PHP_BUILD + "\\lib";
292	}
293}
294
295function add_extra_dirs()
296{
297	var path, i, f;
298
299	if (PHP_EXTRA_INCLUDES.length) {
300		path = PHP_EXTRA_INCLUDES.split(';');
301		for (i = 0; i < path.length; i++) {
302			f = FSO.GetAbsolutePathName(path[i]);
303			if (FSO.FolderExists(f)) {
304				ADD_FLAG("CFLAGS", '/I "' + f + '" ');
305			}
306		}
307	}
308	if (PHP_EXTRA_LIBS.length) {
309		path = PHP_EXTRA_LIBS.split(';');
310		for (i = 0; i < path.length; i++) {
311			f = FSO.GetAbsolutePathName(path[i]);
312			if (FSO.FolderExists(f)) {
313				if (VCVERS <= 1200 && f.indexOf(" ") >= 0) {
314					ADD_FLAG("LDFLAGS", '/libpath:"\\"' + f + '\\"" ');
315				} else {
316					ADD_FLAG("LDFLAGS", '/libpath:"' + f + '" ');
317				}
318			}
319		}
320	}
321
322}
323
324probe_basic_headers();
325add_extra_dirs();
326
327//DEFINE("PHP_BUILD", PHP_PHP_BUILD);
328
329STDOUT.WriteBlankLines(1);
330STDOUT.WriteLine("Build dir: " + get_define('BUILD_DIR'));
331STDOUT.WriteLine("PHP Core:  " + get_define('PHPDLL') + " and " + get_define('PHPLIB'));
332
333
334if (VCVERS == 1200) {
335	AC_DEFINE('ZEND_DVAL_TO_LVAL_CAST_OK', 1);
336}
337
338if (VCVERS >= 1400) {
339	AC_DEFINE('HAVE_STRNLEN', 1);
340}
341
342STDOUT.WriteBlankLines(1);
343
344if (PHP_SNAPSHOT_TEMPLATE == "no") {
345	/* default is as a sibling of the php_build dir */
346	if (FSO.FolderExists(PHP_PHP_BUILD + "\\template")) {
347		PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\template");
348	} else if (FSO.FolderExists(PHP_PHP_BUILD + "\\..\\template")) {
349		PHP_SNAPSHOT_TEMPLATE = FSO.GetAbsolutePathName(PHP_PHP_BUILD + "\\..\\template");
350	}
351}
352
353DEFINE('SNAPSHOT_TEMPLATE', PHP_SNAPSHOT_TEMPLATE);
354
355if (PHP_DSP != "no") {
356	if (FSO.FolderExists("tmp")) {
357		FSO.DeleteFolder("tmp");
358	}
359	FSO.CreateFolder("tmp");
360}
361
362AC_DEFINE("PHP_DIR", PHP_DIR);
363DEFINE("PHP_DIR", PHP_DIR);
364