1################################################################################
2#
3# binutils
4#
5################################################################################
6
7# Version is set when using buildroot toolchain.
8# If not, we do like other packages
9BINUTILS_VERSION = $(call qstrip,$(BR2_BINUTILS_VERSION))
10ifeq ($(BINUTILS_VERSION),)
11ifeq ($(BR2_arc),y)
12BINUTILS_VERSION = arc-2023.09-release
13else
14BINUTILS_VERSION = 2.41
15endif
16endif # BINUTILS_VERSION
17
18ifeq ($(BINUTILS_VERSION),arc-2023.09-release)
19BINUTILS_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,binutils-gdb,$(BINUTILS_VERSION))
20BINUTILS_SOURCE = binutils-gdb-$(BINUTILS_VERSION).tar.gz
21BINUTILS_FROM_GIT = y
22endif
23
24BINUTILS_SITE ?= $(BR2_GNU_MIRROR)/binutils
25BINUTILS_SOURCE ?= binutils-$(BINUTILS_VERSION).tar.xz
26BINUTILS_EXTRA_CONFIG_OPTIONS = $(call qstrip,$(BR2_BINUTILS_EXTRA_CONFIG_OPTIONS))
27BINUTILS_INSTALL_STAGING = YES
28BINUTILS_DEPENDENCIES = zlib $(TARGET_NLS_DEPENDENCIES)
29BINUTILS_MAKE_OPTS = LIBS=$(TARGET_NLS_LIBS)
30BINUTILS_LICENSE = GPL-3.0+, libiberty LGPL-2.1+
31BINUTILS_LICENSE_FILES = COPYING3 COPYING.LIB
32BINUTILS_CPE_ID_VENDOR = gnu
33
34ifeq ($(BINUTILS_FROM_GIT),y)
35BINUTILS_DEPENDENCIES += host-flex host-bison
36HOST_BINUTILS_DEPENDENCIES += host-flex host-bison
37endif
38
39# When binutils sources are fetched from the binutils-gdb repository,
40# they also contain the gdb sources, but gdb shouldn't be built, so we
41# disable it.
42BINUTILS_DISABLE_GDB_CONF_OPTS = \
43	--disable-sim \
44	--disable-gdb
45
46# We need to specify host & target to avoid breaking ARM EABI
47BINUTILS_CONF_OPTS = \
48	--disable-multilib \
49	--disable-werror \
50	--host=$(GNU_TARGET_NAME) \
51	--target=$(GNU_TARGET_NAME) \
52	--enable-install-libiberty \
53	--enable-build-warnings=no \
54	--with-system-zlib \
55	--disable-gprofng \
56	$(BINUTILS_DISABLE_GDB_CONF_OPTS) \
57	$(BINUTILS_EXTRA_CONFIG_OPTIONS) \
58	--without-zstd
59
60ifeq ($(BR2_STATIC_LIBS),y)
61BINUTILS_CONF_OPTS += --disable-plugins
62endif
63
64# Don't build documentation. It takes up extra space / build time,
65# and sometimes needs specific makeinfo versions to work
66BINUTILS_CONF_ENV += MAKEINFO=true
67BINUTILS_MAKE_OPTS += MAKEINFO=true
68BINUTILS_INSTALL_TARGET_OPTS = DESTDIR=$(TARGET_DIR) MAKEINFO=true install
69HOST_BINUTILS_CONF_ENV += MAKEINFO=true
70HOST_BINUTILS_MAKE_OPTS += MAKEINFO=true
71HOST_BINUTILS_INSTALL_OPTS += MAKEINFO=true install
72
73# Workaround a build issue with -Os for ARM Cortex-M cpus.
74# (Binutils 2.25.1 and 2.26.1)
75# https://sourceware.org/bugzilla/show_bug.cgi?id=20552
76ifeq ($(BR2_ARM_CPU_ARMV7M)$(BR2_OPTIMIZE_S),yy)
77BINUTILS_CONF_ENV += CFLAGS="$(TARGET_CFLAGS) -O2"
78endif
79
80# "host" binutils should actually be "cross"
81# We just keep the convention of "host utility" for now
82HOST_BINUTILS_CONF_OPTS = \
83	--disable-multilib \
84	--disable-werror \
85	--target=$(GNU_TARGET_NAME) \
86	--disable-shared \
87	--enable-static \
88	--with-sysroot=$(STAGING_DIR) \
89	--enable-poison-system-directories \
90	--without-debuginfod \
91	--enable-plugins \
92	--enable-lto \
93	$(BINUTILS_DISABLE_GDB_CONF_OPTS) \
94	$(BINUTILS_EXTRA_CONFIG_OPTIONS) \
95	--without-zstd
96
97ifeq ($(BR2_BINUTILS_GPROFNG),y)
98HOST_BINUTILS_DEPENDENCIES += host-bison
99HOST_BINUTILS_CONF_OPTS += --enable-gprofng
100else
101HOST_BINUTILS_CONF_OPTS += --disable-gprofng
102endif
103
104# binutils run configure script of subdirs at make time, so ensure
105# our TARGET_CONFIGURE_ARGS are taken into consideration for those
106BINUTILS_MAKE_ENV = $(TARGET_CONFIGURE_ARGS)
107
108# We just want libbfd, libiberty and libopcodes,
109# not the full-blown binutils in staging
110define BINUTILS_INSTALL_STAGING_CMDS
111	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/bfd DESTDIR=$(STAGING_DIR) install
112	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/opcodes DESTDIR=$(STAGING_DIR) install
113	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/libiberty DESTDIR=$(STAGING_DIR) install
114	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/libsframe DESTDIR=$(STAGING_DIR) install
115endef
116
117# If we don't want full binutils on target
118ifneq ($(BR2_PACKAGE_BINUTILS_TARGET),y)
119# libiberty is static-only, so it is only installed to staging, above.
120define BINUTILS_INSTALL_TARGET_CMDS
121	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/bfd DESTDIR=$(TARGET_DIR) install
122	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/opcodes DESTDIR=$(TARGET_DIR) install
123endef
124endif
125
126ifneq ($(ARCH_XTENSA_OVERLAY_FILE),)
127define BINUTILS_XTENSA_OVERLAY_EXTRACT
128	$(call arch-xtensa-overlay-extract,$(@D),binutils)
129endef
130BINUTILS_POST_EXTRACT_HOOKS += BINUTILS_XTENSA_OVERLAY_EXTRACT
131BINUTILS_EXTRA_DOWNLOADS += $(ARCH_XTENSA_OVERLAY_URL)
132HOST_BINUTILS_POST_EXTRACT_HOOKS += BINUTILS_XTENSA_OVERLAY_EXTRACT
133HOST_BINUTILS_EXTRA_DOWNLOADS += $(ARCH_XTENSA_OVERLAY_URL)
134endif
135
136# Hardlinks between binaries in different directories cause a problem
137# with rpath fixup, so we de-hardlink those binaries, and replace them
138# with copies instead.
139BINUTILS_TOOLS = ar as ld ld.bfd nm objcopy objdump ranlib readelf strip
140define HOST_BINUTILS_FIXUP_HARDLINKS
141	$(foreach tool,$(BINUTILS_TOOLS),\
142		rm -f $(HOST_DIR)/$(GNU_TARGET_NAME)/bin/$(tool) && \
143		cp -a $(HOST_DIR)/bin/$(GNU_TARGET_NAME)-$(tool) \
144			$(HOST_DIR)/$(GNU_TARGET_NAME)/bin/$(tool)
145	)
146endef
147HOST_BINUTILS_POST_INSTALL_HOOKS += HOST_BINUTILS_FIXUP_HARDLINKS
148
149$(eval $(autotools-package))
150$(eval $(host-autotools-package))
151