]> git.saurik.com Git - apple/libc.git/blob - xcodescripts/headers.sh
9b02baa3aa0fb53963ef65ceb5bad9170ccb42ec
[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}/${INSTALL_PATH_PREFIX}/System/Library/Frameworks/System.framework
29 KERNELFRAMEWORK=${DSTROOT}/${INSTALL_PATH_PREFIX}/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 stdbool.h
95 stddef.h
96 stdio.h
97 stdint.h
98 stdlib.h
99 strhash.h
100 string.h
101 stringlist.h
102 strings.h
103 struct.h
104 sysexits.h
105 syslog.h
106 tar.h
107 termios.h
108 time.h
109 timeconv.h
110 ttyent.h
111 ulimit.h
112 unistd.h
113 util.h
114 utime.h
115 vis.h
116 wchar.h
117 wctype.h
118 wordexp.h
119 xlocale.h
120 )
121 if [ "x${FEATURE_LEGACY_RUNE_APIS}" == "x1" ]; then
122 INC_INSTHDRS=( "${INC_INSTHDRS[@]}" rune.h )
123 fi
124 if [ "x${FEATURE_LEGACY_UTMP_APIS}" == "x1" ]; then
125 INC_INSTHDRS=( "${INC_INSTHDRS[@]}" utmp.h )
126 fi
127
128 INC_INSTHDRS=(
129 "${INC_INSTHDRS[@]/#/${SRCROOT}/include/}"
130 ${SRCROOT}/include/FreeBSD/nl_types.h
131 ${SRCROOT}/include/NetBSD/utmpx.h
132 ${SRCROOT}/stdtime/FreeBSD/tzfile.h
133 )
134 INSTHDRS=( "${INSTHDRS[@]}" "${INC_INSTHDRS[@]}" )
135
136 INC_ARPA_INSTHDRS=( ftp.h inet.h nameser_compat.h telnet.h tftp.h )
137 ARPA_INSTHDRS=( "${INC_ARPA_INSTHDRS[@]/#/${SRCROOT}/include/arpa/}" )
138
139 if [ "x${FEATURE_THERM_NOTIFICATION_APIS}" == "x1" ]; then
140 INC_THERM_INSTHDRS=( OSThermalNotification.h )
141 THERM_INSTHDRS=( "${INC_THERM_INSTHDRS[@]/#/${SRCROOT}/include/libkern/}" )
142 fi
143
144 INC_PROTO_INSTHDRS=( routed.h rwhod.h talkd.h timed.h )
145 PROTO_INSTHDRS=( "${INC_PROTO_INSTHDRS[@]/#/${SRCROOT}/include/protocols/}" )
146
147 INC_SECURE_INSTHDRS=( _common.h _string.h _stdio.h )
148 SECURE_INSTHDRS=( "${INC_SECURE_INSTHDRS[@]/#/${SRCROOT}/include/secure/}" )
149
150 SYS_INSTHDRS=( ${SRCROOT}/include/sys/acl.h ${SRCROOT}/include/sys/statvfs.h )
151
152 INC_XLOCALE_INSTHDRS=(
153 __wctype.h
154 _ctype.h
155 _inttypes.h
156 _langinfo.h
157 _monetary.h
158 _regex.h
159 _stdio.h
160 _stdlib.h
161 _string.h
162 _time.h
163 _wchar.h
164 _wctype.h
165 )
166 XLOCALE_INSTHDRS=( "${INC_XLOCALE_INSTHDRS[@]/#/${SRCROOT}/include/xlocale/}" )
167
168 TYPES_INSTHDRS=(
169 ${SRCROOT}/include/_types/_intmax_t.h
170 ${SRCROOT}/include/_types/_nl_item.h
171 ${SRCROOT}/include/_types/_uint16_t.h
172 ${SRCROOT}/include/_types/_uint32_t.h
173 ${SRCROOT}/include/_types/_uint64_t.h
174 ${SRCROOT}/include/_types/_uint8_t.h
175 ${SRCROOT}/include/_types/_uintmax_t.h
176 ${SRCROOT}/include/_types/_wctrans_t.h
177 ${SRCROOT}/include/_types/_wctype_t.h
178 )
179
180 LOCALHDRS=(
181 ${SRCROOT}/darwin/libc_private.h
182 ${SRCROOT}/gen/assumes.h
183 ${SRCROOT}/gen/utmpx_thread.h
184 ${SRCROOT}/nls/FreeBSD/msgcat.h
185 )
186
187 OS_LOCALHDRS=( ${SRCROOT}/os/assumes.h ${SRCROOT}/os/debug_private.h )
188
189 PRIV_INSTHDRS=(
190 ${SRCROOT}/stdlib/FreeBSD/atexit.h
191 )
192
193 PRIV_BTREEHDRS=(
194 ${SRCROOT}/db/btree/FreeBSD/btree.h
195 ${SRCROOT}/db/btree/FreeBSD/bt_extern.h
196 )
197
198 SYS_INSTHDRS=(
199 ${SRCROOT}/include/sys/acl.h
200 ${SRCROOT}/include/sys/rbtree.h
201 ${SRCROOT}/include/sys/statvfs.h
202 )
203 PRIVUUID_INSTHDRS=( ${SRCROOT}/uuid/namespace.h )
204
205 ${MKDIR} ${INCDIR}/arpa
206 ${MKDIR} ${INCDIR}/libkern
207 ${MKDIR} ${INCDIR}/malloc
208 ${MKDIR} ${INCDIR}/protocols
209 ${MKDIR} ${INCDIR}/secure
210 ${MKDIR} ${INCDIR}/sys
211 ${MKDIR} ${INCDIR}/xlocale
212 ${MKDIR} ${INCDIR}/_types
213 ${INSTALL} -m ${INSTALLMODE} ${INSTHDRS[@]} ${INCDIR}
214 ${INSTALL} -m ${INSTALLMODE} ${ARPA_INSTHDRS[@]} ${INCDIR}/arpa
215 if [ "x${FEATURE_MEM_NOTIFICATION_APIS}" == "x1" ]; then
216 ${INSTALL} -m ${INSTALLMODE} ${MEM_INSTHDRS[@]} ${INCDIR}/libkern
217 fi
218 if [ "x${FEATURE_THERM_NOTIFICATION_APIS}" == "x1" ]; then
219 ${INSTALL} -m ${INSTALLMODE} ${THERM_INSTHDRS[@]} ${INCDIR}/libkern
220 fi
221 ${INSTALL} -m ${INSTALLMODE} ${PROTO_INSTHDRS[@]} ${INCDIR}/protocols
222 ${INSTALL} -m ${INSTALLMODE} ${SECURE_INSTHDRS[@]} ${INCDIR}/secure
223 ${INSTALL} -m ${INSTALLMODE} ${SYS_INSTHDRS[@]} ${INCDIR}/sys
224 ${INSTALL} -m ${INSTALLMODE} ${XLOCALE_INSTHDRS[@]} ${INCDIR}/xlocale
225 ${INSTALL} -m ${INSTALLMODE} ${TYPES_INSTHDRS[@]} ${INCDIR}/_types
226 ${MKDIR} ${LOCINCDIR}
227 ${MKDIR} ${LOCINCDIR}/os
228 ${INSTALL} -m ${INSTALLMODE} ${LOCALHDRS[@]} ${LOCINCDIR}
229 ${INSTALL} -m ${INSTALLMODE} ${OS_LOCALHDRS[@]} ${LOCINCDIR}/os
230 ${MKDIR} ${PRIVHDRS}/btree
231 ${MKDIR} ${PRIVHDRS}/machine
232 ${MKDIR} ${PRIVHDRS}/uuid
233 ${MKDIR} ${PRIVHDRS}/sys
234 ${MKDIR} ${PRIVKERNELHDRS}/uuid
235 ${INSTALL} -m ${INSTALLMODE} ${PRIV_INSTHDRS[@]} ${PRIVHDRS}
236 ${INSTALL} -m ${INSTALLMODE} ${PRIV_BTREEHDRS[@]} ${PRIVHDRS}/btree
237 ${MV} ${INCDIR}/asm.h ${PRIVHDRS}/machine
238 ${INSTALL} -m ${INSTALLMODE} ${SYS_INSTHDRS[@]} ${PRIVHDRS}/sys
239 ${INSTALL} -m ${INSTALLMODE} ${PRIVUUID_INSTHDRS[@]} ${PRIVHDRS}/uuid
240 ${INSTALL} -m ${INSTALLMODE} ${PRIVUUID_INSTHDRS[@]} ${PRIVKERNELHDRS}/uuid
241
242 for i in `${FIND} "${DSTROOT}" -name \*.h -print0 | ${XARGS} -0 ${GREP} -l '^//Begin-Libc'`; do
243 ${CHMOD} u+w $i &&
244 ${ECHO} ${ED} - $i \< ${SRCROOT}/xcodescripts/strip-header.ed &&
245 ${ED} - $i < ${SRCROOT}/xcodescripts/strip-header.ed &&
246 ${CHMOD} u-w $i || exit 1;
247 done
248 for i in `${FIND} "${DSTROOT}" -name \*.h -print0 | ${XARGS} -0 ${FGREP} -l -e UNIFDEF -e OPEN_SOURCE`; do
249 ${CHMOD} u+w $i &&
250 ${CP} $i $i.orig &&
251 ${ECHO} ${UNIFDEF} ${UNIFDEFARGS} $i.orig \> $i &&
252 { ${UNIFDEF} ${UNIFDEFARGS} $i.orig > $i || [ $? -ne 2 ]; } &&
253 ${RM} $i.orig &&
254 ${CHMOD} u-w $i || exit 1;
255 done
256
257 exit 0