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