]> git.saurik.com Git - apple/libsystem.git/blame - xcodescripts/linker_arguments.sh
Libsystem-1292.100.5.tar.gz
[apple/libsystem.git] / xcodescripts / linker_arguments.sh
CommitLineData
2fbbb8fa 1#!/bin/bash -x
bdffa7b9
A
2
3if [ $# -ne 5 ]; then
4 echo "Usage: $0 <archs> <variants> <outputdir> <sdkroot> <srcroot>" 1>&2
5 exit 1
6fi
7
b8ce8438
A
8shopt -s nullglob
9
bdffa7b9
A
10ARCHS="$1"
11VARIANTS="$2"
12OUTPUTDIR="$3"
13SDKROOT="$4"
14SRCROOT="$5"
15
b8ce8438
A
16LIBSYS="${SDKROOT}/${SDK_INSTALL_ROOT}/usr/local/lib/system"
17LSYS="${SDKROOT}/${SDK_INSTALL_ROOT}/usr/lib/system"
bdffa7b9
A
18
19mkdir -p "${OUTPUTDIR}"
20
21for arch in ${ARCHS}; do
22 for variant in ${VARIANTS}; do
23 OUTPUTFILE="${OUTPUTDIR}/linker_arguments.${arch}.${variant}.txt"
2fbbb8fa 24 OUTPUTCONFIG="${OUTPUTDIR}/config.${arch}.${variant}.h"
bdffa7b9
A
25 TEMPDIR="${OUTPUTDIR}/linker_arguments_tmp"
26
b8ce8438
A
27 SDK_INSTALL_VARIANT="${DRIVERKIT:+_driverkit}"
28
3186893e
A
29 # Unwinding i386 dependencies.
30 # there are no more "real" uses of i386 Libsystem, only dependency
31 # cycles from within the umbrella (plus libobjc and libc++).
32 # We will remove non-critical dylibs (that have no real dependents
33 # anymore) from the umbrella to decrease the overall size of the
34 # i386 umbrella.
35 # (Note that there is no i386 driverkit so this does not conflict
36 # with the preceding rule)
37 if [ "$arch" = "i386" ]; then
38 SDK_INSTALL_VARIANT="_i386"
39 fi
40
bdffa7b9
A
41 mkdir -p "${TEMPDIR}"
42
43 ACTUALLIBS="${TEMPDIR}/${arch}.${variant}.actuallibs"
44 ALLLIBS="${TEMPDIR}/${arch}.${variant}.alllibs"
45 FROMUSRLIBSYSTEM="${TEMPDIR}/${arch}.${variant}.fromusrlibsystem"
46 FROMUSRLOCALLIBSYSTEM="${TEMPDIR}/${arch}.${variant}.fromusrlocallibsystem"
47 INUSRLIBSYSTEM="${TEMPDIR}/${arch}.${variant}.inusrlibsystem"
48 INUSRLOCALLIBSYSTEM="${TEMPDIR}/${arch}.${variant}.inusrlocallibsystem"
49 MISSINGLIBS="${TEMPDIR}/${arch}.${variant}.missinglibs"
50 POSSIBLEUSRLOCALLIBSYSTEM="${TEMPDIR}/${arch}.${variant}.possibleusrlocallibsystem"
b8ce8438
A
51 OPTIONALLIBS="${SRCROOT}/optionallibs${SDK_INSTALL_VARIANT}"
52 REQUIREDLIBS="${SRCROOT}/requiredlibs${SDK_INSTALL_VARIANT}"
bdffa7b9
A
53
54 if [ ${variant} = "normal" ]; then
55 SUFFIX=""
56 else
57 SUFFIX="_${variant}"
58 fi
59
60 rm -f "${OUTPUTFILE}"
61
62 cat ${REQUIREDLIBS} ${OPTIONALLIBS} | sort > ${ALLLIBS}
63
64 # Strip away variant information to do presence checks
65 # non-normal variants can always link against normal clients
706576d5
A
66 cd ${LSYS} && ls lib*.{dylib,tbd,api,spi} | sed -E -e 's/_(debug|profile|static)\././' | while read l; do
67 if [ "${l: -6}" == ".dylib" ]; then
68 xcrun -sdk "${SDKROOT}" lipo "${LSYS}/${l}" -verify_arch "${arch}" 2>/dev/null
69 else
70 xcrun -sdk "${SDKROOT}" tapi archive "${LSYS}/${l}" --verify-arch "${arch}" 2>/dev/null
71 fi
72 if [ $? -eq 0 ]; then
73 echo "${l}"
74 fi
bdffa7b9 75 done | sed -E -e 's/^lib//' -e 's/\..*$$//' | sort -u > ${INUSRLIBSYSTEM}
b8ce8438 76 [ -d ${LIBSYS} ] && cd ${LIBSYS} && ls lib*.a | sed -E -e 's/_(debug|profile|static)\././' | while read l; do
bdffa7b9
A
77 xcrun -sdk "${SDKROOT}" lipo "${LIBSYS}/${l}" -verify_arch "${arch}" 2>/dev/null
78 if [ $? -eq 0 ]; then
79 echo "${l}"
80 fi
81 done | sed -E -e 's/^lib//' -e 's/\..*$$//' | sort -u > ${INUSRLOCALLIBSYSTEM}
2fbbb8fa
A
82
83 while read line ; do
84 for lib in ${line} ; do
85 egrep "^${lib}$" ${INUSRLIBSYSTEM} && break
86 done
87 done < ${ALLLIBS} > ${FROMUSRLIBSYSTEM}
88
89 while read line ; do
90 for lib in ${line} ; do
706576d5 91 egrep -q "^${lib}$" ${INUSRLIBSYSTEM} && break
2fbbb8fa
A
92 egrep "^${lib}$" ${INUSRLOCALLIBSYSTEM} && break
93 done
94 done < ${ALLLIBS} > ${POSSIBLEUSRLOCALLIBSYSTEM}
95
bdffa7b9
A
96 comm -13 ${FROMUSRLIBSYSTEM} ${POSSIBLEUSRLOCALLIBSYSTEM} > ${FROMUSRLOCALLIBSYSTEM}
97 cat ${FROMUSRLIBSYSTEM} ${FROMUSRLOCALLIBSYSTEM} | sort > ${ACTUALLIBS}
2fbbb8fa
A
98
99 while read line ; do
100 found=0
101 for lib in ${line} ; do
102 egrep -q "^${lib}$" ${ACTUALLIBS} && found=1
103 done
104 [[ $found == 0 ]] && echo ${line}
105 done < ${REQUIREDLIBS} > ${MISSINGLIBS}
bdffa7b9
A
106
107 if [ -s ${MISSINGLIBS} ]; then
108 echo '*** missing required libs ***'
109 cat ${MISSINGLIBS}
110 exit 1
111 fi
112
2fbbb8fa
A
113 cat ${FROMUSRLIBSYSTEM} | while read lib; do
114 echo "#define HAVE_"$(echo "${lib/_sim/}" | tr 'a-z' 'A-Z')" 1"
115 done >> "${OUTPUTCONFIG}"
116
bdffa7b9
A
117 cat ${FROMUSRLIBSYSTEM} | while read lib; do
118 echo "-Wl,-reexport-l${lib}"
119 done >> "${OUTPUTFILE}"
120
121 # Allow static archives to degrade to their non-variant versions
122 cat ${FROMUSRLOCALLIBSYSTEM} | while read lib; do
123 LPATH="${LIBSYS}/lib${lib}${SUFFIX}.a"
124 xcrun -sdk "${SDKROOT}" lipo "${LPATH}" -verify_arch "${arch}" 2>/dev/null
125 if [ $? -ne 0 ]; then
126 LPATH="${LIBSYS}/lib${lib}.a"
127 fi
128 echo "-Wl,-force_load,${LPATH}"
129 done >> "${OUTPUTFILE}"
130
131 echo "Final contents of ${OUTPUTFILE}:"
132 cat "${OUTPUTFILE}"
133 done
134done
135
136MARKERFILE="${OUTPUTDIR}/linker_arguments_changed.c"
137
138for arch in ${ARCHS}; do
139 for variant in ${VARIANTS}; do
140 OUTPUTFILE="${OUTPUTDIR}/linker_arguments.${arch}.${variant}.txt"
141 cat "${OUTPUTFILE}"
142 done
143done | shasum | sed 's,^,// ,' > "${MARKERFILE}"
144
145exit 0