6 printf "%s\n" "Output of:" >$EXE.out
7 printf "%s\n" "$*" >>$EXE.out
8 printf "%s\n" "==========" >>$EXE.out
9 $debug && echo "Trying: $*"
22 # Sanitize lib list (dups, extra spaces etc)
23 LDLIBS=`echo "$LDLIBS" | xargs -n1 | sort | uniq | xargs`
25 # First link with all libs. If it fails, bail out
26 echo "Trying libraries: $LDLIBS"
27 # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
28 l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
29 test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
31 -o $EXE -Wl,-Map -Wl,$EXE.map \
32 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
33 -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
36 echo "Failed: $* $l_list"
41 # Now try to remove each lib and build without it.
42 # Stop when no lib can be removed.
43 while test "$LDLIBS"; do
44 $debug && echo "Trying libraries: $LDLIBS"
46 for one in $LDLIBS; do
47 without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs`
48 # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
49 l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
50 test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
51 $debug && echo "Trying -l options: '$l_list'"
53 -o $EXE -Wl,-Map -Wl,$EXE.map \
54 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
55 -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
59 echo "Library $one is not needed"
63 echo "Library $one is needed"
66 # All libs were needed, can't remove any
68 # If there is no space char, the list has just one lib.
69 # I'm not sure that in this case lib really is 100% needed.
70 # Let's try linking without it anyway... thus commented out.
71 #{ echo "$LDLIBS" | grep -q ' '; } || break
74 # Make the binary with final, minimal list of libs
75 echo "Final link with: $LDLIBS"
76 l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
77 test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
78 # --verbose gives us gobs of info to stdout (e.g. linker script used)
79 if ! test -f busybox_ldscript; then
81 -o $EXE -Wl,-Map -Wl,$EXE.map \
82 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
83 -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
84 $l_list -Wl,--verbose \
87 echo "Custom linker script 'busybox_ldscript' found, using it"
88 # Add SORT_BY_ALIGNMENT to linker script (found in $EXE.out):
89 # .rodata : { *(.rodata SORT_BY_ALIGNMENT(.rodata.*) .gnu.linkonce.r.*) }
90 # *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*)
91 # *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*)
92 # This will eliminate most of the padding (~3kb).
94 -o $EXE -Wl,-Map -Wl,$EXE.map \
95 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
96 -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
97 $l_list -Wl,--verbose \
98 -Wl,-T -Wl,busybox_ldscript \
104 sharedlib_dir="0_lib"
106 if test "$CONFIG_BUILD_LIBBUSYBOX" = y; then
107 mkdir "$sharedlib_dir" 2>/dev/null
108 test -d "$sharedlib_dir" || {
109 echo "Cannot make directory $sharedlib_dir"
112 ln -s "libbusybox.so.$BB_VER" "$sharedlib_dir"/libbusybox.so 2>/dev/null
114 EXE="$sharedlib_dir/libbusybox.so.${BB_VER}_unstripped"
116 -o $EXE -Wl,-Map -Wl,$EXE.map \
117 -shared -fPIC -Wl,--enable-new-dtags \
118 -Wl,--start-group -Wl,--whole-archive $A_FILES -Wl,--no-whole-archive -Wl,--end-group \
119 $l_list -Wl,--verbose \
120 -Wl,-soname="libbusybox.so.$BB_VER" \
123 echo "Linking $EXE failed"
127 strip -s --remove-section=.note --remove-section=.comment $EXE -o "$sharedlib_dir/libbusybox.so.$BB_VER"
128 chmod a+x "$sharedlib_dir/libbusybox.so.$BB_VER"
129 echo "libbusybox: $sharedlib_dir/libbusybox.so.$BB_VER"
132 if test "$CONFIG_FEATURE_SHARED_BUSYBOX" = y; then
133 EXE="$sharedlib_dir/busybox_unstripped"
135 -o $EXE -Wl,-Map -Wl,$EXE.map \
136 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
137 -Wl,--start-group $O_FILES -Wl,--end-group \
139 -L"$sharedlib_dir" -lbusybox \
141 echo "Linking $EXE failed"
145 strip -s --remove-section=.note --remove-section=.comment $EXE -o "$sharedlib_dir/busybox"
146 echo "busybox linked against libbusybox: $sharedlib_dir/busybox"
149 if test "$CONFIG_FEATURE_INDIVIDUAL" = y; then
150 echo "Linking individual applets against libbusybox (see $sharedlib_dir/*)"
151 gcc -DNAME_MAIN_CNAME -E -include include/autoconf.h include/applets.h \
155 while read name main junk; do
158 void bbox_prepare_main(char **argv);
159 int $main(int argc, char **argv);
161 const char *applet_name = \"$name\";
163 int main(int argc, char **argv)
165 bbox_prepare_main(argv);
166 return $main(argc, argv);
168 " >"$sharedlib_dir/applet.c"
170 EXE="$sharedlib_dir/$name"
171 try $CC $LDFLAGS "$sharedlib_dir/applet.c" \
173 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
174 -L"$sharedlib_dir" -lbusybox \
176 echo "Linking $EXE failed"
180 rm -- "$sharedlib_dir/applet.c" $EXE.out
181 strip -s --remove-section=.note --remove-section=.comment $EXE
186 # libbusybox.so is needed only for -lbusybox at link time,
187 # it is not needed at runtime. Deleting to reduce confusion.
188 rm "$sharedlib_dir"/libbusybox.so 2>/dev/null
189 exit 0 # or else we may confuse make