1##
2# Makefile for Apple Release Control (Archive Extraction & Patch)
3#
4# Copyright (c) 2005-2010 Apple Inc.
5#
6# @APPLE_LICENSE_HEADER_START@
7# 
8# Portions Copyright (c) 2005-2009 Apple Inc.  All Rights Reserved.
9# This file contains Original Code and/or Modifications of Original Code
10# as defined in and that are subject to the Apple Public Source License
11# Version 2.0 (the 'License'). You may not use this file except in
12# compliance with the License. Please obtain a copy of the License at
13# http://www.opensource.apple.com/apsl/ and read it before using this
14# file.
15#
16# The Original Code and all software distributed under the License are
17# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
18# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
19# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
20# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
21# Please see the License for the specific language governing rights and
22# limitations under the License.
23# @APPLE_LICENSE_HEADER_END@
24##
25# This header must be included after GNUsource.make or Common.make
26#
27# Set these variables as needed before including this file:
28#  GnuAfterInstall - project-specific post-install targets. This MUST be defined
29#                    for the AEP post-install helper targets to be invoked.
30#  AEP_Version - open source project version, used in archive name and
31#                extracted directory
32#  AEP_Patches - list of file names (from patches subdirectory) to
33#                run thru patch and apply to extracted sources
34#  AEP_LicenseFile - full path to license file
35#  AEP_BuildInSources - override default BuildDirectory and set to Sources;
36#                       this would be necessary if the project should be built
37#                       in the extracted source directory because the real
38#                       sources (with configure) are located there.
39#  Extra_Configure_Environment - additional environment variables only needed for
40#                                the invocation of configure; this would be
41#                                necessary if the project requires extra build flags
42#                                but doesn't want to override everything defined by
43#                                configure.
44#
45# The following variables will be defined if empty:
46#  AEP_Project           [ $(Project)                                ]
47#  AEP_ProjVers          [ $(AEP_Project)-$(AEP_Version)             ]
48#  AEP_Filename          [ $(AEP_ProjVers).tar.[bg]z*                ]
49#  AEP_ExtractDir        [ $(AEP_ProjVers)                           ]
50#  AEP_LicenseFile       [ $(SRCROOT)/$(ProjectName).txt             ]
51#  AEP_ConfigDir         [ $(ETCDIR)                                 ]
52#
53# Additionally, the following variables may also be defined before
54# including this file:
55#  AEP_Binaries - list of binaries to archive to SYMROOT and strip in DSTROOT
56#  AEP_LaunchdConfigs - launchd config files in SRCROOT to be installed
57#                       into LAUNCHDDIR
58#  AEP_StartupItem - startup items name to be installed into
59#                    SYSTEM_STARTUP_DIR; assumes existence of
60#                    StartupParameters.plist and Localizable.strings
61#  AEP_ManPages - man pages provided outside the extracted project
62#  AEP_ConfigFiles - standard set of configuration files; ".default" versions
63#                    will be created as well
64#  Dependencies - list of subprojects which should be built before main project.
65#
66# Finally, a new target, archive-strip-binaries, is made available to copy
67# AEP_Binaries to SYMROOT and strip the versions in DSTROOT. To leverage this
68# target, it should be defined as the first item in GnuAfterInstall.
69##
70
71ifdef AEP_Binaries
72GnuAfterInstall += archive-strip-binaries
73endif
74GnuAfterInstall += install-startup-files install-open-source-files
75GnuAfterInstall += install-top-level-man-pages install-configuration-files
76
77
78#
79# Define AEP variables
80#
81ifndef AEP_Project
82    AEP_Project		= $(Project)
83endif
84
85ifndef AEP_ProjVers
86  ifdef AEP_Version
87    AEP_ProjVers	= $(AEP_Project)-$(AEP_Version)
88  else
89    AEP_ProjVers	= $(AEP_Project)
90  endif
91endif
92
93ifndef AEP_Filename
94    AEP_Filename	= $(wildcard $(AEP_ProjVers).tar.gz $(AEP_ProjVers).tar.bz2)
95endif
96ifeq ($(suffix $(AEP_Filename)),.bz2)
97    AEP_ExtractOption	= j
98else
99    AEP_ExtractOption	= z
100endif
101
102ifndef AEP_ExtractDir
103    AEP_ExtractDir	= $(AEP_ProjVers)
104endif
105
106ifndef AEP_LicenseFile
107    AEP_LicenseFile	= $(SRCROOT)/$(ProjectName).txt
108endif
109
110ifndef AEP_ManPages
111    AEP_ManPages := $(wildcard *.[1-9] man/*.[1-9])
112endif
113
114ifndef AEP_ConfigDir
115    AEP_ConfigDir	= $(ETCDIR)
116endif
117
118#AEP_ExtractRoot		= $(SRCROOT)
119AEP_ExtractRoot		= $(OBJROOT)
120
121# Redefine the Sources directory defined elsewhere
122# ...but save the version of ConfigStamp (based on Sources)
123# GNUSource.make uses.
124GNUConfigStamp		:= $(ConfigStamp)
125Sources			= $(AEP_ExtractRoot)/$(AEP_Project)
126
127# Redefine Configure to allow extra "helper" environment variables.
128# This logic was moved to GNUSource.make in 10A251, so only override the setting
129# if building on an earlier system. (Make_Flags is only defined with that patch.)
130ifndef Make_Flags
131ifdef Extra_Configure_Environment
132      Configure		:= $(Extra_Configure_Environment) $(Configure)
133endif
134endif
135
136
137# Open Source configuration directories
138OSVDIR	= $(USRDIR)/local/OpenSourceVersions
139OSLDIR	= $(USRDIR)/local/OpenSourceLicenses
140
141# Launchd / startup item paths
142LAUNCHDDIR		= $(NSSYSTEMDIR)$(NSLIBRARYSUBDIR)/LaunchDaemons
143SYSTEM_STARTUP_DIR	= $(NSSYSTEMDIR)$(NSLIBRARYSUBDIR)/StartupItems
144
145
146#
147# AEP targets
148#
149.PHONY: extract-source build-dependencies archive-strip-binaries
150.PHONY: install-open-source-files install-startup-files
151.PHONY: install-top-level-man-pages install-configuration-files
152
153ifdef ConfigStamp
154$(GNUConfigStamp): extract-source build-dependencies
155else
156build:: extract-source build-dependencies
157endif
158
159# Because GNUSource's ConfigStamp's rules are processed before this file is included,
160# it's easier to copy the sources to the build directory and work from there.
161extract-source::
162ifeq ($(AEP),YES)
163	@echo "Extracting source for $(Project)..."
164	$(MKDIR) $(AEP_ExtractRoot)
165	$(TAR) -C $(AEP_ExtractRoot) -$(AEP_ExtractOption)xf $(SRCROOT)/$(AEP_Filename)
166	$(RMDIR) $(Sources)
167	$(_v) $(RM) $(GNUConfigStamp)
168	$(MV) $(AEP_ExtractRoot)/$(AEP_ExtractDir) $(Sources)
169ifdef AEP_Patches
170	for patchfile in $(AEP_Patches); do \
171	   echo "Applying $$patchfile..."; \
172	   cd $(Sources) && $(PATCH) -p1 -F0 < $(SRCROOT)/patches/$$patchfile || exit 1; \
173	done
174endif
175ifeq ($(AEP_BuildInSources),YES)
176ifneq ($(Sources),$(BuildDirectory))
177	@echo "Copying sources to build directory..."
178	$(_v) $(CP) $(Sources) $(BuildDirectory)
179endif
180endif
181else
182	@echo "Source extraction for $(Project) skipped!"
183endif
184
185# Common.make's recurse doesn't reset SRCROOT and misdefines Sources
186build-dependencies:
187ifdef Dependencies
188	$(_v) for Dependency in $(Dependencies); do			\
189		$(MAKE) -C $${Dependency} $(TARGET)			\
190			SRCROOT=$(SRCROOT)/$${Dependency}		\
191			OBJROOT=$(OBJROOT)				\
192			SYMROOT=$(SYMROOT)				\
193			DSTROOT=$(DSTROOT)				\
194			BuildDirectory=$(OBJROOT)/Build/$${Dependency}	\
195			Sources=$(OBJROOT)/$${Dependency}		\
196			CoreOSMakefiles=$(CoreOSMakefiles)		\
197			$(Extra_Dependency_Flags);			\
198		done
199endif
200
201archive-strip-binaries:: $(SYMROOT)
202ifdef AEP_Binaries
203	@echo "Archiving and stripping binaries..."
204	$(_v) for file in $(addprefix $(DSTROOT),$(AEP_Binaries));	\
205	do \
206		$(CP) $${file} $(SYMROOT);				\
207		$(DSYMUTIL) --out=$(SYMROOT)/$${file##*/}.dSYM $${file};\
208		$(STRIP) -S $${file};					\
209	done
210endif
211
212install-startup-files::
213ifdef AEP_LaunchdConfigs
214	@echo "Installing launchd configuration files..."
215	$(INSTALL_DIRECTORY) $(DSTROOT)$(LAUNCHDDIR)
216	$(INSTALL_FILE) $(AEP_LaunchdConfigs) $(DSTROOT)$(LAUNCHDDIR)
217endif
218ifdef AEP_StartupItem
219	@echo "Installing StartupItem..."
220	$(INSTALL_DIRECTORY) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
221	$(INSTALL_SCRIPT) $(StartupItem) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
222	$(INSTALL_FILE) StartupParameters.plist $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
223	$(INSTALL_DIRECTORY) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)/Resources/English.lproj
224	$(INSTALL_FILE) Localizable.strings $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)/Resources/English.lproj
225endif
226
227install-open-source-files::
228	@echo "Installing Apple-internal open-source documentation..."
229	if [ -e $(SRCROOT)/$(ProjectName).plist ]; then	\
230		$(MKDIR) $(DSTROOT)/$(OSVDIR);	   	\
231		$(INSTALL_FILE) $(SRCROOT)/$(ProjectName).plist $(DSTROOT)/$(OSVDIR)/$(ProjectName).plist;	\
232	else	\
233		echo "WARNING: No open-source file for this project!";	\
234	fi
235	if [ -e $(AEP_LicenseFile) ]; then	\
236		$(MKDIR) $(DSTROOT)/$(OSLDIR);	\
237		$(INSTALL_FILE) $(AEP_LicenseFile) $(DSTROOT)/$(OSLDIR)/$(ProjectName).txt;	\
238	else	\
239		echo "WARNING: No open-source file for this project!";	\
240	fi
241
242
243#
244# Install any man pages at the top-level directory or its "man" subdirectory
245#
246install-top-level-man-pages::
247ifdef AEP_ManPages
248	@echo "Installing top-level man pages..."
249	for _page in $(AEP_ManPages); do				\
250		_section_dir=$(Install_Man)/man$${_page##*\.};		\
251		$(INSTALL_DIRECTORY) $(DSTROOT)$${_section_dir};	\
252		$(INSTALL_FILE) $${_page} $(DSTROOT)$${_section_dir};	\
253	done
254endif
255
256
257#
258# Install configuration files and their corresponding ".default" files
259# to one standard location.
260#
261install-configuration-files::
262ifdef AEP_ConfigFiles
263	@echo "Installing configuration files..."
264	$(INSTALL_DIRECTORY) $(DSTROOT)$(AEP_ConfigDir)
265	for file in $(AEP_ConfigFiles); \
266	do \
267		$(INSTALL_FILE) $${file} $(DSTROOT)$(AEP_ConfigDir); \
268		$(CHMOD) u+w $(DSTROOT)$(AEP_ConfigDir)/$${file}; \
269		if [ "${file##*.}" != "default" ]; then \
270			$(INSTALL_FILE) $${file} $(DSTROOT)$(AEP_ConfigDir)/$${file}.default; \
271		fi; \
272	done
273endif
274
275
276clean::
277	$(_v) if [ -d $(Sources) ]; then \
278	    cd $(Sources) && make clean; \
279	fi
280
281$(DSTROOT) $(DSTROOT)$(AEP_ConfigDir) $(SYMROOT) $(TMPDIR):
282	$(MKDIR) $@
283