aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/trylink17
1 files changed, 12 insertions, 5 deletions
diff --git a/scripts/trylink b/scripts/trylink
index 6b74f092d..2255deee7 100755
--- a/scripts/trylink
+++ b/scripts/trylink
@@ -1,5 +1,6 @@
1#!/bin/sh 1#!/bin/sh
2 2
3#debug=true
3debug=false 4debug=false
4 5
5# Linker flags used: 6# Linker flags used:
@@ -77,7 +78,13 @@ CFLAGS="$3"
77LDFLAGS="$4" 78LDFLAGS="$4"
78O_FILES="$5" 79O_FILES="$5"
79A_FILES="$6" 80A_FILES="$6"
81# We try to drop libraries from LDLIBS if build works without them,
82# but ones from CONFIG_EXTRA_LDLIBS are always linked in.
83# (For example, musl has stub utmp implementation, and if you link with
84# a real utmp library in LDLIBS, dropping it "works" but resulting binary
85# does not work properly).
80LDLIBS="$7" 86LDLIBS="$7"
87CONFIG_EXTRA_LDLIBS="$8"
81 88
82# The --sort-section option is not supported by older versions of ld 89# The --sort-section option is not supported by older versions of ld
83SORT_SECTION="-Wl,--sort-section,alignment" 90SORT_SECTION="-Wl,--sort-section,alignment"
@@ -125,8 +132,8 @@ LDLIBS=`echo "$LDLIBS" | xargs -n1 | sort | uniq | xargs`
125# First link with all libs. If it fails, bail out 132# First link with all libs. If it fails, bail out
126echo "Trying libraries: $LDLIBS" 133echo "Trying libraries: $LDLIBS"
127# "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" 134# "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
128l_list=`echo " $LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g'` 135l_list=`echo " $LDLIBS $CONFIG_EXTRA_LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g' -e 's/^ *//'`
129test "x$l_list" != "x" && l_list="$START_GROUP $l_list $END_GROUP" 136test x"$l_list" != x"" && l_list="$START_GROUP $l_list $END_GROUP"
130try $CC $CFLAGS $LDFLAGS \ 137try $CC $CFLAGS $LDFLAGS \
131 -o $EXE \ 138 -o $EXE \
132 $SORT_COMMON \ 139 $SORT_COMMON \
@@ -151,7 +158,7 @@ while test "$LDLIBS"; do
151 for one in $LDLIBS; do 158 for one in $LDLIBS; do
152 without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs` 159 without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs`
153 # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" 160 # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
154 l_list=`echo " $without_one " | sed -e 's: \([^- ][^ ]*\): -l\1:g'` 161 l_list=`echo " $without_one $CONFIG_EXTRA_LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g' -e 's/^ *//'`
155 test x"$l_list" != x"" && l_list="$START_GROUP $l_list $END_GROUP" 162 test x"$l_list" != x"" && l_list="$START_GROUP $l_list $END_GROUP"
156 $debug && echo "Trying -l options: '$l_list'" 163 $debug && echo "Trying -l options: '$l_list'"
157 try $CC $CFLAGS $LDFLAGS \ 164 try $CC $CFLAGS $LDFLAGS \
@@ -179,8 +186,8 @@ done
179 186
180# Make the binary with final, minimal list of libs 187# Make the binary with final, minimal list of libs
181echo "Final link with: ${LDLIBS:-<none>}" 188echo "Final link with: ${LDLIBS:-<none>}"
182l_list=`echo " $LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g'` 189l_list=`echo " $LDLIBS $CONFIG_EXTRA_LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g' -e 's/^ *//'`
183test "x$l_list" != "x" && l_list="$START_GROUP $l_list $END_GROUP" 190test x"$l_list" != x"" && l_list="$START_GROUP $l_list $END_GROUP"
184# --verbose gives us gobs of info to stdout (e.g. linker script used) 191# --verbose gives us gobs of info to stdout (e.g. linker script used)
185if ! test -f busybox_ldscript; then 192if ! test -f busybox_ldscript; then
186 try $CC $CFLAGS $LDFLAGS \ 193 try $CC $CFLAGS $LDFLAGS \