xref: /OK3568_Linux_fs/buildroot/package/glibc/glibc.mk (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun################################################################################
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# glibc
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun################################################################################
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun# Generate version string using:
8*4882a593Smuzhiyun#   git describe --match 'glibc-*' --abbrev=40 origin/release/MAJOR.MINOR/master | cut -d '-' -f 2-
9*4882a593Smuzhiyun# When updating the version, please also update localedef
10*4882a593Smuzhiyunifeq ($(BR2_PACKAGE_GLIBC_2_28),y)
11*4882a593SmuzhiyunGLIBC_VERSION = 2.28-69-g1e5c5303a522764d7e9d2302a60e4a32cdb902f1
12*4882a593Smuzhiyunelse
13*4882a593SmuzhiyunGLIBC_VERSION = 2.36-81-g4f4d7a13edfd2fdc57c9d76e1fd6d017fb47550c
14*4882a593Smuzhiyunendif
15*4882a593Smuzhiyun# Upstream doesn't officially provide an https download link.
16*4882a593Smuzhiyun# There is one (https://sourceware.org/git/glibc.git) but it's not reliable,
17*4882a593Smuzhiyun# sometimes the connection times out. So use an unofficial github mirror.
18*4882a593Smuzhiyun# When updating the version, check it on the official repository;
19*4882a593Smuzhiyun# *NEVER* decide on a version string by looking at the mirror.
20*4882a593Smuzhiyun# Then check that the mirror has been synced already (happens once a day.)
21*4882a593SmuzhiyunGLIBC_SITE = $(call github,bminor,glibc,$(GLIBC_VERSION))
22*4882a593Smuzhiyun
23*4882a593SmuzhiyunGLIBC_LICENSE = GPL-2.0+ (programs), LGPL-2.1+, BSD-3-Clause, MIT (library)
24*4882a593SmuzhiyunGLIBC_LICENSE_FILES = COPYING COPYING.LIB LICENSES
25*4882a593SmuzhiyunGLIBC_CPE_ID_VENDOR = gnu
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun# glibc is part of the toolchain so disable the toolchain dependency
28*4882a593SmuzhiyunGLIBC_ADD_TOOLCHAIN_DEPENDENCY = NO
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun# Before glibc is configured, we must have the first stage
31*4882a593Smuzhiyun# cross-compiler and the kernel headers
32*4882a593SmuzhiyunGLIBC_DEPENDENCIES = host-gcc-initial linux-headers host-bison host-gawk \
33*4882a593Smuzhiyun	$(BR2_MAKE_HOST_DEPENDENCY) $(BR2_PYTHON3_HOST_DEPENDENCY)
34*4882a593Smuzhiyun
35*4882a593SmuzhiyunGLIBC_SUBDIR = build
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunGLIBC_INSTALL_STAGING = YES
38*4882a593Smuzhiyun
39*4882a593SmuzhiyunGLIBC_INSTALL_STAGING_OPTS = install_root=$(STAGING_DIR) install
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun# Thumb build is broken, build in ARM mode
42*4882a593Smuzhiyunifeq ($(BR2_ARM_INSTRUCTIONS_THUMB),y)
43*4882a593SmuzhiyunGLIBC_EXTRA_CFLAGS += -marm
44*4882a593Smuzhiyunendif
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun# MIPS64 defaults to n32 so pass the correct -mabi if
47*4882a593Smuzhiyun# we are using a different ABI. OABI32 is also used
48*4882a593Smuzhiyun# in MIPS so we pass -mabi=32 in this case as well
49*4882a593Smuzhiyun# even though it's not strictly necessary.
50*4882a593Smuzhiyunifeq ($(BR2_MIPS_NABI64),y)
51*4882a593SmuzhiyunGLIBC_EXTRA_CFLAGS += -mabi=64
52*4882a593Smuzhiyunelse ifeq ($(BR2_MIPS_OABI32),y)
53*4882a593SmuzhiyunGLIBC_EXTRA_CFLAGS += -mabi=32
54*4882a593Smuzhiyunendif
55*4882a593Smuzhiyun
56*4882a593Smuzhiyunifeq ($(BR2_ENABLE_DEBUG),y)
57*4882a593SmuzhiyunGLIBC_EXTRA_CFLAGS += -g
58*4882a593Smuzhiyunendif
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun# glibc explicitly requires compile barriers between files
61*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_4_7),y)
62*4882a593SmuzhiyunGLIBC_EXTRA_CFLAGS += -fno-lto
63*4882a593Smuzhiyunendif
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun# The stubs.h header is not installed by install-headers, but is
66*4882a593Smuzhiyun# needed for the gcc build. An empty stubs.h will work, as explained
67*4882a593Smuzhiyun# in http://gcc.gnu.org/ml/gcc/2002-01/msg00900.html. The same trick
68*4882a593Smuzhiyun# is used by Crosstool-NG.
69*4882a593Smuzhiyunifeq ($(BR2_TOOLCHAIN_BUILDROOT_GLIBC),y)
70*4882a593Smuzhiyundefine GLIBC_ADD_MISSING_STUB_H
71*4882a593Smuzhiyun	mkdir -p $(STAGING_DIR)/usr/include/gnu
72*4882a593Smuzhiyun	touch $(STAGING_DIR)/usr/include/gnu/stubs.h
73*4882a593Smuzhiyunendef
74*4882a593Smuzhiyunendif
75*4882a593Smuzhiyun
76*4882a593SmuzhiyunGLIBC_CONF_ENV = \
77*4882a593Smuzhiyun	ac_cv_path_BASH_SHELL=/bin/$(if $(BR2_PACKAGE_BASH),bash,sh) \
78*4882a593Smuzhiyun	libc_cv_forced_unwind=yes \
79*4882a593Smuzhiyun	libc_cv_ssp=no
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun# POSIX shell does not support localization, so remove the corresponding
82*4882a593Smuzhiyun# syntax from ldd if bash is not selected.
83*4882a593Smuzhiyunifeq ($(BR2_PACKAGE_BASH),)
84*4882a593Smuzhiyundefine GLIBC_LDD_NO_BASH
85*4882a593Smuzhiyun	$(SED) 's/$$"/"/g' $(@D)/elf/ldd.bash.in
86*4882a593Smuzhiyunendef
87*4882a593SmuzhiyunGLIBC_POST_PATCH_HOOKS += GLIBC_LDD_NO_BASH
88*4882a593Smuzhiyunendif
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun# Override the default library locations of /lib64/<abi> and
91*4882a593Smuzhiyun# /usr/lib64/<abi>/ for RISC-V.
92*4882a593Smuzhiyunifeq ($(BR2_riscv),y)
93*4882a593Smuzhiyunifeq ($(BR2_RISCV_64),y)
94*4882a593SmuzhiyunGLIBC_CONF_ENV += libc_cv_slibdir=/lib64 libc_cv_rtlddir=/lib
95*4882a593Smuzhiyunelse
96*4882a593SmuzhiyunGLIBC_CONF_ENV += libc_cv_slibdir=/lib32 libc_cv_rtlddir=/lib
97*4882a593Smuzhiyunendif
98*4882a593Smuzhiyunendif
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun# glibc requires make >= 4.0 since 2.28 release.
101*4882a593Smuzhiyun# https://www.sourceware.org/ml/libc-alpha/2018-08/msg00003.html
102*4882a593SmuzhiyunGLIBC_MAKE = $(BR2_MAKE)
103*4882a593SmuzhiyunGLIBC_CONF_ENV += ac_cv_prog_MAKE="$(BR2_MAKE)"
104*4882a593Smuzhiyun
105*4882a593Smuzhiyunifeq ($(BR2_PACKAGE_GLIBC_KERNEL_COMPAT),)
106*4882a593Smuzhiyunifeq ($(BR2_PACKAGE_LINUX_HEADERS_AUTO_VERSION),y)
107*4882a593SmuzhiyunGLIBC_CONF_OPTS += --enable-kernel=$(LINUX_HEADERS_VERSION_REAL)
108*4882a593Smuzhiyunelse
109*4882a593SmuzhiyunGLIBC_CONF_OPTS += --enable-kernel=$(call qstrip,$(BR2_TOOLCHAIN_HEADERS_AT_LEAST))
110*4882a593Smuzhiyunendif
111*4882a593Smuzhiyunendif
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun# Even though we use the autotools-package infrastructure, we have to
114*4882a593Smuzhiyun# override the default configure commands for several reasons:
115*4882a593Smuzhiyun#
116*4882a593Smuzhiyun#  1. We have to build out-of-tree, but we can't use the same
117*4882a593Smuzhiyun#     'symbolic link to configure' used with the gcc packages.
118*4882a593Smuzhiyun#
119*4882a593Smuzhiyun#  2. We have to execute the configure script with bash and not sh.
120*4882a593Smuzhiyun#
121*4882a593Smuzhiyun# Glibc nowadays can be build with optimization flags f.e. -Os
122*4882a593Smuzhiyun
123*4882a593SmuzhiyunGLIBC_CFLAGS = $(TARGET_OPTIMIZATION)
124*4882a593Smuzhiyun# crash in qemu-system-nios2 with -Os
125*4882a593Smuzhiyunifeq ($(BR2_nios2),y)
126*4882a593SmuzhiyunGLIBC_CFLAGS += -O2
127*4882a593Smuzhiyunendif
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun# glibc can't be built without optimization
130*4882a593Smuzhiyunifeq ($(BR2_OPTIMIZE_0),y)
131*4882a593SmuzhiyunGLIBC_CFLAGS += -O1
132*4882a593Smuzhiyunendif
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun# glibc can't be built with Optimize for fast
135*4882a593Smuzhiyunifeq ($(BR2_OPTIMIZE_FAST),y)
136*4882a593SmuzhiyunGLIBC_CFLAGS += -O2
137*4882a593Smuzhiyunendif
138*4882a593Smuzhiyun
139*4882a593Smuzhiyundefine GLIBC_CONFIGURE_CMDS
140*4882a593Smuzhiyun	mkdir -p $(@D)/build
141*4882a593Smuzhiyun	# Do the configuration
142*4882a593Smuzhiyun	(cd $(@D)/build; \
143*4882a593Smuzhiyun		$(TARGET_CONFIGURE_OPTS) \
144*4882a593Smuzhiyun		CFLAGS="$(GLIBC_CFLAGS) $(GLIBC_EXTRA_CFLAGS)" CPPFLAGS="" \
145*4882a593Smuzhiyun		CXXFLAGS="$(GLIBC_CFLAGS) $(GLIBC_EXTRA_CFLAGS)" \
146*4882a593Smuzhiyun		$(GLIBC_CONF_ENV) \
147*4882a593Smuzhiyun		$(SHELL) $(@D)/configure \
148*4882a593Smuzhiyun		--target=$(GNU_TARGET_NAME) \
149*4882a593Smuzhiyun		--host=$(GNU_TARGET_NAME) \
150*4882a593Smuzhiyun		--build=$(GNU_HOST_NAME) \
151*4882a593Smuzhiyun		--prefix=/usr \
152*4882a593Smuzhiyun		--enable-shared \
153*4882a593Smuzhiyun		$(if $(BR2_x86_64),--enable-lock-elision) \
154*4882a593Smuzhiyun		--with-pkgversion="Buildroot" \
155*4882a593Smuzhiyun		--disable-profile \
156*4882a593Smuzhiyun		--disable-werror \
157*4882a593Smuzhiyun		--without-gd \
158*4882a593Smuzhiyun		--with-headers=$(STAGING_DIR)/usr/include \
159*4882a593Smuzhiyun		$(GLIBC_CONF_OPTS))
160*4882a593Smuzhiyun	$(GLIBC_ADD_MISSING_STUB_H)
161*4882a593Smuzhiyunendef
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun#
164*4882a593Smuzhiyun# We also override the install to target commands since we only want
165*4882a593Smuzhiyun# to install the libraries, and nothing more.
166*4882a593Smuzhiyun#
167*4882a593Smuzhiyun
168*4882a593SmuzhiyunGLIBC_LIBS_LIB = \
169*4882a593Smuzhiyun	ld*.so.* libanl.so.* libc.so.* libcrypt.so.* libdl.so.* libgcc_s.so.* \
170*4882a593Smuzhiyun	libm.so.* libpthread.so.* libresolv.so.* librt.so.* \
171*4882a593Smuzhiyun	libutil.so.* libnss_files.so.* libnss_dns.so.* libmvec.so.*
172*4882a593Smuzhiyun
173*4882a593Smuzhiyunifeq ($(BR2_PACKAGE_GDB),y)
174*4882a593SmuzhiyunGLIBC_LIBS_LIB += libthread_db.so.*
175*4882a593Smuzhiyunendif
176*4882a593Smuzhiyun
177*4882a593Smuzhiyunifeq ($(BR2_PACKAGE_GLIBC_UTILS),y)
178*4882a593SmuzhiyunGLIBC_TARGET_UTILS_USR_BIN = posix/getconf elf/ldd
179*4882a593SmuzhiyunGLIBC_TARGET_UTILS_SBIN = elf/ldconfig
180*4882a593Smuzhiyunifeq ($(BR2_SYSTEM_ENABLE_NLS),y)
181*4882a593SmuzhiyunGLIBC_TARGET_UTILS_USR_BIN += locale/locale
182*4882a593Smuzhiyunendif
183*4882a593Smuzhiyunendif
184*4882a593Smuzhiyun
185*4882a593Smuzhiyundefine GLIBC_INSTALL_TARGET_CMDS
186*4882a593Smuzhiyun	for libpattern in $(GLIBC_LIBS_LIB); do \
187*4882a593Smuzhiyun		$(call copy_toolchain_lib_root,$$libpattern) ; \
188*4882a593Smuzhiyun	done
189*4882a593Smuzhiyun	$(foreach util,$(GLIBC_TARGET_UTILS_USR_BIN), \
190*4882a593Smuzhiyun		$(INSTALL) -D -m 0755 $(@D)/build/$(util) $(TARGET_DIR)/usr/bin/$(notdir $(util))
191*4882a593Smuzhiyun	)
192*4882a593Smuzhiyun	$(foreach util,$(GLIBC_TARGET_UTILS_SBIN), \
193*4882a593Smuzhiyun		$(INSTALL) -D -m 0755 $(@D)/build/$(util) $(TARGET_DIR)/sbin/$(notdir $(util))
194*4882a593Smuzhiyun	)
195*4882a593Smuzhiyunendef
196*4882a593Smuzhiyun
197*4882a593Smuzhiyunifeq ($(BR2_PACKAGE_GLIBC_GEN_LD_CACHE),y)
198*4882a593SmuzhiyunGLIBC_DEPENDENCIES += host-qemu
199*4882a593Smuzhiyun
200*4882a593Smuzhiyundefine GLIBC_GEN_LD_CACHE
201*4882a593Smuzhiyun	mkdir -p $(TARGET_DIR)/etc $(TARGET_DIR)/tmp
202*4882a593Smuzhiyun	$(QEMU_USER) $(GLIBC_DIR)/build/elf/ldconfig -r $(TARGET_DIR) || true
203*4882a593Smuzhiyunendef
204*4882a593SmuzhiyunGLIBC_TARGET_FINALIZE_HOOKS += GLIBC_GEN_LD_CACHE
205*4882a593Smuzhiyunendif
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun$(eval $(autotools-package))
208