1 .include <CoreOS/Standard/Commands.mk>
2 .include <CoreOS/Standard/Variables.mk>
4 ALLARCHS = arm i386 ppc ppc64 x86_64 # installsrc doesn't set RC_ARCHS
5 CODESIGN != xcrun -find codesign
18 OBJROOT = $(TOP)/OBJROOT
24 SYMROOT = $(TOP)/SYMROOT
31 FIRST_ARCH != ${PERL} -e 'print $$ARGV[0]' ${RC_ARCHS}
32 .ifndef RC_NONARCH_CFLAGS
33 RC_NONARCH_CFLAGS = -pipe
35 .ifdef ALTUSRLOCALLIBSYSTEM
36 LIBSYS = $(ALTUSRLOCALLIBSYSTEM)
38 LIBSYS = $(SDKROOT)/usr/local/lib/system
40 .ifdef ALTUSRLIBSYSTEM
41 LSYS = $(ALTUSRLIBSYSTEM)
43 LSYS = $(SDKROOT)/usr/lib/system
45 NJOBS != ${PERL} -e '$$n = `$(SYSCTL) -n hw.ncpu`; printf "%d\n", $$n < 2 ? 2 : ($$n * 1.5)'
47 MYBSDMAKE = $(BSDMAKE) -f Makefile -P
49 MYBSDMAKE = $(BSDMAKE) -f Makefile
51 MYBSDMAKEJ = $(MYBSDMAKE) -j $(NJOBS)
53 # Set the DONT-BUILD-arch-form variable to non-empty to turn off building
54 #DONT-BUILD-x86_64-static = 1
56 # These variables are to guarantee that the left-hand side of an expression is
61 # Map RC_ARCHS to MACHINE_ARCH
62 .for A in $(RC_ARCHS) $(MYARCH) # {
63 MACHINE_ARCH-$(A) = $(A:C/^armv.*/arm/)
66 FORMS := dynamic debug profile static
68 OBJSUFFIX-dynamic = So
70 OBJSUFFIX-profile = po
75 ROOTS := DSTROOT OBJROOT SYMROOT
76 .for R in $(ROOTS) # {
82 # These are the non B&I defaults
83 .ifndef RC_ProjectName
87 installhdrs: roots installhdrs-real
88 build: roots build-static build-profile build-debug build-dynamic
89 install: roots installhdrs install-all
91 .else # RC_ProjectName
93 RC_ProjectNameBase := $(RC_ProjectName:%_Sim=%)
94 .if $(RC_ProjectName) == $(RC_ProjectNameBase)
97 INSTALL_PREFIX = $(SDKROOT)
100 # And these are to deal with B&I building libc differently
101 # based on RC_ProjectName.
102 .if $(RC_ProjectNameBase) == Libc
104 build: roots build-dynamic
105 install: roots BI-install-dynamic
107 .if $(RC_ProjectNameBase) == Libc_headers
108 installhdrs: roots installhdrs-real
110 install: roots installhdrs-real
112 .if $(RC_ProjectNameBase) == Libc_man
115 install: roots install-man
117 .if $(RC_ProjectNameBase) == Libc_static
119 build: roots build-static
120 install: roots BI-install-static
122 .if $(RC_ProjectNameBase) == Libc_debug
124 build: roots build-debug
125 install: roots BI-install-debug
127 .if $(RC_ProjectNameBase) == Libc_profile
129 build: roots build-profile
130 install: roots BI-install-profile
132 .endif # RC_ProjectName
134 # Make a copy of System.framework/Versions/B/PrivateHeaders, with headers
135 # patched so that we can build variant symbols independently
136 SYSTEMFRAMEWORK = System.framework
137 VERSIONSB = Versions/B
138 PRIVATEHEADERPATH = $(SYSTEMFRAMEWORK)/$(VERSIONSB)/PrivateHeaders
139 FRAMEWORKS = $(OBJROOT)/Frameworks
140 .ifdef ALTFRAMEWORKSPATH
141 FRAMEWORKPATH = ${ALTFRAMEWORKSPATH}
143 FRAMEWORKPATH = ${SDKROOT}/System/Library/Frameworks
146 $(SRCROOT)/patchHeaders $(FRAMEWORKPATH)/$(PRIVATEHEADERPATH) $(FRAMEWORKS)/$(PRIVATEHEADERPATH:H)
147 ${LN} -fs $(VERSIONSB)/PrivateHeaders $(FRAMEWORKS)/$(SYSTEMFRAMEWORK)/PrivateHeaders
149 AUTOPATCHED = $(SRCROOT)/.autopatched
151 .for F in $(FORMS) # {
152 .if $(dynamic) == $(F) # {
157 PSUFFIX-$(F) = $(PARTIAL)$(SUFFIX-$(F))
159 .for A in $(RC_ARCHS) # {
160 .if empty(DONT-BUILD-$(A)-$(F)) # {
163 ${MKDIR} $(OBJROOT)/obj.$(A) && \
164 MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH=$(MACHINE_ARCH-$(A)) CCARCH=$(A) \
165 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
166 RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" MAKEFLAGS="" \
167 OBJSUFFIX="$(OBJSUFFIX-$(F))" \
168 $(MYBSDMAKEJ) libc$(SUFFIX-$(F)).a
171 @echo Not building libc$(PSUFFIX-$(F)).a for $(A)
175 NARCHS-$(F) != ${ECHO} $(ARCHS-$(F)) | ${WC} -w
177 build-$(F): $(FRAMEWORKS) $(AUTOPATCHED)
178 .for A in $(RC_ARCHS) # {
179 build-$(F): build-$(A)-$(F)
181 .if $(NARCHS-$(F)) == 0 # {
183 @echo No libc$(PSUFFIX-$(F)).a built
185 LIPOARGS-$(F) != ${PERL} -e 'printf "%s\n", join(" ", map(qq(-arch $$_ \"$(OBJROOT)/obj.$$_/libc$(SUFFIX-$(F)).a\"), qw($(ARCHS-$(F)))))'
186 .if $(dynamic) == $(F) # {
187 LIPODYLDARGS-$(F) != ${PERL} -e 'printf "%s\n", join(" ", map(qq(-arch $$_ \"$(OBJROOT)/obj.$$_/libc-dyld.a\"), qw($(ARCHS-$(F)))))'
190 .if $(NARCHS-$(F)) == 1 # {
191 ${CP} "$(OBJROOT)/obj.$(RC_ARCHS)/libc$(SUFFIX-$(F)).a" "$(SYMROOT)/libc$(PSUFFIX-$(F)).a"
192 .if $(dynamic) == $(F) # {
193 ${CP} "$(OBJROOT)/obj.$(RC_ARCHS)/libc-dyld.a" "$(SYMROOT)/libc-dyld.a"
196 ${LIPO} -create $(LIPOARGS-$(F)) -output "$(SYMROOT)/libc$(PSUFFIX-$(F)).a"
197 .if $(dynamic) == $(F) # {
198 ${LIPO} -create $(LIPODYLDARGS-$(F)) -output "$(SYMROOT)/libc-dyld.a"
204 # We autopatch the files into the directory containing the Makefile.inc. This
205 # will happen at installsrc.
207 .for A in $(ALLARCHS) # {
208 MACHINE_ARCH=$(A) SRCROOT="$(SRCROOT)" \
209 $(MYBSDMAKE) -C "$(SRCROOT)" autopatch
210 .endfor # ALLARCHS # }
214 ${TAR} -cp --exclude .git --exclude .svn --exclude CVS . | ${TAR} -pox -C "$(SRCROOT)"
216 installsrc: copysrc $(AUTOPATCHED)
219 MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)$(INSTALL_PREFIX)" MAKEFLAGS="" \
220 DSTROOT="$(DSTROOT)$(INSTALL_PREFIX)" OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
221 $(MYBSDMAKEJ) installhdrs
222 .for A in $(RC_ARCHS) # {
223 ${MKDIR} "$(OBJROOT)/obj.$(A)" && \
224 MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH=$(MACHINE_ARCH-$(A)) CCARCH=$(A) \
225 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
226 MAKEFLAGS="" RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" \
227 $(MYBSDMAKEJ) installhdrs-md
228 .endfor # RC_ARCHS # }
230 .for F in $(FORMS) # {
231 BI-install-$(F): build-$(F)
232 $(CC) -dynamiclib -o $(SYMROOT)/libsystem_c$(SUFFIX-$(F)).dylib $(RC_ARCHS:C/^/-arch /g) \
233 -compatibility_version 1 -current_version $(RC_ProjectSourceVersion) \
234 -install_name /usr/lib/system/libsystem_c$(SUFFIX-$(F)).dylib -nostdlib -Wl,-umbrella,System \
235 -all_load $(SYMROOT)/libc$(PSUFFIX-$(F)).a -Wl,-interposable_list,$(SRCROOT)/interposable.list \
236 -L$(LSYS) -L$(SDKROOT)/usr/lib -lSystem -lgcc
237 ${MKDIR} $(DSTROOT)/usr/local/lib/system
238 ${MKDIR} $(DSTROOT)/usr/lib/system
239 ${INSTALL} $(SYMROOT)/libsystem_c$(SUFFIX-$(F)).dylib $(DSTROOT)/usr/lib/system
240 ${STRIP} -S $(DSTROOT)/usr/lib/system/libsystem_c$(SUFFIX-$(F)).dylib
241 -${CODESIGN} -s - $(DSTROOT)/usr/lib/system/libsystem_c$(SUFFIX-$(F)).dylib
242 .if $(dynamic) == $(F) # {
243 if [ -f "$(SYMROOT)/libc-dyld.a" ]; then \
244 ${ECHO} "Installing libc-dyld.a" && \
245 ${MKDIR} $(DSTROOT)/usr/local/lib/dyld && \
246 ${INSTALL} -m 444 "$(SYMROOT)/libc-dyld.a" \
247 $(DSTROOT)/usr/local/lib/dyld/libc.a && \
248 ${LN} -sf "../dyld/libc.a" "$(DSTROOT)/usr/local/lib/system/libc-dyld.a" && \
249 ${RANLIB} "$(DSTROOT)/usr/local/lib/dyld/libc.a" || exit 1; \
251 .for A in $(RC_ARCHS) # {
252 MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH=$(MACHINE_ARCH-$(A)) CCARCH=$(A) \
253 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
254 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
255 MAKEFLAGS="" RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" \
256 $(MYBSDMAKE) copyfiles
257 .endfor # RC_ARCHS # }
261 # Don't use -j here; it may try to make links before the files are copied
262 MANARGS != ${TEST} `id -u` -eq 0 || ${ECHO} MINSTALL=/usr/bin/install
263 # Variables.mk defines MANDIR=${SHAREDIR}/man, but bsd.man.mk expects that
264 # MANDIR=${SHAREDIR}/man/man, so we override.
265 MANARGS += MANDIR=${SHAREDIR}/man/man
267 ${MKDIR} $(DSTROOT)/usr/share/man/man2
268 ${MKDIR} $(DSTROOT)/usr/share/man/man3
269 ${MKDIR} $(DSTROOT)/usr/share/man/man4
270 ${MKDIR} $(DSTROOT)/usr/share/man/man5
271 ${MKDIR} $(DSTROOT)/usr/share/man/man7
272 MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)$(INSTALL_PREFIX)" \
273 DSTROOT='$(DSTROOT)$(INSTALL_PREFIX)' OBJROOT='$(OBJROOT)' SYMROOT='$(SYMROOT)' \
274 MACHINE_ARCH="$(MACHINE_ARCH-$(FIRST_ARCH))" CCARCH=$(FIRST_ARCH) MAKEFLAGS="" \
275 RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" \
276 $(MYBSDMAKE) all-man maninstall $(MANARGS)
278 install-all: build install-man
279 .for F in $(FORMS) # {
280 install-all: BI-install-$(F)
284 .for F in $(FORMS) # {
285 ${RM} $(SYMROOT)/libc$(PSUFFIX-$(F)).a
287 .for A in $(RC_ARCHS) # {
288 ${RMDIR} $(OBJROOT)/obj.$(A)
289 .endfor # RC_ARCHS # }