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