separate iar and gcc build for clean make, also add cpu specific make

This commit is contained in:
hathach
2023-06-24 17:35:37 +07:00
parent 50e61e0e16
commit edbf06aaab
10 changed files with 275 additions and 221 deletions

View File

@@ -5,8 +5,15 @@ ifeq ($(TOOLCHAIN),gcc)
-mfloat-abi=hard \
-mfpu=fpv5-d16 \
#set(FREERTOS_PORT GCC_ARM_CM7 CACHE INTERNAL "")
FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/ARM_CM7/r0p1
else ifeq ($(TOOLCHAIN),iar)
# TODO support IAR
CFLAGS += \
--cpu cortex-m7 \
--fpu VFPv5_D16 \
ASFLAGS += \
--cpu cortex-m7 \
--fpu VFPv5_D16 \
endif
FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/ARM_CM7/r0p1

View File

@@ -0,0 +1,77 @@
# makefile for arm gcc toolchain
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
AS = $(CC) -x assembler-with-cpp
LD = $(CC)
GDB = $(CROSS_COMPILE)gdb
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
# CPU specific flags
include $(TOP)/tools/make/cpu/$(CPU_CORE).mk
# ---------------------------------------
# Compiler Flags
# ---------------------------------------
CFLAGS += \
-MD \
-ggdb \
-fdata-sections \
-ffunction-sections \
-fsingle-precision-constant \
-fno-strict-aliasing \
-Wall \
-Wextra \
-Werror \
-Wfatal-errors \
-Wdouble-promotion \
-Wstrict-prototypes \
-Wstrict-overflow \
-Werror-implicit-function-declaration \
-Wfloat-equal \
-Wundef \
-Wshadow \
-Wwrite-strings \
-Wsign-compare \
-Wmissing-format-attribute \
-Wunreachable-code \
-Wcast-align \
-Wcast-function-type \
-Wcast-qual \
-Wnull-dereference \
-Wuninitialized \
-Wunused \
-Wreturn-type \
-Wredundant-decls \
# conversion is too strict for most mcu driver, may be disable sign/int/arith-conversion
# -Wconversion
# Size Optimization as default
CFLAGS_OPTIMIZED ?= -Os
# Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -O0
NO_LTO = 1
else
CFLAGS += $(CFLAGS_OPTIMIZED)
endif
# ---------------------------------------
# Linker Flags
# ---------------------------------------
LDFLAGS += \
-Wl,-Map=$@.map \
-Wl,-cref \
-Wl,-gc-sections \
# Some toolchain such as renesas rx does not support --print-memory-usage flags
ifneq ($(FAMILY),rx)
LDFLAGS += -Wl,--print-memory-usage
endif
LDFLAGS += \
-Wl,--print-memory-usage \

View File

@@ -0,0 +1,78 @@
SRC_S += $(GCC_SRC_S)
# Assembly files can be name with upper case .S, convert it to .s
SRC_S := $(SRC_S:.S=.s)
# Due to GCC LTO bug https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966
# assembly file should be placed first in linking order
# '_asm' suffix is added to object of assembly file
OBJ += $(addprefix $(BUILD)/obj/, $(SRC_S:.s=_asm.o))
OBJ += $(addprefix $(BUILD)/obj/, $(SRC_C:.c=.o))
CFLAGS += $(GCC_CFLAGS) -MD
# LTO makes it difficult to analyze map file for optimizing size purpose
# We will run this option in ci
ifeq ($(NO_LTO),1)
CFLAGS := $(filter-out -flto,$(CFLAGS))
endif
ifneq ($(CFLAGS_SKIP),)
CFLAGS := $(filter-out $(CFLAGS_SKIP),$(CFLAGS))
endif
LDFLAGS += $(CFLAGS)
ifdef LD_FILE
LDFLAGS += -Wl,-T,$(TOP)/$(LD_FILE)
endif
ifdef GCC_LD_FILE
LDFLAGS += -Wl,-T,$(TOP)/$(GCC_LD_FILE)
endif
ifneq ($(SKIP_NANOLIB), 1)
LDFLAGS += --specs=nosys.specs --specs=nano.specs
endif
ASFLAGS += $(CFLAGS)
LIBS_GCC ?= -lgcc -lm -lnosys
# libc
LIBS += $(LIBS_GCC)
ifneq ($(BOARD), spresense)
LIBS += -lc
endif
# ---------------------------------------
# Rules
# ---------------------------------------
# Compile .c file
$(BUILD)/obj/%.o: %.c
@echo CC $(notdir $@)
@$(CC) $(CFLAGS) -c -o $@ $<
# ASM sources lower case .s
$(BUILD)/obj/%_asm.o: %.s
@echo AS $(notdir $@)
@$(AS) $(ASFLAGS) -c -o $@ $<
# ASM sources upper case .S
$(BUILD)/obj/%_asm.o: %.S
@echo AS $(notdir $@)
@$(AS) $(ASFLAGS) -c -o $@ $<
$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) -O binary $^ $@
$(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) -O ihex $^ $@
$(BUILD)/$(PROJECT).elf: $(OBJ)
@echo LINK $@
@$(LD) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group

View File

@@ -0,0 +1,13 @@
# makefile for arm iar toolchain
AS = iasmarm
LD = ilinkarm
OBJCOPY = ielftool --silent
SIZE = size
include $(TOP)/tools/make/cpu/$(CPU_CORE).mk
# Enable extension mode (gcc compatible)
CFLAGS += -e --debug --silent
# silent mode
ASFLAGS += -S

View File

@@ -0,0 +1,44 @@
SRC_S += $(IAR_SRC_S)
# Assembly files can be name with upper case .S, convert it to .s
SRC_S := $(SRC_S:.S=.s)
# Due to GCC LTO bug https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966
# assembly file should be placed first in linking order
# '_asm' suffix is added to object of assembly file
OBJ += $(addprefix $(BUILD)/obj/, $(SRC_S:.s=_asm.o))
OBJ += $(addprefix $(BUILD)/obj/, $(SRC_C:.c=.o))
# Linker script
LDFLAGS += --config $(TOP)/$(IAR_LD_FILE)
# ---------------------------------------
# Rules
# ---------------------------------------
# Compile .c file
$(BUILD)/obj/%.o: %.c
@echo CC $(notdir $@)
@$(CC) $(CFLAGS) -c -o $@ $<
# ASM sources lower case .s
$(BUILD)/obj/%_asm.o: %.s
@echo AS $(notdir $@)
@$(AS) $(ASFLAGS) -c -o $@ $<
# ASM sources upper case .S
$(BUILD)/obj/%_asm.o: %.S
@echo AS $(notdir $@)
@$(AS) $(ASFLAGS) -c -o $@ $<
$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) --bin $^ $@
$(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) --ihex $^ $@
$(BUILD)/$(PROJECT).elf: $(OBJ)
@echo LINK $@
@$(LD) -o $@ $(LDFLAGS) $^