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