6 printf "%s\n" "Output of:" >$EXE.out
7 printf "%s\n" "$*" >>$EXE.out
8 printf "%s\n" "==========" >>$EXE.out
9 $debug && echo "Trying: $*"
23 # Sanitize lib list (dups, extra spaces etc)
24 LDLIBS=`echo "$LDLIBS" | xargs -n1 | sort | uniq | xargs`
26 # First link with all libs. If it fails, bail out
27 echo "Trying libraries: $LDLIBS"
28 # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
29 l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
30 test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
32 -o $EXE -Wl,-Map -Wl,$EXE.map \
33 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
34 -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
38 echo "Failed: $* $l_list"
43 # Now try to remove each lib and build without it.
44 # Stop when no lib can be removed.
45 while test "$LDLIBS"; do
46 $debug && echo "Trying libraries: $LDLIBS"
48 for one in $LDLIBS; do
49 without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs`
50 # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
51 l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
52 test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
53 $debug && echo "Trying -l options: '$l_list'"
55 -o $EXE -Wl,-Map -Wl,$EXE.map \
56 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
57 -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
61 echo "Library $one is not needed"
65 echo "Library $one is needed"
68 # All libs were needed, can't remove any
70 # If there is no space char, the list has just one lib.
71 # I'm not sure that in this case lib really is 100% needed.
72 # Let's try linking without it anyway... thus commented out.
73 #{ echo "$LDLIBS" | grep -q ' '; } || break
76 # Make the binary with final, minimal list of libs
77 echo "Final link with: $LDLIBS"
78 l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
79 test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group -Wl,--verbose"
80 # --verbose gives us gobs of info to stdout (e.g. linker script used)
81 if ! test -f busybox_ldscript; then
83 -o $EXE -Wl,-Map -Wl,$EXE.map \
84 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
85 -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
86 $l_list -Wl,--verbose \
89 echo "Custom linker script 'busybox_ldscript' found, using it"
90 # Add SORT_BY_ALIGNMENT to linker script (found in $EXE.out):
91 # .rodata : { *(.rodata SORT_BY_ALIGNMENT(.rodata.*) .gnu.linkonce.r.*) }
92 # *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*)
93 # *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*)
94 # This will eliminate most of the padding (~3kb).
96 -o $EXE -Wl,-Map -Wl,$EXE.map \
97 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
98 -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
99 $l_list -Wl,--verbose \
100 -Wl,-T -Wl,busybox_ldscript \
104 mkdir 0lib 2>/dev/null
105 test -d 0lib || exit 1
106 ln -s libbusybox.so.1.8.0 0lib/libbusybox.so 2>/dev/null
108 EXE="0lib/libbusybox.so.1.8.0"
110 -o $EXE -Wl,-Map -Wl,$EXE.map \
111 -shared -fPIC -Wl,--enable-new-dtags \
112 -Wl,--start-group -Wl,--whole-archive $A_FILES -Wl,--no-whole-archive -Wl,--end-group \
113 $l_list -Wl,--verbose \
114 -Wl,-soname="libbusybox.so.1.8.0" \
118 echo "Linking $EXE failed"
121 strip -s --remove-section=.note --remove-section=.comment $EXE
125 -o $EXE -Wl,-Map -Wl,$EXE.map \
126 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
127 -Wl,--start-group $O_FILES -Wl,--end-group \
128 $l_list -Wl,--verbose \
132 echo "Linking $EXE failed"
135 strip -s --remove-section=.note --remove-section=.comment $EXE