]> Git Repo - uclibc-ng.git/blobdiff - libc/Makefile
Backport handling of AS_NEEDED
[uclibc-ng.git] / libc / Makefile
index e46b633b735faf3bbec61c2af10c6323b39a19c0..d27990665f51da25875da9d963f4b738496c3e78 100644 (file)
 TOPDIR=../
 include $(TOPDIR)Rules.mak
 
-ifeq ($(strip $(UCLIBC_CTOR_DTOR)),y)
-CRTOBJS=../../lib/crti.o ../../lib/crt0.o ../../lib/crtn.o
-else
-CRTOBJS=../../lib/crt0.o
-endif
-
 DIRS = misc pwd_grp stdio string termios inet signal stdlib sysdeps unistd
 
 # Check if the target architecture has a version script for
@@ -43,39 +37,76 @@ DIRS = misc pwd_grp stdio string termios inet signal stdlib sysdeps unistd
 VERSION_SCRIPT:=${shell if [ -f sysdeps/linux/$(TARGET_ARCH)/libc.map ] ; then \
         echo "--version-script sysdeps/linux/$(TARGET_ARCH)/libc.map"; fi}
 
-all: halfclean subdirs $(LIBNAME) $(DO_SHARED)
-
-ar-target:
-       $(CROSS)ranlib $(LIBNAME)
-       $(INSTALL) -d $(TOPDIR)lib
-       $(RM) $(TOPDIR)lib/$(LIBNAME)
-       $(INSTALL) -m 644 $(LIBNAME) $(TOPDIR)lib
-
-$(LIBNAME): subdirs ar-target
+# we have SHARED_MAJORNAME=libc.so.$(MAJOR_VERSION) defined in Rules.mak
+LIB_NAME := libc
+AR_LIB_NAME := $(TOPDIR)lib/$(LIB_NAME).a
+SO_LIB_NAME = $(TOPDIR)lib/$(LIB_NAME).so
+SO_FULL_NAME = libuClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so
 
+ifeq ($(HAVE_SHARED),y)
+all: $(SO_LIB_NAME)
+else
+all: $(AR_LIB_NAME)
+endif
 
-shared: $(TOPDIR)lib/$(LIBNAME)
-       $(LD) $(LDFLAGS) $(VERSION_SCRIPT) -soname=$(SHARED_MAJORNAME) -o $(SHARED_FULLNAME) \
-               --whole-archive $(LIBNAME) \
-               $(TOPDIR)libc/misc/internals/interp.o --no-whole-archive \
-               -init __uClibc_init
-       @true #$(RM) -r tmp
+# Some functions are duplicated across subdirs, and when you pass $(AR)
+# the same object file more than once, it'll add it to the archive multiple 
+# times (boo!).  So what we do here is:
+#  - import all the objects (thus we may have dupes)
+#  - delete all the dupes
+#  - re-import certain objects based upon preference
+#    - the sysdeps dir should override all other symbols for example
+# We need to use shell globbing with obj.* because if we use make's wildcard,
+# the wildcard will be evaluated when `make` is run instead of when the make 
+# target is evaluated.  That means if you run `rm obj.* ; make`, the wildcard 
+# will evaluate to no files :(.
+shared_$(LIB_NAME).a: subdirs
+       $(RM) $@
+       objs=`cat obj.*` ; \
+       $(AR) $(ARFLAGS) $@ $$objs && \
+       $(AR) dN 2 $@ $$objs && \
+       $(AR) dN 2 $@ $$objs
+       @for objfile in obj.signal \
+                       obj.string.generic obj.string.$(TARGET_ARCH) obj.string \
+                       obj.sysdeps.common obj.sysdeps.$(TARGET_ARCH) ; do \
+               if [ -e $$objfile ] ; then \
+                       if [ "$(MAKE_IS_SILENT)" = "n" ] ; then \
+                               echo $(AR) $(ARFLAGS) $@ $$objfile ; \
+                       fi ; \
+                       objs=`cat $$objfile` ; \
+               fi ; \
+               $(AR) $(ARFLAGS) $@ $$objs || exit 1 ; \
+       done
+
+$(AR_LIB_NAME): shared_$(LIB_NAME).a
        $(INSTALL) -d $(TOPDIR)lib
-       $(RM) $(TOPDIR)lib/$(SHARED_FULLNAME)
-       $(INSTALL) -m 644 $(SHARED_FULLNAME) $(TOPDIR)lib
-       $(LN) -sf $(SHARED_FULLNAME) $(TOPDIR)lib/libc.so
-       $(LN) -sf $(SHARED_FULLNAME) $(TOPDIR)lib/$(SHARED_MAJORNAME)
-
-halfclean:
-       @$(RM) $(LIBNAME) uClibc_config.h
-       @$(RM) $(SHARED_FULLNAME) $(SHARED_MAJORNAME) uClibc-0.* libc.so*
+       $(RM) $@
+       cp $< $@
+       $(AR) $(ARFLAGS) $@ misc/internals/static.o `cat nonshared_obj.*`
+
+$(SO_LIB_NAME): $(AR_LIB_NAME)
+       $(RM) $(TOPDIR)lib/$(SO_FULL_NAME) $(TOPDIR)lib/$(SHARED_MAJORNAME) $@
+       $(LD) $(LDFLAGS) $(VERSION_SCRIPT) -soname=$(SHARED_MAJORNAME) \
+               -o $(TOPDIR)lib/$(SO_FULL_NAME) --whole-archive shared_$(LIB_NAME).a \
+               --no-whole-archive $(TOPDIR)libc/misc/internals/interp.o \
+               -init __uClibc_init $(TOPDIR)lib/$(UCLIBC_LDSO) $(LDADD_LIBFLOAT) $(LIBGCC)
+       $(LN) -sf $(SO_FULL_NAME) $(TOPDIR)lib/$(SHARED_MAJORNAME)
+       $(RM) $(TOPDIR)lib/$(NONSHARED_LIBNAME)
+       $(AR) $(ARFLAGS) $(TOPDIR)lib/$(NONSHARED_LIBNAME) `cat nonshared_obj.*`
+       echo "/* GNU ld script" > $@
+       echo " * Use the shared library, but some functions are only in" >> $@
+       echo " * the static library, so try that secondarily. */" >> $@
+ifeq ($(COMPAT_ATEXIT),y)
+       echo "GROUP ( $(NONSHARED_LIBNAME) $(SHARED_MAJORNAME) $(ASNEEDED) )" >> $@
+else
+       echo "GROUP ( $(SHARED_MAJORNAME) $(NONSHARED_LIBNAME) $(ASNEEDED) )" >> $@
+endif
 
 tags:
        ctags -R
 
-clean: subdirs_clean halfclean
-       @$(RM) -r tmp
-       $(RM) include/asm include/linux include/bits
+clean: subdirs_clean
+       $(RM) *.a obj.* nonshared_obj.*
 
 subdirs: $(patsubst %, _dir_%, $(DIRS))
 subdirs_clean: $(patsubst %, _dirclean_%, $(DIRS))
@@ -87,4 +118,3 @@ $(patsubst %, _dirclean_%, $(DIRS)) : dummy
        $(MAKE) -C $(patsubst _dirclean_%, %, $@) clean
 
 .PHONY: dummy subdirs
-
This page took 0.027512 seconds and 4 git commands to generate.