]> git.saurik.com Git - apple/libc.git/blob - xcodescripts/headers.sh
b8c99c9e5c0b6f8f02a1b762bd5211d89f78f85f
[apple/libc.git] / xcodescripts / headers.sh
1 #!/bin/bash
2 set -x
3
4 # Skip installing headers during Xcode build (buildit uses installhdrs+install)
5 if [ "$ACTION" == build ]; then exit 0; fi
6
7 # Installs Libc header files
8
9 MKDIR="mkdir -p"
10 INSTALL=install
11 MV=mv
12 ECHO=echo
13 CHMOD=chmod
14 CP=cp
15 UNIFDEF=unifdef
16 FIND=find
17 RM=rm
18 ED=ed
19 XARGS=xargs
20 GREP=grep
21 FGREP=fgrep
22
23 eval $(${SRCROOT}/xcodescripts/generate_features.pl --bash)
24 UNIFDEFARGS=$(${SRCROOT}/xcodescripts/generate_features.pl --unifdef)
25
26 INCDIR=${DSTROOT}/${PUBLIC_HEADERS_FOLDER_PATH}
27 LOCINCDIR=${DSTROOT}/${PRIVATE_HEADERS_FOLDER_PATH}
28 SYSTEMFRAMEWORK=${DSTROOT}/System/Library/Frameworks/System.framework
29 KERNELFRAMEWORK=${DSTROOT}/System/Library/Frameworks/Kernel.framework
30
31 PRIVHDRS=${SYSTEMFRAMEWORK}/Versions/B/PrivateHeaders
32 PRIVKERNELHDRS=${KERNELFRAMEWORK}/Versions/A/PrivateHeaders
33 INSTALLMODE=$([[ `id -u` -eq 0 ]] && echo 444 || echo 644)
34
35 INSTHDRS=(
36 ${SRCROOT}/gen/get_compat.h
37 ${SRCROOT}/gen/execinfo.h
38 )
39
40 INC_INSTHDRS=(
41 _locale.h
42 _types.h
43 _wctype.h
44 _xlocale.h
45 aio.h
46 alloca.h
47 ar.h
48 assert.h
49 asm.h
50 bitstring.h
51 cpio.h
52 crt_externs.h
53 ctype.h
54 db.h
55 dirent.h
56 disktab.h
57 err.h
58 errno.h
59 fcntl.h
60 fmtmsg.h
61 fnmatch.h
62 fsproperties.h
63 fstab.h
64 fts.h
65 ftw.h
66 getopt.h
67 glob.h
68 inttypes.h
69 iso646.h
70 langinfo.h
71 libc.h
72 libgen.h
73 limits.h
74 locale.h
75 memory.h
76 monetary.h
77 monitor.h
78 mpool.h
79 ndbm.h
80 nlist.h
81 paths.h
82 printf.h
83 poll.h
84 ranlib.h
85 readpassphrase.h
86 regex.h
87 runetype.h
88 search.h
89 semaphore.h
90 sgtty.h
91 signal.h
92 stab.h
93 standards.h
94 stddef.h
95 stdio.h
96 stdint.h
97 stdlib.h
98 strhash.h
99 string.h
100 stringlist.h
101 strings.h
102 struct.h
103 sysexits.h
104 syslog.h
105 tar.h
106 termios.h
107 time.h
108 timeconv.h
109 ttyent.h
110 ulimit.h
111 unistd.h
112 util.h
113 utime.h
114 vis.h
115 wchar.h
116 wctype.h
117 wordexp.h
118 xlocale.h
119 )
120 if [ "x${FEATURE_LEGACY_RUNE_APIS}" == "x1" ]; then
121 INC_INSTHDRS=( "${INC_INSTHDRS[@]}" rune.h )
122 fi
123 if [ "x${FEATURE_LEGACY_UTMP_APIS}" == "x1" ]; then
124 INC_INSTHDRS=( "${INC_INSTHDRS[@]}" utmp.h )
125 fi
126
127 INC_INSTHDRS=(
128 "${INC_INSTHDRS[@]/#/${SRCROOT}/include/}"
129 ${SRCROOT}/include/FreeBSD/nl_types.h
130 ${SRCROOT}/include/NetBSD/utmpx.h
131 ${SRCROOT}/stdtime/FreeBSD/tzfile.h
132 )
133 INSTHDRS=( "${INSTHDRS[@]}" "${INC_INSTHDRS[@]}" )
134
135 INC_ARPA_INSTHDRS=( ftp.h inet.h nameser_compat.h telnet.h tftp.h )
136 ARPA_INSTHDRS=( "${INC_ARPA_INSTHDRS[@]/#/${SRCROOT}/include/arpa/}" )
137
138 if [ "x${FEATURE_THERM_NOTIFICATION_APIS}" == "x1" ]; then
139 INC_THERM_INSTHDRS=( OSThermalNotification.h )
140 THERM_INSTHDRS=( "${INC_THERM_INSTHDRS[@]/#/${SRCROOT}/include/libkern/}" )
141 fi
142
143 INC_PROTO_INSTHDRS=( routed.h rwhod.h talkd.h timed.h )
144 PROTO_INSTHDRS=( "${INC_PROTO_INSTHDRS[@]/#/${SRCROOT}/include/protocols/}" )
145
146 INC_SECURE_INSTHDRS=( _common.h _string.h _stdio.h )
147 SECURE_INSTHDRS=( "${INC_SECURE_INSTHDRS[@]/#/${SRCROOT}/include/secure/}" )
148
149 SYS_INSTHDRS=( ${SRCROOT}/include/sys/acl.h ${SRCROOT}/include/sys/statvfs.h )
150
151 INC_XLOCALE_INSTHDRS=(
152 __wctype.h
153 _ctype.h
154 _inttypes.h
155 _langinfo.h
156 _monetary.h
157 _regex.h
158 _stdio.h
159 _stdlib.h
160 _string.h
161 _time.h
162 _wchar.h
163 _wctype.h
164 )
165 XLOCALE_INSTHDRS=( "${INC_XLOCALE_INSTHDRS[@]/#/${SRCROOT}/include/xlocale/}" )
166
167 TYPES_INSTHDRS=(
168 ${SRCROOT}/include/_types/_intmax_t.h
169 ${SRCROOT}/include/_types/_nl_item.h
170 ${SRCROOT}/include/_types/_uint16_t.h
171 ${SRCROOT}/include/_types/_uint32_t.h
172 ${SRCROOT}/include/_types/_uint64_t.h
173 ${SRCROOT}/include/_types/_uint8_t.h
174 ${SRCROOT}/include/_types/_uintmax_t.h
175 ${SRCROOT}/include/_types/_wctrans_t.h
176 ${SRCROOT}/include/_types/_wctype_t.h
177 )
178
179 LOCALHDRS=(
180 ${SRCROOT}/darwin/libc_private.h
181 ${SRCROOT}/gen/assumes.h
182 ${SRCROOT}/gen/utmpx_thread.h
183 ${SRCROOT}/nls/FreeBSD/msgcat.h
184 )
185
186 OS_LOCALHDRS=( ${SRCROOT}/os/assumes.h ${SRCROOT}/os/debug_private.h )
187
188 PRIV_INSTHDRS=(
189 ${SRCROOT}/stdlib/FreeBSD/atexit.h
190 )
191
192 PRIV_BTREEHDRS=(
193 ${SRCROOT}/db/btree/FreeBSD/btree.h
194 ${SRCROOT}/db/btree/FreeBSD/bt_extern.h
195 )
196
197 SYS_INSTHDRS=(
198 ${SRCROOT}/include/sys/acl.h
199 ${SRCROOT}/include/sys/rbtree.h
200 ${SRCROOT}/include/sys/statvfs.h
201 )
202 PRIVUUID_INSTHDRS=( ${SRCROOT}/uuid/namespace.h )
203
204 ${MKDIR} ${INCDIR}/arpa
205 ${MKDIR} ${INCDIR}/libkern
206 ${MKDIR} ${INCDIR}/malloc
207 ${MKDIR} ${INCDIR}/protocols
208 ${MKDIR} ${INCDIR}/secure
209 ${MKDIR} ${INCDIR}/sys
210 ${MKDIR} ${INCDIR}/xlocale
211 ${MKDIR} ${INCDIR}/_types
212 ${INSTALL} -m ${INSTALLMODE} ${INSTHDRS[@]} ${INCDIR}
213 ${INSTALL} -m ${INSTALLMODE} ${ARPA_INSTHDRS[@]} ${INCDIR}/arpa
214 if [ "x${FEATURE_MEM_NOTIFICATION_APIS}" == "x1" ]; then
215 ${INSTALL} -m ${INSTALLMODE} ${MEM_INSTHDRS[@]} ${INCDIR}/libkern
216 fi
217 if [ "x${FEATURE_THERM_NOTIFICATION_APIS}" == "x1" ]; then
218 ${INSTALL} -m ${INSTALLMODE} ${THERM_INSTHDRS[@]} ${INCDIR}/libkern
219 fi
220 ${INSTALL} -m ${INSTALLMODE} ${PROTO_INSTHDRS[@]} ${INCDIR}/protocols
221 ${INSTALL} -m ${INSTALLMODE} ${SECURE_INSTHDRS[@]} ${INCDIR}/secure
222 ${INSTALL} -m ${INSTALLMODE} ${SYS_INSTHDRS[@]} ${INCDIR}/sys
223 ${INSTALL} -m ${INSTALLMODE} ${XLOCALE_INSTHDRS[@]} ${INCDIR}/xlocale
224 ${INSTALL} -m ${INSTALLMODE} ${TYPES_INSTHDRS[@]} ${INCDIR}/_types
225 ${MKDIR} ${LOCINCDIR}
226 ${MKDIR} ${LOCINCDIR}/os
227 ${INSTALL} -m ${INSTALLMODE} ${LOCALHDRS[@]} ${LOCINCDIR}
228 ${INSTALL} -m ${INSTALLMODE} ${OS_LOCALHDRS[@]} ${LOCINCDIR}/os
229 ${MKDIR} ${PRIVHDRS}/btree
230 ${MKDIR} ${PRIVHDRS}/machine
231 ${MKDIR} ${PRIVHDRS}/uuid
232 ${MKDIR} ${PRIVHDRS}/sys
233 ${MKDIR} ${PRIVKERNELHDRS}/uuid
234 ${INSTALL} -m ${INSTALLMODE} ${PRIV_INSTHDRS[@]} ${PRIVHDRS}
235 ${INSTALL} -m ${INSTALLMODE} ${PRIV_BTREEHDRS[@]} ${PRIVHDRS}/btree
236 ${MV} ${INCDIR}/asm.h ${PRIVHDRS}/machine
237 ${INSTALL} -m ${INSTALLMODE} ${SYS_INSTHDRS[@]} ${PRIVHDRS}/sys
238 ${INSTALL} -m ${INSTALLMODE} ${PRIVUUID_INSTHDRS[@]} ${PRIVHDRS}/uuid
239 ${INSTALL} -m ${INSTALLMODE} ${PRIVUUID_INSTHDRS[@]} ${PRIVKERNELHDRS}/uuid
240
241 for i in `${FIND} "${DSTROOT}" -name \*.h -print0 | ${XARGS} -0 ${GREP} -l '^//Begin-Libc'`; do
242 ${CHMOD} u+w $i &&
243 ${ECHO} ${ED} - $i \< ${SRCROOT}/xcodescripts/strip-header.ed &&
244 ${ED} - $i < ${SRCROOT}/xcodescripts/strip-header.ed &&
245 ${CHMOD} u-w $i || exit 1;
246 done
247 for i in `${FIND} "${DSTROOT}" -name \*.h -print0 | ${XARGS} -0 ${FGREP} -l -e UNIFDEF -e OPEN_SOURCE`; do
248 ${CHMOD} u+w $i &&
249 ${CP} $i $i.orig &&
250 ${ECHO} ${UNIFDEF} ${UNIFDEFARGS} $i.orig \> $i &&
251 { ${UNIFDEF} ${UNIFDEFARGS} $i.orig > $i || [ $? -ne 2 ]; } &&
252 ${RM} $i.orig &&
253 ${CHMOD} u-w $i || exit 1;
254 done
255
256 exit 0