xref: /PHP-8.3/win32/build/Makefile (revision a7d57e24)
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)
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) --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) --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	@if "$(SED)" neq "" $(SED) -i "s,^#ifndef YYTOKENTYPE,#include \"zend.h\"\n#ifndef YYTOKENTYPE,g" Zend/zend_language_parser.h
88
89sapi\phpdbg\phpdbg_parser.c sapi\phpdbg\phpdbg_parser.h: sapi\phpdbg\phpdbg_parser.y
90	$(BISON) --output=sapi/phpdbg/phpdbg_parser.c -v -d sapi/phpdbg/phpdbg_parser.y
91
92!if $(RE2C) != ""
93Zend\zend_ini_scanner.c Zend\zend_ini_scanner_defs.h: Zend\zend_ini_scanner.l
94	$(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
95
96Zend\zend_language_scanner.c Zend\zend_language_scanner_defs.h: Zend\zend_language_scanner.l
97	$(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
98
99sapi\phpdbg\phpdbg_lexer.c: sapi\phpdbg\phpdbg_lexer.l
100	$(RE2C) $(RE2C_FLAGS) --no-generation-date -cbdFo sapi/phpdbg/phpdbg_lexer.c sapi/phpdbg/phpdbg_lexer.l
101!endif
102
103!if "$(ZTS)" == "1"
104PHP8_PGD_SUFFIX=ts
105!else
106PHP8_PGD_SUFFIX=
107!endif
108
109!if $(PGOMGR) != ""
110PHP8_PGD_OPTION=/PGD:$(PGOPGD_DIR)\php8$(PHP8_PGD_SUFFIX).pgd
111!else
112PHP8_PGD_OPTION=
113!endif
114
115PHPDLL_RES=$(BUILD_DIR)\$(PHPDLL).res
116
117$(MCFILE): win32\build\wsyslog.mc
118	$(MC) -h win32\ -r $(BUILD_DIR)\ -x $(BUILD_DIR)\ win32\build\wsyslog.mc
119
120#	$(RC) /fo $(MCFILE) $(BUILD_DIR)\wsyslog.rc
121
122!if $(MT) == ""
123_VC_MANIFEST_EMBED_EXE=
124_VC_MANIFEST_EMBED_DLL=
125!else
126_VC_MANIFEST_EMBED_EXE= if exist $@.manifest $(MT) -nologo -manifest $@.manifest -outputresource:$@;1
127_VC_MANIFEST_EMBED_DLL= if exist $@.manifest $(MT) -nologo -manifest $@.manifest -outputresource:$@;2
128!endif
129
130$(PHPDLL_RES): win32\build\template.rc
131	$(RC) /nologo /fo $(PHPDLL_RES) /d FILE_DESCRIPTION="\"PHP Script Interpreter\"" \
132		/d FILE_NAME="\"$(PHPDLL)\"" /d PRODUCT_NAME="\"PHP Script Interpreter\"" \
133		/I$(BUILD_DIR) /d MC_INCLUDE="\"$(MCFILE)\"" \
134		win32\build\template.rc
135
136$(BUILD_DIR)\$(PHPDLL): generated_files $(PHPDEF) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(PHPDLL_RES) $(ASM_OBJS) $(MCFILE)
137	@copy win32\build\default.manifest $(BUILD_DIR)\$(PHPDLL).manifest >nul
138#	@$(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)
139	@"$(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)
140	-@$(_VC_MANIFEST_EMBED_DLL)
141
142$(BUILD_DIR)\$(PHPLIB): $(BUILD_DIR)\$(PHPDLL)
143
144$(BUILD_DIR) $(BUILD_DIRS_SUB) $(BUILD_DIR_DEV):
145	@echo Recreating build dirs
146	@if not exist $(BUILD_DIR) mkdir $(BUILD_DIR)
147	@cd $(BUILD_DIR)
148	@for %D in ($(BUILD_DIRS_SUB)) do @if not exist %D @mkdir %D > NUL
149	@if not exist $(BUILD_DIR_DEV) @mkdir $(BUILD_DIR_DEV) > NUL
150	@cd "$(PHP_SRC_DIR)"
151
152
153clean-sapi:
154	@echo Cleaning SAPI
155	@for %D in (_x $(EXT_TARGETS)) do @if exist $(BUILD_DIR)\%D @del /F /Q $(BUILD_DIR)\%D > NUL
156	@for %D in (_x $(PECL_TARGETS)) do @if exist $(BUILD_DIR)\%D @del /F /Q $(BUILD_DIR)\%D > NUL
157	@for %D in (_x $(SAPI_TARGETS)) do @if exist $(BUILD_DIR)\%D @del /F /Q $(BUILD_DIR)\%D > NUL
158	-@del /F /Q $(BUILD_DIR)\$(PHPDLL)
159
160clean: clean-sapi
161	@echo Cleaning distribution build dirs
162	@cd $(BUILD_DIR)
163	@for %D in (_x $(BUILD_DIRS_SUB)) do @if exist %D @del /F /Q %D\*.* > NUL
164	@cd "$(PHP_SRC_DIR)"
165	-@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
166	-rd /s /q $(BUILD_DIR)\php-$(PHP_VERSION_STRING)
167
168clean-pecl:
169	@echo Cleaning PECL targets only
170	-rd /s /q $(BUILD_DIR)\pecl
171
172clean-all:
173	@echo Cleaning standard build dirs
174	@cd $(BUILD_DIR)
175	@for %D in (_x $(BUILD_DIRS_SUB)) do @if exist %D @rd /s /q %D
176	@cd "$(PHP_SRC_DIR)"
177	-@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
178
179clean-pgo: clean-all
180	-rd /s /q $(BUILD_DIR)\php-$(PHP_VERSION_STRING)
181	-rd /s /q $(BUILD_DIR)\pecl-$(PHP_VERSION_STRING)
182	-rd /s /q $(BUILD_DIR)\php-test-pack-$(PHP_VERSION_STRING)
183	-del /f /q $(BUILD_DIR)\$(DIST_ZIP_SNAP)
184	-del /f /q $(BUILD_DIR)\$(DIST_ZIP_DEBUG_PACK)
185	-del /f /q $(BUILD_DIR)\$(DIST_ZIP_PECL)
186	-del /f /q $(BUILD_DIR)\$(DIST_ZIP_TEST_PACK)
187
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