1 ALLARCHS = arm i386 ppc ppc64 x86_64 # installsrc doesn't set RC_ARCHS
14 OBJROOT = $(PWD)/OBJROOT
20 SYMROOT = $(PWD)/SYMROOT
27 .ifndef RC_NONARCH_CFLAGS
28 RC_NONARCH_CFLAGS = -pipe
30 .ifdef ALTUSRLOCALLIBSYSTEM
31 LIBSYS = $(ALTUSRLOCALLIBSYSTEM)
33 LIBSYS = $(SDKROOT)/usr/local/lib/system
35 NJOBS != perl -e '$$n = `/usr/sbin/sysctl -n hw.ncpu`; printf "%d\n", $$n < 2 ? 2 : ($$n * 1.5)'
36 BSDMAKE = bsdmake -f Makefile
37 #BSDMAKEJ = $(BSDMAKE) -j $(NJOBS) -P
38 BSDMAKEJ = $(BSDMAKE) -j $(NJOBS)
40 # Set the DONT-BUILD-arch-form variable to non-empty to turn off building
41 #DONT-BUILD-x86_64-static = 1
43 # These variables are to guarantee that the left-hand side of an expression is
48 # Map RC_ARCHS to MACHINE_ARCH
49 .for A in $(RC_ARCHS) $(ARCH) # {
50 MACHINE_ARCH-$(A) = $(A:C/^armv.*/arm/)
53 FORMS := dynamic debug profile static
55 OBJSUFFIX-dynamic = So
57 OBJSUFFIX-profile = po
62 ROOTS := DSTROOT OBJROOT SYMROOT
63 .for R in $(ROOTS) # {
69 # These are the non B&I defaults
70 .ifndef RC_ProjectName
72 installhdrs: roots installhdrs-real
73 build: roots build-static build-profile build-debug build-dynamic
74 install: roots installhdrs install-all
76 .else # RC_ProjectName
78 # And these are to deal with B&I building libc differently
79 # based on RC_ProjectName.
80 .if $(RC_ProjectName) == Libc
82 build: roots build-dynamic
83 install: roots BI-install-dynamic
85 .if $(RC_ProjectName) == Libc_headers
86 installhdrs: roots installhdrs-real
88 install: roots installhdrs-real
90 .if $(RC_ProjectName) == Libc_man
93 install: roots install-man
95 .if $(RC_ProjectName) == Libc_static
97 build: roots build-static
98 install: roots BI-install-static
100 .if $(RC_ProjectName) == Libc_debug
102 build: roots build-debug
103 install: roots BI-install-debug
105 .if $(RC_ProjectName) == Libc_profile
107 build: roots build-profile
108 install: roots BI-install-profile
110 .endif # RC_ProjectName
112 # Make a copy of System.framework/Versions/B/PrivateHeaders, with headers
113 # patched so that we can build variant symbols independently
114 SYSTEMFRAMEWORK = System.framework
115 VERSIONSB = Versions/B
116 PRIVATEHEADERPATH = $(SYSTEMFRAMEWORK)/$(VERSIONSB)/PrivateHeaders
117 FRAMEWORKS = $(OBJROOT)/Frameworks
118 .ifdef ALTFRAMEWORKSPATH
119 FRAMEWORKPATH = ${ALTFRAMEWORKSPATH}
121 FRAMEWORKPATH = ${SDKROOT}/System/Library/Frameworks
124 $(SRCROOT)/patchHeaders $(FRAMEWORKPATH)/$(PRIVATEHEADERPATH) $(FRAMEWORKS)/$(PRIVATEHEADERPATH:H)
125 ln -fs $(VERSIONSB)/PrivateHeaders $(FRAMEWORKS)/$(SYSTEMFRAMEWORK)/PrivateHeaders
127 AUTOPATCHED = $(SRCROOT)/.autopatched
129 .for F in $(FORMS) # {
130 .if $(dynamic) == $(F) # {
135 PSUFFIX-$(F) = $(PARTIAL)$(SUFFIX-$(F))
137 .for A in $(RC_ARCHS) # {
138 .if empty(DONT-BUILD-$(A)-$(F)) # {
141 mkdir -p $(OBJROOT)/obj.$(A) && \
142 MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH=$(MACHINE_ARCH-$(A)) CCARCH=$(A) \
143 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
144 RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" MAKEFLAGS="" \
145 OBJSUFFIX="$(OBJSUFFIX-$(F))" \
146 $(BSDMAKEJ) libc$(SUFFIX-$(F)).a
149 @echo Not building libc$(PSUFFIX-$(F)).a for $(A)
153 NARCHS-$(F) != echo $(ARCHS-$(F)) | wc -w
155 build-$(F): $(FRAMEWORKS) $(AUTOPATCHED)
156 .for A in $(RC_ARCHS) # {
157 build-$(F): build-$(A)-$(F)
159 .if $(NARCHS-$(F)) == 0 # {
161 @echo No libc$(PSUFFIX-$(F)).a built
163 LIPOARGS-$(F) != perl -e 'printf "%s\n", join(" ", map(qq(-arch $$_ \"$(OBJROOT)/obj.$$_/libc$(SUFFIX-$(F)).a\"), qw($(ARCHS-$(F)))))'
165 .if $(NARCHS-$(F)) == 1 # {
166 cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc$(SUFFIX-$(F)).a" "$(SYMROOT)/libc$(PSUFFIX-$(F)).a"
168 lipo -create $(LIPOARGS-$(F)) -output "$(SYMROOT)/libc$(PSUFFIX-$(F)).a"
173 # We autopatch the files into the directory containing the Makefile.inc. This
174 # will happen at installsrc.
176 .for A in $(ALLARCHS) # {
177 MACHINE_ARCH=$(A) SRCROOT="$(SRCROOT)" \
178 $(BSDMAKE) -C "$(SRCROOT)" autopatch
179 .endfor # ALLARCHS # }
183 pax -rw -p p . "$(SRCROOT)"
185 installsrc: copysrc $(AUTOPATCHED)
188 MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" MAKEFLAGS="" \
189 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
190 $(BSDMAKEJ) installhdrs
191 .for A in $(RC_ARCHS) # {
192 mkdir -p "$(OBJROOT)/obj.$(A)" && \
193 MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH=$(MACHINE_ARCH-$(A)) CCARCH=$(A) \
194 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
195 MAKEFLAGS="" RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" \
196 $(BSDMAKEJ) installhdrs-md
197 .endfor # RC_ARCHS # }
199 .for F in $(FORMS) # {
200 BI-install-$(F): build-$(F)
201 mkdir -p $(DSTROOT)/usr/local/lib/system
202 if [ -f "$(SYMROOT)/libc$(PSUFFIX-$(F)).a" ]; then \
203 echo "Installing libc$(PSUFFIX-$(F)).a" && \
204 install -c -m 444 "$(SYMROOT)/libc$(PSUFFIX-$(F)).a" \
205 $(DSTROOT)/usr/local/lib/system && \
206 ranlib "$(DSTROOT)/usr/local/lib/system/libc$(PSUFFIX-$(F)).a" || exit 1; \
208 .if $(dynamic) == $(F) # {
209 .for A in $(RC_ARCHS) # {
210 MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH=$(MACHINE_ARCH-$(A)) CCARCH=$(A) \
211 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
212 DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \
213 MAKEFLAGS="" RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" \
215 .endfor # RC_ARCHS # }
219 # Don't use -j here; it may try to make links before the files are copied
220 MANARGS != test `id -u` -eq 0 || echo MINSTALL=/usr/bin/install
222 mkdir -p $(DSTROOT)/usr/share/man/man2
223 mkdir -p $(DSTROOT)/usr/share/man/man3
224 mkdir -p $(DSTROOT)/usr/share/man/man4
225 mkdir -p $(DSTROOT)/usr/share/man/man5
226 mkdir -p $(DSTROOT)/usr/share/man/man7
227 MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" \
228 DSTROOT='$(DSTROOT)' OBJROOT='$(OBJROOT)' SYMROOT='$(SYMROOT)' \
229 MACHINE_ARCH="$(MACHINE_ARCH-$(ARCH))" CCARCH=$(ARCH) MAKEFLAGS="" \
230 RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" \
231 $(BSDMAKE) all-man maninstall $(MANARGS)
233 install-all: build install-man
234 .for F in $(FORMS) # {
235 install-all: BI-install-$(F)
239 .for F in $(FORMS) # {
240 rm -f $(SYMROOT)/libc$(PSUFFIX-$(F)).a
242 .for A in $(RC_ARCHS) # {
243 rm -rf $(OBJROOT)/obj.$(A)
244 .endfor # RC_ARCHS # }