From ce583ece03817055eebaa34a4bf777cfcf41d19d Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Thu, 26 Jan 2017 00:35:36 +0100 Subject: [PATCH] Makefile: Improve auto-detection of ARM cross compiler Try an 'educated guess' for a suitable toolchain if no explicit CROSS_COMPILE was set (but still default to "arm-none-eabi-"). Signed-off-by: Bernhard Nortmann --- Makefile | 7 +++++-- README.md | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 11721e4..dea2864 100644 --- a/Makefile +++ b/Makefile @@ -52,9 +52,12 @@ MISC_TOOLS = phoenix_info sunxi-nand-image-builder # Note: To use this target, set/adjust CROSS_COMPILE and MKSUNXIBOOT if needed BINFILES = jtag-loop.sunxi fel-sdboot.sunxi uart0-helloworld-sdboot.sunxi -CROSS_COMPILE ?= arm-none-eabi- -CROSS_CC ?= $(CROSS_COMPILE)gcc 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' | cut -f 1 | sed -e 's/-gcc/-/'),$(CROSS_DEFAULT)) +CROSS_CC ?= $(CROSS_COMPILE)gcc DESTDIR ?= PREFIX ?= /usr/local diff --git a/README.md b/README.md index ef43d90..e9d7803 100644 --- a/README.md +++ b/README.md @@ -112,8 +112,9 @@ and our default target (when simply using `make`). * `make target-tools` builds tools that are intended for the target (Allwinner SoC), using a -cross-compiler. The toolchain prefix *CROSS_COMPILE* defaults to `arm-none-eabi-`, -adjust it if needed. +cross-compiler. The Makefile will try to auto-detect a suitable toolchain +prefix, and falls back to `arm-none-eabi-` otherwise. +If needed, you may override this by explicitly setting *CROSS_COMPILE*.
_Hint:_ When compiling 'natively' on the target platform you may simply use an empty toolchain prefix here (`make target-tools CROSS_COMPILE=` or `make all CROSS_COMPILE=`).