]>
Commit | Line | Data |
---|---|---|
2fbbb8fa | 1 | #!/bin/bash -x |
bdffa7b9 A |
2 | |
3 | if [ $# -ne 5 ]; then | |
4 | echo "Usage: $0 <archs> <variants> <outputdir> <sdkroot> <srcroot>" 1>&2 | |
5 | exit 1 | |
6 | fi | |
7 | ||
b8ce8438 A |
8 | shopt -s nullglob |
9 | ||
bdffa7b9 A |
10 | ARCHS="$1" |
11 | VARIANTS="$2" | |
12 | OUTPUTDIR="$3" | |
13 | SDKROOT="$4" | |
14 | SRCROOT="$5" | |
15 | ||
b8ce8438 A |
16 | LIBSYS="${SDKROOT}/${SDK_INSTALL_ROOT}/usr/local/lib/system" |
17 | LSYS="${SDKROOT}/${SDK_INSTALL_ROOT}/usr/lib/system" | |
bdffa7b9 A |
18 | |
19 | mkdir -p "${OUTPUTDIR}" | |
20 | ||
21 | for 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 | ||
bdffa7b9 A |
29 | mkdir -p "${TEMPDIR}" |
30 | ||
31 | ACTUALLIBS="${TEMPDIR}/${arch}.${variant}.actuallibs" | |
32 | ALLLIBS="${TEMPDIR}/${arch}.${variant}.alllibs" | |
33 | FROMUSRLIBSYSTEM="${TEMPDIR}/${arch}.${variant}.fromusrlibsystem" | |
34 | FROMUSRLOCALLIBSYSTEM="${TEMPDIR}/${arch}.${variant}.fromusrlocallibsystem" | |
35 | INUSRLIBSYSTEM="${TEMPDIR}/${arch}.${variant}.inusrlibsystem" | |
36 | INUSRLOCALLIBSYSTEM="${TEMPDIR}/${arch}.${variant}.inusrlocallibsystem" | |
37 | MISSINGLIBS="${TEMPDIR}/${arch}.${variant}.missinglibs" | |
38 | POSSIBLEUSRLOCALLIBSYSTEM="${TEMPDIR}/${arch}.${variant}.possibleusrlocallibsystem" | |
b8ce8438 A |
39 | OPTIONALLIBS="${SRCROOT}/optionallibs${SDK_INSTALL_VARIANT}" |
40 | REQUIREDLIBS="${SRCROOT}/requiredlibs${SDK_INSTALL_VARIANT}" | |
bdffa7b9 A |
41 | |
42 | if [ ${variant} = "normal" ]; then | |
43 | SUFFIX="" | |
44 | else | |
45 | SUFFIX="_${variant}" | |
46 | fi | |
47 | ||
48 | rm -f "${OUTPUTFILE}" | |
49 | ||
50 | cat ${REQUIREDLIBS} ${OPTIONALLIBS} | sort > ${ALLLIBS} | |
51 | ||
52 | # Strip away variant information to do presence checks | |
53 | # non-normal variants can always link against normal clients | |
706576d5 A |
54 | cd ${LSYS} && ls lib*.{dylib,tbd,api,spi} | sed -E -e 's/_(debug|profile|static)\././' | while read l; do |
55 | if [ "${l: -6}" == ".dylib" ]; then | |
56 | xcrun -sdk "${SDKROOT}" lipo "${LSYS}/${l}" -verify_arch "${arch}" 2>/dev/null | |
57 | else | |
58 | xcrun -sdk "${SDKROOT}" tapi archive "${LSYS}/${l}" --verify-arch "${arch}" 2>/dev/null | |
59 | fi | |
60 | if [ $? -eq 0 ]; then | |
61 | echo "${l}" | |
62 | fi | |
bdffa7b9 | 63 | done | sed -E -e 's/^lib//' -e 's/\..*$$//' | sort -u > ${INUSRLIBSYSTEM} |
b8ce8438 | 64 | [ -d ${LIBSYS} ] && cd ${LIBSYS} && ls lib*.a | sed -E -e 's/_(debug|profile|static)\././' | while read l; do |
bdffa7b9 A |
65 | xcrun -sdk "${SDKROOT}" lipo "${LIBSYS}/${l}" -verify_arch "${arch}" 2>/dev/null |
66 | if [ $? -eq 0 ]; then | |
67 | echo "${l}" | |
68 | fi | |
69 | done | sed -E -e 's/^lib//' -e 's/\..*$$//' | sort -u > ${INUSRLOCALLIBSYSTEM} | |
2fbbb8fa A |
70 | |
71 | while read line ; do | |
72 | for lib in ${line} ; do | |
73 | egrep "^${lib}$" ${INUSRLIBSYSTEM} && break | |
74 | done | |
75 | done < ${ALLLIBS} > ${FROMUSRLIBSYSTEM} | |
76 | ||
77 | while read line ; do | |
78 | for lib in ${line} ; do | |
706576d5 | 79 | egrep -q "^${lib}$" ${INUSRLIBSYSTEM} && break |
2fbbb8fa A |
80 | egrep "^${lib}$" ${INUSRLOCALLIBSYSTEM} && break |
81 | done | |
82 | done < ${ALLLIBS} > ${POSSIBLEUSRLOCALLIBSYSTEM} | |
83 | ||
bdffa7b9 A |
84 | comm -13 ${FROMUSRLIBSYSTEM} ${POSSIBLEUSRLOCALLIBSYSTEM} > ${FROMUSRLOCALLIBSYSTEM} |
85 | cat ${FROMUSRLIBSYSTEM} ${FROMUSRLOCALLIBSYSTEM} | sort > ${ACTUALLIBS} | |
2fbbb8fa A |
86 | |
87 | while read line ; do | |
88 | found=0 | |
89 | for lib in ${line} ; do | |
90 | egrep -q "^${lib}$" ${ACTUALLIBS} && found=1 | |
91 | done | |
92 | [[ $found == 0 ]] && echo ${line} | |
93 | done < ${REQUIREDLIBS} > ${MISSINGLIBS} | |
bdffa7b9 A |
94 | |
95 | if [ -s ${MISSINGLIBS} ]; then | |
96 | echo '*** missing required libs ***' | |
97 | cat ${MISSINGLIBS} | |
98 | exit 1 | |
99 | fi | |
100 | ||
2fbbb8fa A |
101 | cat ${FROMUSRLIBSYSTEM} | while read lib; do |
102 | echo "#define HAVE_"$(echo "${lib/_sim/}" | tr 'a-z' 'A-Z')" 1" | |
103 | done >> "${OUTPUTCONFIG}" | |
104 | ||
bdffa7b9 A |
105 | cat ${FROMUSRLIBSYSTEM} | while read lib; do |
106 | echo "-Wl,-reexport-l${lib}" | |
107 | done >> "${OUTPUTFILE}" | |
108 | ||
109 | # Allow static archives to degrade to their non-variant versions | |
110 | cat ${FROMUSRLOCALLIBSYSTEM} | while read lib; do | |
111 | LPATH="${LIBSYS}/lib${lib}${SUFFIX}.a" | |
112 | xcrun -sdk "${SDKROOT}" lipo "${LPATH}" -verify_arch "${arch}" 2>/dev/null | |
113 | if [ $? -ne 0 ]; then | |
114 | LPATH="${LIBSYS}/lib${lib}.a" | |
115 | fi | |
116 | echo "-Wl,-force_load,${LPATH}" | |
117 | done >> "${OUTPUTFILE}" | |
118 | ||
119 | echo "Final contents of ${OUTPUTFILE}:" | |
120 | cat "${OUTPUTFILE}" | |
121 | done | |
122 | done | |
123 | ||
124 | MARKERFILE="${OUTPUTDIR}/linker_arguments_changed.c" | |
125 | ||
126 | for arch in ${ARCHS}; do | |
127 | for variant in ${VARIANTS}; do | |
128 | OUTPUTFILE="${OUTPUTDIR}/linker_arguments.${arch}.${variant}.txt" | |
129 | cat "${OUTPUTFILE}" | |
130 | done | |
131 | done | shasum | sed 's,^,// ,' > "${MARKERFILE}" | |
132 | ||
133 | exit 0 |