1################################################################################
2#
3# uclibc
4#
5################################################################################
6
7UCLIBC_VERSION = 1.0.48
8UCLIBC_SOURCE = uClibc-ng-$(UCLIBC_VERSION).tar.xz
9UCLIBC_SITE = https://downloads.uclibc-ng.org/releases/$(UCLIBC_VERSION)
10UCLIBC_LICENSE = LGPL-2.1+
11UCLIBC_LICENSE_FILES = COPYING.LIB
12UCLIBC_INSTALL_STAGING = YES
13UCLIBC_CPE_ID_VENDOR = uclibc-ng_project
14UCLIBC_CPE_ID_PRODUCT = uclibc-ng
15
16# uclibc is part of the toolchain so disable the toolchain dependency
17UCLIBC_ADD_TOOLCHAIN_DEPENDENCY = NO
18
19# Before uClibc is configured, we must have the first stage
20# cross-compiler and the kernel headers
21UCLIBC_DEPENDENCIES = host-gcc-initial linux-headers
22
23# specifying UCLIBC_CONFIG_FILE on the command-line overrides the .config
24# setting.
25# check-package disable Ifdef
26ifndef UCLIBC_CONFIG_FILE
27UCLIBC_CONFIG_FILE = $(call qstrip,$(BR2_UCLIBC_CONFIG))
28endif
29
30UCLIBC_KCONFIG_EDITORS = menuconfig nconfig
31UCLIBC_KCONFIG_FILE = $(UCLIBC_CONFIG_FILE)
32UCLIBC_KCONFIG_FRAGMENT_FILES = $(call qstrip,$(BR2_UCLIBC_CONFIG_FRAGMENT_FILES))
33
34# UCLIBC_MAKE_FLAGS set HOSTCC to the default HOSTCC, which may be
35# wrapped with ccache. However, host-ccache may not already be built
36# and installed when we apply the configuration, so we override that
37# to use the non-ccached host compiler.
38UCLIBC_KCONFIG_OPTS = \
39	$(UCLIBC_MAKE_FLAGS) \
40	HOSTCC="$(HOSTCC_NOCCACHE)" \
41	PREFIX=$(STAGING_DIR) \
42	DEVEL_PREFIX=/usr/ \
43	RUNTIME_PREFIX=$(STAGING_DIR)/
44
45UCLIBC_TARGET_ARCH = $(call qstrip,$(BR2_UCLIBC_TARGET_ARCH))
46
47UCLIBC_GENERATE_LOCALES = $(call qstrip,$(BR2_GENERATE_LOCALE))
48
49ifeq ($(UCLIBC_GENERATE_LOCALES),)
50# We need at least one locale
51UCLIBC_LOCALES = en_US
52else
53# Strip out the encoding part of locale names, if any
54UCLIBC_LOCALES = \
55	$(foreach locale,$(UCLIBC_GENERATE_LOCALES),\
56	$(firstword $(subst .,$(space),$(locale))))
57endif
58
59# noMMU binary formats
60ifeq ($(BR2_BINFMT_FLAT),y)
61define UCLIBC_BINFMT_CONFIG
62	$(call KCONFIG_ENABLE_OPT,UCLIBC_FORMAT_FLAT)
63	$(call KCONFIG_DISABLE_OPT,UCLIBC_FORMAT_FLAT_SEP_DATA)
64	$(call KCONFIG_DISABLE_OPT,UCLIBC_FORMAT_FDPIC_ELF)
65endef
66endif
67
68#
69# AArch64 definitions
70#
71
72ifeq ($(UCLIBC_TARGET_ARCH),aarch64)
73UCLIBC_ARM64_PAGE_SIZE = CONFIG_AARCH64_PAGE_SIZE_$(call qstrip,$(BR2_ARM64_PAGE_SIZE))
74define UCLIBC_AARCH64_PAGE_SIZE_CONFIG
75	$(SED) '/CONFIG_AARCH64_PAGE_SIZE_*/d' $(@D)/.config
76	$(call KCONFIG_ENABLE_OPT,$(UCLIBC_ARM64_PAGE_SIZE))
77endef
78endif # aarch64
79
80#
81# ARC definitions
82#
83
84ifeq ($(UCLIBC_TARGET_ARCH),arc)
85UCLIBC_ARC_PAGE_SIZE = CONFIG_ARC_PAGE_SIZE_$(call qstrip,$(BR2_ARC_PAGE_SIZE))
86define UCLIBC_ARC_PAGE_SIZE_CONFIG
87	$(SED) '/CONFIG_ARC_PAGE_SIZE_*/d' $(@D)/.config
88	$(call KCONFIG_ENABLE_OPT,$(UCLIBC_ARC_PAGE_SIZE))
89endef
90
91ifeq ($(BR2_ARC_ATOMIC_EXT),)
92define UCLIBC_ARC_ATOMICS_CONFIG
93	$(call KCONFIG_DISABLE_OPT,CONFIG_ARC_HAS_ATOMICS)
94endef
95endif
96
97endif # arc
98
99#
100# ARM definitions
101#
102
103ifeq ($(UCLIBC_TARGET_ARCH),arm)
104define UCLIBC_ARM_ABI_CONFIG
105	$(SED) '/CONFIG_ARM_.ABI/d' $(@D)/.config
106	$(call KCONFIG_ENABLE_OPT,CONFIG_ARM_EABI)
107endef
108
109ifeq ($(BR2_BINFMT_FLAT),y)
110define UCLIBC_ARM_BINFMT_FLAT
111	$(call KCONFIG_DISABLE_OPT,DOPIC)
112endef
113endif
114
115# context functions are written with ARM instructions. Therefore, if
116# we are using a Thumb2-only platform (i.e, Cortex-M), they must be
117# disabled. Thumb1 platforms are not a problem, since they all also
118# support the ARM instructions.
119ifeq ($(BR2_ARM_INSTRUCTIONS_THUMB2):$(BR2_ARM_CPU_HAS_ARM),y:)
120define UCLIBC_ARM_NO_CONTEXT_FUNCS
121	$(call KCONFIG_DISABLE_OPT,UCLIBC_HAS_CONTEXT_FUNCS)
122endef
123endif
124
125endif # arm
126
127#
128# m68k/coldfire definitions
129#
130
131ifeq ($(UCLIBC_TARGET_ARCH),m68k)
132
133# disable DOPIC for flat without separate data
134ifeq ($(BR2_BINFMT_FLAT),y)
135define UCLIBC_M68K_BINFMT_FLAT
136	$(call KCONFIG_DISABLE_OPT,DOPIC)
137endef
138endif
139
140endif # m68k/coldfire
141
142#
143# MIPS definitions
144#
145
146ifeq ($(UCLIBC_TARGET_ARCH),mips)
147UCLIBC_MIPS_ABI = CONFIG_MIPS_$(call qstrip,$(BR2_UCLIBC_MIPS_ABI))_ABI
148define UCLIBC_MIPS_ABI_CONFIG
149	$(SED) '/CONFIG_MIPS_[NO].._ABI/d' $(@D)/.config
150	$(call KCONFIG_ENABLE_OPT,$(UCLIBC_MIPS_ABI))
151endef
152
153UCLIBC_MIPS_NAN = CONFIG_MIPS_NAN_$(call qstrip,$(BR2_UCLIBC_MIPS_NAN))
154define UCLIBC_MIPS_NAN_CONFIG
155	$(SED) '/CONFIG_MIPS_NAN_.*/d' $(@D)/.config
156	$(call KCONFIG_ENABLE_OPT,$(UCLIBC_MIPS_NAN))
157endef
158endif # mips
159
160#
161# SH definitions
162#
163
164ifeq ($(UCLIBC_TARGET_ARCH),sh)
165UCLIBC_SH_TYPE = CONFIG_$(call qstrip,$(BR2_UCLIBC_SH_TYPE))
166define UCLIBC_SH_TYPE_CONFIG
167	$(SED) '/CONFIG_SH[234A]*/d' $(@D)/.config
168	$(call KCONFIG_ENABLE_OPT,$(UCLIBC_SH_TYPE))
169endef
170endif # sh
171
172#
173# SPARC definitions
174#
175
176ifeq ($(UCLIBC_TARGET_ARCH),sparc)
177UCLIBC_SPARC_TYPE = CONFIG_SPARC_$(call qstrip,$(BR2_UCLIBC_SPARC_TYPE))
178define UCLIBC_SPARC_TYPE_CONFIG
179	$(SED) 's/^\(CONFIG_[^_]*[_]*SPARC[^=]*\)=.*/# \1 is not set/g' \
180		$(@D)/.config
181	$(call KCONFIG_ENABLE_OPT,$(UCLIBC_SPARC_TYPE))
182endef
183endif # sparc
184
185#
186# PowerPC definitions
187#
188
189ifeq ($(UCLIBC_TARGET_ARCH),powerpc)
190UCLIBC_POWERPC_TYPE = CONFIG_$(call qstrip,$(BR2_UCLIBC_POWERPC_TYPE))
191define UCLIBC_POWERPC_TYPE_CONFIG
192	$(call KCONFIG_DISABLE_OPT,CONFIG_GENERIC)
193	$(call KCONFIG_DISABLE_OPT,CONFIG_E500)
194	$(call KCONFIG_ENABLE_OPT,$(UCLIBC_POWERPC_TYPE))
195endef
196endif # powerpc
197
198#
199# x86 definitions
200#
201ifeq ($(UCLIBC_TARGET_ARCH),i386)
202UCLIBC_X86_TYPE = CONFIG_$(call qstrip,$(BR2_UCLIBC_X86_TYPE))
203define UCLIBC_X86_TYPE_CONFIG
204	$(call KCONFIG_ENABLE_OPT,$(UCLIBC_X86_TYPE))
205endef
206endif
207
208#
209# Debug
210#
211ifeq ($(BR2_ENABLE_RUNTIME_DEBUG),y)
212define UCLIBC_DEBUG_CONFIG
213	$(call KCONFIG_ENABLE_OPT,DODEBUG)
214endef
215endif
216
217#
218# Endianness
219#
220
221ifeq ($(call qstrip,$(BR2_ENDIAN)),BIG)
222define UCLIBC_ENDIAN_CONFIG
223	$(call KCONFIG_ENABLE_OPT,ARCH_BIG_ENDIAN)
224	$(call KCONFIG_ENABLE_OPT,ARCH_WANTS_BIG_ENDIAN)
225	$(call KCONFIG_DISABLE_OPT,ARCH_LITTLE_ENDIAN)
226	$(call KCONFIG_DISABLE_OPT,ARCH_WANTS_LITTLE_ENDIAN)
227endef
228else
229define UCLIBC_ENDIAN_CONFIG
230	$(call KCONFIG_ENABLE_OPT,ARCH_LITTLE_ENDIAN)
231	$(call KCONFIG_ENABLE_OPT,ARCH_WANTS_LITTLE_ENDIAN)
232	$(call KCONFIG_DISABLE_OPT,ARCH_BIG_ENDIAN)
233	$(call KCONFIG_DISABLE_OPT,ARCH_WANTS_BIG_ENDIAN)
234endef
235endif
236
237#
238# MMU
239#
240
241ifeq ($(BR2_USE_MMU),y)
242define UCLIBC_MMU_CONFIG
243	$(call KCONFIG_ENABLE_OPT,ARCH_HAS_MMU)
244	$(call KCONFIG_ENABLE_OPT,ARCH_USE_MMU)
245endef
246else
247define UCLIBC_MMU_CONFIG
248	$(call KCONFIG_DISABLE_OPT,ARCH_HAS_MMU)
249	$(call KCONFIG_DISABLE_OPT,ARCH_USE_MMU)
250endef
251endif
252
253#
254# IPv6
255#
256
257UCLIBC_IPV6_CONFIG = $(call KCONFIG_ENABLE_OPT,UCLIBC_HAS_IPV6)
258
259#
260# soft-float
261#
262
263ifeq ($(BR2_SOFT_FLOAT),y)
264define UCLIBC_FLOAT_CONFIG
265	$(call KCONFIG_DISABLE_OPT,UCLIBC_HAS_FPU)
266	$(call KCONFIG_ENABLE_OPT,UCLIBC_HAS_FLOATS)
267	$(call KCONFIG_ENABLE_OPT,DO_C99_MATH)
268endef
269else
270define UCLIBC_FLOAT_CONFIG
271	$(call KCONFIG_ENABLE_OPT,UCLIBC_HAS_FPU)
272	$(call KCONFIG_ENABLE_OPT,UCLIBC_HAS_FLOATS)
273endef
274endif
275
276#
277# SSP
278#
279ifeq ($(BR2_TOOLCHAIN_BUILDROOT_USE_SSP),y)
280define UCLIBC_SSP_CONFIG
281	$(call KCONFIG_ENABLE_OPT,UCLIBC_HAS_SSP)
282	$(call KCONFIG_ENABLE_OPT,UCLIBC_BUILD_SSP)
283endef
284else
285define UCLIBC_SSP_CONFIG
286	$(call KCONFIG_DISABLE_OPT,UCLIBC_HAS_SSP)
287	$(call KCONFIG_DISABLE_OPT,UCLIBC_BUILD_SSP)
288endef
289endif
290
291#
292# Threads
293#
294ifeq ($(BR2_PTHREADS_NONE),y)
295define UCLIBC_THREAD_CONFIG
296	$(call KCONFIG_DISABLE_OPT,UCLIBC_HAS_THREADS)
297	$(call KCONFIG_DISABLE_OPT,UCLIBC_HAS_LINUXTHREADS)
298	$(call KCONFIG_DISABLE_OPT,UCLIBC_HAS_THREADS_NATIVE)
299endef
300else ifeq ($(BR2_PTHREADS),y)
301define UCLIBC_THREAD_CONFIG
302	$(call KCONFIG_ENABLE_OPT,UCLIBC_HAS_THREADS)
303	$(call KCONFIG_ENABLE_OPT,UCLIBC_HAS_LINUXTHREADS)
304	$(call KCONFIG_DISABLE_OPT,UCLIBC_HAS_THREADS_NATIVE)
305endef
306else ifeq ($(BR2_PTHREADS_NATIVE),y)
307define UCLIBC_THREAD_CONFIG
308	$(call KCONFIG_ENABLE_OPT,UCLIBC_HAS_THREADS)
309	$(call KCONFIG_DISABLE_OPT,UCLIBC_HAS_LINUXTHREADS)
310	$(call KCONFIG_ENABLE_OPT,UCLIBC_HAS_THREADS_NATIVE)
311endef
312endif
313
314#
315# Thread debug
316#
317
318ifeq ($(BR2_PTHREAD_DEBUG),y)
319UCLIBC_THREAD_DEBUG_CONFIG = $(call KCONFIG_ENABLE_OPT,PTHREADS_DEBUG_SUPPORT)
320else
321UCLIBC_THREAD_DEBUG_CONFIG = $(call KCONFIG_DISABLE_OPT,PTHREADS_DEBUG_SUPPORT)
322endif
323
324#
325# Locale
326#
327
328ifeq ($(BR2_TOOLCHAIN_BUILDROOT_LOCALE),y)
329define UCLIBC_LOCALE_CONFIG
330	$(call KCONFIG_ENABLE_OPT,UCLIBC_HAS_LOCALE)
331	$(call KCONFIG_DISABLE_OPT,UCLIBC_BUILD_ALL_LOCALE)
332	$(call KCONFIG_ENABLE_OPT,UCLIBC_BUILD_MINIMAL_LOCALE)
333	$(call KCONFIG_SET_OPT,UCLIBC_BUILD_MINIMAL_LOCALES,"$(UCLIBC_LOCALES)")
334	$(call KCONFIG_DISABLE_OPT,UCLIBC_PREGENERATED_LOCALE_DATA)
335	$(call KCONFIG_DISABLE_OPT,DOWNLOAD_PREGENERATED_LOCALE_DATA)
336	$(call KCONFIG_ENABLE_OPT,UCLIBC_HAS_XLOCALE)
337	$(call KCONFIG_DISABLE_OPT,UCLIBC_HAS_GLIBC_DIGIT_GROUPING)
338endef
339else
340define UCLIBC_LOCALE_CONFIG
341	$(call KCONFIG_DISABLE_OPT,UCLIBC_HAS_LOCALE)
342endef
343endif
344
345#
346# wchar
347#
348
349ifeq ($(BR2_TOOLCHAIN_BUILDROOT_WCHAR),y)
350UCLIBC_WCHAR_CONFIG = $(call KCONFIG_ENABLE_OPT,UCLIBC_HAS_WCHAR)
351else
352UCLIBC_WCHAR_CONFIG = $(call KCONFIG_DISABLE_OPT,UCLIBC_HAS_WCHAR)
353endif
354
355#
356# static/shared libs
357#
358
359ifeq ($(BR2_STATIC_LIBS),y)
360UCLIBC_SHARED_LIBS_CONFIG = $(call KCONFIG_DISABLE_OPT,HAVE_SHARED)
361else
362UCLIBC_SHARED_LIBS_CONFIG = $(call KCONFIG_ENABLE_OPT,HAVE_SHARED)
363endif
364
365#
366# Commands
367#
368
369UCLIBC_EXTRA_CFLAGS = $(TARGET_ABI) $(TARGET_DEBUGGING)
370
371# uClibc-ng does not build with LTO, so explicitly disable it
372# when using a compiler that may have support for LTO
373ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_4_7),y)
374UCLIBC_EXTRA_CFLAGS += -fno-lto
375endif
376
377UCLIBC_MAKE_FLAGS = \
378	ARCH="$(UCLIBC_TARGET_ARCH)" \
379	CROSS_COMPILE="$(TARGET_CROSS)" \
380	UCLIBC_EXTRA_CFLAGS="$(UCLIBC_EXTRA_CFLAGS)" \
381	HOSTCC="$(HOSTCC)"
382
383define UCLIBC_KCONFIG_FIXUP_CMDS
384	$(call KCONFIG_SET_OPT,CROSS_COMPILER_PREFIX,"$(TARGET_CROSS)")
385	$(call KCONFIG_ENABLE_OPT,TARGET_$(UCLIBC_TARGET_ARCH))
386	$(call KCONFIG_SET_OPT,TARGET_ARCH,"$(UCLIBC_TARGET_ARCH)")
387	$(call KCONFIG_SET_OPT,KERNEL_HEADERS,"$(LINUX_HEADERS_DIR)/usr/include")
388	$(call KCONFIG_SET_OPT,RUNTIME_PREFIX,"/")
389	$(call KCONFIG_SET_OPT,DEVEL_PREFIX,"/usr")
390	$(call KCONFIG_SET_OPT,SHARED_LIB_LOADER_PREFIX,"/lib")
391	$(call KCONFIG_DISABLE_OPT,DOSTRIP)
392	$(UCLIBC_MMU_CONFIG)
393	$(UCLIBC_BINFMT_CONFIG)
394	$(UCLIBC_AARCH64_PAGE_SIZE_CONFIG)
395	$(UCLIBC_ARC_PAGE_SIZE_CONFIG)
396	$(UCLIBC_ARC_ATOMICS_CONFIG)
397	$(UCLIBC_ARM_ABI_CONFIG)
398	$(UCLIBC_ARM_BINFMT_FLAT)
399	$(UCLIBC_ARM_NO_CONTEXT_FUNCS)
400	$(UCLIBC_M68K_BINFMT_FLAT)
401	$(UCLIBC_MIPS_ABI_CONFIG)
402	$(UCLIBC_MIPS_NAN_CONFIG)
403	$(UCLIBC_SH_TYPE_CONFIG)
404	$(UCLIBC_SPARC_TYPE_CONFIG)
405	$(UCLIBC_POWERPC_TYPE_CONFIG)
406	$(UCLIBC_X86_TYPE_CONFIG)
407	$(UCLIBC_DEBUG_CONFIG)
408	$(UCLIBC_ENDIAN_CONFIG)
409	$(UCLIBC_IPV6_CONFIG)
410	$(UCLIBC_FLOAT_CONFIG)
411	$(UCLIBC_SSP_CONFIG)
412	$(UCLIBC_THREAD_CONFIG)
413	$(UCLIBC_THREAD_DEBUG_CONFIG)
414	$(UCLIBC_LOCALE_CONFIG)
415	$(UCLIBC_WCHAR_CONFIG)
416	$(UCLIBC_SHARED_LIBS_CONFIG)
417endef
418
419define UCLIBC_BUILD_CMDS
420	$(MAKE) -C $(@D) $(UCLIBC_MAKE_FLAGS) headers
421	$(MAKE) -C $(@D) $(UCLIBC_MAKE_FLAGS)
422	$(MAKE) -C $(@D)/utils \
423		PREFIX=$(HOST_DIR) \
424		HOSTCC="$(HOSTCC)" hostutils
425endef
426
427ifeq ($(BR2_UCLIBC_INSTALL_UTILS),y)
428define UCLIBC_INSTALL_UTILS_TARGET
429	$(MAKE1) -C $(@D) \
430		CC="$(TARGET_CC)" CPP="$(TARGET_CPP)" LD="$(TARGET_LD)" \
431		ARCH="$(UCLIBC_TARGET_ARCH)" \
432		PREFIX=$(TARGET_DIR) \
433		utils install_utils
434endef
435endif
436
437define UCLIBC_INSTALL_TARGET_CMDS
438	$(MAKE1) -C $(@D) \
439		$(UCLIBC_MAKE_FLAGS) \
440		PREFIX=$(TARGET_DIR) \
441		DEVEL_PREFIX=/usr/ \
442		RUNTIME_PREFIX=/ \
443		install_runtime
444	$(UCLIBC_INSTALL_UTILS_TARGET)
445endef
446
447# STATIC has no ld* tools, only getconf
448ifeq ($(BR2_STATIC_LIBS),)
449define UCLIBC_INSTALL_UTILS_STAGING
450	$(INSTALL) -D -m 0755 $(@D)/utils/ldd.host $(HOST_DIR)/bin/ldd
451	ln -sf ldd $(HOST_DIR)/bin/$(GNU_TARGET_NAME)-ldd
452	$(INSTALL) -D -m 0755 $(@D)/utils/ldconfig.host $(HOST_DIR)/bin/ldconfig
453	ln -sf ldconfig $(HOST_DIR)/bin/$(GNU_TARGET_NAME)-ldconfig
454endef
455endif
456
457define UCLIBC_INSTALL_STAGING_CMDS
458	$(MAKE1) -C $(@D) \
459		$(UCLIBC_MAKE_FLAGS) \
460		PREFIX=$(STAGING_DIR) \
461		DEVEL_PREFIX=/usr/ \
462		RUNTIME_PREFIX=/ \
463		install_runtime install_dev
464	$(UCLIBC_INSTALL_UTILS_STAGING)
465endef
466
467# Checks to give errors that the user can understand
468# Must be before we call to kconfig-package
469ifeq ($(BR2_PACKAGE_UCLIBC)$(BR_BUILDING),yy)
470ifeq ($(call qstrip,$(BR2_UCLIBC_CONFIG)),)
471$(error No uClibc configuration file specified, check your BR2_UCLIBC_CONFIG setting)
472endif
473endif
474
475$(eval $(kconfig-package))
476