]> git.saurik.com Git - apple/coreosmakefiles.git/blame - ReleaseControl/BSDCommon.make
CoreOSMakefiles-75.tar.gz
[apple/coreosmakefiles.git] / ReleaseControl / BSDCommon.make
CommitLineData
859ae4bf
A
1##
2# Makefile for Apple Release Control (Apple projects)
3#
4# Copyright (c) 2007 Apple Inc. All rights reserved.
5#
6# @APPLE_LICENSE_HEADER_START@
7#
8# This file contains Original Code and/or Modifications of Original Code
9# as defined in and that are subject to the Apple Public Source License
10# Version 2.0 (the 'License'). You may not use this file except in
11# compliance with the License. Please obtain a copy of the License at
12# http://www.opensource.apple.com/apsl/ and read it before using this
13# file.
14#
15# The Original Code and all software distributed under the License are
16# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20# Please see the License for the specific language governing rights and
21# limitations under the License.
22#
23# @APPLE_LICENSE_HEADER_END@
24##
25
26include $(MAKEFILEPATH)/CoreOS/ReleaseControl/Common.make
27
28### ###
29### Variables ###
30### ###
31
32Library_Prefix ?= lib
611bdc3f
A
33RELEASE_Library_Suffix = $(Library_Suffix)
34DEBUG_Library_Suffix = _debug$(Library_Suffix)
35PROFILE_Library_Suffix = _profile$(Library_Suffix)
859ae4bf
A
36
37ProductType ?= tool
38ifeq ($(ProductType),tool)
39 ProductName ?= $(Project)
40 Install_Dir ?= /usr/bin
41else
42 ifeq ($(ProductType),dylib)
43 Library_Suffix ?= .dylib
611bdc3f
A
44 ProductName ?= $(Library_Prefix)$(Project)$(Library_Suffix)
45 ProductNameWithVersion ?= $(Library_Prefix)$(Project)$(if $(Library_Version),.$(Library_Version),)$(Library_Suffix)
46 RELEASE_ProductName = $(ProductName)
47 RELEASE_ProductNameWithVersion = $(ProductNameWithVersion)
48 DEBUG_ProductName = $(ProductName:$(Library_Suffix)=$(DEBUG_Library_Suffix))
49 DEBUG_ProductNameWithVersion = $(ProductNameWithVersion:$(Library_Suffix)=$(DEBUG_Library_Suffix))
50 PROFILE_ProductName = $(ProductName:$(Library_Suffix)=$(PROFILE_Library_Suffix))
51 PROFILE_ProductNameWithVersion = $(ProductNameWithVersion:$(Library_Suffix)=$(PROFILE_Library_Suffix))
859ae4bf
A
52 Install_Dir ?= /usr/lib
53 else
54 ifeq ($(ProductType),staticlib)
55 Library_Suffix ?= .a
56 ProductName ?= $(Library_Prefix)$(Project)$(Library_Suffix)
611bdc3f
A
57 RELEASE_ProductName = $(ProductName)
58 DEBUG_ProductName = $(ProductName:$(Library_Suffix)=$(DEBUG_Library_Suffix))
59 PROFILE_ProductName = $(ProductName:$(Library_Suffix)=$(PROFILE_Library_Suffix))
859ae4bf
A
60 Install_Dir ?= /usr/local/lib
61 else
611bdc3f
A
62 ifeq ($(ProductType),none)
63 else
859ae4bf 64 $(error Unknown ProductType: $(ProductType))
611bdc3f 65 endif
859ae4bf
A
66 endif
67 endif
68endif
69
611bdc3f
A
70BUILD_STYLES = RELEASE
71ifeq ($(BuildDebug),YES)
72BUILD_STYLES += DEBUG
73endif
74ifeq ($(BuildProfile),YES)
75BUILD_STYLES += PROFILE
76endif
77
859ae4bf
A
78ALL_FILES = $(CFILES) $(MFILES) $(CXXFILES) $(USERDEFS) $(SERVERDEFS) $(MANPAGES)
79ALL_SRCFILES = $(CFILES) $(MFILES) $(CXXFILES)
80
81## MIG ##
82
94e0d9ed 83MIGFLAGS=$(CFLAGS) $(Extra_MIG_Flags)
859ae4bf
A
84ifneq ($(USERDEFS),)
85CFILES += $(foreach FILE, $(USERDEFS:.defs=_user.c), $(OBJROOT)/$(Project)/$(notdir $(FILE)))
86endif
87ifneq ($(SERVERDEFS),)
88CFILES += $(foreach FILE, $(SERVERDEFS:.defs=_server.c), $(OBJROOT)/$(Project)/$(notdir $(FILE)))
89endif
90ifneq ($(USERDEFS) $(SERVERDEFS),)
91Extra_CC_Flags += -I$(OBJROOT)/$(Project)
92endif
93
94## RPC ##
95
96RPCFLAGS=$(Extra_RPC_Flags)
97ifneq ($(RPCFILES),)
98CFILES += $(foreach FILE, $(RPCFILES:.x=_xdr.c), $(OBJROOT)/$(Project)/$(notdir $(FILE)))
99endif
100ifneq ($(RPCSVCFILES),)
101CFILES += $(foreach FILE, $(RPCFILES:.x=_svc.c), $(OBJROOT)/$(Project)/$(notdir $(FILE)))
102endif
103
611bdc3f
A
104## Lex ##
105
106LFLAGS=$(Extra_L_Flags)
107ifneq ($(LFILES),)
108CFILES += $(foreach FILE, $(LFILES:.l=.yy.c), $(OBJROOT)/$(Project)/$(notdir $(FILE)))
109endif
110
859ae4bf
A
111## Yacc ##
112
113YFLAGS=$(Extra_Y_Flags)
114ifneq ($(YFILES),)
115CFILES += $(foreach FILE, $(YFILES:.y=.c), $(OBJROOT)/$(Project)/$(notdir $(FILE)))
116endif
117
118## SDK Support ##
119
120ifneq ($(SDKROOT),)
121Extra_CC_Flags += -isysroot $(SDKROOT)
122Extra_LD_Flags += -Wl,-syslibroot,$(SDKROOT)
51ef2a1e 123export MIGCC = $(shell xcrun -find -sdk $(SDKROOT) cc)
859ae4bf
A
124endif
125
859ae4bf
A
126## Dylib Support ##
127
128ifeq ($(Library_Compatibility_Version),)
129Library_Compatibility_Version = 1
130endif
131ifeq ($(Library_Current_Version),)
132Library_Current_Version = $(if $(RC_ProjectSourceVersion), $(RC_ProjectSourceVersion), 1)
133endif
134
611bdc3f
A
135RELEASE_OFILE_SUFFIX=.o
136DEBUG_OFILE_SUFFIX=_debug.o
137PROFILE_OFILE_SUFFIX=_profile.o
138
139RELEASE_ALL_OFILES = $(foreach OFILE, \
859ae4bf
A
140 $(CFILES:.c=.o) \
141 $(MFILES:.m=.o) \
51ef2a1e 142 $(CXXFILES:.cc=.o) \
859ae4bf
A
143 $(OTHER_OFILES), \
144 $(OBJROOT)/$(Project)/$(notdir $(OFILE)))
611bdc3f
A
145DEBUG_ALL_OFILES = $(RELEASE_ALL_OFILES:.o=$(DEBUG_OFILE_SUFFIX))
146PROFILE_ALL_OFILES = $(RELEASE_ALL_OFILES:.o=$(PROFILE_OFILE_SUFFIX))
147ALL_OFILES = $(RELEASE_ALL_OFILES) $(DEBUG_ALL_OFILES) $(PROFILE_ALL_OFILES)
148
149RELEASE_CFLAGS = $(CFLAGS)
150DEBUG_CFLAGS = $(CFLAGS) -DDEBUG
151PROFILE_CFLAGS = $(CFLAGS) -pg -DPROFILE
152
153RELEASE_LDFLAGS = $(LDFLAGS)
154DEBUG_LDFLAGS = $(LDFLAGS)
155PROFILE_LDFLAGS = $(LDFLAGS)
859ae4bf
A
156
157### ###
158### Targets ###
159### ###
160
161.PHONY: configure almostclean
162
163Install_Headers_Directory ?= /usr/include
164Install_Private_Headers_Directory ?= /usr/local/include
165
611bdc3f
A
166installhdrs:: _installhdrs
167ifneq ($(SubProjects),)
168 make recurse TARGET=$@ RC_ARCHS="$(RC_ARCHS)"
169endif
170
171_installhdrs::
172 @true # avoid nothing to be done warning
859ae4bf
A
173ifneq ($(Install_Headers),)
174 @echo "Installing headers for $(Project)..."
175 $(INSTALL_DIRECTORY) $(DSTROOT)/$(Install_Headers_Directory)
176 @for HFILE in $(Install_Headers); do \
177 CMD="$(INSTALL_FILE) $${HFILE} $(DSTROOT)/$(Install_Headers_Directory)" ; \
178 echo $${CMD} ; $${CMD} || exit 1 ; \
179 done
180endif
181ifneq ($(Install_Private_Headers),)
182 @echo "Installing private headers for $(Project)..."
183 $(INSTALL_DIRECTORY) $(DSTROOT)/$(Install_Private_Headers_Directory)
184 @for HFILE in $(Install_Private_Headers); do \
185 CMD="$(INSTALL_FILE) $${HFILE} $(DSTROOT)/$(Install_Private_Headers_Directory)" ; \
186 echo $${CMD} ; $${CMD} || exit 1 ; \
187 done
188endif
189
611bdc3f
A
190install:: build _installhdrs
191 @echo "====== Installing $(Project) ====="
192#ifneq ($(SubProjects),)
193# make recurse TARGET=$@ RC_ARCHS="$(RC_ARCHS)"
194#endif
859ae4bf 195 $(INSTALL_DIRECTORY) $(DSTROOT)/$(Install_Dir)
611bdc3f 196ifneq ($(strip $(ALL_OFILES)),)
859ae4bf
A
197 ifeq ($(ProductType),tool)
198 $(INSTALL_PROGRAM) $(SYMROOT)/$(ProductName) $(DSTROOT)/$(Install_Dir)
199 else
200 ifeq ($(ProductType),dylib)
611bdc3f
A
201 @$(foreach STYLE, $(BUILD_STYLES), \
202 CMD="$(INSTALL_DYLIB) $(SYMROOT)/$($(STYLE)_ProductNameWithVersion) \
203 $(DSTROOT)/$(Install_Dir)" ; \
204 echo $${CMD} ; $${CMD} || exit 1 ; \
205 CMD="$(STRIP) -S $(DSTROOT)/$(Install_Dir)/$($(STYLE)_ProductNameWithVersion)" ; \
206 echo $${CMD} ; $${CMD} || exit 1 ; \
207 if [ "$($(STYLE)_ProductName)" != "$($(STYLE)_ProductNameWithVersion)" ]; then \
208 CMD="$(LN) -sf $($(STYLE)_ProductNameWithVersion) \
209 $(DSTROOT)/$(Install_Dir)/$($(STYLE)_ProductName)" ; \
210 echo $${CMD} ; $${CMD} || exit 1 ; \
211 fi ; )
859ae4bf
A
212 else
213 ifeq ($(ProductType),staticlib)
611bdc3f
A
214 @$(foreach STYLE, $(BUILD_STYLES), \
215 CMD="$(INSTALL_LIBRARY) $(SYMROOT)/$($(STYLE)_ProductName) \
216 $(DSTROOT)/$(Install_Dir)" ; \
217 echo $${CMD} ; $${CMD} || exit 1 ; )
859ae4bf
A
218 endif
219 endif
220 endif
221endif
859ae4bf
A
222ifneq ($(MANPAGES),)
223 @make install-man-pages
224endif
225ifneq ($(LAUNCHD_PLISTS),)
226 @make install-launchd-plists
227endif
228 @make after_install
859ae4bf
A
229
230migdefs::
231 @$(MKDIR) $(OBJROOT)/$(Project)
232 @for DEF in $(USERDEFS); do \
233 CMD="$(MIG) $(MIGFLAGS) \
234 -user $(OBJROOT)/$(Project)/$$(basename $${DEF/%.defs/_user.c}) \
235 -header $(OBJROOT)/$(Project)/$$(basename $${DEF/%.defs/.h}) \
236 -server /dev/null \
237 -sheader /dev/null \
238 $${DEF}" ; \
239 echo $${CMD} ; $${CMD} || exit 1 ; \
240 done
241 @for DEF in $(SERVERDEFS); do \
242 CMD="$(MIG) $(MIGFLAGS) \
243 -user /dev/null \
244 -header /dev/null \
245 -server $(OBJROOT)/$(Project)/$$(basename $${DEF/%.defs/_server.c}) \
246 -sheader $(OBJROOT)/$(Project)/$$(basename $${DEF/%.defs/_server.h}) \
247 $${DEF}" ; \
248 echo $${CMD} ; $${CMD} || exit 1 ; \
249 done
250
251rpcfiles:
252 @$(MKDIR) $(OBJROOT)/$(Project)
253 @for FILE in $(RPCFILES); do \
254 OUT=`basename $${FILE} .x` ; \
255 CMD="$(RPCGEN) $(RPCFLAGS) -h \
256 -o $(OBJROOT)/$(Project)/$${OUT}.h $${FILE}"; \
257 echo $${CMD} ; $${CMD} || exit 1 ; \
258 CMD="$(RPCGEN) $(RPCFLAGS) -c \
259 -o $(OBJROOT)/$(Project)/$${OUT}_xdr.c $${FILE}"; \
260 echo $${CMD} ; $${CMD} || exit 1 ; \
261 done
262 @for FILE in $(RPCSVCFILES); do \
263 OUT=`basename $${FILE} .x` ; \
264 CMD="$(RPCGEN) $(RPCFLAGS) -m \
265 -o $(OBJROOT)/$(Project)/$${OUT}_svc.c $${FILE}"; \
266 echo $${CMD} ; $${CMD} || exit 1; \
267 done
268
611bdc3f
A
269lfiles:
270 @$(MKDIR) $(OBJROOT)/$(Project)
271 @for FILE in $(LFILES); do \
272 OUT=`basename $${FILE} .l` ; \
273 CMD="$(LEX) $(LFLAGS) \
274 --header-file=$(OBJROOT)/$(Project)/$${OUT}.yy.h \
275 -o $(OBJROOT)/$(Project)/$${OUT}.yy.c $${FILE}"; \
276 echo $${CMD} ; $${CMD} || exit 1; \
277 done
278
859ae4bf
A
279yfiles:
280 @$(MKDIR) $(OBJROOT)/$(Project)
281 @for FILE in $(YFILES); do \
282 OUT=`basename $${FILE} .y` ; \
283 CMD="$(YACC) $(YFLAGS) -d \
284 -o $(OBJROOT)/$(Project)/$${OUT}.c $${FILE}"; \
285 echo $${CMD} ; $${CMD} || exit 1 ; \
286 done
287
611bdc3f
A
288build:: migdefs rpcfiles yfiles lfiles $(ALL_FILES)
289ifneq ($(SubProjects),)
290 make recurse TARGET=install RC_ARCHS="$(RC_ARCHS)"
291endif
859ae4bf
A
292 @$(MKDIR) $(OBJROOT)/$(Project)
293 @$(MKDIR) $(SYMROOT)
294
611bdc3f
A
295 @$(foreach STYLE, $(BUILD_STYLES), \
296 echo ===== Building $(ProductName) $(STYLE) ===== ; \
297 for CFILE in $(ALL_SRCFILES); do \
298 OFILE=$(OBJROOT)/$(Project)/$$(echo $$(basename $${CFILE}) | \
299 sed -e 's,\.[^.]*$$,$($(STYLE)_OFILE_SUFFIX),') ; \
300 if [ ! "$${OFILE}" -nt "$${CFILE}" ]; then \
301 CMD="$(CC) $($(STYLE)_CFLAGS) -c -o $${OFILE} $${CFILE}" ; \
859ae4bf 302 echo $$CMD ; $$CMD || exit 1 ; \
611bdc3f
A
303 fi ; \
304 done ; )
859ae4bf 305
611bdc3f 306ifneq ($(strip $(ALL_OFILES)),)
859ae4bf 307 ifeq ($(ProductType),tool)
611bdc3f
A
308 @echo ===== Linking $(ProductName) RELEASE =====
309 $(CC) $(RELEASE_LDFLAGS) -o $(SYMROOT)/$(ProductName) \
310 $(RELEASE_ALL_OFILES)
311 dsymutil --out $(SYMROOT)/$(ProductName).dSYM \
312 $(SYMROOT)/$(ProductName) || true
859ae4bf
A
313 else
314 ifeq ($(ProductType),dylib)
611bdc3f
A
315 @$(foreach STYLE, $(BUILD_STYLES), \
316 echo ===== Linking $(ProductName) $(STYLE) ===== ; \
317 CMD="$(CC) -dynamiclib $($(STYLE)_LDFLAGS) \
859ae4bf
A
318 -dynamic \
319 -compatibility_version $(Library_Compatibility_Version) \
320 -current_version $(Library_Current_Version) \
611bdc3f
A
321 -install_name `echo $(Install_Dir)/$($(STYLE)_ProductNameWithVersion) | sed 's,//,/,g'` \
322 -o $(SYMROOT)/$($(STYLE)_ProductNameWithVersion) \
323 $($(STYLE)_ALL_OFILES)" ; \
324 echo $${CMD} ; $${CMD} || exit 1 ; \
325 CMD="dsymutil --out $(SYMROOT)/$($(STYLE)_ProductNameWithVersion).dSYM \
326 $(SYMROOT)/$($(STYLE)_ProductNameWithVersion)" ; \
327 echo $${CMD} ; $${CMD} ; )
859ae4bf
A
328 else
329 ifeq ($(ProductType),staticlib)
611bdc3f
A
330 @$(foreach STYLE, $(BUILD_STYLES), \
331 echo ===== Linking $(ProductName) $(STYLE) ===== ; \
332 CMD="$(LIBTOOL) -static -o $(SYMROOT)/$($(STYLE)_ProductName) \
333 $($(STYLE)_ALL_OFILES)" ; \
334 echo $${CMD} ; $${CMD} || exit 1 ; )
859ae4bf
A
335 endif
336 endif
337 endif
859ae4bf
A
338endif
339
340install-man-pages::
341 @echo "Installing man pages for $(Project)..."
342 @for MANPAGE in $(MANPAGES); do \
343 SECTION=$${MANPAGE/*./} ; \
344 MANDIR=$(DSTROOT)/usr/share/man/man$${SECTION} ; \
345 $(INSTALL_DIRECTORY) $${MANDIR} || exit 1 ; \
346 CMD="$(INSTALL_FILE) $${MANPAGE} $${MANDIR}" ; \
347 echo $$CMD ; $$CMD || exit 1 ; \
348 done
349
350install-launchd-plists::
351 @echo "Installing launchd plists for $(Project)..."
352 @for PLIST in $(LAUNCHD_PLISTS); do \
353 PLIST_DIR=$(DSTROOT)/System/Library/LaunchDaemons ; \
354 $(INSTALL_DIRECTORY) $${PLIST_DIR} || exit 1 ; \
355 CMD="$(INSTALL_FILE) $${PLIST} $${PLIST_DIR}" ; \
356 echo $$CMD ; $$CMD || exit 1 ; \
357 done
358
359after_install:
360
361almostclean::
362 @echo "Cleaning $(Project)..."
363 $(_v) $(MAKE) -C $(BuildDirectory) clean