[patch] build shared library

Bernhard Fischer rep.nop at aon.at
Wed Sep 7 19:11:17 UTC 2005


On Tue, Sep 06, 2005 at 11:56:55PM -0500, Rob Landley wrote:
>On Tuesday 06 September 2005 07:48, Allan Clark wrote:

>> It sould be simple to convert a list of files to a makefile using some
>> kind of awk, piping that to "make -f -", but it would save little over
>> using a makefile that called out specific targets.
>
>I've fiddled with building lots of stuff.  Maybe half the applets can be built 
>using just one file (whatever the *.c file is for that applet name).
>
>The next largest set of low hanging fruit is applets that need to link with 
>things like "libcoreutils", which really should be consolidated with libbb.  

Something like the attached?
Note that you will need to 'make libbusybox.so' since $(libraries-m) is
currently empty to not harm innocent third parties which just invoke
make.
There y number of duplicate symbols in libunarchive exposed by this
which ought to be fixed regardless of that patch in this varian to go in
or not.

I urge anyone interrested in trying it out and fixing libunarchive.


>I really don't see much point in having "locally" shared code; it's either 
>shared or it isn't shared.  (We can always prefix the filenames with 
>coreutils_ if it makes people feel better. :)
>
>Some things need other libraries; miscutils/dc.c needs "-lm", for example.

That's what i ment with $($(APPLET)-libs):
in miscutils/Makefile.in do:
MISCUTILS-y-libs:=#for the builtin applets
MISCUTILS-m-libs:=#for standalone applets
MISCUTILS-$(CONFIG_DC)-libs+=-lm

and then, instead of these lines:
$(MISCUTILS_DIR)$(MISCUTILS_AR): $(patsubst %,$(MISCUTILS_DIR)%, $(MISCUTILS-y))
        $(AR) $(ARFLAGS) $@ $(patsubst %,$(MISCUTILS_DIR)%, $(MISCUTILS-y))

say:
$(MISCUTILS_DIR)$(MISCUTILS_AR): $(patsubst %,$(MISCUTILS_DIR)%, $(MISCUTILS-y))
        $(AR) $(ARFLAGS) $@ $^ $(MISCUTILS-y-libs)


>
>If there are any applets that actually need two .c files, then either another 
>applet needs one of those .c files (so it can go in libbb), or else the 
>two .c files should probably be consolidated.  (Anybody complaining about 
>this making a .c file too long should either A) try to shrink it, B) look at 
>"ash.c" until they get a sense of perspective.)
>
>By the way, probably the worst case scenario for a standalone build is 
>"ash.c".  This doesn't come close to building standalone; spits out a ton of 
>unintelligible errors, and after about half an hour of reading through it I 
>had to go lie down.
tried that and got a headache too. hmz.
>
>P.S.  part of the reason I've dredged standalone back up and put more work 
>into it recently is it lets us close bug 18. :)

For this to work, we need to check at least if the preprocessor is
satisfied, i.e. provide fallbacks for {,UN}RESERVE_CONFIG_BUFFER. If
it's acceptable to link against abovementioned libbusybox.so, then we
need to provide the definitions for the functions exposed by libbusybox
(e.g. xmalloc to name just one).


-------------- next part --------------
diff -X excl -rduNp busybox.so.oorig/applets/install.sh busybox.so/applets/install.sh
--- busybox.so.oorig/applets/install.sh	2005-09-02 13:35:48.000000000 +0200
+++ busybox.so/applets/install.sh	2005-09-07 15:46:00.116743019 +0200
@@ -4,7 +4,8 @@ export LC_ALL=POSIX
 export LC_CTYPE=POSIX
 
 prefix=$1
-if [ "$prefix" = "" ]; then
+# Some versions of [ can't deal with empty strings for the '=' operation
+if [ "x$prefix" = "x" ]; then
     echo "No installation directory, aborting."
     exit 1;
 fi
@@ -15,10 +16,20 @@ else
 fi
 h=`sort busybox.links | uniq`
 
+# get the target dir for the libs; This is an incomplete/incorrect list for now
+case $(uname -m) in
+x86_64|ppc64*|sparc64*|ia64*|hppa*64*) libdir=/lib64 ;;
+*) libdir=/lib ;;
+esac
 
 rm -f $prefix/bin/busybox || exit 1
 mkdir -p $prefix/bin || exit 1
+mkdir -p $prefix/$libdir || exit 1
 install -m 755 busybox $prefix/bin/busybox || exit 1
