]> git.saurik.com Git - apple/libc.git/blob - xcodescripts/headers.sh
2c53924545579c66c239315ec05d0a949db937d0
[apple/libc.git] / xcodescripts / headers.sh
1 #!/bin/bash
2 set -x
3
4 # Installs Libc header files
5
6 if [ -n "${DRIVERKIT}" -a -z "${DRIVERKITSDK}" ]; then
7 # Run script in the mode that installs public DriverKit SDK headers first:
8 # required to get the correct header unifdef ordering, that mode strips out more
9 # and rewrites all headers under the parent directory (/System/DriverKit)
10 DRIVERKITSDK=1 SDK_INSTALL_HEADERS_ROOT="${SDK_INSTALL_ROOT}" "${BASH}" -e "$0"
11 fi
12
13 MKDIR="mkdir -p"
14 INSTALL=install
15 MV=mv
16 ECHO=echo
17 CHMOD=chmod
18 CP=cp
19 UNIFDEF=unifdef
20 FIND=find
21 RM=rm
22 ED=ed
23 XARGS=xargs
24 GREP=grep
25 FGREP=fgrep
26
27 eval $(${SRCROOT}/xcodescripts/generate_features.pl --bash)
28 UNIFDEFARGS=$(${SRCROOT}/xcodescripts/generate_features.pl --unifdef)
29
30 if [[ "${DEPLOYMENT_LOCATION}" == "NO" ]] ; then
31 HDRROOT=${BUILT_PRODUCTS_DIR}
32 else
33 HDRROOT=${DSTROOT}
34 fi
35
36 INCDIR=${HDRROOT}/${SDK_INSTALL_HEADERS_ROOT}/usr/include
37 LOCINCDIR=${HDRROOT}/${SDK_INSTALL_HEADERS_ROOT}/usr/local/include
38 SYSTEMFRAMEWORK=${HDRROOT}/${SDK_INSTALL_HEADERS_ROOT}/System/Library/Frameworks/System.framework
39 KERNELFRAMEWORK=${HDRROOT}/${SDK_INSTALL_HEADERS_ROOT}/System/Library/Frameworks/Kernel.framework
40
41 PRIVHDRS=${SYSTEMFRAMEWORK}/Versions/B/PrivateHeaders
42 PRIVKERNELHDRS=${KERNELFRAMEWORK}/Versions/A/PrivateHeaders
43 INSTALLMODE=$([[ `id -u` -eq 0 ]] && echo 444 || echo 644)
44
45 if [ -z "${DRIVERKITSDK}" ]; then
46
47 INSTHDRS=(
48 ${SRCROOT}/gen/get_compat.h
49 ${SRCROOT}/gen/execinfo.h
50 )
51
52 INC_INSTHDRS=(
53 __wctype.h
54 _ctype.h
55 _locale.h
56 _regex.h
57 _stdio.h
58 _types.h
59 _wctype.h
60 _xlocale.h
61 _ctermid.h
62 aio.h
63 alloca.h
64 ar.h
65 assert.h
66 asm.h
67 bitstring.h
68 cpio.h
69 crt_externs.h
70 ctype.h
71 db.h
72 dirent.h
73 disktab.h
74 err.h
75 errno.h
76 fcntl.h
77 fmtmsg.h
78 fnmatch.h
79 fsproperties.h
80 fstab.h
81 fts.h
82 ftw.h
83 getopt.h
84 glob.h
85 inttypes.h
86 iso646.h
87 langinfo.h
88 libc.h
89 libgen.h
90 limits.h
91 locale.h
92 memory.h
93 monetary.h
94 monitor.h
95 mpool.h
96 ndbm.h
97 nlist.h
98 paths.h
99 printf.h
100 poll.h
101 ranlib.h
102 readpassphrase.h
103 regex.h
104 runetype.h
105 search.h
106 semaphore.h
107 sgtty.h
108 signal.h
109 stab.h
110 standards.h
111 stddef.h
112 stdio.h
113 stdint.h
114 stdlib.h
115 strhash.h
116 string.h
117 stringlist.h
118 strings.h
119 struct.h
120 sysexits.h
121 syslog.h
122 tar.h
123 termios.h
124 time.h
125 timeconv.h
126 ttyent.h
127 ulimit.h
128 unistd.h
129 util.h
130 utime.h
131 vis.h
132 wchar.h
133 wctype.h
134 wordexp.h
135 xlocale.h
136 )
137 if [ "x${FEATURE_LEGACY_RUNE_APIS}" == "x1" ]; then
138 INC_INSTHDRS=( "${INC_INSTHDRS[@]}" rune.h )
139 fi
140 if [ "x${FEATURE_LEGACY_UTMP_APIS}" == "x1" ]; then
141 INC_INSTHDRS=( "${INC_INSTHDRS[@]}" utmp.h )
142 fi
143
144 INC_INSTHDRS=(
145 "${INC_INSTHDRS[@]/#/${SRCROOT}/include/}"
146 ${SRCROOT}/include/FreeBSD/nl_types.h
147 ${SRCROOT}/include/NetBSD/utmpx.h
148 ${SRCROOT}/stdtime/FreeBSD/tzfile.h
149 )
150 INSTHDRS=( "${INSTHDRS[@]}" "${INC_INSTHDRS[@]}" )
151
152 INC_ARPA_INSTHDRS=( ftp.h inet.h nameser_compat.h telnet.h tftp.h )
153 ARPA_INSTHDRS=( "${INC_ARPA_INSTHDRS[@]/#/${SRCROOT}/include/arpa/}" )
154
155 if [ "x${FEATURE_THERM_NOTIFICATION_APIS}" == "x1" ]; then
156 INC_THERM_INSTHDRS=( OSThermalNotification.h )
157 THERM_INSTHDRS=( "${INC_THERM_INSTHDRS[@]/#/${SRCROOT}/include/libkern/}" )
158 fi
159
160 INC_PROTO_INSTHDRS=( routed.h rwhod.h talkd.h timed.h )
161 PROTO_INSTHDRS=( "${INC_PROTO_INSTHDRS[@]/#/${SRCROOT}/include/protocols/}" )
162
163 INC_SECURE_INSTHDRS=( _common.h _string.h _strings.h _stdio.h )
164 SECURE_INSTHDRS=( "${INC_SECURE_INSTHDRS[@]/#/${SRCROOT}/include/secure/}" )
165
166 SYS_INSTHDRS=( ${SRCROOT}/include/sys/acl.h ${SRCROOT}/include/sys/statvfs.h )
167
168 INC_XLOCALE_INSTHDRS=(
169 __wctype.h
170 _ctype.h
171 _inttypes.h
172 _langinfo.h
173 _monetary.h
174 _regex.h
175 _stdio.h
176 _stdlib.h
177 _string.h
178 _time.h
179 _wchar.h
180 _wctype.h
181 )
182 XLOCALE_INSTHDRS=( "${INC_XLOCALE_INSTHDRS[@]/#/${SRCROOT}/include/xlocale/}" )
183
184 TYPES_INSTHDRS=(
185 ${SRCROOT}/include/_types/_intmax_t.h
186 ${SRCROOT}/include/_types/_nl_item.h
187 ${SRCROOT}/include/_types/_uint16_t.h
188 ${SRCROOT}/include/_types/_uint32_t.h
189 ${SRCROOT}/include/_types/_uint64_t.h
190 ${SRCROOT}/include/_types/_uint8_t.h
191 ${SRCROOT}/include/_types/_uintmax_t.h
192 ${SRCROOT}/include/_types/_wctrans_t.h
193 ${SRCROOT}/include/_types/_wctype_t.h
194 )
195
196 LOCALHDRS=(
197 ${SRCROOT}/darwin/libc_private.h
198 ${SRCROOT}/gen/utmpx_thread.h
199 ${SRCROOT}/nls/FreeBSD/msgcat.h
200 ${SRCROOT}/gen/thread_stack_pcs.h
201 ${SRCROOT}/libdarwin/h/dirstat.h
202 )
203
204 OS_LOCALHDRS=( ${SRCROOT}/os/assumes.h ${SRCROOT}/os/debug_private.h )
205
206 PRIV_INSTHDRS=(
207 ${SRCROOT}/stdlib/FreeBSD/atexit.h
208 )
209
210 PRIV_BTREEHDRS=(
211 ${SRCROOT}/db/btree/FreeBSD/btree.h
212 ${SRCROOT}/db/btree/FreeBSD/bt_extern.h
213 )
214
215 SYS_INSTHDRS=(
216 ${SRCROOT}/include/sys/acl.h
217 ${SRCROOT}/include/sys/rbtree.h
218 ${SRCROOT}/include/sys/statvfs.h
219 )
220 PRIVUUID_INSTHDRS=( ${SRCROOT}/uuid/namespace.h )
221
222 else # DRIVERKITSDK
223
224 # Public DriverKit SDK headers
225
226 UNIFDEFARGS="${UNIFDEFARGS} -U_USE_EXTENDED_LOCALES_"
227
228 INC_INSTHDRS=(
229 __wctype.h
230 _ctype.h
231 _locale.h
232 _stdio.h
233 _types.h
234 _wctype.h
235 alloca.h
236 assert.h
237 ctype.h
238 inttypes.h
239 limits.h
240 locale.h
241 runetype.h
242 stddef.h
243 stdio.h
244 stdint.h
245 stdlib.h
246 string.h
247 strings.h
248 time.h
249 wchar.h
250 wctype.h
251 )
252
253 TYPES_INSTHDRS=(
254 ${SRCROOT}/include/_types/_intmax_t.h
255 ${SRCROOT}/include/_types/_uint16_t.h
256 ${SRCROOT}/include/_types/_uint32_t.h
257 ${SRCROOT}/include/_types/_uint64_t.h
258 ${SRCROOT}/include/_types/_uint8_t.h
259 ${SRCROOT}/include/_types/_uintmax_t.h
260 ${SRCROOT}/include/_types/_wctrans_t.h
261 ${SRCROOT}/include/_types/_wctype_t.h
262 )
263
264 INC_INSTHDRS=(
265 "${INC_INSTHDRS[@]/#/${SRCROOT}/include/}"
266 )
267 INSTHDRS=( "${INSTHDRS[@]}" "${INC_INSTHDRS[@]}" )
268
269 INC_SECURE_INSTHDRS=( _common.h _string.h _strings.h _stdio.h )
270 SECURE_INSTHDRS=( "${INC_SECURE_INSTHDRS[@]/#/${SRCROOT}/include/secure/}" )
271
272 fi # DRIVERKITSDK
273
274 if [ -n "${INSTHDRS}" ]; then
275 ${MKDIR} ${INCDIR}
276 ${INSTALL} -m ${INSTALLMODE} ${INSTHDRS[@]} ${INCDIR}
277 fi
278 if [ -n "${ARPA_INSTHDRS}" ]; then
279 ${MKDIR} ${INCDIR}/arpa
280 ${INSTALL} -m ${INSTALLMODE} ${ARPA_INSTHDRS[@]} ${INCDIR}/arpa
281 fi
282 if [ -n "${THERM_INSTHDRS}" ]; then
283 ${MKDIR} ${INCDIR}/libkern
284 ${INSTALL} -m ${INSTALLMODE} ${THERM_INSTHDRS[@]} ${INCDIR}/libkern
285 fi
286 if [ -n "${PROTO_INSTHDRS}" ]; then
287 ${MKDIR} ${INCDIR}/protocols
288 ${INSTALL} -m ${INSTALLMODE} ${PROTO_INSTHDRS[@]} ${INCDIR}/protocols
289 fi
290 if [ -n "${SECURE_INSTHDRS}" ]; then
291 ${MKDIR} ${INCDIR}/secure
292 ${INSTALL} -m ${INSTALLMODE} ${SECURE_INSTHDRS[@]} ${INCDIR}/secure
293 fi
294 if [ -n "${SYS_INSTHDRS}" ]; then
295 ${MKDIR} ${INCDIR}/sys
296 ${INSTALL} -m ${INSTALLMODE} ${SYS_INSTHDRS[@]} ${INCDIR}/sys
297 fi
298 if [ -n "${XLOCALE_INSTHDRS}" ]; then
299 ${MKDIR} ${INCDIR}/xlocale
300 ${INSTALL} -m ${INSTALLMODE} ${XLOCALE_INSTHDRS[@]} ${INCDIR}/xlocale
301 fi
302 if [ -n "${TYPES_INSTHDRS}" ]; then
303 ${MKDIR} ${INCDIR}/_types
304 ${INSTALL} -m ${INSTALLMODE} ${TYPES_INSTHDRS[@]} ${INCDIR}/_types
305 fi
306 if [ -n "${LOCALHDRS}" ]; then
307 ${MKDIR} ${LOCINCDIR}
308 ${INSTALL} -m ${INSTALLMODE} ${LOCALHDRS[@]} ${LOCINCDIR}
309 fi
310 if [ -n "${OS_LOCALHDRS}" ]; then
311 ${MKDIR} ${LOCINCDIR}/os
312 ${INSTALL} -m ${INSTALLMODE} ${OS_LOCALHDRS[@]} ${LOCINCDIR}/os
313 fi
314 if [ -n "${PRIV_INSTHDRS}" ]; then
315 ${MKDIR} ${PRIVHDRS}
316 ${INSTALL} -m ${INSTALLMODE} ${PRIV_INSTHDRS[@]} ${PRIVHDRS}
317 fi
318 if [ -n "${PRIV_BTREEHDRS}" ]; then
319 ${MKDIR} ${PRIVHDRS}/btree
320 ${INSTALL} -m ${INSTALLMODE} ${PRIV_BTREEHDRS[@]} ${PRIVHDRS}/btree
321 fi
322 if [ -n "${SYS_INSTHDRS}" ]; then
323 ${MKDIR} ${PRIVHDRS}/sys
324 ${INSTALL} -m ${INSTALLMODE} ${SYS_INSTHDRS[@]} ${PRIVHDRS}/sys
325 fi
326 if [ -n "${PRIVUUID_INSTHDRS}" ]; then
327 ${MKDIR} ${PRIVHDRS}/uuid
328 ${INSTALL} -m ${INSTALLMODE} ${PRIVUUID_INSTHDRS[@]} ${PRIVHDRS}/uuid
329 ${MKDIR} ${PRIVKERNELHDRS}/uuid
330 ${INSTALL} -m ${INSTALLMODE} ${PRIVUUID_INSTHDRS[@]} ${PRIVKERNELHDRS}/uuid
331 fi
332 if [ -f "${INCDIR}/asm.h" ]; then
333 ${MKDIR} ${PRIVHDRS}/machine
334 ${MV} ${INCDIR}/asm.h ${PRIVHDRS}/machine
335 fi
336
337 for i in `${FIND} "${HDRROOT}/${SDK_INSTALL_HEADERS_ROOT}" -name \*.h -print0 | ${XARGS} -0 ${GREP} -l '^//Begin-Libc'`; do
338 ${CHMOD} u+w $i &&
339 ${ECHO} ${ED} - $i \< ${SRCROOT}/xcodescripts/strip-header.ed &&
340 ${ED} - $i < ${SRCROOT}/xcodescripts/strip-header.ed &&
341 ${CHMOD} u-w $i || exit 1;
342 done
343 for i in `${FIND} "${HDRROOT}/${SDK_INSTALL_HEADERS_ROOT}" -name \*.h -print0 | ${XARGS} -0 ${FGREP} -l -e UNIFDEF -e OPEN_SOURCE -e _USE_EXTENDED_LOCALES_`; do
344 ${CHMOD} u+w $i &&
345 ${CP} $i $i.orig &&
346 ${ECHO} ${UNIFDEF} ${UNIFDEFARGS} $i.orig \> $i &&
347 { ${UNIFDEF} ${UNIFDEFARGS} $i.orig > $i || [ $? -ne 2 ]; } &&
348 ${RM} $i.orig &&
349 ${CHMOD} u-w $i || exit 1;
350 done
351
352 exit 0