]> git.saurik.com Git - apple/coreosmakefiles.git/blob - ReleaseControl/BSDCommon.make
CoreOSMakefiles-75.tar.gz
[apple/coreosmakefiles.git] / ReleaseControl / BSDCommon.make
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
26 include $(MAKEFILEPATH)/CoreOS/ReleaseControl/Common.make
27
28 ### ###
29 ### Variables ###
30 ### ###
31
32 Library_Prefix ?= lib
33 RELEASE_Library_Suffix = $(Library_Suffix)
34 DEBUG_Library_Suffix = _debug$(Library_Suffix)
35 PROFILE_Library_Suffix = _profile$(Library_Suffix)
36
37 ProductType ?= tool
38 ifeq ($(ProductType),tool)
39 ProductName ?= $(Project)
40 Install_Dir ?= /usr/bin
41 else
42 ifeq ($(ProductType),dylib)
43 Library_Suffix ?= .dylib
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))
52 Install_Dir ?= /usr/lib
53 else
54 ifeq ($(ProductType),staticlib)
55 Library_Suffix ?= .a
56 ProductName ?= $(Library_Prefix)$(Project)$(Library_Suffix)
57 RELEASE_ProductName = $(ProductName)
58 DEBUG_ProductName = $(ProductName:$(Library_Suffix)=$(DEBUG_Library_Suffix))
59 PROFILE_ProductName = $(ProductName:$(Library_Suffix)=$(PROFILE_Library_Suffix))
60 Install_Dir ?= /usr/local/lib
61 else
62 ifeq ($(ProductType),none)
63 else
64 $(error Unknown ProductType: $(ProductType))
65 endif
66 endif
67 endif
68 endif
69
70 BUILD_STYLES = RELEASE
71 ifeq ($(BuildDebug),YES)
72 BUILD_STYLES += DEBUG
73 endif
74 ifeq ($(BuildProfile),YES)
75 BUILD_STYLES += PROFILE
76 endif
77
78 ALL_FILES = $(CFILES) $(MFILES) $(CXXFILES) $(USERDEFS) $(SERVERDEFS) $(MANPAGES)
79 ALL_SRCFILES = $(CFILES) $(MFILES) $(CXXFILES)
80
81 ## MIG ##
82
83 MIGFLAGS=$(CFLAGS) $(Extra_MIG_Flags)
84 ifneq ($(USERDEFS),)
85 CFILES += $(foreach FILE, $(USERDEFS:.defs=_user.c), $(OBJROOT)/$(Project)/$(notdir $(FILE)))
86 endif
87 ifneq ($(SERVERDEFS),)
88 CFILES += $(foreach FILE, $(SERVERDEFS:.defs=_server.c), $(OBJROOT)/$(Project)/$(notdir $(FILE)))
89 endif
90 ifneq ($(USERDEFS) $(SERVERDEFS),)
91 Extra_CC_Flags += -I$(OBJROOT)/$(Project)
92 endif
93
94 ## RPC ##
95
96 RPCFLAGS=$(Extra_RPC_Flags)
97 ifneq ($(RPCFILES),)
98 CFILES += $(foreach FILE, $(RPCFILES:.x=_xdr.c), $(OBJROOT)/$(Project)/$(notdir $(FILE)))
99 endif
100 ifneq ($(RPCSVCFILES),)
101 CFILES += $(foreach FILE, $(RPCFILES:.x=_svc.c), $(OBJROOT)/$(Project)/$(notdir $(FILE)))
102 endif
103
104 ## Lex ##
105
106 LFLAGS=$(Extra_L_Flags)
107 ifneq ($(LFILES),)
108 CFILES += $(foreach FILE, $(LFILES:.l=.yy.c), $(OBJROOT)/$(Project)/$(notdir $(FILE)))
109 endif
110
111 ## Yacc ##
112
113 YFLAGS=$(Extra_Y_Flags)
114 ifneq ($(YFILES),)
115 CFILES += $(foreach FILE, $(YFILES:.y=.c), $(OBJROOT)/$(Project)/$(notdir $(FILE)))
116 endif
117
118 ## SDK Support ##
119
120 ifneq ($(SDKROOT),)
121 Extra_CC_Flags += -isysroot $(SDKROOT)
122 Extra_LD_Flags += -Wl,-syslibroot,$(SDKROOT)
123 export MIGCC = $(shell xcrun -find -sdk $(SDKROOT) cc)
124 endif
125
126 ## Dylib Support ##
127
128 ifeq ($(Library_Compatibility_Version),)
129 Library_Compatibility_Version = 1
130 endif
131 ifeq ($(Library_Current_Version),)
132 Library_Current_Version = $(if $(RC_ProjectSourceVersion), $(RC_ProjectSourceVersion), 1)
133 endif
134
135 RELEASE_OFILE_SUFFIX=.o
136 DEBUG_OFILE_SUFFIX=_debug.o
137 PROFILE_OFILE_SUFFIX=_profile.o
138
139 RELEASE_ALL_OFILES = $(foreach OFILE, \
140 $(CFILES:.c=.o) \
141 $(MFILES:.m=.o) \
142 $(CXXFILES:.cc=.o) \
143 $(OTHER_OFILES), \
144 $(OBJROOT)/$(Project)/$(notdir $(OFILE)))
145 DEBUG_ALL_OFILES = $(RELEASE_ALL_OFILES:.o=$(DEBUG_OFILE_SUFFIX))
146 PROFILE_ALL_OFILES = $(RELEASE_ALL_OFILES:.o=$(PROFILE_OFILE_SUFFIX))
147 ALL_OFILES = $(RELEASE_ALL_OFILES) $(DEBUG_ALL_OFILES) $(PROFILE_ALL_OFILES)
148
149 RELEASE_CFLAGS = $(CFLAGS)
150 DEBUG_CFLAGS = $(CFLAGS) -DDEBUG
151 PROFILE_CFLAGS = $(CFLAGS) -pg -DPROFILE
152
153 RELEASE_LDFLAGS = $(LDFLAGS)
154 DEBUG_LDFLAGS = $(LDFLAGS)
155 PROFILE_LDFLAGS = $(LDFLAGS)
156
157 ### ###
158 ### Targets ###
159 ### ###
160
161 .PHONY: configure almostclean
162
163 Install_Headers_Directory ?= /usr/include
164 Install_Private_Headers_Directory ?= /usr/local/include
165
166 installhdrs:: _installhdrs
167 ifneq ($(SubProjects),)
168 make recurse TARGET=$@ RC_ARCHS="$(RC_ARCHS)"
169 endif
170
171 _installhdrs::
172 @true # avoid nothing to be done warning
173 ifneq ($(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
180 endif
181 ifneq ($(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
188 endif
189
190 install:: build _installhdrs
191 @echo "====== Installing $(Project) ====="
192 #ifneq ($(SubProjects),)
193 # make recurse TARGET=$@ RC_ARCHS="$(RC_ARCHS)"
194 #endif
195 $(INSTALL_DIRECTORY) $(DSTROOT)/$(Install_Dir)
196 ifneq ($(strip $(ALL_OFILES)),)
197 ifeq ($(ProductType),tool)
198 $(INSTALL_PROGRAM) $(SYMROOT)/$(ProductName) $(DSTROOT)/$(Install_Dir)
199 else
200 ifeq ($(ProductType),dylib)
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 ; )
212 else
213 ifeq ($(ProductType),staticlib)
214 @$(foreach STYLE, $(BUILD_STYLES), \
215 CMD="$(INSTALL_LIBRARY) $(SYMROOT)/$($(STYLE)_ProductName) \
216 $(DSTROOT)/$(Install_Dir)" ; \
217 echo $${CMD} ; $${CMD} || exit 1 ; )
218 endif
219 endif
220 endif
221 endif
222 ifneq ($(MANPAGES),)
223 @make install-man-pages
224 endif
225 ifneq ($(LAUNCHD_PLISTS),)
226 @make install-launchd-plists
227 endif
228 @make after_install
229
230 migdefs::
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
251 rpcfiles:
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
269 lfiles:
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
279 yfiles:
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
288 build:: migdefs rpcfiles yfiles lfiles $(ALL_FILES)
289 ifneq ($(SubProjects),)
290 make recurse TARGET=install RC_ARCHS="$(RC_ARCHS)"
291 endif
292 @$(MKDIR) $(OBJROOT)/$(Project)
293 @$(MKDIR) $(SYMROOT)
294
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}" ; \
302 echo $$CMD ; $$CMD || exit 1 ; \
303 fi ; \
304 done ; )
305
306 ifneq ($(strip $(ALL_OFILES)),)
307 ifeq ($(ProductType),tool)
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
313 else
314 ifeq ($(ProductType),dylib)
315 @$(foreach STYLE, $(BUILD_STYLES), \
316 echo ===== Linking $(ProductName) $(STYLE) ===== ; \
317 CMD="$(CC) -dynamiclib $($(STYLE)_LDFLAGS) \
318 -dynamic \
319 -compatibility_version $(Library_Compatibility_Version) \
320 -current_version $(Library_Current_Version) \
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} ; )
328 else
329 ifeq ($(ProductType),staticlib)
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 ; )
335 endif
336 endif
337 endif
338 endif
339
340 install-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
350 install-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
359 after_install:
360
361 almostclean::
362 @echo "Cleaning $(Project)..."
363 $(_v) $(MAKE) -C $(BuildDirectory) clean