Skip to content

Commit e15a0d2

Browse files
committed
Detect the sysroot path of the ARM GNU toolchain automatically
Originally, the default path of ld-linux.so is set to a specific path for Arm architecture. However, Considering that developers may manually install the ARM GNU toolchain, the sysroot path may not match the default path. This commit improves arm.mk to use a more convenient method to automatically detect the correct sysroot path.
1 parent b1893cf commit e15a0d2

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

mk/arm.mk

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,38 @@ ARCH_DEFS = \
1212
\#define PLT_ENT_SIZE 12\n$\
1313
\#define R_ARCH_JUMP_SLOT 0x16\n$\
1414
"
15-
RUNNER_LD_PREFIX=-L /usr/arm-linux-gnueabihf/
15+
16+
# Find the sysroot of the ARM GNU toolchain.
17+
#
18+
# Since developers may install the toolchain manually instead of
19+
# using a package manager such as apt, we cannot assume that the
20+
# path of ld-linux is always "/usr/arm-linux-gnueabihf".
21+
#
22+
# For example, if the toolchain is installed under "/opt/arm",
23+
# the command "arm-linux-gnueabihf-gcc --print-sysroot" will
24+
# prints "/opt/arm/sysroot", and the build system can use this
25+
# as LD_LINUX_PATH directly.
26+
ifneq ($(HOST_ARCH),$(ARCH_NAME))
27+
CROSS_COMPILE = arm-linux-gnueabihf-
28+
ARM_CC = $(CROSS_COMPILE)gcc
29+
ARM_CC := $(shell which $(ARM_CC))
30+
LD_LINUX_PATH := $(shell cd $(shell $(ARM_CC) --print-sysroot) 2>/dev/null && pwd)
31+
ifeq ("$(LD_LINUX_PATH)","/")
32+
LD_LINUX_PATH := $(shell dirname "$(shell which $(ARM_CC))")/..
33+
LD_LINUX_PATH := $(shell cd $(LD_LINUX_PATH) 2>/dev/null && pwd)
34+
LD_LINUX_PATH := $(LD_LINUX_PATH)/$(shell echo $(CROSS_COMPILE) | sed s'/.$$//')/libc
35+
LD_LINUX_PATH := $(shell cd $(LD_LINUX_PATH) 2>/dev/null && pwd)
36+
ifndef LD_LINUX_PATH
37+
LD_LINUX_PATH = /usr/$(shell echo $(CROSS_COMPILE) | sed s'/.$$//')
38+
LD_LINUX_PATH := $(shell cd $(LD_LINUX_PATH) 2>/dev/null && pwd)
39+
endif
40+
endif
41+
42+
ifeq ($(DYNLINK),1)
43+
ifndef LD_LINUX_PATH
44+
$(error "Dynamic linking mode requires ld-linux.so")
45+
endif
46+
endif
47+
48+
RUNNER_LD_PREFIX = -L $(LD_LINUX_PATH)
49+
endif

0 commit comments

Comments
 (0)