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
This commit is contained in:
Thomas Martitz 2012-03-28 22:57:13 +02:00
parent c56950ea3a
commit 7b1a369cf7
10 changed files with 69 additions and 39 deletions

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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__*/

57
tools/configure vendored
View file

@ -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 <<EOF
#ifndef __BUILD_AUTOCONF_H
#define __BUILD_AUTOCONF_H
/* lower case names match the what's exported in the Makefile
* upper case name looks nicer in the code */
#define arch_none 0
#define ARCH_NONE 0
#define arch_sh 1
#define ARCH_SH 1
#define arch_m68k 2
#define ARCH_M68K 2
#define arch_arm 3
#define ARCH_ARM 3
#define arch_mips 4
#define ARCH_MIPS 4
#define arch_x86 5
#define ARCH_X86 5
#define arch_amd64 6
#define ARCH_AMD64 6
/* Define target machine architecture */
#define ARCH ${arch}
/* Optinally define architecture version */
${Darch_version}
/* Define endianess for the target or simulator platform */
#define ${defendian} 1
@ -3827,6 +3873,7 @@ export FLASHFILE=${flash}
export TARGET_ID=${target_id}
export TARGET=-D${target}
export ARCH=${arch}
export ARCH_VERSION=${arch_version}
export CPU=${t_cpu}
export MANUFACTURER=${t_manufacturer}
export OBJDIR=${pwd}

View file

@ -79,12 +79,12 @@ endif
#included before codecs.make and plugins.make so they see them)
ifndef APP_TYPE
include $(ROOTDIR)/lib/libsetjmp/libsetjmp.make
ifeq (arm,$(ARCH))
ifeq (arch_arm,$(ARCH))
include $(ROOTDIR)/lib/arm_support/arm_support.make
endif
endif
ifeq (arm,$(ARCH))
ifeq (arch_arm,$(ARCH))
include $(ROOTDIR)/lib/unwarminder/unwarminder.make
endif