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