1#
2# Apple wrapper Makefile for PostgreSQL
3# Copyright (c) 2012-2013 Apple Inc. All Rights Reserved.
4#
5# This build of PostgreSQLQ 9.1.x is only intended for data migration purposes.
6
7# General project info for use with RC/GNUsource.make makefile
8Project         = postgresql
9ProjectName     = PostgreSQL
10UserType        = Administrator
11ToolType        = Commands
12Submission      = 64.2
13
14# Include common server build variables
15-include /AppleInternal/ServerTools/ServerBuildVariables.xcconfig
16
17# Variables only used by project
18ServicesDir = $(NSLIBRARYSUBDIR)/Server
19ServiceDir = $(ServicesDir)/$(ProjectName)
20DBDir = $(ServiceDir)/postgresql9.1/pgsql
21
22# Environment is passed to BOTH configure AND make, which can cause problems if these
23# variables are intended to help configure, but not override the result.
24Extra_CC_Flags	= -Os -g -Wall -Wno-deprecated-declarations
25# This allows extra variables to be passed _just_ to configure.
26Extra_Configure_Environment	= CFLAGS="$$RC_CFLAGS $(Extra_CC_Flags)" \
27					LDFLAGS="$$RC_CFLAGS $(Extra_CC_Flags)" \
28					LDFLAGS_EX="-mdynamic-no-pic" \
29					EXTRA_LDFLAGS_PROGRAM="-mdynamic-no-pic" \
30					LIBS="-L$(SDKROOT)/usr/lib" \
31					INCLUDES="-I$(SDKROOT)/usr/include/libxml2"
32
33# The configure flags are ordered to match current output of ./configure --help.
34# Extra indentation represents suboptions.
35Extra_Configure_Flags	= --prefix=$(SERVER_INSTALL_PATH_PREFIX)$(LIBEXECDIR)/postgresql9.1 \
36			--sbindir=$(SERVER_INSTALL_PATH_PREFIX)$(LIBEXECDIR)/postgresql9.1 \
37			--bindir=$(SERVER_INSTALL_PATH_PREFIX)$(LIBEXECDIR)/postgresql9.1 \
38			--sysconfdir=$(SERVER_INSTALL_PATH_PREFIX)$(ETCDIR) \
39			--localstatedir=$(DBDir) \
40			--libdir=$(SERVER_INSTALL_PATH_PREFIX)$(USRLIBDIR)/postgresql9.1 \
41			--datarootdir=$(SERVER_INSTALL_PATH_PREFIX)$(SHAREDIR)/postgresql9.1 \
42			--includedir=$(ServiceDir)/pgbuild_tmp \
43			--enable-thread-safety \
44			--enable-dtrace \
45			--with-tcl \
46			--with-perl \
47			--with-python \
48			--with-gssapi \
49			--with-krb5 \
50			--with-pam \
51			--with-ldap \
52			--with-bonjour \
53			--with-openssl \
54			--with-libxml \
55			--with-libxslt \
56			--with-system-tzdata=$(SHAREDIR)/zoneinfo \
57			--with-pgport=5433
58
59Extra_Make_Flags	=
60
61# Additional project info used with AEP
62AEP		= YES
63AEP_Version	= 9.1.9
64AEP_LicenseFile	= $(Sources)/COPYRIGHT
65AEP_Patches     = arches.patch pg_config_manual_h.patch \
66					radar7687126.patch radar7756388.patch radar8304089.patch \
67					initdb.patch _int_bool.c.patch prep_buildtree.patch
68
69AEP_Binaries	= $(SERVER_INSTALL_PATH_PREFIX)$(LIBEXECDIR)/postgresql9.1/* $(SERVER_INSTALL_PATH_PREFIX)$(USRLIBDIR)/postgresql9.1/* $(SERVER_INSTALL_PATH_PREFIX)$(USRLIBDIR)/postgresql9.1/pgxs/src/test/regress/pg_regress
70
71Configure_Products = config.log src/include/pg_config.h
72GnuAfterInstall	= install-contrib install-macosx cleanup-temp archive-strip-binaries
73ContribTools	= hstore intarray pg_upgrade pg_upgrade_support
74
75# Local targets that must be defined before including the following
76# files to get the dependency order correct
77.PHONY: $(GnuAfterInstall)
78
79# Include common makefile targets for B&I
80include $(MAKEFILEPATH)/CoreOS/ReleaseControl/GNUSource.make
81#include $(MAKEFILEPATH)/CoreOS/ReleaseControl/AEP.make
82#
83# Define AEP variables
84#
85ifndef AEP_Project
86    AEP_Project		= $(Project)
87endif
88
89ifndef AEP_ProjVers
90  ifdef AEP_Version
91    AEP_ProjVers	= $(AEP_Project)-$(AEP_Version)
92  else
93    AEP_ProjVers	= $(AEP_Project)
94  endif
95endif
96
97ifndef AEP_Filename
98    AEP_Filename	= $(wildcard $(AEP_ProjVers).tar.gz $(AEP_ProjVers).tar.bz2)
99endif
100ifeq ($(suffix $(AEP_Filename)),.bz2)
101    AEP_ExtractOption	= j
102else
103    AEP_ExtractOption	= z
104endif
105
106ifndef AEP_ExtractDir
107    AEP_ExtractDir	= $(AEP_ProjVers)
108endif
109
110ifndef AEP_LicenseFile
111    AEP_LicenseFile	= $(SRCROOT)/$(ProjectName).txt
112endif
113
114ifndef AEP_ManPages
115    AEP_ManPages := $(wildcard *.[1-9] man/*.[1-9])
116endif
117
118ifndef AEP_ConfigDir
119    AEP_ConfigDir	= $(ETCDIR)
120endif
121
122ifndef AEP_Binaries
123    AEP_Binaries	= $(subst ./,/,$(shell cd $(DSTROOT) && $(FIND) . -type f -perm +0111 -exec $(SHELL) -c 'test \"`file -b --mime-type {}`\" = \"application/octet-stream\"' \; -print))
124endif
125
126#AEP_ExtractRoot		= $(SRCROOT)
127AEP_ExtractRoot		= $(OBJROOT)
128
129# Redefine the Sources directory defined elsewhere
130# ...but save the version of ConfigStamp (based on Sources)
131# GNUSource.make uses.
132GNUConfigStamp		:= $(ConfigStamp)
133Sources			= $(AEP_ExtractRoot)/$(AEP_Project)
134
135# Redefine Configure to allow extra "helper" environment variables.
136# This logic was moved to GNUSource.make in 10A251, so only override the setting
137# if building on an earlier system. (Make_Flags is only defined with that patch.)
138ifndef Make_Flags
139ifdef Extra_Configure_Environment
140      Configure		:= $(Extra_Configure_Environment) $(Configure)
141endif
142endif
143
144
145# Open Source configuration directories
146OSVDIR	= $(USRDIR)/local/OpenSourceVersions
147OSLDIR	= $(USRDIR)/local/OpenSourceLicenses
148
149# Launchd / startup item paths
150LAUNCHDDIR		= $(NSSYSTEMDIR)$(NSLIBRARYSUBDIR)/LaunchDaemons
151SYSTEM_STARTUP_DIR	= $(NSSYSTEMDIR)$(NSLIBRARYSUBDIR)/StartupItems
152
153
154#
155# AEP targets
156#
157.PHONY: extract-source build-dependencies archive-strip-binaries
158.PHONY: install-open-source-files install-startup-files
159.PHONY: install-top-level-man-pages install-configuration-files
160
161ifdef ConfigStamp
162$(GNUConfigStamp): extract-source build-dependencies
163else
164build:: extract-source build-dependencies
165endif
166
167# Because GNUSource's ConfigStamp's rules are processed before this file is included,
168# it's easier to copy the sources to the build directory and work from there.
169extract-source::
170ifeq ($(AEP),YES)
171	@echo "Extracting source for $(Project)..."
172	$(MKDIR) $(AEP_ExtractRoot)
173	$(TAR) -C $(AEP_ExtractRoot) -$(AEP_ExtractOption)xf $(SRCROOT)/$(AEP_Filename)
174	$(RMDIR) $(Sources)
175	$(_v) $(RM) $(GNUConfigStamp)
176	$(MV) $(AEP_ExtractRoot)/$(AEP_ExtractDir) $(Sources)
177ifdef AEP_Patches
178	for patchfile in $(AEP_Patches); do \
179	   echo "Applying $$patchfile..."; \
180	   cd $(Sources) && $(PATCH) -lp1 < $(SRCROOT)/patches/$$patchfile; \
181	done
182endif
183ifeq ($(AEP_BuildInSources),YES)
184ifneq ($(Sources),$(BuildDirectory))
185	@echo "Copying sources to build directory..."
186	$(_v) $(CP) $(Sources) $(BuildDirectory)
187endif
188endif
189else
190	@echo "Source extraction for $(Project) skipped!"
191endif
192
193# Common.make's recurse doesn't reset SRCROOT and misdefines Sources
194build-dependencies:
195ifdef Dependencies
196	$(_v) for Dependency in $(Dependencies); do			\
197		$(MKDIR) $(SYMROOT)/$${Dependency};			\
198		$(MAKE) -C $${Dependency} $(TARGET)			\
199			SRCROOT=$(SRCROOT)/$${Dependency}		\
200			OBJROOT=$(OBJROOT)				\
201			SYMROOT=$(SYMROOT)/$${Dependency}		\
202			DSTROOT=$(DSTROOT)				\
203			BuildDirectory=$(OBJROOT)/Build/$${Dependency}	\
204			Sources=$(OBJROOT)/$${Dependency}		\
205			CoreOSMakefiles=$(CoreOSMakefiles)		\
206			$(Extra_Dependency_Flags);			\
207		done
208endif
209
210archive-strip-binaries:: $(SYMROOT)
211ifdef AEP_Binaries
212	@echo "Archiving and stripping binaries..."
213	$(_v) for file in $(addprefix $(DSTROOT),$(AEP_Binaries));	\
214	do \
215		_type=`file -b --mime-type $${file}`;			\
216		if [ "$${_type}" = "application/octet-stream" ]; then	\
217			echo "\tProcessing $${file}...";			\
218			$(CP) $${file} $(SYMROOT);				\
219			$(DSYMUTIL) --out=$(SYMROOT)/$${file##*/}.dSYM $${file};\
220			$(STRIP) -S $${file};					\
221		else	\
222			echo "\tSkipped non-binary $${file}; type is $${_type}";\
223		fi	\
224	done
225endif
226
227install-startup-files::
228ifdef AEP_LaunchdConfigs
229	@echo "Installing launchd configuration files..."
230	$(INSTALL_DIRECTORY) $(DSTROOT)$(LAUNCHDDIR)
231	$(INSTALL_FILE) $(AEP_LaunchdConfigs) $(DSTROOT)$(LAUNCHDDIR)
232endif
233ifdef AEP_StartupItem
234	@echo "Installing StartupItem..."
235	$(INSTALL_DIRECTORY) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
236	$(INSTALL_SCRIPT) $(StartupItem) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
237	$(INSTALL_FILE) StartupParameters.plist $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
238	$(INSTALL_DIRECTORY) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)/Resources/English.lproj
239	$(INSTALL_FILE) Localizable.strings $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)/Resources/English.lproj
240endif
241
242install-open-source-files::
243	@echo "Installing Apple-internal open-source documentation..."
244	if [ -e $(SRCROOT)/$(ProjectName).plist ]; then	\
245		$(MKDIR) $(DSTROOT)/$(OSVDIR);	   	\
246		$(INSTALL_FILE) $(SRCROOT)/$(ProjectName).plist $(DSTROOT)/$(OSVDIR)/$(ProjectName).plist;	\
247	else	\
248		echo "WARNING: No open-source file for this project!";	\
249	fi
250	if [ -e $(AEP_LicenseFile) ]; then	\
251		$(MKDIR) $(DSTROOT)/$(OSLDIR);	\
252		$(INSTALL_FILE) $(AEP_LicenseFile) $(DSTROOT)/$(OSLDIR)/$(ProjectName).txt;	\
253	else	\
254		echo "WARNING: No open-source file for this project!";	\
255	fi
256
257
258#
259# Install any man pages at the top-level directory or its "man" subdirectory
260#
261install-top-level-man-pages::
262ifdef AEP_ManPages
263	@echo "Installing top-level man pages..."
264	for _page in $(AEP_ManPages); do				\
265		_section_dir=$(Install_Man)/man$${_page##*\.};		\
266		$(INSTALL_DIRECTORY) $(DSTROOT)$${_section_dir};	\
267		$(INSTALL_FILE) $${_page} $(DSTROOT)$${_section_dir};	\
268	done
269endif
270
271
272#
273# Install configuration files and their corresponding ".default" files
274# to one standard location.
275#
276install-configuration-files::
277ifdef AEP_ConfigFiles
278	@echo "Installing configuration files..."
279	$(INSTALL_DIRECTORY) $(DSTROOT)$(AEP_ConfigDir)
280	for file in $(AEP_ConfigFiles); \
281	do \
282		$(INSTALL_FILE) $${file} $(DSTROOT)$(AEP_ConfigDir); \
283		$(CHMOD) u+w $(DSTROOT)$(AEP_ConfigDir)/$${file}; \
284		if [ "${file##*.}" != "default" ]; then \
285			$(INSTALL_FILE) $${file} $(DSTROOT)$(AEP_ConfigDir)/$${file}.default; \
286		fi; \
287	done
288endif
289
290
291clean::
292	$(_v) if [ -d $(Sources) ]; then \
293	    cd $(Sources) && make clean; \
294	fi
295
296$(DSTROOT) $(DSTROOT)$(AEP_ConfigDir) $(SYMROOT) $(TMPDIR):
297	$(MKDIR) $@
298
299###### End AEP.Make
300
301# Override settings from above includes
302BuildDirectory	= $(OBJROOT)/Build
303Install_Target	= install
304# This needs to be overridden because the project properly uses DESTDIR and
305# INSTALL_ROOT (which is included in Environment).
306Install_Flags	= DESTDIR="$(DSTROOT)"
307
308
309# Build rules
310install-contrib:
311	@echo "Installing specific tools from contrib:"
312	for tool in $(ContribTools); do \
313		echo "...Installing $${tool}...";	\
314		$(MAKE) -C $(BuildDirectory)/contrib/$${tool} $(Install_Flags) $(Install_Target); \
315	done
316
317install-macosx:
318	@echo "Creating service directories..."
319	@echo "Done."
320
321cleanup-temp:
322	@echo "Removing unnecessary files from DSTROOT..."
323	$(RM) -rvf $(DSTROOT)$(NSLIBRARYSUBDIR)
324	@echo "Done."
325