From 7b1a369cf7801f98139189ade463f3a460f78d85 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Wed, 28 Mar 2012 22:57:13 +0200 Subject: build system: completely autodetect target cpu architecture. The existing ARCH Makefile variable is exported to the C code as well. Additionally the version (arm-only for now) is detected as well. This allows to for complete autodetection, i.e. that optimized ASM is picked up if determined by preprocessor (CPU_ARM, etc). Building a sim/raaa on a arm host will now automatically generate a arm optmized build like we have for native targets. Change-Id: I0b35393f8fb3ebd20beaa9e7371fa57bf3782107 --- apps/codecs/codecs.make | 4 +-- apps/codecs/demac/libdemac.make | 2 +- apps/codecs/lib/libcodec.make | 2 +- apps/codecs/libmad/libmad.make | 2 +- apps/codecs/libspeex/libspeex.make | 2 +- apps/codecs/libwmavoice/libwmavoice.make | 2 +- firmware/asm/asm.make | 3 +- firmware/export/config.h | 30 ++++------------- tools/configure | 57 +++++++++++++++++++++++++++++--- tools/root.make | 4 +-- 10 files changed, 69 insertions(+), 39 deletions(-) diff --git a/apps/codecs/codecs.make b/apps/codecs/codecs.make index 605d8a3556..f2d2f13794 100644 --- a/apps/codecs/codecs.make +++ b/apps/codecs/codecs.make @@ -88,7 +88,7 @@ $(WMAPROLIB) : CODECFLAGS += -O1 $(WMAVOICELIB) : CODECFLAGS += -O1 # fine-tuning of CODECFLAGS per cpu arch -ifeq ($(ARCH),arm) +ifeq ($(ARCH),arch_arm) # redo per arm generation $(ALACLIB) : CODECFLAGS += -O2 $(AYLIB) : CODECFLAGS += -O1 @@ -100,7 +100,7 @@ ifeq ($(ARCH),arm) $(VGMLIB) : CODECFLAGS += -O1 $(EMU2413LIB) : CODECFLAGS += -O3 $(WAVPACKLIB) : CODECFLAGS += -O3 -else ifeq ($(ARCH),m68k) +else ifeq ($(ARCH),arch_m68k) $(A52LIB) : CODECFLAGS += -O2 $(ASFLIB) : CODECFLAGS += -O3 $(ATRACLIB) : CODECFLAGS += -O2 diff --git a/apps/codecs/demac/libdemac.make b/apps/codecs/demac/libdemac.make index 4614344849..62ad53dfcc 100644 --- a/apps/codecs/demac/libdemac.make +++ b/apps/codecs/demac/libdemac.make @@ -12,7 +12,7 @@ DEMACLIB := $(CODECDIR)/libdemac.a DEMACLIB_SRC := $(call preprocess, $(APPSDIR)/codecs/demac/libdemac/SOURCES) DEMACLIB_OBJ := $(call c2obj, $(DEMACLIB_SRC)) OTHER_SRC += $(DEMACLIB_SRC) -ifeq ($(CPU),arm) +ifeq ($(ARCH),arch_arm) OTHER_SRC += $(APPSDIR)/codecs/demac/libdemac/udiv32_arm-pre.S endif DEMACLIB_PRE := $(subst .a,-pre.a,$(DEMACLIB)) diff --git a/apps/codecs/lib/libcodec.make b/apps/codecs/lib/libcodec.make index ca9b2c4fe2..7aef72f2b1 100644 --- a/apps/codecs/lib/libcodec.make +++ b/apps/codecs/lib/libcodec.make @@ -20,7 +20,7 @@ CODECLIBFLAGS = $(filter-out -O%,$(CODECFLAGS)) ifeq ($(MEMORYSIZE),2) CODECLIBFLAGS += -Os -else ifeq ($(CPU),coldfire) +else ifeq ($(ARCH),arch_m68k) CODECLIBFLAGS += -O2 else CODECLIBFLAGS += -O1 diff --git a/apps/codecs/libmad/libmad.make b/apps/codecs/libmad/libmad.make index f8423b88fe..4ed8ab1e8c 100644 --- a/apps/codecs/libmad/libmad.make +++ b/apps/codecs/libmad/libmad.make @@ -16,7 +16,7 @@ MADFLAGS = $(filter-out -O%,$(CODECFLAGS)) -I$(APPSDIR)/codecs/libmad MADFLAGS += -UDEBUG -DNDEBUG -DHAVE_LIMITS_H # libmad is faster on ARM-targets with -O1 than -O2 -ifeq ($(CPU),arm) +ifeq ($(ARCH),arch_arm) MADFLAGS += -O1 else MADFLAGS += -O2 diff --git a/apps/codecs/libspeex/libspeex.make b/apps/codecs/libspeex/libspeex.make index cc2c3caee1..1089982d27 100644 --- a/apps/codecs/libspeex/libspeex.make +++ b/apps/codecs/libspeex/libspeex.make @@ -23,7 +23,7 @@ VOICESPEEXFLAGS = $(filter-out -ffunction-sections, $(filter-out -DCODEC,$(_SPEE # libspeex is faster on ARM-targets with -O1 instead of -O2 SPEEXFLAGS = $(filter-out -O%,$(_SPEEXFLAGS)) -ifeq ($(CPU),arm) +ifeq ($(ARCH),arch_arm) SPEEXFLAGS += -O1 else SPEEXFLAGS += -O2 diff --git a/apps/codecs/libwmavoice/libwmavoice.make b/apps/codecs/libwmavoice/libwmavoice.make index 0497e18e1b..b35756c64a 100644 --- a/apps/codecs/libwmavoice/libwmavoice.make +++ b/apps/codecs/libwmavoice/libwmavoice.make @@ -19,7 +19,7 @@ $(WMAVOICELIB): $(WMAVOICELIB_OBJ) WMAVOICEFLAGS = -I$(APPSDIR)/codecs/libwmavoice $(filter-out -O%,$(CODECFLAGS)) -ifeq ($(CPU),coldfire) +ifeq ($(ARCH),arch_m68k) WMAVOICEFLAGS += -O2 else WMAVOICEFLAGS += -O1 diff --git a/firmware/asm/asm.make b/firmware/asm/asm.make index 17b666ee5e..69147c506e 100644 --- a/firmware/asm/asm.make +++ b/firmware/asm/asm.make @@ -10,8 +10,9 @@ # Collect dummy C files in firmware/asm ASM_DUMMY_SRC := $(notdir $(call preprocess, $(FIRMDIR)/asm/SOURCES)) +ASM_ARCH := $(subst arch_,,$(ARCH)) # strip arch_ prefix from $(ARCH) # Get the corresponding real source files under firmware/asm/$ARCH (C or ASM) -ASM_C_SRC := $(addprefix $(FIRMDIR)/asm/$(ARCH)/,$(ASM_DUMMY_SRC)) +ASM_C_SRC := $(addprefix $(FIRMDIR)/asm/$(ASM_ARCH)/,$(ASM_DUMMY_SRC)) ASM_S_SRC := $(ASM_C_SRC:.c=.S) # ASM_SRC now contains only files that exist under $ARCH diff --git a/firmware/export/config.h b/firmware/export/config.h index 80bd83d61d..254128c844 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -526,12 +526,12 @@ Lyre prototype 1 */ #ifndef __PCTOOL__ /* define for all cpus from SH family */ -#if (CONFIG_CPU == SH7034) +#if (ARCH == ARCH_SH) && (CONFIG_CPU == SH7034) #define CPU_SH #endif /* define for all cpus from coldfire family */ -#if (CONFIG_CPU == MCF5249) || (CONFIG_CPU == MCF5250) +#if (ARCH == ARCH_M68K) && ((CONFIG_CPU == MCF5249) || (CONFIG_CPU == MCF5250)) #define CPU_COLDFIRE #endif @@ -565,31 +565,13 @@ Lyre prototype 1 */ #endif /* define for all cpus from ARM family */ -#if ((CONFIG_PLATFORM & PLATFORM_MAEMO5) && defined(MAEMO_ARM_BUILD)) \ - || (CONFIG_PLATFORM & PLATFORM_PANDORA) +#if ARCH == ARCH_ARM #define CPU_ARM -#define ARM_ARCH 7 /* ARMv7 */ - -#elif (CONFIG_CPU == IMX31L) || defined(SAMSUNG_YPR0) \ - || ((CONFIG_PLATFORM & PLATFORM_MAEMO4) && defined(MAEMO_ARM_BUILD)) -#define CPU_ARM -#define ARM_ARCH 6 /* ARMv6 */ - -#elif defined(CPU_TCC77X) || defined(CPU_TCC780X) || (CONFIG_CPU == DM320) \ - || (CONFIG_CPU == AT91SAM9260) || (CONFIG_CPU == AS3525v2) \ - || (CONFIG_CPU == S5L8702) || (CONFIG_CPU == IMX233) \ - || (CONFIG_CPU == RK27XX) ||(CONFIG_PLATFORM & PLATFORM_ANDROID) -#define CPU_ARM -#define ARM_ARCH 5 /* ARMv5 */ - -#elif defined(CPU_PP) || (CONFIG_CPU == PNX0101) || (CONFIG_CPU == S3C2440) \ - || (CONFIG_CPU == DSC25) || defined(CPU_S5L870X) || (CONFIG_CPU == AS3525) -#define CPU_ARM -#define ARM_ARCH 4 /* ARMv4 */ +#define ARM_ARCH ARCH_VERSION /* ARMv{4,5,6,7} */ #endif -#if (CONFIG_CPU == JZ4732) -#define CPU_MIPS 32 +#if ARCH == ARCH_MIPS +#define CPU_MIPS ARCH_VERSION /* 32, 64 */ #endif #endif /*__PCTOOL__*/ diff --git a/tools/configure b/tools/configure index ffded7eb87..5181ce4a19 100755 --- a/tools/configure +++ b/tools/configure @@ -523,6 +523,8 @@ arm7ejscc () { } mipselcc () { + arch="mips" + arch_version=32 # FIXME: autodetect version (32 or 64) prefixtools mipsel-elf- # mips is predefined, but we want it for paths. use __mips instead GCCOPTS="$CCOPTS -march=mips32 -mtune=r4600 -mno-mips16 -mno-long-calls -Umips" @@ -3674,21 +3676,36 @@ if [ -z "$arch" ]; then arch="m68k" elif [ -n "$(echo $cpp_defines | grep -w __arm__)" ]; then arch="arm" + # cpp defines like "#define __ARM_ARCH_4TE__ 1" (where we want to extract the 4) + arch_version="$(echo $cpp_defines | sed s,\ ,\\n,g | grep __ARM_ARCH | sed -e 's,.*\([0-9]\).*,\1,')" elif [ -n "$(echo $cpp_defines | grep -w __mips__)" ]; then - arch="mips" + arch="mips" # FIXME: autodetect version (32 or 64) elif [ -n "$(echo $cpp_defines | grep -w _X86_)" ]; then arch="x86" elif [ -n "$(echo $cpp_defines | grep -w __x86_64__)" ]; then arch="amd64" else - arch="unknown" + arch="none" echo "Warning: Could not determine target arch" fi - if [ "$arch" != "unknown" ]; then - echo "Automatically selected arch: $arch" + if [ "$arch" != "none" ]; then + if [ -n "$arch_version" ]; then + echo "Automatically selected arch: $arch (ver $arch_version)" + else + echo "Automatically selected arch: $arch" + fi fi; else - echo "Manually selected arch: $arch" + if [ -n "$arch_version" ]; then + echo "Manually selected arch: $arch (ver $arch_version)" + else + echo "Manually selected arch: $arch" + fi +fi + +arch="arch_$arch" +if [ -n "$arch_version" ]; then + Darch_version="#define ARCH_VERSION $arch_version" fi if test -n "$ccache"; then @@ -3720,6 +3737,35 @@ cat > autoconf.h <