4f315ee60e8b1b8178324c257a7b834b096ecf72
[m6w6/travis-pecl] / Makefile
1 export
2
3 PHP ?= 5.6
4 JOBS ?= 2
5 PHP_MIRROR ?= http://us1.php.net/distributions/
6 TMPDIR ?= /tmp
7
8 tmpnam := $(TMPDIR)/php-$(PHP)-$(shell env |grep -E '^with_|^enable_' | tr -c '[a-zA-Z_]' -)
9 makdir := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
10
11 ifdef TRAVIS_JOB_NUMBER
12 prefix ?= $(HOME)/job-$(TRAVIS_JOB_NUMBER)
13 else
14 prefix ?= $(tmpnam)
15 endif
16 exec_prefix ?= $(prefix)
17 bindir = $(exec_prefix)/bin
18 srcdir := $(prefix)/src
19 ifdef TRAVIS_BUILD_DIR
20 curdir ?= $(TRAVIS_BUILD_DIR)
21 else
22 # CURDIR is a make builtin
23 curdir ?= $(CURDIR)
24 endif
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))
41
42 PHP_VERSION_MAJOR = $(firstword $(subst ., ,$(PHP)))
43 PHP_VERSIONS_JSON = $(srcdir)/php-versions$(PHP_VERSION_MAJOR).json
44 PHP_VERSION ?= $(shell test -e $(PHP_VERSIONS_JSON) && cat $(PHP_VERSIONS_JSON) | $(makdir)/php-version.php $(PHP))
45
46 CPPCHECK ?= -v -j $(JOBS) --std=c89 --enable=warning,portability,style --error-exitcode=42 --suppressions-list=$(makdir)/cppcheck.suppressions -I.
47
48 .SUFFIXES:
49
50 .PHONY: all
51 all: php
52
53 ## -- PHP
54
55 .PHONY: clean
56 clean:
57 @if test -d $(srcdir)/php-$(PHP_VERSION); then cd $(srcdir)/php-$(PHP_VERSION); make distclean || true; fi
58
59 .PHONY: check
60 check: $(PHP_VERSIONS_JSON)
61 @if test -z "$(PHP)"; then echo "No php version specified, e.g. PHP=5.6"; exit 1; fi
62
63 .PHONY: reconf
64 reconf: check $(srcdir)/php-$(PHP_VERSION)/configure
65 cd $(srcdir)/php-$(PHP_VERSION) && ./configure --cache-file=config.cache --prefix=$(prefix)
66
67 .PHONY: php
68 php: check $(bindir)/php | $(PECL_INI)
69 -for EXT_SONAME in $(extdir)/*.so; do \
70 EXT_SONAME=$$(basename $$EXT_SONAME); \
71 if test "$$EXT_SONAME" != "*.so" && ! grep -q extension=$$EXT_SONAME $(PECL_INI); then \
72 echo extension=$$EXT_SONAME >> $(PECL_INI); \
73 fi \
74 done
75
76 $(PHP_VERSIONS_JSON): $(makdir)/php-version.php | $(srcdir)
77 curl -Sso $@ "http://php.net/releases/index.php?json&version=$(PHP_VERSION_MAJOR)&max=-1"
78
79 $(srcdir)/php-$(PHP_VERSION)/configure: | $(PHP_VERSIONS_JSON)
80 if test $(PHP_VERSION) = "master"; then \
81 cd $(srcdir) && git clone --depth 1 -b master https://github.com/php/php-src php-master && cd php-master && ./buildconf; \
82 else \
83 curl -Ss $(PHP_MIRROR)/php-$(PHP_VERSION).tar.bz2 | tar xj -C $(srcdir); \
84 fi
85
86 $(srcdir)/php-$(PHP_VERSION)/Makefile: $(srcdir)/php-$(PHP_VERSION)/configure | $(PHP_VERSIONS_JSON)
87 cd $(srcdir)/php-$(PHP_VERSION) && ./configure --cache-file=config.cache --prefix=$(prefix)
88
89 $(srcdir)/php-$(PHP_VERSION)/sapi/cli/php: $(srcdir)/php-$(PHP_VERSION)/Makefile | $(PHP_VERSIONS_JSON)
90 cd $(srcdir)/php-$(PHP_VERSION) && make -j $(JOBS) || make
91
92 $(bindir)/php: $(srcdir)/php-$(PHP_VERSION)/sapi/cli/php | $(PHP_VERSIONS_JSON)
93 cd $(srcdir)/php-$(PHP_VERSION) && make install
94
95 $(srcdir) $(extdir) $(with_config_file_scan_dir):
96 mkdir -p $@
97
98 ## -- PECL
99
100 .PHONY: pecl-check
101 pecl-check:
102 @if test -z "$(PECL)"; then echo "No pecl extension specified, e.g. PECL=pecl_http:http"; exit 1; fi
103
104 .PHONY: pecl-clean
105 pecl-clean:
106 @if test -d $(PECL_DIR); then cd $(PECL_DIR); make distclean || true; fi
107
108 .PHONY: pecl-rm
109 pecl-rm:
110 rm -f $(extdir)/$(PECL_SONAME).so
111
112 $(PECL_INI): | $(with_config_file_scan_dir)
113 touch $@
114
115 $(PECL_DIR)/config.m4:
116 mkdir -p $(PECL_DIR)
117 curl -Ss $(PECL_MIRROR)/$(PECL_EXTENSION)$(if $(PECL_VERSION),/$(PECL_VERSION)) | tar xz --strip-components 1 -C $(PECL_DIR)
118
119 $(PECL_DIR)/configure: $(PECL_DIR)/config.m4
120 cd $(PECL_DIR) && $(bindir)/phpize
121
122 $(PECL_DIR)/Makefile: $(PECL_DIR)/configure
123 cd $(PECL_DIR) && ./configure --cache-file=config.cache
124
125 $(PECL_DIR)/.libs/$(PECL_SONAME).so: $(PECL_DIR)/Makefile
126 cd $(PECL_DIR) && make -j $(JOBS) || make
127
128 $(extdir)/$(PECL_SONAME).so: $(PECL_DIR)/.libs/$(PECL_SONAME).so $(extdir)
129 cd $(PECL_DIR) && make install
130
131 .PHONY: pecl
132 pecl: pecl-check php $(extdir)/$(PECL_SONAME).so | $(PECL_INI)
133 grep -q extension=$(PECL_SONAME).so $(PECL_INI) || echo extension=$(PECL_SONAME).so >> $(PECL_INI)
134
135 .PHONY: ext-clean
136 ext-clean: pecl-clean
137
138 .PHONY: ext-rm
139 ext-rm: pecl-rm
140
141 .PHONY: ext
142 ext: pecl-check pecl
143 $(makdir)/check-packagexml.php package.xml
144
145 .PHONY: test
146 test: php
147 REPORT_EXIT_STATUS=1 $(bindir)/php run-tests.php -q -p $(bindir)/php --set-timeout 300 --show-diff tests
148
149 .PHONY: cppcheck
150 cppcheck:
151 cppcheck $(CPPCHECK) $$(awk -F= '/^CPPFLAGS|^INCLUDES/{print $$2}' <Makefile) .
152
153 pharext/%: $(PECL_INI) php | $(srcdir)/../%.ext.phar
154 for phar in $|; do $(bindir)/php $$phar --prefix=$(prefix) --ini=$(PECL_INI); done