build ext in CURDIR
[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
16 enable_maintainer_zts ?= no
17 enable_debug ?= no
18 enable_all ?= no
19 with_config_file_scan_dir ?= $(prefix)/etc/php.d
20
21 with_php_config ?= $(bindir)/php-config
22 extdir = $(shell test -x $(with_php_config) && $(with_php_config) --extension-dir)
23
24 PECL_MIRROR ?= http://pecl.php.net/get/
25 PECL_EXTENSION ?= $(shell echo $(PECL) | cut -d: -f1)
26 PECL_SONAME ?= $(if $(shell echo $(PECL) | cut -d: -f2),$(shell echo $(PECL) | cut -d: -f2),$(PECL_EXTENSION))
27 PECL_VERSION ?= $(shell echo $(PECL) | cut -d: -f3 -s)
28 PECL_INI = $(with_config_file_scan_dir)/pecl.ini
29 PECL_DIR ?= $(srcdir)/pecl-$(PECL_EXTENSION)
30
31 PHP_VERSION_MAJOR = $(firstword $(subst ., ,$(PHP)))
32 PHP_VERSIONS_JSON = $(srcdir)/php-versions$(PHP_VERSION_MAJOR).json
33 PHP_VERSION ?= $(shell test -e $(PHP_VERSIONS_JSON) && cat $(PHP_VERSIONS_JSON) | $(srcdir)/php-version.php $(PHP))
34
35 .SUFFIXES:
36
37 .PHONY: all
38 all: php
39
40 ## -- PHP
41
42 .PHONY: clean
43 clean:
44 @if test -d $(srcdir)/php-$(PHP_VERSION); then cd $(srcdir)/php-$(PHP_VERSION); make distclean || true; fi
45
46 .PHONY: check
47 check: $(PHP_VERSIONS_JSON)
48 @if test -z "$(PHP)"; then echo "No php version specified, e.g. PHP=5.6"; exit 1; fi
49
50 .PHONY: reconf
51 reconf: check $(srcdir)/php-$(PHP_VERSION)/configure
52 cd $(srcdir)/php-$(PHP_VERSION) && ./configure -C --prefix=$(prefix)
53
54 .PHONY: php
55 php: check $(bindir)/php
56
57 $(PHP_VERSIONS_JSON): $(srcdir)/php-version.php
58 curl -Sso $@ "http://php.net/releases/index.php?json&version=$(PHP_VERSION_MAJOR)&max=-1"
59
60 $(srcdir)/php-$(PHP_VERSION)/configure: | $(PHP_VERSIONS_JSON)
61 if test $(PHP_VERSION) = "master"; then \
62 cd $(srcdir) && git clone --depth 1 -b master https://github.com/php/php-src php-master && cd php-master && ./buildconf; \
63 else \
64 curl -Ss $(PHP_MIRROR)/php-$(PHP_VERSION).tar.bz2 | tar xj -C $(srcdir); \
65 fi
66
67 $(srcdir)/php-$(PHP_VERSION)/Makefile: $(srcdir)/php-$(PHP_VERSION)/configure | $(PHP_VERSIONS_JSON)
68 cd $(srcdir)/php-$(PHP_VERSION) && ./configure -C --prefix=$(prefix)
69
70 $(srcdir)/php-$(PHP_VERSION)/sapi/cli/php: $(srcdir)/php-$(PHP_VERSION)/Makefile | $(PHP_VERSIONS_JSON)
71 cd $(srcdir)/php-$(PHP_VERSION) && make -j $(JOBS) || make
72
73 $(bindir)/php: $(srcdir)/php-$(PHP_VERSION)/sapi/cli/php | $(PHP_VERSIONS_JSON)
74 cd $(srcdir)/php-$(PHP_VERSION) && make install
75
76 $(with_config_file_scan_dir):
77 mkdir -p $@
78
79 ## -- PECL
80
81 .PHONY: pecl-check
82 pecl-check:
83 @if test -z "$(PECL)"; then echo "No pecl extension specified, e.g. PECL=pecl_http:http"; exit 1; fi
84
85 .PHONY: pecl-clean
86 pecl-clean:
87 @if test -d $(PECL_DIR); then cd $(PECL_DIR); make distclean || true; fi
88
89 .PHONY: pecl-rm
90 pecl-rm:
91 rm -f $(extdir)/$(PECL_SONAME).so
92
93 $(PECL_INI): | $(with_config_file_scan_dir)
94 touch $@
95
96 $(PECL_DIR)/config.m4:
97 mkdir -p $(PECL_DIR)
98 curl -Ss $(PECL_MIRROR)/$(PECL_EXTENSION)$(if $(PECL_VERSION),/$(PECL_VERSION)) | tar xz --strip-components 1 -C $(PECL_DIR)
99
100 $(PECL_DIR)/configure: $(PECL_DIR)/config.m4
101 cd $(PECL_DIR) && $(bindir)/phpize
102
103 $(PECL_DIR)/Makefile: $(PECL_DIR)/configure
104 cd $(PECL_DIR) && ./configure -C
105
106 $(PECL_DIR)/.libs/$(PECL_SONAME).so: $(PECL_DIR)/Makefile
107 cd $(PECL_DIR) && make -j $(JOBS) || make
108
109 $(extdir)/$(PECL_SONAME).so: $(PECL_DIR)/.libs/$(PECL_SONAME).so
110 cd $(PECL_DIR) && make install
111
112 .PHONY: pecl
113 pecl: pecl-check php $(extdir)/$(PECL_SONAME).so | $(PECL_INI)
114 grep -q extension=$(PECL_SONAME).so $(PECL_INI) || echo extension=$(PECL_SONAME).so >> $(PECL_INI)
115
116 .PHONY: ext-clean
117 ext-clean: pecl-clean
118
119 .PHONY: ext-rm
120 ext-rm: PECL_DIR:=$(CURDIR)
121 ext-rm: pecl-rm
122
123 .PHONY: ext
124 ext: PECL_DIR:=$(CURDIR)
125 ext: pecl-check pecl
126 $(srcdir)/check-packagexml.php package.xml
127
128 .PHONY: php
129 test: PECL_DIR:=$(CURDIR)
130 test: php
131 REPORT_EXIT_STATUS=1 $(bindir)/php run-tests.php -q -p $(bindir)/php --set-timeout 300 --show-diff tests
132
133 pharext/%: $(PECL_INI) php | $(srcdir)/../%.ext.phar
134 for phar in $|; do $(bindir)/php $$phar --prefix=$(prefix) --ini=$(PECL_INI); done