1#
2# Apple wrapper Makefile for PHP
3# Copyright (c) 2008-2014 Apple Inc. All Rights Reserved.
4##
5#
6
7# General project info for use with RC/GNUsource.make makefile
8Project         = php
9ProjectName     = apache_mod_php
10UserType        = Developer
11ToolType        = Commands
12Submission      = 93
13
14# Environment is passed to BOTH configure AND make, which can cause problems if these
15# variables are intended to help configure, but not override the result.
16Environment	= YACC=/usr/local/bin/bison-1.28 \
17			php_cv_bison_version=1.28 \
18			LEX=/usr/local/bin/lex-2.5.4 \
19			MAKEOBJDIR="$(BuildDirectory)" \
20			INSTALL_ROOT="$(DSTROOT)" \
21			TMPDIR="$(TMPDIR)" TEMPDIR="$(TMPDIR)" 
22# This allows extra variables to be passed _just_ to configure.
23Extra_Configure_Environment	= CFLAGS="$$RC_CFLAGS -Os -g" \
24					LDFLAGS="$$RC_CFLAGS -Os -g" \
25					EXTRA_LIBS="-lresolv" \
26					EXTRA_LDFLAGS_PROGRAM="-mdynamic-no-pic"
27
28build_host_target_alias=`$SHELL "$(Sources)/config.guess"`
29# The configure flags are ordered to match current output of ./configure --help.
30# Extra indentation represents suboptions.
31Extra_Configure_Flags	= --sysconfdir=$(ETCDIR) \
32			--with-apxs2=$(USRSBINDIR)/apxs \
33			--enable-cli \
34			--with-config-file-path=/etc \
35			--with-config-file-scan-dir=/Library/Server/Web/Config/php \
36			--with-libxml-dir=$(USRDIR) \
37			--with-openssl=$(USRDIR) \
38			--with-kerberos=$(USRDIR) \
39			--with-zlib=$(USRDIR) \
40			--enable-bcmath \
41			--with-bz2=$(USRDIR) \
42			--enable-calendar \
43			--disable-cgi \
44			--with-curl=$(USRDIR) \
45			--enable-dba \
46			--with-ndbm=$(USRDIR) \
47			--enable-exif \
48			--enable-fpm \
49			--enable-ftp \
50			--with-png-dir=no \
51			--with-gd \
52			--with-jpeg-dir=$(DSTROOT)$(USRDIR)/local \
53			--enable-gd-native-ttf \
54			--with-icu-dir=$(USRDIR) \
55			--with-ldap=$(USRDIR)\
56			--with-ldap-sasl=$(USRDIR) \
57			--with-libedit=$(USRDIR) \
58			--enable-mbstring \
59			--enable-mbregex \
60			--with-mysql=mysqlnd \
61			--with-mysqli=mysqlnd \
62			--without-pear \
63			--with-pear=no\
64			--with-pdo-mysql=mysqlnd \
65			--with-mysql-sock=/var/mysql/mysql.sock \
66			--with-readline=$(USRDIR) \
67			--enable-shmop \
68			--with-snmp=$(USRDIR) \
69			--enable-soap \
70			--enable-sockets \
71			--enable-sysvmsg --enable-sysvsem --enable-sysvshm \
72			--with-tidy \
73			--enable-wddx \
74			--with-xmlrpc \
75			--with-iconv-dir=$(USRDIR) \
76			--with-xsl=$(USRDIR) \
77			--enable-zend-multibyte \
78			--enable-zip
79
80
81# Additional project info used with AEP
82AEP		= YES
83AEP_Version	= 5.5.14
84AEP_LicenseFile	= $(Sources)/LICENSE
85AEP_Patches	=  \
86			MacOSX_build.patch \
87			iconv.patch pear.patch phar.patch
88AEP_ConfigDir	= $(ETCDIR)
89AEP_Binaries	= $(shell $(USRSBINDIR)/apxs -q LIBEXECDIR)/*.so $(USRBINDIR)/php $(USRSBINDIR)/php-fpm
90AEP_ManPages	= pear.1 phar.1 phar.phar.1
91Dependencies	= libjpeg 
92GnuAfterInstall = archive-strip-binaries install-macosx install-xdebug install-open-source-files # needs a path adjustment
93
94
95# Local targets that must be defined before including the following
96# files to get the dependency order correct
97.PHONY: post-extract-source $(GnuAfterInstall)
98
99# Include common makefile targets for B&I
100include $(MAKEFILEPATH)/CoreOS/ReleaseControl/GNUSource.make
101# Define AEP variables
102#
103ifndef AEP_Project
104    AEP_Project		= $(Project)
105endif
106
107ifndef AEP_ProjVers
108  ifdef AEP_Version
109    AEP_ProjVers	= $(AEP_Project)-$(AEP_Version)
110  else
111    AEP_ProjVers	= $(AEP_Project)
112  endif
113endif
114
115ifndef AEP_Filename
116    AEP_Filename	= $(wildcard $(AEP_ProjVers).tar.gz $(AEP_ProjVers).tar.bz2)
117endif
118ifeq ($(suffix $(AEP_Filename)),.bz2)
119    AEP_ExtractOption	= j
120else
121    AEP_ExtractOption	= z
122endif
123
124ifndef AEP_ExtractDir
125    AEP_ExtractDir	= $(AEP_ProjVers)
126endif
127
128ifndef AEP_LicenseFile
129    AEP_LicenseFile	= $(SRCROOT)/$(ProjectName).txt
130endif
131
132ifndef AEP_ManPages
133    AEP_ManPages := $(wildcard *.[1-9] man/*.[1-9])
134endif
135
136ifndef AEP_ConfigDir
137    AEP_ConfigDir	= $(ETCDIR)
138endif
139
140ifndef AEP_Binaries
141    AEP_Binaries	= $(subst ./,/,$(shell cd $(DSTROOT) && $(FIND) . -type f -perm +0111 -exec $(SHELL) -c 'test \"`file -b --mime-type {}`\" = \"application/octet-stream\"' \; -print))
142endif
143
144#AEP_ExtractRoot		= $(SRCROOT)
145AEP_ExtractRoot		= $(OBJROOT)
146
147# Redefine the Sources directory defined elsewhere
148# ...but save the version of ConfigStamp (based on Sources)
149# GNUSource.make uses.
150GNUConfigStamp		:= $(ConfigStamp)
151Sources			= $(AEP_ExtractRoot)/$(AEP_Project)
152
153# Redefine Configure to allow extra "helper" environment variables.
154# This logic was moved to GNUSource.make in 10A251, so only override the setting
155# if building on an earlier system. (Make_Flags is only defined with that patch.)
156ifndef Make_Flags
157ifdef Extra_Configure_Environment
158      Configure		:= $(Extra_Configure_Environment) $(Configure)
159endif
160endif
161
162
163# Open Source configuration directories
164OSVDIR	= $(USRDIR)/local/OpenSourceVersions
165OSLDIR	= $(USRDIR)/local/OpenSourceLicenses
166
167# Launchd / startup item paths
168LAUNCHDDIR		= $(NSSYSTEMDIR)$(NSLIBRARYSUBDIR)/LaunchDaemons
169SYSTEM_STARTUP_DIR	= $(NSSYSTEMDIR)$(NSLIBRARYSUBDIR)/StartupItems
170
171
172#
173# AEP targets
174#
175.PHONY: extract-source build-dependencies archive-strip-binaries
176.PHONY: install-open-source-files install-startup-files
177.PHONY: install-top-level-man-pages install-configuration-files
178
179ifdef ConfigStamp
180$(GNUConfigStamp): extract-source build-dependencies
181else
182build:: extract-source build-dependencies
183endif
184
185# Because GNUSource's ConfigStamp's rules are processed before this file is included,
186# it's easier to copy the sources to the build directory and work from there.
187extract-source::
188ifeq ($(AEP),YES)
189	@echo "Extracting source for $(Project)..."
190	$(MKDIR) $(AEP_ExtractRoot)
191	$(TAR) -C $(AEP_ExtractRoot) -$(AEP_ExtractOption)xf $(SRCROOT)/$(AEP_Filename)
192	$(RMDIR) $(Sources)
193	$(_v) $(RM) $(GNUConfigStamp)
194	$(MV) $(AEP_ExtractRoot)/$(AEP_ExtractDir) $(Sources)
195ifdef AEP_Patches
196	for patchfile in $(AEP_Patches); do \
197	   echo "Applying $$patchfile..."; \
198	   cd $(Sources) && $(PATCH) -lp1 < $(SRCROOT)/patches/$$patchfile; \
199	done
200endif
201ifeq ($(AEP_BuildInSources),YES)
202ifneq ($(Sources),$(BuildDirectory))
203	@echo "Copying sources to build directory..."
204	$(_v) $(CP) $(Sources) $(BuildDirectory)
205endif
206endif
207else
208	@echo "Source extraction for $(Project) skipped!"
209endif
210
211# Common.make's recurse doesn't reset SRCROOT and misdefines Sources
212build-dependencies:
213ifdef Dependencies
214	$(_v) for Dependency in $(Dependencies); do			\
215		$(MKDIR) $(SYMROOT)/$${Dependency};			\
216		$(MAKE) -C $${Dependency} $(TARGET)			\
217			SRCROOT=$(SRCROOT)/$${Dependency}		\
218			OBJROOT=$(OBJROOT)				\
219			SYMROOT=$(SYMROOT)/$${Dependency}		\
220			DSTROOT=$(DSTROOT)				\
221			BuildDirectory=$(OBJROOT)/Build/$${Dependency}	\
222			Sources=$(OBJROOT)/$${Dependency}		\
223			CoreOSMakefiles=$(CoreOSMakefiles)		\
224			$(Extra_Dependency_Flags);			\
225		done
226endif
227
228archive-strip-binaries:: $(SYMROOT)
229ifdef AEP_Binaries
230	@echo "Archiving and stripping binaries..."
231	$(_v) for file in $(addprefix $(DSTROOT),$(AEP_Binaries));	\
232	do \
233		_type=`file -b --mime-type $${file}`;			\
234		if [ "$${_type}" = "application/octet-stream" ]; then	\
235			echo "\tProcessing $${file}...";			\
236			$(CP) $${file} $(SYMROOT);				\
237			$(DSYMUTIL) --out=$(SYMROOT)/$${file##*/}.dSYM $${file};\
238			$(STRIP) -S $${file};					\
239		else	\
240			echo "\tSkipped non-binary $${file}; type is $${_type}";\
241		fi	\
242	done
243endif
244
245install-startup-files::
246ifdef AEP_LaunchdConfigs
247	@echo "Installing launchd configuration files..."
248	$(INSTALL_DIRECTORY) $(DSTROOT)$(LAUNCHDDIR)
249	$(INSTALL_FILE) $(AEP_LaunchdConfigs) $(DSTROOT)$(LAUNCHDDIR)
250endif
251ifdef AEP_StartupItem
252	@echo "Installing StartupItem..."
253	$(INSTALL_DIRECTORY) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
254	$(INSTALL_SCRIPT) $(StartupItem) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
255	$(INSTALL_FILE) StartupParameters.plist $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
256	$(INSTALL_DIRECTORY) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)/Resources/English.lproj
257	$(INSTALL_FILE) Localizable.strings $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)/Resources/English.lproj
258endif
259
260install-open-source-files::
261	@echo "Installing Apple-internal open-source documentation..."
262	if [ -e $(SRCROOT)/$(ProjectName).plist ]; then	\
263		$(MKDIR) $(DSTROOT)/$(OSVDIR);	   	\
264		$(INSTALL_FILE) $(SRCROOT)/$(ProjectName).plist $(DSTROOT)/$(OSVDIR)/$(ProjectName).plist;	\
265	else	\
266		echo "WARNING: No open-source file for this project!";	\
267	fi
268	if [ -e $(AEP_LicenseFile) ]; then	\
269		$(MKDIR) $(DSTROOT)/$(OSLDIR);	\
270		$(INSTALL_FILE) $(AEP_LicenseFile) $(DSTROOT)/$(OSLDIR)/$(ProjectName).txt;	\
271	else	\
272		echo "WARNING: No open-source file for this project!";	\
273	fi
274
275
276#
277# Install any man pages at the top-level directory or its "man" subdirectory
278#
279install-top-level-man-pages::
280ifdef AEP_ManPages
281	@echo "Installing top-level man pages..."
282	for _page in $(AEP_ManPages); do				\
283		_section_dir=$(Install_Man)/man$${_page##*\.};		\
284		$(INSTALL_DIRECTORY) $(DSTROOT)$${_section_dir};	\
285		$(INSTALL_FILE) $${_page} $(DSTROOT)$${_section_dir};	\
286	done
287endif
288
289
290#
291# Install configuration files and their corresponding ".default" files
292# to one standard location.
293#
294install-configuration-files::
295ifdef AEP_ConfigFiles
296	@echo "Installing configuration files..."
297	$(INSTALL_DIRECTORY) $(DSTROOT)$(AEP_ConfigDir)
298	for file in $(AEP_ConfigFiles); \
299	do \
300		$(INSTALL_FILE) $${file} $(DSTROOT)$(AEP_ConfigDir); \
301		$(CHMOD) u+w $(DSTROOT)$(AEP_ConfigDir)/$${file}; \
302		if [ "${file##*.}" != "default" ]; then \
303			$(INSTALL_FILE) $${file} $(DSTROOT)$(AEP_ConfigDir)/$${file}.default; \
304		fi; \
305	done
306endif
307
308
309clean::
310	$(_v) if [ -d $(Sources) ]; then \
311	    cd $(Sources) && make clean; \
312	fi
313
314$(DSTROOT) $(DSTROOT)$(AEP_ConfigDir) $(SYMROOT) $(TMPDIR):
315	$(MKDIR) $@
316
317#include $(MAKEFILEPATH)/CoreOS/ReleaseControl/AEP.make
318
319# Override settings from above includes
320BuildDirectory	= $(OBJROOT)/Build/$(AEP_Project)
321Install_Target	= install
322TMPDIR		= $(OBJROOT)/Build/tmp
323# This needs to be overridden because the project properly uses DESTDIR and
324# INSTALL_ROOT (which is included in Environment).
325Install_Flags	= DESTDIR="$(DSTROOT)"
326
327#
328# "ifeq / ifneq" are processed at read time; since these use variables defined
329# by the included files above, this must be performed after the includes.
330#
331# The PCRE library is only installed on Snow Leopard and later.
332ifneq ($(strip $(wildcard $(USRDIR)/local/include/pcre.*)),)
333Extra_Configure_Flags	+= --with-pcre-regex=$(USRDIR)
334endif
335
336# Build rules
337# Dependency info necessary to ensure temp directory and cleanup are performed.
338lazy_install_source:: $(TMPDIR)
339$(GNUConfigStamp): post-extract-source $(TMPDIR)
340
341# Post-extract target
342post-extract-source: extract-source
343	@echo "Executing extra patch after extraction..."
344	$(PERL) -i -pe 's|-i -a -n php5|-i -n php5|g' $(Sources)/configure
345	$(PERL) -i -pe 's|rm -f conftest|rm -rf conftest|g' $(Sources)/configure
346
347# Invoke pearcmd.php manually (instead of via /usr/bin/pear) so we can force
348# lookups from DSTROOT instead of final install location.
349PEAR		= $(DSTROOT)$(USRBINDIR)/php -C -q \
350		-n -d include_path=$(DSTROOT)$(USRLIBDIR)/php $(PEAR_Cmd)
351PEAR_Cmd	= $(TMPDIR)/pearcmd.php
352
353install-macosx:
354	@echo "Cleaning up install for Mac OS X..."
355	-$(RMDIR) $(DSTROOT)$(ETCDIR)/apache2
356	$(CHOWN) -R root:wheel $(DSTROOT)/
357	$(INSTALL_FILE) $(Sources)/php.ini-production $(DSTROOT)$(AEP_ConfigDir)/php.ini.default
358	$(PERL) -i -pe 's|^extension_dir =.*|extension_dir = $(USRLIBDIR)/php/extensions/no-debug-non-zts-20121212|' $(DSTROOT)$(AEP_ConfigDir)/php.ini.default
359	$(INSTALL_DIRECTORY) $(DSTROOT)$(USRLIBDIR)/php/extensions/no-debug-non-zts-20121212
360	@echo "Removing references to DSTROOT in php-config and include files..."
361	$(CP) $(DSTROOT)$(USRBINDIR)/php-config $(SYMROOT)/php-config \
362		&& $(SED) -e 's=-L$(DSTROOT)$(USRDIR)/local/lib==' $(SYMROOT)/php-config \
363		| $(SED) -e 's@$(DSTROOT)@@g' > $(DSTROOT)$(USRBINDIR)/php-config
364	$(CP) $(DSTROOT)$(USRINCLUDEDIR)/$(Project)/main/build-defs.h $(SYMROOT) \
365		&& LANG=C $(SED) -e 's@$(DSTROOT)@@g' $(SYMROOT)/build-defs.h \
366			> $(DSTROOT)$(USRINCLUDEDIR)/$(Project)/main/build-defs.h
367	@echo "Archiving private static libraries..."
368	-$(MV) $(DSTROOT)$(USRDIR)/local/lib/* $(SYMROOT)
369	@echo "Deleting private dependencies..."
370	-$(RMDIR) $(DSTROOT)$(USRDIR)/local/lib
371	-$(RMDIR) $(DSTROOT)$(USRDIR)/local/include
372	-$(RMDIR) $(DSTROOT)$(USRDIR)/local/bin
373	-$(RMDIR) $(DSTROOT)$(USRDIR)/local/share
374	@echo "Installing PEAR phar for installation at setup time."
375	$(INSTALL_FILE) $(SRCROOT)/install-pear-nozlib.phar $(DSTROOT)$(USRLIBDIR)/php
376	@echo "Fixing PEAR configuration file..."
377	if [ -e $(DSTROOT)/$(USRLIBDIR)/php/pearcmd.php ]; then	\
378		$(CP) $(DSTROOT)/$(USRLIBDIR)/php/pearcmd.php $(PEAR_Cmd);	\
379		$(PATCH) -l $(PEAR_Cmd) $(SRCROOT)/patches/pearcmd.patch;	\
380		$(PEAR) -C $(DSTROOT)$(ETCDIR)/pear.conf config-set \
381			cache_dir /tmp/pear/cache system;	\
382		$(PEAR) -C $(DSTROOT)$(ETCDIR)/pear.conf config-set \
383			download_dir /tmp/pear/download system;	\
384		$(PEAR) -C $(DSTROOT)$(ETCDIR)/pear.conf config-set \
385			temp_dir /tmp/pear/temp system;		\
386	fi
387	@echo "Cleaning up PEAR junk files..."
388	-$(RMDIR) $(DSTROOT)$(USRLIBDIR)/php/test
389	-$(RM) -rf $(DSTROOT)/.channels \
390		$(DSTROOT)/.depdb \
391		$(DSTROOT)/.depdblock \
392		$(DSTROOT)/.filemap \
393		$(DSTROOT)/.lock \
394		$(DSTROOT)/.registry \
395		$(DSTROOT)$(USRLIBDIR)/php/.lock \
396		$(DSTROOT)$(USRLIBDIR)/php/.depdblock
397	-$(STRIP) -x $(DSTROOT)/usr/bin/php $(DSTROOT)/usr/sbin/php-fpm
398	-$(RM) -rf $(DSTROOT)/usr/var
399	-$(MV) $(DSTROOT)/usr/php $(DSTROOT)/usr/share
400	@echo "Mac OS X-specific cleanup complete."
401
402install-xdebug:
403	@echo "Installing XDebug extension..."
404	$(MAKE) -C xdebug $(TARGET)				\
405			SRCROOT=$(SRCROOT)/xdebug		\
406			OBJROOT=$(OBJROOT)			\
407			SYMROOT=$(SYMROOT)			\
408			DSTROOT=$(DSTROOT)			\
409			BuildDirectory=$(OBJROOT)/Build/xdebug	\
410			Sources=$(OBJROOT)/xdebug		\
411			CoreOSMakefiles=$(CoreOSMakefiles)
412	@echo "XDebug extension installed."
413
414$(DSTROOT)$(LIBEXECDIR)/apache2 $(TMPDIR):
415	$(MKDIR) $@
416
417refresh-pear:
418	curl -RO# http://pear.php.net/install-pear-nozlib.phar
419	curl -RO# http://pear2.php.net/pyrus.phar
420