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