]>
Commit | Line | Data |
---|---|---|
34e8f829 A |
1 | .include <CoreOS/Standard/Commands.mk> |
2 | .include <CoreOS/Standard/Variables.mk> | |
3 | ||
b5d655f7 | 4 | ALLARCHS = arm i386 ppc ppc64 x86_64 # installsrc doesn't set RC_ARCHS |
1f2f436a | 5 | CODESIGN != xcrun -find codesign |
34e8f829 | 6 | TOP != ${PWD} |
224c7076 A |
7 | .ifdef DSTROOT |
8 | DESTDIR = $(DSTROOT) | |
9 | .else | |
10 | .ifdef DESTDIR | |
11 | DSTROOT = $(DESTDIR) | |
12 | .else | |
13 | DSTROOT = / | |
14 | DESTDIR = / | |
15 | .endif | |
16 | .endif | |
8e029c65 | 17 | .ifndef OBJROOT |
34e8f829 | 18 | OBJROOT = $(TOP)/OBJROOT |
224c7076 A |
19 | .endif |
20 | .ifndef SRCROOT | |
34e8f829 | 21 | SRCROOT = $(TOP) |
8e029c65 A |
22 | .endif |
23 | .ifndef SYMROOT | |
34e8f829 | 24 | SYMROOT = $(TOP)/SYMROOT |
8e029c65 | 25 | .endif |
34e8f829 | 26 | MYARCH != ${ARCH} |
8e029c65 | 27 | .ifndef RC_ARCHS |
34e8f829 | 28 | RC_ARCHS = $(MYARCH) |
8e029c65 A |
29 | RC_$(RC_ARCHS) = 1 |
30 | .endif | |
34e8f829 | 31 | FIRST_ARCH != ${PERL} -e 'print $$ARGV[0]' ${RC_ARCHS} |
b5d655f7 A |
32 | .ifndef RC_NONARCH_CFLAGS |
33 | RC_NONARCH_CFLAGS = -pipe | |
34 | .endif | |
8e029c65 A |
35 | .ifdef ALTUSRLOCALLIBSYSTEM |
36 | LIBSYS = $(ALTUSRLOCALLIBSYSTEM) | |
37 | .else | |
b5d655f7 | 38 | LIBSYS = $(SDKROOT)/usr/local/lib/system |
8e029c65 | 39 | .endif |
1f2f436a A |
40 | .ifdef ALTUSRLIBSYSTEM |
41 | LSYS = $(ALTUSRLIBSYSTEM) | |
42 | .else | |
43 | LSYS = $(SDKROOT)/usr/lib/system | |
44 | .endif | |
34e8f829 A |
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) | |
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 |
58 | dynamic = dynamic | |
59 | static = static | |
60 | ||
b5d655f7 | 61 | # Map RC_ARCHS to MACHINE_ARCH |
34e8f829 | 62 | .for A in $(RC_ARCHS) $(MYARCH) # { |
b5d655f7 A |
63 | MACHINE_ARCH-$(A) = $(A:C/^armv.*/arm/) |
64 | .endfor # RC_ARCHS } | |
8e029c65 A |
65 | |
66 | FORMS := dynamic debug profile static | |
67 | ||
b5d655f7 A |
68 | OBJSUFFIX-dynamic = So |
69 | OBJSUFFIX-debug = do | |
70 | OBJSUFFIX-profile = po | |
71 | OBJSUFFIX-static = o | |
72 | ||
8e029c65 A |
73 | all: build |
74 | ||
224c7076 A |
75 | ROOTS := DSTROOT OBJROOT SYMROOT |
76 | .for R in $(ROOTS) # { | |
77 | roots: $($(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 |
85 | RC_ProjectName = Libc |
86 | ||
224c7076 A |
87 | installhdrs: roots installhdrs-real |
88 | build: roots build-static build-profile build-debug build-dynamic | |
89 | install: roots installhdrs install-all | |
8e029c65 A |
90 | |
91 | .else # RC_ProjectName | |
92 | ||
1f2f436a A |
93 | RC_ProjectNameBase := $(RC_ProjectName:%_Sim=%) |
94 | .if $(RC_ProjectName) == $(RC_ProjectNameBase) | |
95 | INSTALL_PREFIX = | |
96 | .else | |
97 | INSTALL_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 | 103 | installhdrs: |
224c7076 A |
104 | build: roots build-dynamic |
105 | install: roots BI-install-dynamic | |
8e029c65 | 106 | .endif |
1f2f436a | 107 | .if $(RC_ProjectNameBase) == Libc_headers |
224c7076 | 108 | installhdrs: roots installhdrs-real |
8e029c65 | 109 | build: |
224c7076 | 110 | install: roots installhdrs-real |
8e029c65 | 111 | .endif |
1f2f436a | 112 | .if $(RC_ProjectNameBase) == Libc_man |
8e029c65 A |
113 | installhdrs: |
114 | build: | |
224c7076 | 115 | install: roots install-man |
8e029c65 | 116 | .endif |
1f2f436a | 117 | .if $(RC_ProjectNameBase) == Libc_static |
8e029c65 | 118 | installhdrs: |
224c7076 A |
119 | build: roots build-static |
120 | install: roots BI-install-static | |
8e029c65 | 121 | .endif |
1f2f436a | 122 | .if $(RC_ProjectNameBase) == Libc_debug |
8e029c65 | 123 | installhdrs: |
224c7076 A |
124 | build: roots build-debug |
125 | install: roots BI-install-debug | |
8e029c65 | 126 | .endif |
1f2f436a | 127 | .if $(RC_ProjectNameBase) == Libc_profile |
8e029c65 | 128 | installhdrs: |
224c7076 A |
129 | build: roots build-profile |
130 | install: 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 | |
136 | SYSTEMFRAMEWORK = System.framework | |
137 | VERSIONSB = Versions/B | |
138 | PRIVATEHEADERPATH = $(SYSTEMFRAMEWORK)/$(VERSIONSB)/PrivateHeaders | |
139 | FRAMEWORKS = $(OBJROOT)/Frameworks | |
140 | .ifdef ALTFRAMEWORKSPATH | |
141 | FRAMEWORKPATH = ${ALTFRAMEWORKSPATH} | |
8e029c65 | 142 | .else |
b5d655f7 | 143 | FRAMEWORKPATH = ${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 | |
149 | AUTOPATCHED = $(SRCROOT)/.autopatched | |
1f2f436a | 150 | PARTIAL = |
224c7076 A |
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) | |
8e029c65 | 162 | build-$(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 # } { |
170 | build-$(A)-$(F): | |
171 | @echo Not building libc$(PSUFFIX-$(F)).a for $(A) | |
172 | .endif # } | |
173 | .endfor # RC_ARCHS } | |
174 | ||
34e8f829 | 175 | NARCHS-$(F) != ${ECHO} $(ARCHS-$(F)) | ${WC} -w |
224c7076 A |
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 # } { | |
34e8f829 A |
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 # } | |
224c7076 A |
189 | build-$(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 | ||
213 | copysrc: | |
1f2f436a | 214 | ${TAR} -cp --exclude .git --exclude .svn --exclude CVS . | ${TAR} -pox -C "$(SRCROOT)" |
224c7076 A |
215 | |
216 | installsrc: copysrc $(AUTOPATCHED) | |
217 | ||
218 | installhdrs-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 | 231 | BI-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 |
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 | |
8e029c65 | 266 | install-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 | |
278 | install-all: build install-man | |
224c7076 | 279 | .for F in $(FORMS) # { |
8e029c65 | 280 | install-all: BI-install-$(F) |
224c7076 | 281 | .endfor # FORMS } |
8e029c65 A |
282 | |
283 | clean: | |
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 # } |