[OpenWrt-Devel] [PATCH 1/2] toolchain: The glorious return of glibc, ver 2.21

Jeff Waugh jdub at bethesignal.org
Wed Mar 11 13:17:28 EDT 2015


It's the eglibc packaging with a bit of spit-polishing. And testing. :-)

Signed-off-by: Jeff Waugh <jdub at bethesignal.org>
---
 config/Config-build.in                             |  2 +-
 include/package-defaults.mk                        |  2 +-
 include/version.mk                                 |  1 +
 package/libs/toolchain/Makefile                    | 18 +++++
 .../libs/toolchain/glibc-files/etc/nsswitch.conf   | 13 +++
 toolchain/Config.in                                | 16 +++-
 toolchain/glibc/Config.in                          | 12 +++
 toolchain/glibc/Config.version                     | 21 +++++
 toolchain/glibc/Makefile                           | 31 ++++++++
 toolchain/glibc/common.mk                          | 93 ++++++++++++++++++++++
 toolchain/glibc/headers/Makefile                   | 27 +++++++
 toolchain/glibc/include/libintl.h                  |  6 ++
 12 files changed, 238 insertions(+), 4 deletions(-)
 create mode 100644 package/libs/toolchain/glibc-files/etc/nsswitch.conf
 create mode 100644 toolchain/glibc/Config.in
 create mode 100644 toolchain/glibc/Config.version
 create mode 100644 toolchain/glibc/Makefile
 create mode 100644 toolchain/glibc/common.mk
 create mode 100644 toolchain/glibc/headers/Makefile
 create mode 100644 toolchain/glibc/include/libintl.h

diff --git a/config/Config-build.in b/config/Config-build.in
index d184d1f..e4afe28 100644
--- a/config/Config-build.in
+++ b/config/Config-build.in
@@ -187,7 +187,7 @@ menu "Global build settings"
 
 	choice
 		prompt "Preferred standard C++ library"
-		default USE_LIBSTDCXX if USE_EGLIBC
+		default USE_LIBSTDCXX if USE_GLIBC || USE_EGLIBC
 		default USE_UCLIBCXX
 		help
 		  Select the preferred standard C++ library for all packages that support this.
diff --git a/include/package-defaults.mk b/include/package-defaults.mk
index 6a345b6..a34252c 100644
--- a/include/package-defaults.mk
+++ b/include/package-defaults.mk
@@ -5,7 +5,7 @@
 # See /LICENSE for more information.
 #
 
-PKG_DEFAULT_DEPENDS = +libc +USE_EGLIBC:librt +USE_EGLIBC:libpthread
+PKG_DEFAULT_DEPENDS = +libc +USE_EGLIBC:librt +USE_EGLIBC:libpthread +USE_GLIBC:librt +USE_GLIBC:libpthread
 
 ifneq ($(PKG_NAME),toolchain)
   PKG_FIXUP_DEPENDS = $(if $(filter kmod-%,$(1)),$(2),$(PKG_DEFAULT_DEPENDS) $(filter-out $(PKG_DEFAULT_DEPENDS),$(2)))
diff --git a/include/version.mk b/include/version.mk
index 99af96e..b23fd12 100644
--- a/include/version.mk
+++ b/include/version.mk
@@ -55,6 +55,7 @@ endef
 VERSION_TAINT_SPECS := \
 	-ALL:no-all \
 	-IPV6:no-ipv6 \
+	+USE_GLIBC:glibc \
 	+USE_EGLIBC:eglibc \
 	+USE_MKLIBS:mklibs \
 	+BUSYBOX_CUSTOM:busybox \
diff --git a/package/libs/toolchain/Makefile b/package/libs/toolchain/Makefile
index 42b9935..d3a4da6 100644
--- a/package/libs/toolchain/Makefile
+++ b/package/libs/toolchain/Makefile
@@ -420,6 +420,24 @@ ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
 	$(CP) $(TOOLCHAIN_DIR)/lib/libstdc++.so.* $(1)/usr/lib/
   endef
 
