]> git.saurik.com Git - apple/libc.git/blame - BSDmakefile
Libc-763.13.tar.gz
[apple/libc.git] / BSDmakefile
CommitLineData
34e8f829
A
1.include <CoreOS/Standard/Commands.mk>
2.include <CoreOS/Standard/Variables.mk>
3
b5d655f7 4ALLARCHS = arm i386 ppc ppc64 x86_64 # installsrc doesn't set RC_ARCHS
1f2f436a 5CODESIGN != xcrun -find codesign
34e8f829 6TOP != ${PWD}
224c7076
A
7.ifdef DSTROOT
8DESTDIR = $(DSTROOT)
9.else
10.ifdef DESTDIR
11DSTROOT = $(DESTDIR)
12.else
13DSTROOT = /
14DESTDIR = /
15.endif
16.endif
8e029c65 17.ifndef OBJROOT
34e8f829 18OBJROOT = $(TOP)/OBJROOT
224c7076
A
19.endif
20.ifndef SRCROOT
34e8f829 21SRCROOT = $(TOP)
8e029c65
A
22.endif
23.ifndef SYMROOT
34e8f829 24SYMROOT = $(TOP)/SYMROOT
8e029c65 25.endif
34e8f829 26MYARCH != ${ARCH}
8e029c65 27.ifndef RC_ARCHS
34e8f829 28RC_ARCHS = $(MYARCH)
8e029c65
A
29RC_$(RC_ARCHS) = 1
30.endif
34e8f829 31FIRST_ARCH != ${PERL} -e 'print $$ARGV[0]' ${RC_ARCHS}
b5d655f7
A
32.ifndef RC_NONARCH_CFLAGS
33RC_NONARCH_CFLAGS = -pipe
34.endif
8e029c65
A
35.ifdef ALTUSRLOCALLIBSYSTEM
36LIBSYS = $(ALTUSRLOCALLIBSYSTEM)
37.else
b5d655f7 38LIBSYS = $(SDKROOT)/usr/local/lib/system
8e029c65 39.endif
1f2f436a
A
40.ifdef ALTUSRLIBSYSTEM
41LSYS = $(ALTUSRLIBSYSTEM)
42.else
43LSYS = $(SDKROOT)/usr/lib/system
44.endif
34e8f829
A
45NJOBS != ${PERL} -e '$$n = `$(SYSCTL) -n hw.ncpu`; printf "%d\n", $$n < 2 ? 2 : ($$n * 1.5)'
46.ifdef DEBUG
47MYBSDMAKE = $(BSDMAKE) -f Makefile -P
48.else
49MYBSDMAKE = $(BSDMAKE) -f Makefile
50.endif
51MYBSDMAKEJ = $(MYBSDMAKE) -j $(NJOBS)
224c7076
A
52
53# Set the DONT-BUILD-arch-form variable to non-empty to turn off building
54#DONT-BUILD-x86_64-static = 1
8e029c65 55
224c7076 56# These variables are to guarantee that the left-hand side of an expression is
8e029c65
A
57# always a variable
58dynamic = dynamic
59static = static
60
b5d655f7 61# Map RC_ARCHS to MACHINE_ARCH
34e8f829 62.for A in $(RC_ARCHS) $(MYARCH) # {
b5d655f7
A
63MACHINE_ARCH-$(A) = $(A:C/^armv.*/arm/)
64.endfor # RC_ARCHS }
8e029c65
A
65
66FORMS := dynamic debug profile static
67
b5d655f7
A
68OBJSUFFIX-dynamic = So
69OBJSUFFIX-debug = do
70OBJSUFFIX-profile = po
71OBJSUFFIX-static = o
72
8e029c65
A
73all: build
74
224c7076
A
75ROOTS := DSTROOT OBJROOT SYMROOT
76.for R in $(ROOTS) # {
77roots: $($(R))
78$($(R)):
34e8f829 79 ${MKDIR} '$($(R))'
224c7076
A
80.endfor # ROOTS }
81
8e029c65
A
82# These are the non B&I defaults
83.ifndef RC_ProjectName
224c7076 84
1f2f436a
A
85RC_ProjectName = Libc
86
224c7076
A
87installhdrs: roots installhdrs-real
88build: roots build-static build-profile build-debug build-dynamic
89install: roots installhdrs install-all
8e029c65
A
90
91.else # RC_ProjectName
92
1f2f436a
A
93RC_ProjectNameBase := $(RC_ProjectName:%_Sim=%)
94.if $(RC_ProjectName) == $(RC_ProjectNameBase)
95INSTALL_PREFIX =
96.else
97INSTALL_PREFIX = $(SDKROOT)
98.endif
99
8e029c65
A
100# And these are to deal with B&I building libc differently
101# based on RC_ProjectName.
1f2f436a 102.if $(RC_ProjectNameBase) == Libc
8e029c65 103installhdrs:
224c7076
A
104build: roots build-dynamic
105install: roots BI-install-dynamic
8e029c65 106.endif
1f2f436a 107.if $(RC_ProjectNameBase) == Libc_headers
224c7076 108installhdrs: roots installhdrs-real
8e029c65 109build:
224c7076 110install: roots installhdrs-real
8e029c65 111.endif
1f2f436a 112.if $(RC_ProjectNameBase) == Libc_man
8e029c65
A
113installhdrs:
114build:
224c7076 115install: roots install-man
8e029c65 116.endif
1f2f436a 117.if $(RC_ProjectNameBase) == Libc_static
8e029c65 118installhdrs:
224c7076
A
119build: roots build-static
120install: roots BI-install-static
8e029c65 121.endif
1f2f436a 122.if $(RC_ProjectNameBase) == Libc_debug
8e029c65 123installhdrs:
224c7076
A
124build: roots build-debug
125install: roots BI-install-debug
8e029c65 126.endif
1f2f436a 127.if $(RC_ProjectNameBase) == Libc_profile
8e029c65 128installhdrs:
224c7076
A
129build: roots build-profile
130install: roots BI-install-profile
8e029c65
A
131.endif
132.endif # RC_ProjectName
133
224c7076
A
134# Make a copy of System.framework/Versions/B/PrivateHeaders, with headers
135# patched so that we can build variant symbols independently
136SYSTEMFRAMEWORK = System.framework
137VERSIONSB = Versions/B
138PRIVATEHEADERPATH = $(SYSTEMFRAMEWORK)/$(VERSIONSB)/PrivateHeaders
139FRAMEWORKS = $(OBJROOT)/Frameworks
140.ifdef ALTFRAMEWORKSPATH
141FRAMEWORKPATH = ${ALTFRAMEWORKSPATH}
8e029c65 142.else
b5d655f7 143FRAMEWORKPATH = ${SDKROOT}/System/Library/Frameworks
8e029c65 144.endif
224c7076
A
145$(FRAMEWORKS):
146 $(SRCROOT)/patchHeaders $(FRAMEWORKPATH)/$(PRIVATEHEADERPATH) $(FRAMEWORKS)/$(PRIVATEHEADERPATH:H)
34e8f829 147 ${LN} -fs $(VERSIONSB)/PrivateHeaders $(FRAMEWORKS)/$(SYSTEMFRAMEWORK)/PrivateHeaders
224c7076
A
148
149AUTOPATCHED = $(SRCROOT)/.autopatched
1f2f436a 150PARTIAL =
224c7076
A
151.for F in $(FORMS) # {
152.if $(dynamic) == $(F) # {
153SUFFIX-$(F) =
154.else # } {
155SUFFIX-$(F) = _$(F)
156.endif # }
157PSUFFIX-$(F) = $(PARTIAL)$(SUFFIX-$(F))
158
159.for A in $(RC_ARCHS) # {
160.if empty(DONT-BUILD-$(A)-$(F)) # {
161ARCHS-$(F) += $(A)
8e029c65 162build-$(A)-$(F):
34e8f829 163 ${MKDIR} $(OBJROOT)/obj.$(A) && \
b5d655f7 164 MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH=$(MACHINE_ARCH-$(A)) CCARCH=$(A) \
224c7076 165 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
b5d655f7
A
166 RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" MAKEFLAGS="" \
167 OBJSUFFIX="$(OBJSUFFIX-$(F))" \
34e8f829 168 $(MYBSDMAKEJ) libc$(SUFFIX-$(F)).a
224c7076
A
169.else # } {
170build-$(A)-$(F):
171 @echo Not building libc$(PSUFFIX-$(F)).a for $(A)
172.endif # }
173.endfor # RC_ARCHS }
174
34e8f829 175NARCHS-$(F) != ${ECHO} $(ARCHS-$(F)) | ${WC} -w
224c7076
A
176
177build-$(F): $(FRAMEWORKS) $(AUTOPATCHED)
178.for A in $(RC_ARCHS) # {
179build-$(F): build-$(A)-$(F)
180.endfor # RC_ARCHS }
181.if $(NARCHS-$(F)) == 0 # {
182build-$(F):
183 @echo No libc$(PSUFFIX-$(F)).a built
184.else # } {
34e8f829
A
185LIPOARGS-$(F) != ${PERL} -e 'printf "%s\n", join(" ", map(qq(-arch $$_ \"$(OBJROOT)/obj.$$_/libc$(SUFFIX-$(F)).a\"), qw($(ARCHS-$(F)))))'
186.if $(dynamic) == $(F) # {
187LIPODYLDARGS-$(F) != ${PERL} -e 'printf "%s\n", join(" ", map(qq(-arch $$_ \"$(OBJROOT)/obj.$$_/libc-dyld.a\"), qw($(ARCHS-$(F)))))'
188.endif # }
224c7076
A
189build-$(F):
190.if $(NARCHS-$(F)) == 1 # {
34e8f829
A
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"
194.endif # }
224c7076 195.else # } {
34e8f829
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"
199.endif # }
224c7076
A
200.endif # }
201.endif # }
202.endfor # FORMS }
203
204# We autopatch the files into the directory containing the Makefile.inc. This
205# will happen at installsrc.
206$(AUTOPATCHED):
b5d655f7
A
207.for A in $(ALLARCHS) # {
208 MACHINE_ARCH=$(A) SRCROOT="$(SRCROOT)" \
34e8f829 209 $(MYBSDMAKE) -C "$(SRCROOT)" autopatch
b5d655f7 210.endfor # ALLARCHS # }
224c7076
A
211 touch $(AUTOPATCHED)
212
213copysrc:
1f2f436a 214 ${TAR} -cp --exclude .git --exclude .svn --exclude CVS . | ${TAR} -pox -C "$(SRCROOT)"
224c7076
A
215
216installsrc: copysrc $(AUTOPATCHED)
217
218installhdrs-real:
1f2f436a
A
219 MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)$(INSTALL_PREFIX)" MAKEFLAGS="" \
220 DSTROOT="$(DSTROOT)$(INSTALL_PREFIX)" OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
34e8f829 221 $(MYBSDMAKEJ) installhdrs
224c7076 222.for A in $(RC_ARCHS) # {
34e8f829 223 ${MKDIR} "$(OBJROOT)/obj.$(A)" && \
b5d655f7 224 MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH=$(MACHINE_ARCH-$(A)) CCARCH=$(A) \
224c7076 225 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
b5d655f7 226 MAKEFLAGS="" RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" \
34e8f829 227 $(MYBSDMAKEJ) installhdrs-md
224c7076 228.endfor # RC_ARCHS # }
8e029c65 229
224c7076 230.for F in $(FORMS) # {
8e029c65 231BI-install-$(F): build-$(F)
1f2f436a
A
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
34e8f829 237 ${MKDIR} $(DSTROOT)/usr/local/lib/system
1f2f436a
A
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
224c7076 242.if $(dynamic) == $(F) # {
34e8f829
A
243 if [ -f "$(SYMROOT)/libc-dyld.a" ]; then \
244 ${ECHO} "Installing libc-dyld.a" && \
1f2f436a 245 ${MKDIR} $(DSTROOT)/usr/local/lib/dyld && \
34e8f829 246 ${INSTALL} -m 444 "$(SYMROOT)/libc-dyld.a" \
1f2f436a
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; \
34e8f829 250 fi
224c7076 251.for A in $(RC_ARCHS) # {
b5d655f7 252 MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH=$(MACHINE_ARCH-$(A)) CCARCH=$(A) \
224c7076
A
253 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
254 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
b5d655f7 255 MAKEFLAGS="" RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" \
34e8f829 256 $(MYBSDMAKE) copyfiles
224c7076
A
257.endfor # RC_ARCHS # }
258.endif # }
259.endfor # FORMS }
8e029c65
A
260
261# Don't use -j here; it may try to make links before the files are copied
34e8f829
A
262MANARGS != ${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.
265MANARGS += MANDIR=${SHAREDIR}/man/man
8e029c65 266install-man:
34e8f829
A
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
1f2f436a
A
272 MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)$(INSTALL_PREFIX)" \
273 DSTROOT='$(DSTROOT)$(INSTALL_PREFIX)' OBJROOT='$(OBJROOT)' SYMROOT='$(SYMROOT)' \
34e8f829 274 MACHINE_ARCH="$(MACHINE_ARCH-$(FIRST_ARCH))" CCARCH=$(FIRST_ARCH) MAKEFLAGS="" \
b5d655f7 275 RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" \
34e8f829 276 $(MYBSDMAKE) all-man maninstall $(MANARGS)
8e029c65
A
277
278install-all: build install-man
224c7076 279.for F in $(FORMS) # {
8e029c65 280install-all: BI-install-$(F)
224c7076 281.endfor # FORMS }
8e029c65
A
282
283clean:
224c7076 284.for F in $(FORMS) # {
34e8f829 285 ${RM} $(SYMROOT)/libc$(PSUFFIX-$(F)).a
224c7076
A
286.endfor # FORMS }
287.for A in $(RC_ARCHS) # {
34e8f829 288 ${RMDIR} $(OBJROOT)/obj.$(A)
224c7076 289.endfor # RC_ARCHS # }