+for i in libbusybox.so*
+do
+	[ -f $i ] && install -m 644 $i $prefix/$libdir/
+done
 
 for i in $h ; do
 	appdir=`dirname $i`
diff -X excl -rduNp busybox.so.oorig/Makefile busybox.so/Makefile
--- busybox.so.oorig/Makefile	2005-09-02 13:35:51.000000000 +0200
+++ busybox.so/Makefile	2005-09-07 15:46:00.117742888 +0200
@@ -110,7 +110,7 @@ _all: all
 
 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
 
-all: busybox busybox.links doc
+all: busybox busybox.links $(libraries-m) doc
 
 all_tree:	$(ALL_MAKEFILES)
 
@@ -233,6 +233,30 @@ finished2:
 	$(SECHO) Finished installing...
 	$(SECHO)
 
+
+ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
+libraries-m:=libbusybox.so
+LIBRARIES+= -lc -lcrypt
+endif
+
+
+libbusybox-obj:=archival/libunarchive/libunarchive.a \
+networking/libiproute/libiproute.a libpwdgrp/libpwdgrp.a \
+coreutils/libcoreutils/libcoreutils.a libbb/libbb.a
+
+libbusybox-obj-dirs:=-L./archival/libunarchive -L./networking/libiproute \
+-L./libpwdgrp -L./coreutils/libcoreutils -L./libbb
+
+
+libbusybox-soname:=libbusybox.so.1.0.0
+libbusybox.so: $(libbusybox-obj)
+	$(CC) $(CFLAGS) -Wl,-soname=$(libbusybox-soname) \
+	-Wl,--enable-new-dtags -Wl,--reduce-memory-overheads -Wl,-z,combreloc \
+	-Wl,-shared -Wl,--as-needed -o $@ \
+	-Wl,--whole-archive -Wl,--start-group $^ $(LIBRARIES) \
+	-Wl,--end-group -Wl,--no-whole-archive
+	ln -s $@ $(libbusybox-soname)
+
 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
 
 all: menuconfig
@@ -289,6 +313,7 @@ clean:
 	- find . -name .\*.flags -exec rm -f {} \;
 	- find . -name \*.o -exec rm -f {} \;
 	- find . -name \*.a -exec rm -f {} \;
+	- find . -name \*.so -exec rm -f {} \;
 
 distclean: clean
 	- rm -f scripts/split-include scripts/mkdep
diff -X excl -rduNp busybox.so.oorig/Rules.mak busybox.so/Rules.mak
--- busybox.so.oorig/Rules.mak	2005-09-02 13:35:51.000000000 +0200
+++ busybox.so/Rules.mak	2005-09-07 15:46:00.119742627 +0200
@@ -165,15 +165,22 @@ else
 endif
 ifeq ($(strip $(CONFIG_DEBUG)),y)
     CFLAGS  +=$(WARNINGS) -g -D_GNU_SOURCE
-    LDFLAGS +=-Wl,-warn-common
+    LDFLAGS +=-Wl,-warn-common -Wl,--no-undefined-version
     STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging
 else
     CFLAGS+=$(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE -DNDEBUG
-    LDFLAGS += -Wl,-warn-common
-    STRIPCMD:=$(STRIP) -s --remove-section=.note --remove-section=.comment
+    LDFLAGS += -Wl,-warn-common -Wl,--sort-common
+    STRIPCMD:=$(STRIP) -s --remove-section=.note --remove-section=.comment \
+	--remove-section=.version
 endif
 ifeq ($(strip $(CONFIG_STATIC)),y)
     LDFLAGS += --static
+else
+    LIBRARIES += -ldl
+endif
+
+ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
+    CFLAGS += -fPIC
 endif
 
 ifeq ($(strip $(PREFIX)),)
diff -X excl -rduNp busybox.so.oorig/sysdeps/linux/Config.in busybox.so/sysdeps/linux/Config.in
--- busybox.so.oorig/sysdeps/linux/Config.in	2005-09-02 13:35:47.000000000 +0200
+++ busybox.so/sysdeps/linux/Config.in	2005-09-07 15:46:00.121742365 +0200
@@ -164,6 +164,13 @@ config CONFIG_STATIC
 
 	  Most people will leave this set to 'N'.
 
+config CONFIG_BUILD_LIBBUSYBOX
+	bool "Build shared libbusybox"
+	default y
+	help
+	  Build a shared library libbusybox.so which contains all
+	  libraries used inside busybox.
+
 config CONFIG_LFS
 	bool "Build with Large File Support (for accessing files > 2 GB)"
 	default n


More information about the busybox mailing list