1##
2# Copyright (c) 2008-2010 Apple Inc. All Rights Reserved.
3##
4#
5
6# General project info
7Project         = libjpeg
8UserType        = Developer
9ToolType        = Library
10
11# Some Makefile features are available only on Snow Leopard and later.
12_OS_VERSION = $(shell sw_vers -productVersion | cut -d. -f1-2)
13
14# Project-specific additions.
15#Extra_Environment	= 
16Extra_Configure_Flags	= --enable-static --disable-shared
17Extra_Make_Flags		=
18# Required or AEP parts won't be picked up.
19GnuAfterInstall		= install-macosx
20
21# Override defaults because we do want this in /usr/local...
22Install_Prefix	= $(USRDIR)/local
23Install_Man	= $(Install_Prefix)/share/man
24Install_Info	= $(Install_Prefix)/info
25
26# Automatic Extract & Patch
27AEP		= YES
28AEP_Version	= 9
29AEP_Filename	= jpegsrc.v$(AEP_Version).tar.gz
30AEP_ExtractDir	= jpeg-$(AEP_Version)
31AEP_Patches	=
32# License file must be empty as this is a subproject.
33AEP_LicenseFile	=
34
35
36# Defines only used here.
37
38# Local targets that must be defined before including the following
39# files to get the dependency order correct
40install::
41
42# Include common makefile targets for B&I
43include $(MAKEFILEPATH)/CoreOS/ReleaseControl/GNUSource.make
44
45
46#GnuAfterInstall += archive-strip-binaries
47GnuAfterInstall += install-startup-files install-open-source-files
48GnuAfterInstall += install-top-level-man-pages install-configuration-files
49
50
51#
52# Define AEP variables
53#
54ifndef AEP_Project
55    AEP_Project		= $(Project)
56endif
57
58ifndef AEP_ProjVers
59  ifdef AEP_Version
60    AEP_ProjVers	= $(AEP_Project)-$(AEP_Version)
61  else
62    AEP_ProjVers	= $(AEP_Project)
63  endif
64endif
65
66ifndef AEP_Filename
67    AEP_Filename	= $(wildcard $(AEP_ProjVers).tar.gz $(AEP_ProjVers).tar.bz2)
68endif
69ifeq ($(suffix $(AEP_Filename)),.bz2)
70    AEP_ExtractOption	= j
71else
72    AEP_ExtractOption	= z
73endif
74
75ifndef AEP_ExtractDir
76    AEP_ExtractDir	= $(AEP_ProjVers)
77endif
78
79ifndef AEP_LicenseFile
80    AEP_LicenseFile	= $(SRCROOT)/$(ProjectName).txt
81endif
82
83ifndef AEP_ManPages
84    AEP_ManPages := $(wildcard *.[1-9] man/*.[1-9])
85endif
86
87ifndef AEP_ConfigDir
88    AEP_ConfigDir	= $(ETCDIR)
89endif
90
91ifndef AEP_Binaries
92    AEP_Binaries	= $(subst ./,/,$(shell cd $(DSTROOT) && $(FIND) . -type f -perm +0111 -exec $(SHELL) -c 'test \"`file -b --mime-type {}`\" = \"application/octet-stream\"' \; -print))
93endif
94
95#AEP_ExtractRoot		= $(SRCROOT)
96AEP_ExtractRoot		= $(OBJROOT)
97
98# Redefine the Sources directory defined elsewhere
99# ...but save the version of ConfigStamp (based on Sources)
100# GNUSource.make uses.
101GNUConfigStamp		:= $(ConfigStamp)
102Sources			= $(AEP_ExtractRoot)/$(AEP_Project)
103
104# Redefine Configure to allow extra "helper" environment variables.
105# This logic was moved to GNUSource.make in 10A251, so only override the setting
106# if building on an earlier system. (Make_Flags is only defined with that patch.)
107ifndef Make_Flags
108ifdef Extra_Configure_Environment
109      Configure		:= $(Extra_Configure_Environment) $(Configure)
110endif
111endif
112
113
114# Open Source configuration directories
115OSVDIR	= $(USRDIR)/local/OpenSourceVersions
116OSLDIR	= $(USRDIR)/local/OpenSourceLicenses
117
118# Launchd / startup item paths
119LAUNCHDDIR		= $(NSSYSTEMDIR)$(NSLIBRARYSUBDIR)/LaunchDaemons
120SYSTEM_STARTUP_DIR	= $(NSSYSTEMDIR)$(NSLIBRARYSUBDIR)/StartupItems
121
122
123#
124# AEP targets
125#
126.PHONY: extract-source build-dependencies archive-strip-binaries
127.PHONY: install-open-source-files install-startup-files
128.PHONY: install-top-level-man-pages install-configuration-files
129
130ifdef ConfigStamp
131$(GNUConfigStamp): extract-source build-dependencies
132else
133build:: extract-source build-dependencies
134endif
135
136# Because GNUSource's ConfigStamp's rules are processed before this file is included,
137# it's easier to copy the sources to the build directory and work from there.
138extract-source::
139ifeq ($(AEP),YES)
140	@echo "Extracting source for $(Project)..."
141	$(MKDIR) $(AEP_ExtractRoot)
142	$(TAR) -C $(AEP_ExtractRoot) -$(AEP_ExtractOption)xf $(SRCROOT)/$(AEP_Filename)
143	$(RMDIR) $(Sources)
144	$(_v) $(RM) $(GNUConfigStamp)
145	$(MV) $(AEP_ExtractRoot)/$(AEP_ExtractDir) $(Sources)
146ifdef AEP_Patches
147	for patchfile in $(AEP_Patches); do \
148	   echo "Applying $$patchfile..."; \
149	   cd $(Sources) && $(PATCH) -lp1 < $(SRCROOT)/patches/$$patchfile; \
150	done
151endif
152ifeq ($(AEP_BuildInSources),YES)
153ifneq ($(Sources),$(BuildDirectory))
154	@echo "Copying sources to build directory..."
155	$(_v) $(CP) $(Sources) $(BuildDirectory)
156endif
157endif
158else
159	@echo "Source extraction for $(Project) skipped!"
160endif
161
162# Common.make's recurse doesn't reset SRCROOT and misdefines Sources
163build-dependencies:
164ifdef Dependencies
165	$(_v) for Dependency in $(Dependencies); do			\
166		$(MKDIR) $(SYMROOT)/$${Dependency};			\
167		$(MAKE) -C $${Dependency} $(TARGET)			\
168			SRCROOT=$(SRCROOT)/$${Dependency}		\
169			OBJROOT=$(OBJROOT)				\
170			SYMROOT=$(SYMROOT)/$${Dependency}		\
171			DSTROOT=$(DSTROOT)				\
172			BuildDirectory=$(OBJROOT)/Build/$${Dependency}	\
173			Sources=$(OBJROOT)/$${Dependency}		\
174			CoreOSMakefiles=$(CoreOSMakefiles)		\
175			$(Extra_Dependency_Flags);			\
176		done
177endif
178
179archive-strip-binaries:: $(SYMROOT)
180ifdef AEP_Binaries
181	@echo "Archiving and stripping binaries..."
182	$(_v) for file in $(addprefix $(DSTROOT),$(AEP_Binaries));	\
183	do \
184		_type=`file -b --mime-type $${file}`;			\
185		if [ "$${_type}" = "application/octet-stream" ]; then	\
186			echo "\tProcessing $${file}...";			\
187			$(CP) $${file} $(SYMROOT);				\
188			$(DSYMUTIL) --out=$(SYMROOT)/$${file##*/}.dSYM $${file};\
189			$(STRIP) -S $${file};					\
190		else	\
191			echo "\tSkipped non-binary $${file}; type is $${_type}";\
192		fi	\
193	done
194endif
195
196install-startup-files::
197ifdef AEP_LaunchdConfigs
198	@echo "Installing launchd configuration files..."
199	$(INSTALL_DIRECTORY) $(DSTROOT)$(LAUNCHDDIR)
200	$(INSTALL_FILE) $(AEP_LaunchdConfigs) $(DSTROOT)$(LAUNCHDDIR)
201endif
202ifdef AEP_StartupItem
203	@echo "Installing StartupItem..."
204	$(INSTALL_DIRECTORY) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
205	$(INSTALL_SCRIPT) $(StartupItem) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
206	$(INSTALL_FILE) StartupParameters.plist $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
207	$(INSTALL_DIRECTORY) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)/Resources/English.lproj
208	$(INSTALL_FILE) Localizable.strings $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)/Resources/English.lproj
209endif
210
211install-open-source-files::
212	@echo "Installing Apple-internal open-source documentation..."
213	if [ -e $(SRCROOT)/$(ProjectName).plist ]; then	\
214		$(MKDIR) $(DSTROOT)/$(OSVDIR);	   	\
215		$(INSTALL_FILE) $(SRCROOT)/$(ProjectName).plist $(DSTROOT)/$(OSVDIR)/$(ProjectName).plist;	\
216	else	\
217		echo "WARNING: No open-source file for this project!";	\
218	fi
219	if [ -e $(AEP_LicenseFile) ]; then	\
220		$(MKDIR) $(DSTROOT)/$(OSLDIR);	\
221		$(INSTALL_FILE) $(AEP_LicenseFile) $(DSTROOT)/$(OSLDIR)/$(ProjectName).txt;	\
222	else	\
223		echo "WARNING: No open-source file for this project!";	\
224	fi
225
226
227#
228# Install any man pages at the top-level directory or its "man" subdirectory
229#
230install-top-level-man-pages::
231ifdef AEP_ManPages
232	@echo "Installing top-level man pages..."
233	for _page in $(AEP_ManPages); do				\
234		_section_dir=$(Install_Man)/man$${_page##*\.};		\
235		$(INSTALL_DIRECTORY) $(DSTROOT)$${_section_dir};	\
236		$(INSTALL_FILE) $${_page} $(DSTROOT)$${_section_dir};	\
237	done
238endif
239
240
241#
242# Install configuration files and their corresponding ".default" files
243# to one standard location.
244#
245install-configuration-files::
246ifdef AEP_ConfigFiles
247	@echo "Installing configuration files..."
248	$(INSTALL_DIRECTORY) $(DSTROOT)$(AEP_ConfigDir)
249	for file in $(AEP_ConfigFiles); \
250	do \
251		$(INSTALL_FILE) $${file} $(DSTROOT)$(AEP_ConfigDir); \
252		$(CHMOD) u+w $(DSTROOT)$(AEP_ConfigDir)/$${file}; \
253		if [ "${file##*.}" != "default" ]; then \
254			$(INSTALL_FILE) $${file} $(DSTROOT)$(AEP_ConfigDir)/$${file}.default; \
255		fi; \
256	done
257endif
258
259
260clean::
261	$(_v) if [ -d $(Sources) ]; then \
262	    cd $(Sources) && make clean; \
263	fi
264
265$(DSTROOT) $(DSTROOT)$(AEP_ConfigDir) $(SYMROOT) $(TMPDIR):
266	$(MKDIR) $@
267
268
269#
270# Override settings from above include
271#
272DESTDIR	= $(DSTROOT)
273
274# This needs to be overridden because the project properly uses DESTDIR.
275Install_Flags	= DESTDIR="$(DSTROOT)"
276# This project does not support the default "install-strip" target.
277Install_Target	= install
278
279# Done with overrides
280
281install-macosx:
282	@echo "No additional work necessary for Mac OS X."
283