+  define Package/glibc/install
+	$(CP) ./glibc-files/* $(1)/
+	rm -f $(1)/etc/localtime
+	$(LN) /tmp/localtime $(1)/etc/localtime
+	$(INSTALL_DIR) $(1)/lib
+	$(CP) \
+		$(TOOLCHAIN_DIR)/lib/ld*.so.* \
+		$(TOOLCHAIN_DIR)/lib/ld-$(LIBC_SO_VERSION).so \
+		$(1)/lib/
+	for file in libanl libc libcidn libcrypt libdl libm libnsl libnss_dns libnss_files libresolv libutil; do \
+		for file in $(TOOLCHAIN_DIR)/lib/$$$$file.so.* $(TOOLCHAIN_DIR)/lib/$$$$file-$(LIBC_SO_VERSION).so; do \
+			if [ -e "$$$$file" ]; then \
+				$(CP) $$$$file $(1)/lib/; \
+			fi; \
+		done; \
+	done
+  endef
+
   use_libutil=$(if $(CONFIG_EGLIBC_OPTION_EGLIBC_UTMP),libutil)
   use_libnsl=$(if $(CONFIG_EGLIBC_OPTION_EGLIBC_NIS),libnsl)
   use_nsswitch=$(if $(CONFIG_EGLIBC_OPTION_EGLIBC_NSSWITCH),libnss_dns libnss_files)
diff --git a/package/libs/toolchain/glibc-files/etc/nsswitch.conf b/package/libs/toolchain/glibc-files/etc/nsswitch.conf
new file mode 100644
index 0000000..981c425
--- /dev/null
+++ b/package/libs/toolchain/glibc-files/etc/nsswitch.conf
@@ -0,0 +1,13 @@
+passwd:files
+shadow:files
+group:files
+hosts:dns files
+bootparams:files
+ethers:files
+netmasks:files
+networks:files
+protocols:files
+rpc:files
+services:files
+automount:files
+aliases:files
diff --git a/toolchain/Config.in b/toolchain/Config.in
index ecd9d20..307343f 100644
--- a/toolchain/Config.in
+++ b/toolchain/Config.in
@@ -216,6 +216,11 @@ choice
 	help
 	  Select the C library implementation.
 
+	config LIBC_USE_GLIBC
+		bool "Use glibc"
+		select USE_GLIBC
+		depends on !avr32
+
 	config LIBC_USE_EGLIBC
 		bool "Use eglibc"
 		select USE_EGLIBC
@@ -233,6 +238,7 @@ choice
 
 endchoice
 
+source "toolchain/glibc/Config.in"
 source "toolchain/eglibc/Config.in"
 source "toolchain/uClibc/Config.in"
 source "toolchain/musl/Config.in"
@@ -256,6 +262,9 @@ config INSIGHT
 	help
 	  Enable if you want to build insight-gdb.
 
+config USE_GLIBC
+	bool
+
 config USE_EGLIBC
 	bool
 	default y if !TOOLCHAINOPTS && !EXTERNAL_TOOLCHAIN && !NATIVE_TOOLCHAIN && (aarch64 || aarch64_be || octeon)
@@ -273,26 +282,29 @@ config USE_EXTERNAL_LIBC
 
 source "toolchain/gcc/Config.version"
 
+source "toolchain/glibc/Config.version"
 source "toolchain/eglibc/Config.version"
 source "toolchain/uClibc/Config.version"
 source "toolchain/musl/Config.version"
 
 config LIBC
 	string
+	default "glibc"   if USE_GLIBC
 	default "eglibc"  if USE_EGLIBC
 	default "uClibc"  if USE_UCLIBC
 	default "musl"	  if USE_MUSL
 
 config LIBC_VERSION
 	string
+	default GLIBC_VERSION   if USE_GLIBC
 	default EGLIBC_VERSION  if USE_EGLIBC
 	default UCLIBC_VERSION  if USE_UCLIBC
 	default MUSL_VERSION	if USE_MUSL
 
 config TARGET_SUFFIX
 	string
-	default "gnueabi"         if USE_EGLIBC && (arm || armeb)
-	default "gnu"             if USE_EGLIBC && !(arm || armeb)
+	default "gnueabi"         if (USE_GLIBC || USE_EGLIBC) && (arm || armeb)
+	default "gnu"             if (USE_GLIBC || USE_EGLIBC) && !(arm || armeb)
 	default "uclibcgnueabi"   if USE_UCLIBC && (arm || armeb)
 	default "uclibc"          if USE_UCLIBC && !(arm || armeb)
 	default "muslgnueabi"     if USE_MUSL && (arm || armeb)
diff --git a/toolchain/glibc/Config.in b/toolchain/glibc/Config.in
new file mode 100644
index 0000000..5aa55cf
--- /dev/null
+++ b/toolchain/glibc/Config.in
@@ -0,0 +1,12 @@
+choice
+	prompt "glibc version"
+	depends on TOOLCHAINOPTS && USE_GLIBC
+	default GLIBC_USE_VERSION_2_21
+	help
+	  Select the version of glibc you wish to use.
+
+	config GLIBC_USE_VERSION_2_21
+		bool "glibc 2.21"
+		select GLIBC_VERSION_2_21
+
+endchoice
diff --git a/toolchain/glibc/Config.version b/toolchain/glibc/Config.version
new file mode 100644
index 0000000..9f81db9
--- /dev/null
+++ b/toolchain/glibc/Config.version
@@ -0,0 +1,21 @@
+if USE_GLIBC
+
+config GLIBC_VERSION
+	string
+	default "2.21" if GLIBC_VERSION_2_21
+
+config GLIBC_VERSION_2_21
+	default y if !TOOLCHAINOPTS
+	bool
+
+config GLIBC_REVISION
+	string
+	default "4e42b5b8f8" if GLIBC_VERSION_2_21
+	default ""
+
+endif
+
+#menu "glibc configuration"
+#	depends on !TOOLCHAINOPTS && USE_GLIBC
+#	source toolchain/glibc/config/Config.in
+#endmenu
diff --git a/toolchain/glibc/Makefile b/toolchain/glibc/Makefile
new file mode 100644
index 0000000..f880db8
--- /dev/null
+++ b/toolchain/glibc/Makefile
@@ -0,0 +1,31 @@
+PATH_PREFIX := .
+VARIANT:=final
+HOST_BUILD_PARALLEL:=0
+
+include ./common.mk
+
+define Host/Compile
+	$(MAKE) -C $(CUR_BUILD_DIR) \
+		PARALLELMFLAGS="$(HOST_JOBS)" \
+		BUILD_CFLAGS="$(HOST_CFLAGS)" \
+		all
+endef
+
+define Host/Install
+	$(call Host/SetToolchainInfo)
+	$(MAKE) -C $(CUR_BUILD_DIR) \
+		BUILD_CFLAGS="$(HOST_CFLAGS)" \
+		install_root="$(TOOLCHAIN_DIR)" \
+		install
+	( cd $(TOOLCHAIN_DIR) ; \
+		for d in lib usr/lib ; do \
+		  for f in libc.so libpthread.so libgcc_s.so ; do \
+		    if [ -f $$$$d/$$$$f -a ! -L $$$$d/$$$$f ] ; then \
+		      $(SED) 's,/usr/lib/,,g;s,/lib/,,g' $$$$d/$$$$f ; \
+		    fi \
+		  done \
+		done \
+	)
+endef
+
+$(eval $(call HostBuild))
diff --git a/toolchain/glibc/common.mk b/toolchain/glibc/common.mk
new file mode 100644
index 0000000..4c6b12a
--- /dev/null
+++ b/toolchain/glibc/common.mk
@@ -0,0 +1,93 @@
+#
+# Copyright (C) 2006-2011 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=glibc
+PKG_VERSION:=$(call qstrip,$(CONFIG_GLIBC_VERSION))
+PKG_REVISION:=$(call qstrip,$(CONFIG_GLIBC_REVISION))
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=git://sourceware.org/git/glibc.git
+PKG_SOURCE_VERSION:=$(PKG_REVISION)
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)-r$(PKG_REVISION)
+PKG_SOURCE:=$(PKG_SOURCE_SUBDIR).tar.xz
+
+PATCH_DIR:=$(PATH_PREFIX)/patches/$(PKG_VERSION)
+
+HOST_BUILD_DIR:=$(BUILD_DIR_TOOLCHAIN)/$(PKG_SOURCE_SUBDIR)
+CUR_BUILD_DIR:=$(HOST_BUILD_DIR)-$(VARIANT)
+
+include $(INCLUDE_DIR)/toolchain-build.mk
+
+HOST_STAMP_PREPARED:=$(HOST_BUILD_DIR)/.prepared
+HOST_STAMP_CONFIGURED:=$(CUR_BUILD_DIR)/.configured
+HOST_STAMP_BUILT:=$(CUR_BUILD_DIR)/.built
+HOST_STAMP_INSTALLED:=$(TOOLCHAIN_DIR)/stamp/.glibc_$(VARIANT)_installed
+
+ifeq ($(ARCH),mips64)
+  ifdef CONFIG_MIPS64_ABI_N64
+    TARGET_CFLAGS += -mabi=64
+  endif
+  ifdef CONFIG_MIPS64_ABI_N32
+    TARGET_CFLAGS += -mabi=n32
+  endif
+  ifdef CONFIG_MIPS64_ABI_O32
+    TARGET_CFLAGS += -mabi=32
+  endif
+endif
+
+GLIBC_CONFIGURE:= \
+	BUILD_CC="$(HOSTCC)" \
+	$(TARGET_CONFIGURE_OPTS) \
+	CFLAGS="$(TARGET_CFLAGS)" \
+	libc_cv_slibdir="/lib" \
+	use_ldconfig=no \
+	$(HOST_BUILD_DIR)/configure \
+		--prefix= \
+		--build=$(GNU_HOST_NAME) \
+		--host=$(REAL_GNU_TARGET_NAME) \
+		--with-headers=$(TOOLCHAIN_DIR)/include \
+		--disable-werror \
+		--disable-profile \
+		--without-gd \
+		--without-cvs \
+		--enable-add-ons \
+		--$(if $(CONFIG_SOFT_FLOAT),without,with)-fp
+
+export libc_cv_ssp=no
+export ac_cv_header_cpuid_h=yes
+export HOST_CFLAGS := $(HOST_CFLAGS) -idirafter $(CURDIR)/$(PATH_PREFIX)/include
+
+define Host/SetToolchainInfo
+	$(SED) 's,^\(LIBC_TYPE\)=.*,\1=$(PKG_NAME),' $(TOOLCHAIN_DIR)/info.mk
+	$(SED) 's,^\(LIBC_URL\)=.*,\1=http://www.gnu.org/software/libc/,' $(TOOLCHAIN_DIR)/info.mk
+	$(SED) 's,^\(LIBC_VERSION\)=.*,\1=$(PKG_VERSION),' $(TOOLCHAIN_DIR)/info.mk
+	$(SED) 's,^\(LIBC_SO_VERSION\)=.*,\1=$(PKG_VERSION),' $(TOOLCHAIN_DIR)/info.mk
+endef
+
+define Host/Configure
+	[ -f $(HOST_BUILD_DIR)/.autoconf ] || { \
+		cd $(HOST_BUILD_DIR); \
+		autoconf --force && \
+		touch $(HOST_BUILD_DIR)/.autoconf; \
+	}
+	mkdir -p $(CUR_BUILD_DIR)
+	( cd $(CUR_BUILD_DIR); rm -f config.cache; \
+		$(GLIBC_CONFIGURE) \
+	);
+endef
+
+define Host/Prepare
+	$(call Host/Prepare/Default)
+	ln -snf $(PKG_SOURCE_SUBDIR) $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME)
+endef
+
+define Host/Clean
+	rm -rf $(CUR_BUILD_DIR)* \
+		$(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev \
+		$(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME)
+endef
diff --git a/toolchain/glibc/headers/Makefile b/toolchain/glibc/headers/Makefile
new file mode 100644
index 0000000..f9f411b
--- /dev/null
+++ b/toolchain/glibc/headers/Makefile
@@ -0,0 +1,27 @@
+PATH_PREFIX:=..
+VARIANT:=headers
+
+include ../common.mk
+
+define Host/Compile
+
+endef
+
+define Host/Install
+	$(call Host/SetToolchainInfo)
+	mkdir -p $(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev/{include,lib}
+	$(MAKE) -C $(CUR_BUILD_DIR) \
+		BUILD_CFLAGS="$(HOST_CFLAGS)" \
+		install_root="$(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev" \
+		install-bootstrap-headers=yes \
+		install-headers
+	$(MAKE) -C $(CUR_BUILD_DIR) \
+		csu/subdir_lib
+	( cd $(CUR_BUILD_DIR); \
+		$(CP) csu/crt1.o csu/crti.o csu/crtn.o $(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev/lib/ \
+	)
+	$(TARGET_CC) -nostdlib -nostartfiles -shared -x c /dev/null \
+		-o $(BUILD_DIR_TOOLCHAIN)/$(LIBC)-dev/lib/libc.so
+endef
+
+$(eval $(call HostBuild))
diff --git a/toolchain/glibc/include/libintl.h b/toolchain/glibc/include/libintl.h
new file mode 100644
index 0000000..69cb887
--- /dev/null
+++ b/toolchain/glibc/include/libintl.h
@@ -0,0 +1,6 @@
+#ifndef __FAKE_LIBINTL_H
+#define __FAKE_LIBINTL_H
+
+#define _(X) (X)
+
+#endif
-- 
1.9.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list