]> git.saurik.com Git - apple/libc.git/blob - BSDmakefile
Libc-498.1.5.tar.gz
[apple/libc.git] / BSDmakefile
1 ALLARCHS = arm i386 ppc ppc64 x86_64 # installsrc doesn't set RC_ARCHS
2 PWD != pwd
3 .ifdef DSTROOT
4 DESTDIR = $(DSTROOT)
5 .else
6 .ifdef DESTDIR
7 DSTROOT = $(DESTDIR)
8 .else
9 DSTROOT = /
10 DESTDIR = /
11 .endif
12 .endif
13 .ifndef OBJROOT
14 OBJROOT = $(PWD)/OBJROOT
15 .endif
16 .ifndef SRCROOT
17 SRCROOT = $(PWD)
18 .endif
19 .ifndef SYMROOT
20 SYMROOT = $(PWD)/SYMROOT
21 .endif
22 ARCH != arch
23 .ifndef RC_ARCHS
24 RC_ARCHS = $(ARCH)
25 RC_$(RC_ARCHS) = 1
26 .endif
27 .ifndef RC_NONARCH_CFLAGS
28 RC_NONARCH_CFLAGS = -pipe
29 .endif
30 .ifdef ALTUSRLOCALLIBSYSTEM
31 LIBSYS = $(ALTUSRLOCALLIBSYSTEM)
32 .else
33 LIBSYS = $(SDKROOT)/usr/local/lib/system
34 .endif
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)
39
40 # Set the DONT-BUILD-arch-form variable to non-empty to turn off building
41 #DONT-BUILD-x86_64-static = 1
42
43 # These variables are to guarantee that the left-hand side of an expression is
44 # always a variable
45 dynamic = dynamic
46 static = static
47
48 # Map RC_ARCHS to MACHINE_ARCH
49 .for A in $(RC_ARCHS) $(ARCH) # {
50 MACHINE_ARCH-$(A) = $(A:C/^armv.*/arm/)
51 .endfor # RC_ARCHS }
52
53 FORMS := dynamic debug profile static
54
55 OBJSUFFIX-dynamic = So
56 OBJSUFFIX-debug = do
57 OBJSUFFIX-profile = po
58 OBJSUFFIX-static = o
59
60 all: build
61
62 ROOTS := DSTROOT OBJROOT SYMROOT
63 .for R in $(ROOTS) # {
64 roots: $($(R))
65 $($(R)):
66 mkdir -p '$($(R))'
67 .endfor # ROOTS }
68
69 # These are the non B&I defaults
70 .ifndef RC_ProjectName
71
72 installhdrs: roots installhdrs-real
73 build: roots build-static build-profile build-debug build-dynamic
74 install: roots installhdrs install-all
75
76 .else # RC_ProjectName
77
78 # And these are to deal with B&I building libc differently
79 # based on RC_ProjectName.
80 .if $(RC_ProjectName) == Libc
81 installhdrs:
82 build: roots build-dynamic
83 install: roots BI-install-dynamic
84 .endif
85 .if $(RC_ProjectName) == Libc_headers
86 installhdrs: roots installhdrs-real
87 build:
88 install: roots installhdrs-real
89 .endif
90 .if $(RC_ProjectName) == Libc_man
91 installhdrs:
92 build:
93 install: roots install-man
94 .endif
95 .if $(RC_ProjectName) == Libc_static
96 installhdrs:
97 build: roots build-static
98 install: roots BI-install-static
99 .endif
100 .if $(RC_ProjectName) == Libc_debug
101 installhdrs:
102 build: roots build-debug
103 install: roots BI-install-debug
104 .endif
105 .if $(RC_ProjectName) == Libc_profile
106 installhdrs:
107 build: roots build-profile
108 install: roots BI-install-profile
109 .endif
110 .endif # RC_ProjectName
111
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}
120 .else
121 FRAMEWORKPATH = ${SDKROOT}/System/Library/Frameworks
122 .endif
123 $(FRAMEWORKS):
124 $(SRCROOT)/patchHeaders $(FRAMEWORKPATH)/$(PRIVATEHEADERPATH) $(FRAMEWORKS)/$(PRIVATEHEADERPATH:H)
125 ln -fs $(VERSIONSB)/PrivateHeaders $(FRAMEWORKS)/$(SYSTEMFRAMEWORK)/PrivateHeaders
126
127 AUTOPATCHED = $(SRCROOT)/.autopatched
128 PARTIAL = -partial
129 .for F in $(FORMS) # {
130 .if $(dynamic) == $(F) # {
131 SUFFIX-$(F) =
132 .else # } {
133 SUFFIX-$(F) = _$(F)
134 .endif # }
135 PSUFFIX-$(F) = $(PARTIAL)$(SUFFIX-$(F))
136
137 .for A in $(RC_ARCHS) # {
138 .if empty(DONT-BUILD-$(A)-$(F)) # {
139 ARCHS-$(F) += $(A)
140 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
147 .else # } {
148 build-$(A)-$(F):
149 @echo Not building libc$(PSUFFIX-$(F)).a for $(A)
150 .endif # }
151 .endfor # RC_ARCHS }
152
153 NARCHS-$(F) != echo $(ARCHS-$(F)) | wc -w
154
155 build-$(F): $(FRAMEWORKS) $(AUTOPATCHED)
156 .for A in $(RC_ARCHS) # {
157 build-$(F): build-$(A)-$(F)
158 .endfor # RC_ARCHS }
159 .if $(NARCHS-$(F)) == 0 # {
160 build-$(F):
161 @echo No libc$(PSUFFIX-$(F)).a built
162 .else # } {
163 LIPOARGS-$(F) != perl -e 'printf "%s\n", join(" ", map(qq(-arch $$_ \"$(OBJROOT)/obj.$$_/libc$(SUFFIX-$(F)).a\"), qw($(ARCHS-$(F)))))'
164 build-$(F):
165 .if $(NARCHS-$(F)) == 1 # {
166 cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc$(SUFFIX-$(F)).a" "$(SYMROOT)/libc$(PSUFFIX-$(F)).a"
167 .else # } {
168 lipo -create $(LIPOARGS-$(F)) -output "$(SYMROOT)/libc$(PSUFFIX-$(F)).a"
169 .endif # }
170 .endif # }
171 .endfor # FORMS }
172
173 # We autopatch the files into the directory containing the Makefile.inc. This
174 # will happen at installsrc.
175 $(AUTOPATCHED):
176 .for A in $(ALLARCHS) # {
177 MACHINE_ARCH=$(A) SRCROOT="$(SRCROOT)" \
178 $(BSDMAKE) -C "$(SRCROOT)" autopatch
179 .endfor # ALLARCHS # }
180 touch $(AUTOPATCHED)
181
182 copysrc:
183 pax -rw -p p . "$(SRCROOT)"
184
185 installsrc: copysrc $(AUTOPATCHED)
186
187 installhdrs-real:
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 # }
198
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; \
207 fi
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)" \
214 $(BSDMAKE) copyfiles
215 .endfor # RC_ARCHS # }
216 .endif # }
217 .endfor # FORMS }
218
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
221 install-man:
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)
232
233 install-all: build install-man
234 .for F in $(FORMS) # {
235 install-all: BI-install-$(F)
236 .endfor # FORMS }
237
238 clean:
239 .for F in $(FORMS) # {
240 rm -f $(SYMROOT)/libc$(PSUFFIX-$(F)).a
241 .endfor # FORMS }
242 .for A in $(RC_ARCHS) # {
243 rm -rf $(OBJROOT)/obj.$(A)
244 .endfor # RC_ARCHS # }