efe8378afc5ca7101399dc8185246c0412c7dc32
[m6w6/pecl-ci] / 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 .SUFFIXES:
47
48 .PHONY: all
49 all: php
50
51 ## -- PHP
52
53 .PHONY: clean
54 clean:
55 @if test -d $(srcdir)/php-$(PHP_VERSION); then cd $(srcdir)/php-$(PHP_VERSION); make distclean || true; fi
56
57 .PHONY: check
58 check: $(PHP_VERSIONS_JSON)
59 @if test -z "$(PHP)"; then echo "No php version specified, e.g. PHP=5.6"; exit 1; fi
60
61 .PHONY: reconf
62 reconf: check $(srcdir)/php-$(PHP_VERSION)/configure
63 cd $(srcdir)/php-$(PHP_VERSION) && ./configure --cache-file=config.cache --prefix=$(prefix)
64
65 .PHONY: php
66 php: check $(bindir)/php | $(PECL_INI)
67 -for EXT_SONAME in $(extdir)/*.so; do \
68 EXT_SONAME=$$(basename $$EXT_SONAME); \
69 if test "$$EXT_SONAME" != "*.so" && ! grep -q extension=$$EXT_SONAME $(PECL_INI); then \
70 echo extension=$$EXT_SONAME >> $(PECL_INI); \
71 fi \
72 done
73
74 $(PHP_VERSIONS_JSON): $(makdir)/php-version.php | $(srcdir)
75 curl -Sso $@ "http://php.net/releases/index.php?json&version=$(PHP_VERSION_MAJOR)&max=-1"
76
77 $(srcdir)/php-$(PHP_VERSION)/configure: | $(PHP_VERSIONS_JSON)
78 if test $(PHP_VERSION) = "master"; then \
79 cd $(srcdir) && git clone --depth 1 -b master https://github.com/php/php-src php-master && cd php-master && ./buildconf; \
80 else \
81 curl -Ss $(PHP_MIRROR)/php-$(PHP_VERSION).tar.bz2 | tar xj -C $(srcdir); \
82 fi
83
84 $(srcdir)/php-$(PHP_VERSION)/Makefile: $(srcdir)/php-$(PHP_VERSION)/configure | $(PHP_VERSIONS_JSON)
85 cd $(srcdir)/php-$(PHP_VERSION) && ./configure --cache-file=config.cache --prefix=$(prefix)
86
87 $(srcdir)/php-$(PHP_VERSION)/sapi/cli/php: $(srcdir)/php-$(PHP_VERSION)/Makefile | $(PHP_VERSIONS_JSON)
88 cd $(srcdir)/php-$(PHP_VERSION) && make -j $(JOBS) || make
89
90 $(bindir)/php: $(srcdir)/php-$(PHP_VERSION)/sapi/cli/php | $(PHP_VERSIONS_JSON)
91 cd $(srcdir)/php-$(PHP_VERSION) && make install
92
93 $(srcdir) $(extdir) $(with_config_file_scan_dir):
94 mkdir -p $@
95
96 ## -- PECL
97
98 .PHONY: pecl-check
99 pecl-check:
100 @if test -z "$(PECL)"; then echo "No pecl extension specified, e.g. PECL=pecl_http:http"; exit 1; fi
101
102 .PHONY: pecl-clean
103 pecl-clean:
104 @if test -d $(PECL_DIR); then cd $(PECL_DIR); make distclean || true; fi
105
106 .PHONY: pecl-rm
107 pecl-rm:
108 rm -f $(extdir)/$(PECL_SONAME).so
109
110 $(PECL_INI): | $(with_config_file_scan_dir)
111 touch $@
112
113 $(PECL_DIR)/config.m4:
114 mkdir -p $(PECL_DIR)
115 curl -Ss $(PECL_MIRROR)/$(PECL_EXTENSION)$(if $(PECL_VERSION),/$(PECL_VERSION)) | tar xz --strip-components 1 -C $(PECL_DIR)
116
117 $(PECL_DIR)/configure: $(PECL_DIR)/config.m4
118 cd $(PECL_DIR) && $(bindir)/phpize
119
120 $(PECL_DIR)/Makefile: $(PECL_DIR)/configure
121 cd $(PECL_DIR) && ./configure --cache-file=config.cache
122
123 $(PECL_DIR)/.libs/$(PECL_SONAME).so: $(PECL_DIR)/Makefile
124 cd $(PECL_DIR) && make -j $(JOBS) || make
125
126 $(extdir)/$(PECL_SONAME).so: $(PECL_DIR)/.libs/$(PECL_SONAME).so $(extdir)
127 cd $(PECL_DIR) && make install
128
129 .PHONY: pecl
130 pecl: pecl-check php $(extdir)/$(PECL_SONAME).so | $(PECL_INI)
131 grep -q extension=$(PECL_SONAME).so $(PECL_INI) || echo extension=$(PECL_SONAME).so >> $(PECL_INI)
132
133 .PHONY: ext-clean
134 ext-clean: pecl-clean
135
136 .PHONY: ext-rm
137 ext-rm: pecl-rm
138
139 .PHONY: ext
140 ext: pecl-check pecl
141 $(makdir)/check-packagexml.php package.xml
142
143 .PHONY: php
144 test: php
145 REPORT_EXIT_STATUS=1 $(bindir)/php run-tests.php -q -p $(bindir)/php --set-timeout 300 --show-diff tests
146
147 pharext/%: $(PECL_INI) php | $(srcdir)/../%.ext.phar
148 for phar in $|; do $(bindir)/php $$phar --prefix=$(prefix) --ini=$(PECL_INI); done