toolchain-external: add support for musl C library
authorThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Tue, 8 Oct 2013 18:17:09 +0000 (20:17 +0200)
committerPeter Korsgaard <peter@korsgaard.com>
Wed, 9 Oct 2013 14:01:25 +0000 (16:01 +0200)
This commit adds support for external toolchains based on the musl C
library, as available from http://www.musl-libc.org.

Note that the pre-built musl toolchains available from
http://musl.codu.org/ are not working for the moment, since they lack
sysroot support. However, this problem has been reported to the
maintainer, who has already added sysroot support in his scripts at
https://bitbucket.org/GregorR/musl-cross, and therefore the next
version of the pre-built toolchains should work with Buildroot
out-of-the-box. In the mean time, the musl-cross script must be used
to build the toolchain.

[Peter: reword comment]
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
toolchain/Config.in
toolchain/helpers.mk
toolchain/toolchain-external/Config.in
toolchain/toolchain-external/toolchain-external.mk

index 0f9a7dd9a4e7a8a5a6c6133f17e59f494c82e23e..3980d790a48bc2c2e3282d7381a8e5087c63f414 100644 (file)
@@ -15,6 +15,15 @@ config BR2_TOOLCHAIN_USES_GLIBC
 config BR2_TOOLCHAIN_USES_UCLIBC
        bool
 
+config BR2_TOOLCHAIN_USES_MUSL
+       bool
+       select BR2_LARGEFILE
+       select BR2_INET_IPV6
+       select BR2_USE_WCHAR
+       select BR2_ENABLE_LOCALE
+       select BR2_TOOLCHAIN_HAS_THREADS
+       select BR2_TOOLCHAIN_HAS_THREADS_DEBUG
+
 choice
        prompt "Toolchain type"
        help
index a4a13c732770008742c747d4c3f77f6f376ce15f..b6fe04c417a513ab190f006f92fb6f68bb2d5b7d 100644 (file)
@@ -208,6 +208,17 @@ check_glibc = \
        $(call check_glibc_feature,BR2_USE_MMU,MMU support) ;\
        $(call check_glibc_rpc_feature,$${SYSROOT_DIR})
 
+#
+# Check that the selected C library really is musl
+#
+# $1: sysroot directory
+check_musl = \
+       SYSROOT_DIR="$(strip $1)"; \
+       if test ! -f $${SYSROOT_DIR}/lib/libc.so -o -e $${SYSROOT_DIR}/lib/libm.so ; then \
+               echo "Incorrect selection of the C library" ; \
+               exit -1; \
+       fi
+
 #
 # Check the conformity of Buildroot configuration with regard to the
 # uClibc configuration of the external toolchain, for a particular
index c53577ef60bce32a8a923c67cd9bd72dd3923128..89c799e3d50b985751315fb3f8e17e93483ec6e6 100644 (file)
@@ -860,6 +860,10 @@ config BR2_TOOLCHAIN_EXTERNAL_UCLIBC
        bool
        select BR2_TOOLCHAIN_USES_UCLIBC
 
+config BR2_TOOLCHAIN_EXTERNAL_MUSL
+       bool
+       select BR2_TOOLCHAIN_USES_MUSL
+
 if BR2_TOOLCHAIN_EXTERNAL_CUSTOM
 
 choice
@@ -882,6 +886,13 @@ config BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC
          eglibc configured to exclude key features may cause build failures to
          some packages.
 
+config BR2_TOOLCHAIN_EXTERNAL_CUSTOM_MUSL
+       bool "musl"
+       select BR2_TOOLCHAIN_EXTERNAL_MUSL
+       help
+         Select this option if your external toolchain uses the
+         'musl' C library, available from http://www.musl-libc.org/.
+
 endchoice
 
 if BR2_TOOLCHAIN_EXTERNAL_CUSTOM_UCLIBC
@@ -952,6 +963,7 @@ endif # BR2_TOOLCHAIN_EXTERNAL_CUSTOM_UCLIBC
 config BR2_TOOLCHAIN_EXTERNAL_INET_RPC
        bool "Toolchain has RPC support?"
        select BR2_TOOLCHAIN_HAS_NATIVE_RPC
+       depends on !BR2_TOOLCHAIN_EXTERNAL_MUSL
        default y if BR2_TOOLCHAIN_EXTERNAL_GLIBC
        help
          Select this option if your external toolchain supports
index 2bfe64a888516c0cd443297cf17473f830ecce4d..b2266b6ac0b7b94368416ad3d0190fa090ae4acd 100644 (file)
@@ -68,6 +68,10 @@ ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
 LIB_EXTERNAL_LIBS+=libnss_files.so.* libnss_dns.so.*
 endif
 
+ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
+LIB_EXTERNAL_LIBS += libc.so libgcc_s.so.*
+endif
+
 ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
 USR_LIB_EXTERNAL_LIBS+=libstdc++.so.*
 endif
@@ -353,7 +357,7 @@ endif
 define TOOLCHAIN_EXTERNAL_CONFIGURE_CMDS
        $(Q)$(call check_cross_compiler_exists,$(TOOLCHAIN_EXTERNAL_CC))
        $(Q)LIBC_A_LOCATION=`readlink -f $$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) -print-file-name=libc.a)` ; \
-       SYSROOT_DIR=`echo $${LIBC_A_LOCATION} | sed -r -e 's:usr/lib(32|64)?/(.*/)?libc\.a::'` ; \
+       SYSROOT_DIR=`echo $${LIBC_A_LOCATION} | sed -r -e 's:(usr/)?lib(32|64)?/(.*/)?libc\.a::'` ; \
        if test -z "$${SYSROOT_DIR}" ; then \
                @echo "External toolchain doesn't support --sysroot. Cannot use." ; \
                exit 1 ; \
@@ -368,11 +372,23 @@ define TOOLCHAIN_EXTERNAL_CONFIGURE_CMDS
        fi ; \
        if test "$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC)" = "y" ; then \
                $(call check_uclibc,$${SYSROOT_DIR}) ; \
+       elif test "$(BR2_TOOLCHAIN_EXTERNAL_MUSL)" = "y" ; then \
+               $(call check_musl,$${SYSROOT_DIR}) ; \
        else \
                $(call check_glibc,$${SYSROOT_DIR}) ; \
        fi
 endef
 
+# With the musl C library, the libc.so library directly plays the role
+# of the dynamic library loader. We just need to create a symbolic
+# link to libc.so with the appropriate name.
+ifeq ($(BR2_TOOLCHAIN_EXTERNAL_MUSL),y)
+define TOOLCHAIN_EXTERNAL_MUSL_LD_LINK
+       ln -sf libc.so $(TARGET_DIR)/lib/ld-musl-$(ARCH).so.1
+endef
+TOOLCHAIN_EXTERNAL_POST_INSTALL_STAGING_HOOKS += TOOLCHAIN_EXTERNAL_MUSL_LD_LINK
+endif
+
 # Integration of the toolchain into Buildroot: find the main sysroot
 # and the variant-specific sysroot, then copy the needed libraries to
 # the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)