xref: /PHP-7.2/win32/build/Makefile (revision 60a69dae)
1#  +----------------------------------------------------------------------+
2#  | PHP Version 7                                                        |
3#  +----------------------------------------------------------------------+
4#  | Copyright (c) 1997-2018 The PHP Group                                |
5#  +----------------------------------------------------------------------+
6#  | This source file is subject to version 3.01 of the PHP license,      |
7#  | that is bundled with this package in the file LICENSE, and is        |
8#  | available through the world-wide-web at the following url:           |
9#  | http://www.php.net/license/3_01.txt                                  |
10#  | If you did not receive a copy of the PHP license and are unable to   |
11#  | obtain it through the world-wide-web, please send a note to          |
12#  | license@php.net so we can mail you a copy immediately.               |
13#  +----------------------------------------------------------------------+
14#  | Author: Wez Furlong <wez@thebrainroom.com>                           |
15#  +----------------------------------------------------------------------+
16#
17# $Id$
18# This is the makefile template for the win32 build
19
20CC="$(PHP_CL)"
21LD="$(LINK)"
22MC="$(MC)"
23MT="$(MT)"
24RE2C="$(RE2C)"
25PGOMGR="$(PGOMGR)"
26PHP_BUILD=$(PHP_BUILD)
27
28MCFILE=$(BUILD_DIR)\wsyslog.rc
29BUILD_DIR_DEV_NAME=php-$(PHP_VERSION_STRING)-devel-$(PHP_COMPILER_SHORT)-$(PHP_ARCHITECTURE)
30BUILD_DIR_DEV=$(BUILD_DIR)\$(BUILD_DIR_DEV_NAME)
31
32DIST_ZIP_SNAP=php-$(PHP_VERSION_STRING)$(PHP_ZTS_ARCHIVE_POSTFIX)-Win32-$(PHP_COMPILER_SHORT)-$(PHP_ARCHITECTURE).zip
33DIST_ZIP_PECL=pecl-$(PHP_VERSION_STRING)$(PHP_ZTS_ARCHIVE_POSTFIX)-Win32-$(PHP_COMPILER_SHORT)-$(PHP_ARCHITECTURE).zip
34DIST_ZIP_DEV_PACK=php-devel-pack-$(PHP_VERSION_STRING)$(PHP_ZTS_ARCHIVE_POSTFIX)-Win32-$(PHP_COMPILER_SHORT)-$(PHP_ARCHITECTURE).zip
35DIST_ZIP_TEST_PACK=php-test-pack-$(PHP_VERSION_STRING).zip
36DIST_ZIP_DEBUG_PACK=php-debug-pack-$(PHP_VERSION_STRING)$(PHP_ZTS_ARCHIVE_POSTFIX)-Win32-$(PHP_COMPILER_SHORT)-$(PHP_ARCHITECTURE).zip
37
38!if "$(DEBUGGER)" == "1"
39DEBUGGER_CMD=devenv
40DEBUGGER_ARGS=/debugexe
41!else
42DEBUGGER_CMD=
43DEBUGGER_ARGS=
44!endif
45
46all: generated_files $(EXT_TARGETS) $(PECL_TARGETS) $(SAPI_TARGETS)
47
48build_dirs: $(BUILD_DIR) $(BUILD_DIRS_SUB) $(BUILD_DIR_DEV)
49
50!if $(RE2C) == ""
51generated_files: build_dirs Zend\zend_ini_parser.c \
52	Zend\zend_language_parser.c \
53	sapi\phpdbg\phpdbg_parser.c \
54	$(PHPDEF) $(MCFILE)
55!else
56generated_files: build_dirs Zend\zend_ini_parser.c \
57	Zend\zend_language_parser.c Zend\zend_ini_scanner.c \
58	Zend\zend_language_scanner.c \
59	sapi\phpdbg\phpdbg_parser.c sapi\phpdbg\phpdbg_lexer.c \
60	$(PHPDEF) $(MCFILE)
61!endif
62
63$(BUILD_DIR)\$(PHPDLL).def: $(PHP_DLL_DEF_SOURCES)
64	type $(PHP_DLL_DEF_SOURCES) > $(BUILD_DIR)\$(PHPDLL).def
65
66Zend\zend_ini_parser.c Zend\zend_ini_parser.h: Zend\zend_ini_parser.y
67	$(BISON) --output=Zend/zend_ini_parser.c -v -d -p ini_ Zend/zend_ini_parser.y
68
69Zend\zend_language_parser.c Zend\zend_language_parser.h: Zend\zend_language_parser.y
70	$(BISON) --output=Zend/zend_language_parser.c -v -d -p zend Zend/zend_language_parser.y
71	@if "$(SED)" neq "" $(SED) -i "s,^int zendparse\(.*\),ZEND_API int zendparse\1,g" Zend/zend_language_parser.c
72	@if "$(SED)" neq "" $(SED) -i "s,^int zendparse\(.*\),ZEND_API int zendparse\1,g" Zend/zend_language_parser.h
73	@if "$(SED)" neq "" $(SED) -i "s,^#ifndef YYTOKENTYPE,#include \"zend.h\"\n#ifndef YYTOKENTYPE,g" Zend/zend_language_parser.h
74
75sapi\phpdbg\phpdbg_parser.c sapi\phpdbg\phpdbg_parser.h: sapi\phpdbg\phpdbg_parser.y
76	$(BISON) --output=sapi/phpdbg/phpdbg_parser.c -v -d -p phpdbg_ sapi/phpdbg/phpdbg_parser.y
77
78!if $(RE2C) != ""
79Zend\zend_ini_scanner.c: Zend\zend_ini_scanner.l
80	$(RE2C) $(RE2C_FLAGS) --no-generation-date --case-inverted -cbdFt Zend/zend_ini_scanner_defs.h -oZend/zend_ini_scanner.c Zend/zend_ini_scanner.l
81
82Zend\zend_language_scanner.c: Zend\zend_language_scanner.l
83	$(RE2C) $(RE2C_FLAGS) --no-generation-date --case-inverted -cbdFt Zend/zend_language_scanner_defs.h -oZend/zend_language_scanner.c Zend/zend_language_scanner.l
84
85sapi\phpdbg\phpdbg_lexer.c: sapi\phpdbg\phpdbg_lexer.l
86	$(RE2C) $(RE2C_FLAGS) --no-generation-date -cbdFo sapi/phpdbg/phpdbg_lexer.c sapi/phpdbg/phpdbg_lexer.l
87!endif
88
89!if "$(ZTS)" == "1"
90PHP7_PGD_SUFFIX=ts
91!else
92PHP7_PGD_SUFFIX=
93!endif
94
95!if $(PGOMGR) != ""
96PHP7_PGD_OPTION=/PGD:$(PGOPGD_DIR)\php7$(PHP7_PGD_SUFFIX).pgd
97!else
98PHP7_PGD_OPTION=
99!endif
100
101PHPDLL_RES=$(BUILD_DIR)\$(PHPDLL).res
102
103$(MCFILE): win32\build\wsyslog.mc
104	$(MC) -h win32\ -r $(BUILD_DIR)\ -x $(BUILD_DIR)\ win32\build\wsyslog.mc
105
106#	$(RC) /fo $(MCFILE) $(BUILD_DIR)\wsyslog.rc
107
108!if $(MT) == ""
109_VC_MANIFEST_EMBED_EXE=
110_VC_MANIFEST_EMBED_DLL=
111!else
112_VC_MANIFEST_EMBED_EXE= if exist $@.manifest $(MT) -nologo -manifest $@.manifest -outputresource:$@;1
113_VC_MANIFEST_EMBED_DLL= if exist $@.manifest $(MT) -nologo -manifest $@.manifest -outputresource:$@;2
114!endif
115
116$(PHPDLL_RES): win32\build\template.rc
117	$(RC) /nologo /fo $(PHPDLL_RES) /d FILE_DESCRIPTION="\"PHP Script Interpreter\"" \
118		/d FILE_NAME="\"$(PHPDLL)\"" /d PRODUCT_NAME="\"PHP Script Interpreter\"" \
119		/I$(BUILD_DIR) /d MC_INCLUDE="\"$(MCFILE)\"" \
120		win32\build\template.rc
121
122$(BUILD_DIR)\$(PHPDLL): generated_files $(PHPDEF) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(PHPDLL_RES) $(MCFILE)
123	@copy win32\build\default.manifest $(BUILD_DIR)\$(PHPDLL).manifest >nul
124#	@$(CC) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(STATIC_EXT_LIBS) $(LIBS) $(PHPDLL_RES) /link /out:$(BUILD_DIR)\$(PHPDLL) $(PHP7_PGD_OPTION) $(PHP_LDFLAGS) $(LDFLAGS) $(STATIC_EXT_LDFLAGS)
125	@"$(LINK)" $(PHP_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(LIBS) $(PHPDLL_RES) /out:$(BUILD_DIR)\$(PHPDLL) $(PHP7_PGD_OPTION) $(PHP_LDFLAGS) $(LDFLAGS) $(STATIC_EXT_LDFLAGS)
126	-@$(_VC_MANIFEST_EMBED_DLL)
127
128$(BUILD_DIR)\$(PHPLIB): $(BUILD_DIR)\$(PHPDLL)
129
130$(BUILD_DIR) $(BUILD_DIRS_SUB) $(BUILD_DIR_DEV):
131	@echo Recreating build dirs
132	@if not exist $(BUILD_DIR) mkdir $(BUILD_DIR)
133	@cd $(BUILD_DIR)
134	@for %D in ($(BUILD_DIRS_SUB)) do @if not exist %D @mkdir %D > NUL
135	@if not exist $(BUILD_DIR_DEV) @mkdir $(BUILD_DIR_DEV) > NUL
136	@cd "$(PHP_SRC_DIR)"
137
138
139clean-sapi:
140	@echo Cleaning SAPI
141	@for %D in (_x $(EXT_TARGETS)) do @if exist $(BUILD_DIR)\%D @del /F /Q $(BUILD_DIR)\%D > NUL
142	@for %D in (_x $(PECL_TARGETS)) do @if exist $(BUILD_DIR)\%D @del /F /Q $(BUILD_DIR)\%D > NUL
143	@for %D in (_x $(SAPI_TARGETS)) do @if exist $(BUILD_DIR)\%D @del /F /Q $(BUILD_DIR)\%D > NUL
144	-@del /F /Q $(BUILD_DIR)\$(PHPDLL)
145
146clean: clean-sapi
147	@echo Cleaning distribution build dirs
148	@cd $(BUILD_DIR)
149	@for %D in (_x $(BUILD_DIRS_SUB)) do @if exist %D @del /F /Q %D\*.* > NUL
150	@cd "$(PHP_SRC_DIR)"
151	-@del /F /Q $(BUILD_DIR)\*.res $(BUILD_DIR)\*.manifest $(BUILD_DIR)\*.lib $(BUILD_DIR)\*.ilk $(BUILD_DIR)\*.pdb $(BUILD_DIR)\*.exp $(PHPDEF) $(BUILD_DIR)\php-$(PHP_VERSION_STRING)-Win32.zip $(BUILD_DIR)\pecl-$(PHP_VERSION_STRING)-Win32.zip > NUL
152	-rd /s /q $(BUILD_DIR)\php-$(PHP_VERSION_STRING)
153
154clean-pecl:
155	@echo Cleaning PECL targets only
156	-rd /s /q $(BUILD_DIR)\pecl
157
158clean-all:
159	@echo Cleaning standard build dirs
160	@cd $(BUILD_DIR)
161	@for %D in (_x $(BUILD_DIRS_SUB)) do @if exist %D @rd /s /q %D
162	@cd "$(PHP_SRC_DIR)"
163	-@del /f /q $(BUILD_DIR)\*.res $(BUILD_DIR)\*.lib $(BUILD_DIR)\*.ilk $(BUILD_DIR)\*.pdb $(BUILD_DIR)\*.exp $(PHPDEF) $(BUILD_DIR)\*.rc $(BUILD_DIR)\*.manifest $(BUILD_DIR)\*.dbg $(BUILD_DIR)\*.bin $(BUILD_DIR)\php*.dll $(BUILD_DIR)\php*.exe > NUL
164
165clean-pgo: clean-all
166	-rd /s /q $(BUILD_DIR)\php-$(PHP_VERSION_STRING)
167	-rd /s /q $(BUILD_DIR)\pecl-$(PHP_VERSION_STRING)
168	-rd /s /q $(BUILD_DIR)\php-test-pack-$(PHP_VERSION_STRING)
169	-del /f /q $(BUILD_DIR)\$(DIST_ZIP_SNAP)
170	-del /f /q $(BUILD_DIR)\$(DIST_ZIP_DEBUG_PACK)
171	-del /f /q $(BUILD_DIR)\$(DIST_ZIP_PECL)
172	-del /f /q $(BUILD_DIR)\$(DIST_ZIP_TEST_PACK)
173
174
175!if $(PHP_TEST_INI_PATH) == ""
176test: set-tmp-env
177	$(DEBUGGER_CMD) $(DEBUGGER_ARGS) "$(BUILD_DIR)\php.exe" -d open_basedir= -d output_buffering=0 run-tests.php $(TESTS) -p "$(BUILD_DIR)\php.exe"
178
179run: set-tmp-env
180	$(DEBUGGER_CMD) $(DEBUGGER_ARGS) "$(BUILD_DIR)\php.exe" $(ARGS)
181!else
182test: set-tmp-env
183	$(DEBUGGER_CMD) $(DEBUGGER_ARGS) "$(BUILD_DIR)\php.exe" -n -c $(PHP_TEST_INI_PATH) -d open_basedir= -d output_buffering=0 -d memory_limit=-1 run-tests.php -p "$(BUILD_DIR)\php.exe" -n -c $(PHP_TEST_INI_PATH) $(TESTS)
184
185run: set-tmp-env
186	$(DEBUGGER_CMD) $(DEBUGGER_ARGS) "$(BUILD_DIR)\php.exe" -n -c $(PHP_TEST_INI_PATH) $(ARGS)
187!endif
188
189build-snap: set-tmp-env generated_files
190	@$(MAKE) "$(BUILD_DIR)\$(PHPDLL)"
191	-for %T in ($(SAPI_TARGETS)) do $(MAKE) /I /nologo "%T"
192	-for %T in ($(EXT_TARGETS)) do $(MAKE) /I /nologo "%T"
193	-for %T in ($(PECL_TARGETS)) do $(MAKE) /I /nologo "%T"
194
195build-dist: $(BUILD_DIR)\deplister.exe
196	-rd /s /q $(BUILD_DIR)\php-$(PHP_VERSION_STRING)
197	-rd /s /q $(BUILD_DIR)\pecl-$(PHP_VERSION_STRING)
198	-del /f /q $(BUILD_DIR)\$(DIST_ZIP_SNAP)
199	-del /f /q $(BUILD_DIR)\$(DIST_ZIP_DEBUG_PACK)
200	-del /f /q $(BUILD_DIR)\$(DIST_ZIP_PECL)
201	$(PHP_SDK_PHP_CMD) -d date.timezone=UTC -n -dphar.readonly=0 win32/build/mkdist.php "$(PHP_VERSION_STRING)" "$(BUILD_DIR)" "$(PHP_BUILD)" "$(PHPDLL)" "$(SAPI_TARGETS)" "$(EXT_TARGETS) $(PHP_EXTRA_DIST_FILES)" "$(PECL_TARGETS) $(PECL_EXTRA_DIST_FILES)" "$(SNAPSHOT_TEMPLATE)"
202	cd $(BUILD_DIR)\php-$(PHP_VERSION_STRING)
203	-$(ZIP) -9 -q -r ..\$(DIST_ZIP_SNAP) .
204	cd $(BUILD_DIR)\pecl-$(PHP_VERSION_STRING)
205	-$(ZIP) -9 -q -r ..\$(DIST_ZIP_PECL) .
206	cd $(BUILD_DIR)\php-test-pack-$(PHP_VERSION_STRING)
207	-$(ZIP) -9 -q -r ..\$(DIST_ZIP_TEST_PACK) .
208	cd $(BUILD_DIR)
209	-$(ZIP) -9 -q $(DIST_ZIP_DEBUG_PACK) *.pdb
210	-$(ZIP) -9 -q -r $(DIST_ZIP_DEV_PACK) $(BUILD_DIR_DEV_NAME)
211	cd $(BUILD_DIR)
212
213dist: all build-dist
214snap: build-snap build-devel build-dist
215
216$(BUILD_DIR)\deplister.exe:	win32\build\deplister.c
217	$(CC) /nologo /Fo$(BUILD_DIR)\ /Fd$(BUILD_DIR)\ /Fp$(BUILD_DIR)\ /FR$(BUILD_DIR) /Fe$(BUILD_DIR)\deplister.exe win32\build\deplister.c imagehlp.lib
218
219# need to redirect, since INSTALL is a file in the root...
220install: really-install install-sdk
221
222build-lib: build-ext-libs
223	@if not exist $(BUILD_DIR_DEV)\lib mkdir $(BUILD_DIR_DEV)\lib >nul
224	@copy $(BUILD_DIR)\$(PHPLIB) $(BUILD_DIR_DEV)\lib /y >nul
225
226build-devel: build-headers build-lib
227	@if not exist $(BUILD_DIR_DEV)\script mkdir $(BUILD_DIR_DEV)\script >nul
228	@if not exist $(BUILD_DIR_DEV)\build mkdir $(BUILD_DIR_DEV)\build >nul
229	@copy run-tests.php $(BUILD_DIR_DEV)\script\ /y >nul
230	@copy win32\build\confutils.js $(BUILD_DIR_DEV)\script\ /y >nul
231	@copy win32\build\configure.tail $(BUILD_DIR_DEV)\script\ /y >nul
232	@copy win32\build\config.w32.phpize.in $(BUILD_DIR_DEV)\script\ /y >nul
233	@copy win32\build\Makefile.phpize $(BUILD_DIR_DEV)\script\ /y >nul
234	@copy win32\build\phpize.bat $(BUILD_DIR_DEV)\ /y >nul
235	@copy win32\build\template.rc $(BUILD_DIR_DEV)\build\ /y >nul
236	@copy win32\build\default.manifest $(BUILD_DIR_DEV)\build\ /y >nul
237	@copy $(BUILD_DIR)\devel\config.phpize.js $(BUILD_DIR_DEV)\script\ /y >nul
238	@copy $(BUILD_DIR)\devel\phpize.js $(BUILD_DIR_DEV)\script\ /y >nul
239	@copy $(BUILD_DIR)\devel\ext_deps.js $(BUILD_DIR_DEV)\script\ /y >nul
240
241install-sdk: build-devel
242	@xcopy /Q /Y /E /I $(BUILD_DIR_DEV)\* $(PHP_PREFIX)\SDK
243
244really-install:
245	@if not exist $(PHP_PREFIX) mkdir $(PHP_PREFIX)
246	@if not exist $(PHP_PREFIX)\ext mkdir $(PHP_PREFIX)\ext
247	@echo Installing files under $(PHP_PREFIX)
248	@if exist $(BUILD_DIR)\*.exe copy $(BUILD_DIR)\*.exe $(PHP_PREFIX) /y >nul
249	@type nul > $(BUILD_DIR)\extension_dlls.txt
250	@if exist $(BUILD_DIR)\php_*.dll copy $(BUILD_DIR)\php_*.dll $(PHP_PREFIX)\ext /y >nul & dir /b $(BUILD_DIR)\php_*.dll > $(BUILD_DIR)\extension_dlls.txt
251	@xcopy $(BUILD_DIR)\*.dll /exclude:$(BUILD_DIR)\extension_dlls.txt $(PHP_PREFIX) /y >nul
252	@echo Registering event source with syslog (requires admin rights)
253	@echo It's okay for this step to fail:
254	-$(PHP_PREFIX)\php.exe -n -dextension_dir=$(PHP_PREFIX) win32/build/registersyslog.php $(PHP_PREFIX)\$(PHPDLL)
255