handle opcache as zend_extension
[m6w6/pecl-ci] / Makefile
1 export
2
3 PHP ?= 8.0
4 JOBS ?= 2
5 PHP_MIRROR ?= https://php.net/distributions/
6 TMPDIR ?= /tmp
7
8 mkfile := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
9 makdir := $(dir $(mkfile))
10
11 ifeq (,$(findstring printenv,$(MAKECMDGOALS)))
12 mkargs := $(shell $(MAKE) -f $(mkfile) printenv | sed -n -e '/=no$$/ d; s/=yes$$//' -e 's,with_,,gp' -e 's,enable_,,gp' | tr -c '[a-zA-Z_]' -)
13 endif
14
15 prefix ?= $(TMPDIR)/php-$(PHP)-$(mkargs)
16 exec_prefix ?= $(prefix)
17 bindir = $(exec_prefix)/bin
18 srcdir = $(prefix)/src
19 # CURDIR is a make builtin
20 curdir ?= $(CURDIR)
21
22 enable_maintainer_zts ?= no
23 enable_debug ?= no
24 enable_all ?= no
25 with_config_file_scan_dir ?= $(prefix)/etc/php.d
26
27 with_php_config ?= $(bindir)/php-config
28 extdir = $(shell test -x $(with_php_config) && $(with_php_config) --extension-dir)
29
30 PECL_MIRROR ?= http://pecl.php.net/get/
31 PECL_WORDS := $(subst :, ,$(PECL))
32 PECL_EXTENSION ?= $(word 1,$(PECL_WORDS))
33 PECL_SONAME ?= $(if $(word 2,$(PECL_WORDS)),$(word 2,$(PECL_WORDS)),$(PECL_EXTENSION))
34 PECL_VERSION ?= $(word 3,$(PECL_WORDS))
35 PECL_INI = $(with_config_file_scan_dir)/pecl.ini
36 PECL_DIR := $(if $(filter ext ext%, $(MAKECMDGOALS)), $(curdir), $(srcdir)/pecl-$(PECL_EXTENSION)-$(PECL_VERSION))
37
38 #PHP_VERSION_MAJOR = $(firstword $(subst ., ,$(PHP)))
39
40 PHP_RELEASES = $(srcdir)/releases.tsv
41 PHP_VERSION ?= $(shell test -e $(PHP_RELEASES) && cat $(PHP_RELEASES) | awk -F "\t" '/^$(PHP)\t/{print $$2; exit}')
42
43 CPPCHECK_STD ?= c89
44 CPPCHECK_ENABLE ?= portability,style
45 CPPCHECK_EXITCODE ?= 42
46 CPPCHECK_SUPPRESSIONS ?= $(makdir)/cppcheck.suppressions
47 CPPCHECK_INCLUDES ?= -I. $(shell test -f Makefile && awk -F= '/^CPPFLAGS|^INCLUDES/{print $$2}' <Makefile)
48 CPPCHECK_VERSION ?= 1.82
49 CPPCHECK_ARGS ?= -v -j $(JOBS) --std=$(CPPCHECK_STD) --enable=$(CPPCHECK_ENABLE) --error-exitcode=$(CPPCHECK_EXITCODE) --suppressions-list=$(CPPCHECK_SUPPRESSIONS) $(CPPCHECK_INCLUDES)
50
51 .SUFFIXES:
52
53 .PHONY: all
54 all: php
55
56 .PHONY: printenv
57 printenv:
58 @env | grep -E 'prefix=|dir=' | grep -v config_file_scan_dir | sort
59 @env | grep -E '^PHP|^PECL' | sort
60 @env | grep -E '^with_|^enable_' | grep -Ev 'php_config|config_file_scan_dir' | sort
61
62 .PHONY: versions
63 versions: $(PHP_RELEASES)
64 grep "^$(PHP)" $< | cut -f1-2
65
66 $(PHP_RELEASES): $(makdir)/php-version-url-dist.php $(makdir)/php-version-url-qa.php | $(srcdir)
67 cd $(makdir) && printf "master\tmaster\t%s/fetch-master.sh\n" $$(pwd) >$@
68 curl -sSL "https://php.net/releases/index.php?json&version=8&max=-1" | $(makdir)/php-version-url-dist.php >>$@
69 curl -sSL "https://php.net/releases/index.php?json&version=7&max=-1" | $(makdir)/php-version-url-dist.php >>$@
70 curl -sSL "https://php.net/releases/index.php?json&version=5&max=-1" | $(makdir)/php-version-url-dist.php >>$@
71 curl -sSL "https://qa.php.net/api.php?type=qa-releases&format=json" | $(makdir)/php-version-url-qa.php >>$@
72
73 ## -- PHP
74
75 .PHONY: clean
76 clean:
77 @if test -d $(srcdir)/php-$(PHP_VERSION); then cd $(srcdir)/php-$(PHP_VERSION); make distclean || true; fi
78
79 .PHONY: check
80 check: $(PHP_RELEASES)
81 @if test -z "$(PHP)"; then echo "No php version specified, e.g. PHP=5.6"; exit 1; fi
82 @if test -z "$(PHP_VERSION)"; then echo "No PHP version akin to $(PHP) available"; exit 1; fi
83 if test -d $(srcdir)/php-$(PHP_VERSION)/.git; then cd $(srcdir)/php-$(PHP_VERSION)/; git pull; fi
84
85 .PHONY: reconf
86 reconf: check $(srcdir)/php-$(PHP_VERSION)/configure
87 cd $(srcdir)/php-$(PHP_VERSION) && ./configure --cache-file=config.cache --prefix=$(prefix) && rm -f sapi/cli/php
88
89 .PHONY: php
90 php: check $(bindir)/php | $(PECL_INI)
91 -for EXT_SONAME in $(extdir)/*.so; do \
92 EXT_SONAME=$$(basename $$EXT_SONAME); \
93 if test "$$EXT_SONAME" != "*.so" && ! grep -q extension=$$EXT_SONAME $(PECL_INI); then \
94 if test "$$EXT_SONAME" = "opcache.so"; then \
95 echo zend_extension=$$EXT_SONAME >> $(PECL_INI); \
96 else \
97 echo extension=$$EXT_SONAME >> $(PECL_INI); \
98 fi; \
99 fi \
100 done
101
102 $(srcdir)/php-$(PHP_VERSION)/configure: | $(PHP_RELEASES)
103 cd $(srcdir) && awk -F "\t" '/^$(PHP)\t/{exit system($$3)}' <$|
104
105 $(srcdir)/php-$(PHP_VERSION)/Makefile: $(srcdir)/php-$(PHP_VERSION)/configure | $(PHP_RELEASES)
106 cd $(srcdir)/php-$(PHP_VERSION) && ./configure --cache-file=config.cache --prefix=$(prefix)
107
108 $(srcdir)/php-$(PHP_VERSION)/sapi/cli/php: $(srcdir)/php-$(PHP_VERSION)/Makefile | $(PHP_RELEASES)
109 cd $(srcdir)/php-$(PHP_VERSION) && make -j $(JOBS) || make
110
111 $(bindir)/php: $(srcdir)/php-$(PHP_VERSION)/sapi/cli/php | $(PHP_RELEASES)
112 cd $(srcdir)/php-$(PHP_VERSION) && make -j $(JOBS) install INSTALL=install
113
114 $(srcdir) $(extdir) $(with_config_file_scan_dir):
115 mkdir -p $@
116
117 ## -- PECL
118
119 .PHONY: pecl-check
120 pecl-check:
121 @if test -z "$(PECL)"; then echo "No pecl extension specified, e.g. PECL=pecl_http:http"; exit 1; fi
122
123 .PHONY: pecl-clean
124 pecl-clean:
125 @if test -d $(PECL_DIR); then cd $(PECL_DIR); make distclean || true; fi
126
127 .PHONY: pecl-rm
128 pecl-rm:
129 rm -f $(extdir)/$(PECL_SONAME).so
130
131 $(PECL_INI): | $(with_config_file_scan_dir)
132 touch $@
133
134 $(PECL_DIR)/config.m4:
135 if test "$(PECL_VERSION)" = "master"; then \
136 if test -d $(PECL_DIR); then \
137 cd $(PECL_DIR); \
138 git pull; \
139 else \
140 git clone https://github.com/$(PECL_EXTENSION) $(PECL_DIR); \
141 fi; \
142 else \
143 mkdir -p $(PECL_DIR); \
144 curl -LSs $(PECL_MIRROR)/$(PECL_EXTENSION)$(if $(PECL_VERSION),/$(PECL_VERSION)) \
145 | tar xz --strip-components 1 -C $(PECL_DIR); \
146 fi
147
148 $(PECL_DIR)/configure: $(PECL_DIR)/config.m4
149 cd $(PECL_DIR) && $(bindir)/phpize
150
151 $(PECL_DIR)/Makefile: $(PECL_DIR)/configure
152 cd $(PECL_DIR) && ./configure --cache-file=config.cache
153
154 $(PECL_DIR)/.libs/$(PECL_SONAME).so: $(PECL_DIR)/Makefile
155 cd $(PECL_DIR) && make -j $(JOBS) || make
156
157 $(extdir)/$(PECL_SONAME).so: $(PECL_DIR)/.libs/$(PECL_SONAME).so $(extdir)
158 cd $(PECL_DIR) && make -j $(JOBS) install INSTALL=install
159
160 .PHONY: pecl
161 pecl: pecl-check php $(extdir)/$(PECL_SONAME).so | $(PECL_INI)
162 grep -q extension=$(PECL_SONAME).so $(PECL_INI) || echo extension=$(PECL_SONAME).so >> $(PECL_INI)
163
164 .PHONY: ext-clean
165 ext-clean: pecl-clean
166
167 .PHONY: ext-rm
168 ext-rm: pecl-rm
169
170 .PHONY: ext
171 ext: pecl-check pecl
172 $(makdir)/check-packagexml.php package.xml
173
174 .PHONY: test
175 test: TESTS ?= tests
176 test: php
177 REPORT_EXIT_STATUS=1 $(bindir)/php run-tests.php -q -p $(bindir)/php --set-timeout 300 --show-diff $(TESTS)
178 .PHONY: pecl-test
179 pecl-test: TESTS ?= $(PECL_DIR)/tests
180 pecl-test: php
181 REPORT_EXIT_STATUS=1 $(bindir)/php $(prefix)/lib/php/build/run-tests.php -q -p $(bindir)/php --set-timeout 300 --show-diff $(TESTS)
182
183 pharext/%: $(PECL_INI) php | $(srcdir)/../%.ext.phar
184 for phar in $|; do $(bindir)/php $$phar --prefix=$(prefix) --ini=$(PECL_INI); done
185
186 ## -- CPPCHECK
187
188 $(srcdir)/cppcheck-$(CPPCHECK_VERSION):
189 git clone https://github.com/danmar/cppcheck.git $@ && cd $@ && git checkout $(CPPCHECK_VERSION)
190
191 $(srcdir)/cppcheck-$(CPPCHECK_VERSION)/cppcheck: | $(srcdir)/cppcheck-$(CPPCHECK_VERSION)
192 cd $| && make -j $(JOBS) cppcheck
193
194 .PHONY: cppcheck
195 cppcheck: | $(srcdir)/cppcheck-$(CPPCHECK_VERSION)/cppcheck
196 $| $(CPPCHECK_ARGS) .