Makefile: Improve auto-detection of ARM cross compiler

This patch moves the scan for an ARM gcc into a separate shell
script. To prevent against recursion issues, the new script adds
"-maxdepth 1" to the find invocation; and it now also correctly
handles directories in $PATH that contain spaces in their name.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann@web.de>
This commit is contained in:
Bernhard Nortmann 2017-02-11 13:50:14 +01:00
parent 5e8ea17382
commit d5f5d5d1ad
3 changed files with 16 additions and 4 deletions

View File

@ -56,8 +56,8 @@ MKSUNXIBOOT ?= mksunxiboot
PATH_DIRS := $(shell echo $$PATH | sed -e 's/:/ /g')
# Try to guess a suitable default ARM cross toolchain
CROSS_DEFAULT := arm-none-eabi-
CROSS_COMPILE ?= $(or $(shell find $(PATH_DIRS) -executable -name 'arm*-gcc' -printf '%f\t' 2>/dev/null | cut -f 1 | sed -e 's/-gcc/-/'),$(CROSS_DEFAULT))
CROSS_CC ?= $(CROSS_COMPILE)gcc
CROSS_COMPILE ?= $(or $(shell ./find-arm-gcc.sh),$(CROSS_DEFAULT))
CROSS_CC := $(CROSS_COMPILE)gcc
DESTDIR ?=
PREFIX ?= /usr/local

13
find-arm-gcc.sh Executable file
View File

@ -0,0 +1,13 @@
#
# Try to locate suitable ARM cross compilers available via $PATH
# If any are found, this function will output them as a TAB-delimited list
#
scan_path () {
IFS=":"
for path in $PATH; do
find "$path" -maxdepth 1 -executable -name 'arm*-gcc' -printf '%f\t' 2>/dev/null
done
}
# Use only the first field from result, and convert it to a toolchain prefix
scan_path | cut -f 1 | sed -e 's/-gcc/-/'

View File

@ -17,8 +17,7 @@ all: $(SPL_THUNK) $(THUNKS)
FORCE:
# If not specified explicitly: try to guess a suitable ARM toolchain prefix
PATH_DIRS := $(shell echo $$PATH | sed -e 's/:/ /g')
CROSS_COMPILE ?= $(shell find $(PATH_DIRS) -executable -name 'arm*-gcc' -printf '%f\t' | cut -f 1 | sed -e 's/-gcc/-/')
CROSS_COMPILE ?= $(shell ../find-arm-gcc.sh)
AS := $(CROSS_COMPILE)as
OBJDUMP := $(CROSS_COMPILE)objdump