1#
2# Apple wrapper Makefile for PostgreSQL
3# Copyright (c) 2009-2013 Apple Inc. All Rights Reserved.
4#
5# This build of PostgreSQLQ 9.0.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      = 26.5
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.0/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.0 \
36			--sbindir=$(SERVER_INSTALL_PATH_PREFIX)$(LIBEXECDIR)/postgresql9.0 \
37			--bindir=$(SERVER_INSTALL_PATH_PREFIX)$(LIBEXECDIR)/postgresql9.0 \
38			--sysconfdir=$(SERVER_INSTALL_PATH_PREFIX)$(ETCDIR) \
39			--localstatedir=$(DBDir) \
40			--libdir=$(SERVER_INSTALL_PATH_PREFIX)$(USRLIBDIR)/postgresql9.0 \
41			--datarootdir=$(SERVER_INSTALL_PATH_PREFIX)$(SHAREDIR)/postgresql9.0 \
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.0.13
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
68AEP_Binaries	= $(SERVER_INSTALL_PATH_PREFIX)$(LIBEXECDIR)/postgresql9.0/* $(SERVER_INSTALL_PATH_PREFIX)$(USRLIBDIR)/postgresql9.0/* $(SERVER_INSTALL_PATH_PREFIX)$(USRLIBDIR)/postgresql9.0/pgxs/src/test/regress/pg_regress
69
70Configure_Products = config.log src/include/pg_config.h
71GnuAfterInstall	= install-contrib install-macosx cleanup-temp archive-strip-binaries
72ContribTools	= hstore intarray pg_upgrade pg_upgrade_support
73
74# Local targets that must be defined before including the following
75# files to get the dependency order correct
76.PHONY: $(GnuAfterInstall)
77
78# Include common makefile targets for B&I
79include $(MAKEFILEPATH)/CoreOS/ReleaseControl/GNUSource.make
80#include $(MAKEFILEPATH)/CoreOS/ReleaseControl/AEP.make
81#
82# Define AEP variables
83#
84ifndef AEP_Project
85    AEP_Project		= $(Project)
86endif
87
88ifndef AEP_ProjVers
89  ifdef AEP_Version
90    AEP_ProjVers	= $(AEP_Project)-$(AEP_Version)
91  else
92    AEP_ProjVers	= $(AEP_Project)
93  endif
94endif
95
96ifndef AEP_Filename
97    AEP_Filename	= $(wildcard $(AEP_ProjVers).tar.gz $(AEP_ProjVers).tar.bz2)
98endif
99ifeq ($(suffix $(AEP_Filename)),.bz2)
100    AEP_ExtractOption	= j
101else
102    AEP_ExtractOption	= z
103endif
104
105ifndef AEP_ExtractDir
106    AEP_ExtractDir	= $(AEP_ProjVers)
107endif
108
109ifndef AEP_LicenseFile
110    AEP_LicenseFile	= $(SRCROOT)/$(ProjectName).txt
111endif
112
113ifndef AEP_ManPages
114    AEP_ManPages := $(wildcard *.[1-9] man/*.[1-9])
115endif
116
117ifndef AEP_ConfigDir
118    AEP_ConfigDir	= $(ETCDIR)
119endif
120
121ifndef AEP_Binaries
122    AEP_Binaries	= $(subst ./,/,$(shell cd $(DSTROOT) && $(FIND) . -type f -perm +0111 -exec $(SHELL) -c 'test \"`file -b --mime-type {}`\" = \"application/octet-stream\"' \; -print))
123endif
124
125#AEP_ExtractRoot		= $(SRCROOT)
126AEP_ExtractRoot		= $(OBJROOT)
127
128# Redefine the Sources directory defined elsewhere
129# ...but save the version of ConfigStamp (based on Sources)
130# GNUSource.make uses.
131GNUConfigStamp		:= $(ConfigStamp)
132Sources			= $(AEP_ExtractRoot)/$(AEP_Project)
133
134# Redefine Configure to allow extra "helper" environment variables.
135# This logic was moved to GNUSource.make in 10A251, so only override the setting
136# if building on an earlier system. (Make_Flags is only defined with that patch.)
137ifndef Make_Flags
138ifdef Extra_Configure_Environment
139      Configure		:= $(Extra_Configure_Environment) $(Configure)
140endif
141endif
142
143
144# Open Source configuration directories
145OSVDIR	= $(USRDIR)/local/OpenSourceVersions
146OSLDIR	= $(USRDIR)/local/OpenSourceLicenses
147
148# Launchd / startup item paths
149LAUNCHDDIR		= $(NSSYSTEMDIR)$(NSLIBRARYSUBDIR)/LaunchDaemons
150SYSTEM_STARTUP_DIR	= $(NSSYSTEMDIR)$(NSLIBRARYSUBDIR)/StartupItems
151
152
153#
154# AEP targets
155#
156.PHONY: extract-source build-dependencies archive-strip-binaries
157.PHONY: install-open-source-files install-startup-files
158.PHONY: install-top-level-man-pages install-configuration-files
159
160ifdef ConfigStamp
161$(GNUConfigStamp): extract-source build-dependencies
162else
163build:: extract-source build-dependencies
164endif
165
166# Because GNUSource's ConfigStamp's rules are processed before this file is included,
167# it's easier to copy the sources to the build directory and work from there.
168extract-source::
169ifeq ($(AEP),YES)
170	@echo "Extracting source for $(Project)..."
171	$(MKDIR) $(AEP_ExtractRoot)
172	$(TAR) -C $(AEP_ExtractRoot) -$(AEP_ExtractOption)xf $(SRCROOT)/$(AEP_Filename)
173	$(RMDIR) $(Sources)
174	$(_v) $(RM) $(GNUConfigStamp)
175	$(MV) $(AEP_ExtractRoot)/$(AEP_ExtractDir) $(Sources)
176ifdef AEP_Patches
177	for patchfile in $(AEP_Patches); do \
178	   echo "Applying $$patchfile..."; \
179	   cd $(Sources) && $(PATCH) -lp1 < $(SRCROOT)/patches/$$patchfile; \
180	done
181endif
182ifeq ($(AEP_BuildInSources),YES)
183ifneq ($(Sources),$(BuildDirectory))
184	@echo "Copying sources to build directory..."
185	$(_v) $(CP) $(Sources) $(BuildDirectory)
186endif
187endif
188else
189	@echo "Source extraction for $(Project) skipped!"
190endif
191
192# Common.make's recurse doesn't reset SRCROOT and misdefines Sources
193build-dependencies:
194ifdef Dependencies
195	$(_v) for Dependency in $(Dependencies); do			\
196		$(MKDIR) $(SYMROOT)/$${Dependency};			\
197		$(MAKE) -C $${Dependency} $(TARGET)			\
198			SRCROOT=$(SRCROOT)/$${Dependency}		\
199			OBJROOT=$(OBJROOT)				\
200			SYMROOT=$(SYMROOT)/$${Dependency}		\
201			DSTROOT=$(DSTROOT)				\
202			BuildDirectory=$(OBJROOT)/Build/$${Dependency}	\
203			Sources=$(OBJROOT)/$${Dependency}		\
204			CoreOSMakefiles=$(CoreOSMakefiles)		\
205			$(Extra_Dependency_Flags);			\
206		done
207endif
208
209archive-strip-binaries:: $(SYMROOT)
210ifdef AEP_Binaries
211	@echo "Archiving and stripping binaries..."
212	$(_v) for file in $(addprefix $(DSTROOT),$(AEP_Binaries));	\
213	do \
214		_type=`file -b --mime-type $${file}`;			\
215		if [ "$${_type}" = "application/octet-stream" ]; then	\
216			echo "\tProcessing $${file}...";			\
217			$(CP) $${file} $(SYMROOT);				\
218			$(DSYMUTIL) --out=$(SYMROOT)/$${file##*/}.dSYM $${file};\
219			$(STRIP) -S $${file};					\
220		else	\
221			echo "\tSkipped non-binary $${file}; type is $${_type}";\
222		fi	\
223	done
224endif
225
226install-startup-files::
227ifdef AEP_LaunchdConfigs
228	@echo "Installing launchd configuration files..."
229	$(INSTALL_DIRECTORY) $(DSTROOT)$(LAUNCHDDIR)
230	$(INSTALL_FILE) $(AEP_LaunchdConfigs) $(DSTROOT)$(LAUNCHDDIR)
231endif
232ifdef AEP_StartupItem
233	@echo "Installing StartupItem..."
234	$(INSTALL_DIRECTORY) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
235	$(INSTALL_SCRIPT) $(StartupItem) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
236	$(INSTALL_FILE) StartupParameters.plist $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)
237	$(INSTALL_DIRECTORY) $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)/Resources/English.lproj
238	$(INSTALL_FILE) Localizable.strings $(DSTROOT)$(SYSTEM_STARTUP_DIR)/$(AEP_StartupItem)/Resources/English.lproj
239endif
240
241install-open-source-files::
242	@echo "Installing Apple-internal open-source documentation..."
243	if [ -e $(SRCROOT)/$(ProjectName).plist ]; then	\
244		$(MKDIR) $(DSTROOT)/$(OSVDIR);	   	\
245		$(INSTALL_FILE) $(SRCROOT)/$(ProjectName).plist $(DSTROOT)/$(OSVDIR)/$(ProjectName).plist;	\
246	else	\
247		echo "WARNING: No open-source file for this project!";	\
248	fi
249	if [ -e $(AEP_LicenseFile) ]; then	\
250		$(MKDIR) $(DSTROOT)/$(OSLDIR);	\
251		$(INSTALL_FILE) $(AEP_LicenseFile) $(DSTROOT)/$(OSLDIR)/$(ProjectName).txt;	\
252	else	\
253		echo "WARNING: No open-source file for this project!";	\
254	fi
255
256
257#
258# Install any man pages at the top-level directory or its "man" subdirectory
259#
260install-top-level-man-pages::
261ifdef AEP_ManPages
262	@echo "Installing top-level man pages..."
263	for _page in $(AEP_ManPages); do				\
264		_section_dir=$(Install_Man)/man$${_page##*\.};		\
265		$(INSTALL_DIRECTORY) $(DSTROOT)$${_section_dir};	\
266		$(INSTALL_FILE) $${_page} $(DSTROOT)$${_section_dir};	\
267	done
268endif
269
270
271#
272# Install configuration files and their corresponding ".default" files
273# to one standard location.
274#
275install-configuration-files::
276ifdef AEP_ConfigFiles
277	@echo "Installing configuration files..."
278	$(INSTALL_DIRECTORY) $(DSTROOT)$(AEP_ConfigDir)
279	for file in $(AEP_ConfigFiles); \
280	do \
281		$(INSTALL_FILE) $${file} $(DSTROOT)$(AEP_ConfigDir); \
282		$(CHMOD) u+w $(DSTROOT)$(AEP_ConfigDir)/$${file}; \
283		if [ "${file##*.}" != "default" ]; then \
284			$(INSTALL_FILE) $${file} $(DSTROOT)$(AEP_ConfigDir)/$${file}.default; \
285		fi; \
286	done
287endif
288
289
290clean::
291	$(_v) if [ -d $(Sources) ]; then \
292	    cd $(Sources) && make clean; \
293	fi
294
295$(DSTROOT) $(DSTROOT)$(AEP_ConfigDir) $(SYMROOT) $(TMPDIR):
296	$(MKDIR) $@
297
298###### End AEP.Make
299
300# Override settings from above includes
301BuildDirectory	= $(OBJROOT)/Build
302Install_Target	= install
303# This needs to be overridden because the project properly uses DESTDIR and
304# INSTALL_ROOT (which is included in Environment).
305Install_Flags	= DESTDIR="$(DSTROOT)"
306
307
308# Build rules
309install-contrib:
310	@echo "Installing specific tools from contrib:"
311	for tool in $(ContribTools); do \
312		echo "...Installing $${tool}...";	\
313		$(MAKE) -C $(BuildDirectory)/contrib/$${tool} $(Install_Flags) $(Install_Target); \
314	done
315
316install-macosx:
317	@echo "Creating service directories..."
318	@echo "Done."
319
320cleanup-temp:
321	@echo "Removing unnecessary files from DSTROOT..."
322	$(RM) -rvf $(DSTROOT)$(NSLIBRARYSUBDIR)
323	@echo "Done."
324