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