@@ -12,4 +12,36 @@ 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-gnueabi/
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-gnueabi".
21+ #
22+ # For example, if the toolchain is installed under "/opt/arm",
23+ # the command "arm-linux-gnueabi-gcc --print-sysroot" will
24+ # prints "/opt/arm/sysroot", and the build system can use this
25+ # as LD_LINUX_PATH directly.
26+ CROSS_COMPILE = arm-linux-gnueabi-
27+ ARM_CC = $(CROSS_COMPILE ) gcc
28+ ARM_CC := $(shell which $(ARM_CC ) )
29+ LD_LINUX_PATH := $(shell cd $(shell $(ARM_CC ) --print-sysroot) 2>/dev/null && pwd)
30+ ifeq ("$(LD_LINUX_PATH ) ","/")
31+ LD_LINUX_PATH := $(shell dirname "$(shell which $(ARM_CC ) ) ") /..
32+ LD_LINUX_PATH := $(shell cd $(LD_LINUX_PATH ) 2>/dev/null && pwd)
33+ LD_LINUX_PATH := $(LD_LINUX_PATH ) /$(shell echo $(CROSS_COMPILE ) | sed s'/.$$//') /libc
34+ LD_LINUX_PATH := $(shell cd $(LD_LINUX_PATH ) 2>/dev/null && pwd)
35+ ifndef LD_LINUX_PATH
36+ LD_LINUX_PATH = /usr/$(shell echo $(CROSS_COMPILE ) | sed s'/.$$//')
37+ LD_LINUX_PATH := $(shell cd $(LD_LINUX_PATH ) 2>/dev/null && pwd)
38+ endif
39+ endif
40+
41+ ifeq ($(DYNLINK ) ,1)
42+ ifndef LD_LINUX_PATH
43+ $(error "Dynamic linking mode requires ld-linux.so")
44+ endif
45+ endif
46+
47+ RUNNER_LD_PREFIX = -L $(LD_LINUX_PATH )
0 commit comments