]> git.saurik.com Git - apple/libc.git/blob - BSDmakefile
f787db53feb5e471f52ab63be054891341d2bad0
[apple/libc.git] / BSDmakefile
1 .include <CoreOS/Standard/Commands.mk>
2 .include <CoreOS/Standard/Variables.mk>
3
4 ALLARCHS = arm i386 ppc ppc64 x86_64 # installsrc doesn't set RC_ARCHS
5 CODESIGN != xcrun -find codesign
6 TOP != ${PWD}
7 .ifdef DSTROOT
8 DESTDIR = $(DSTROOT)
9 .else
10 .ifdef DESTDIR
11 DSTROOT = $(DESTDIR)
12 .else
13 DSTROOT = /
14 DESTDIR = /
15 .endif
16 .endif
17 .ifndef OBJROOT
18 OBJROOT = $(TOP)/OBJROOT
19 .endif
20 .ifndef SRCROOT
21 SRCROOT = $(TOP)
22 .endif
23 .ifndef SYMROOT
24 SYMROOT = $(TOP)/SYMROOT
25 .endif
26 MYARCH != ${ARCH}
27 .ifndef RC_ARCHS
28 RC_ARCHS = $(MYARCH)
29 RC_$(RC_ARCHS) = 1
30 .endif
31 FIRST_ARCH != ${PERL} -e 'print $$ARGV[0]' ${RC_ARCHS}
32 .ifndef RC_NONARCH_CFLAGS
33 RC_NONARCH_CFLAGS = -pipe
34 .endif
35 .ifdef ALTUSRLOCALLIBSYSTEM
36 LIBSYS = $(ALTUSRLOCALLIBSYSTEM)
37 .else
38 LIBSYS = $(SDKROOT)/usr/local/lib/system
39 .endif
40 .ifdef ALTUSRLIBSYSTEM
41 LSYS = $(ALTUSRLIBSYSTEM)
42 .else
43 LSYS = $(SDKROOT)/usr/lib/system
44 .endif
45 NJOBS != ${PERL} -e '$$n = `$(SYSCTL) -n hw.ncpu`; printf "%d\n", $$n < 2 ? 2 : ($$n * 1.5)'
46 .ifdef DEBUG
47 MYBSDMAKE = $(BSDMAKE) -f Makefile -P
48 .else
49 MYBSDMAKE = $(BSDMAKE) -f Makefile
50 .endif
51 MYBSDMAKEJ = $(MYBSDMAKE) -j $(NJOBS)
52
53 # Set the DONT-BUILD-arch-form variable to non-empty to turn off building
54 #DONT-BUILD-x86_64-static = 1
55
56 # These variables are to guarantee that the left-hand side of an expression is
57 # always a variable
58 dynamic = dynamic
59 static = static
60
61 # Map RC_ARCHS to MACHINE_ARCH
62 .for A in $(RC_ARCHS) $(MYARCH) # {
63 MACHINE_ARCH-$(A) = $(A:C/^armv.*/arm/)
64 .endfor # RC_ARCHS }
65
66 FORMS := dynamic debug profile static
67
68 OBJSUFFIX-dynamic = So
69 OBJSUFFIX-debug = do
70 OBJSUFFIX-profile = po
71 OBJSUFFIX-static = o
72
73 all: build
74
75 ROOTS := DSTROOT OBJROOT SYMROOT
76 .for R in $(ROOTS) # {
77 roots: $($(R))
78 $($(R)):
79 ${MKDIR} '$($(R))'
80 .endfor # ROOTS }
81
82 # These are the non B&I defaults
83 .ifndef RC_ProjectName
84
85 RC_ProjectName = Libc
86
87 installhdrs: roots installhdrs-real
88 build: roots build-static build-profile build-debug build-dynamic
89 install: roots installhdrs install-all
90
91 .else # RC_ProjectName
92
93 RC_ProjectNameBase := $(RC_ProjectName:%_Sim=%)
94 .if $(RC_ProjectName) == $(RC_ProjectNameBase)
95 INSTALL_PREFIX =
96 .else
97 INSTALL_PREFIX = $(SDKROOT)
98 .endif
99
100 # And these are to deal with B&I building libc differently
101 # based on RC_ProjectName.
102 .if $(RC_ProjectNameBase) == Libc
103 installhdrs:
104 build: roots build-dynamic
105 install: roots BI-install-dynamic
106 .endif
107 .if $(RC_ProjectNameBase) == Libc_headers
108 installhdrs: roots installhdrs-real
109 build:
110 install: roots installhdrs-real
111 .endif
112 .if $(RC_ProjectNameBase) == Libc_man
113 installhdrs:
114 build:
115 install: roots install-man
116 .endif
117 .if $(RC_ProjectNameBase) == Libc_static
118 installhdrs:
119 build: roots build-static
120 install: roots BI-install-static
121 .endif
122 .if $(RC_ProjectNameBase) == Libc_debug
123 installhdrs:
124 build: roots build-debug
125 install: roots BI-install-debug
126 .endif
127 .if $(RC_ProjectNameBase) == Libc_profile
128 installhdrs:
129 build: roots build-profile
130 install: roots BI-install-profile
131 .endif
132 .endif # RC_ProjectName
133
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}
142 .else
143 FRAMEWORKPATH = ${SDKROOT}/System/Library/Frameworks
144 .endif
145 $(FRAMEWORKS):
146 $(SRCROOT)/patchHeaders $(FRAMEWORKPATH)/$(PRIVATEHEADERPATH) $(FRAMEWORKS)/$(PRIVATEHEADERPATH:H)
147 ${LN} -fs $(VERSIONSB)/PrivateHeaders $(FRAMEWORKS)/$(SYSTEMFRAMEWORK)/PrivateHeaders
148
149 AUTOPATCHED = $(SRCROOT)/.autopatched
150 PARTIAL =
151 .for F in $(FORMS) # {
152 .if $(dynamic) == $(F) # {
153 SUFFIX-$(F) =
154 .else # } {
155 SUFFIX-$(F) = _$(F)
156 .endif # }
157 PSUFFIX-$(F) = $(PARTIAL)$(SUFFIX-$(F))
158
159 .for A in $(RC_ARCHS) # {
160 .if empty(DONT-BUILD-$(A)-$(F)) # {
161 ARCHS-$(F) += $(A)
162 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
169 .else # } {
170 build-$(A)-$(F):
171 @echo Not building libc$(PSUFFIX-$(F)).a for $(A)
172 .endif # }
173 .endfor # RC_ARCHS }
174
175 NARCHS-$(F) != ${ECHO} $(ARCHS-$(F)) | ${WC} -w
176
177 build-$(F): $(FRAMEWORKS) $(AUTOPATCHED)
178 .for A in $(RC_ARCHS) # {
179 build-$(F): build-$(A)-$(F)
180 .endfor # RC_ARCHS }
181 .if $(NARCHS-$(F)) == 0 # {
182 build-$(F):
183 @echo No libc$(PSUFFIX-$(F)).a built
184 .else # } {
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)))))'
188 .endif # }
189 build-$(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"
194 .endif # }
195 .else # } {
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 # }
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):
207 .for A in $(ALLARCHS) # {
208 MACHINE_ARCH=$(A) SRCROOT="$(SRCROOT)" \
209 $(MYBSDMAKE) -C "$(SRCROOT)" autopatch
210 .endfor # ALLARCHS # }
211 touch $(AUTOPATCHED)
212
213 copysrc:
214 ${TAR} -cp --exclude .git --exclude .svn --exclude CVS . | ${TAR} -pox -C "$(SRCROOT)"
215
216 installsrc: copysrc $(AUTOPATCHED)
217
218 installhdrs-real:
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 # }
229
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; \
250 fi
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 # }
258 .endif # }
259 .endfor # FORMS }
260
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
266 install-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)
277
278 install-all: build install-man
279 .for F in $(FORMS) # {
280 install-all: BI-install-$(F)
281 .endfor # FORMS }
282
283 clean:
284 .for F in $(FORMS) # {
285 ${RM} $(SYMROOT)/libc$(PSUFFIX-$(F)).a
286 .endfor # FORMS }
287 .for A in $(RC_ARCHS) # {
288 ${RMDIR} $(OBJROOT)/obj.$(A)
289 .endfor # RC_ARCHS # }