2014-05-14 08:56:55 +00:00
|
|
|
# ARM Cortex-Mx common makefile scripts and rules.
|
2014-05-14 08:49:13 +00:00
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
# Processing options coming from the upper Makefile.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Compiler options
|
|
|
|
OPT = $(USE_OPT)
|
|
|
|
COPT = $(USE_COPT)
|
|
|
|
CPPOPT = $(USE_CPPOPT)
|
|
|
|
|
|
|
|
# Garbage collection
|
|
|
|
ifeq ($(USE_LINK_GC),yes)
|
|
|
|
OPT += -ffunction-sections -fdata-sections -fno-common
|
|
|
|
LDOPT := ,--gc-sections
|
|
|
|
else
|
|
|
|
LDOPT :=
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Linker extra options
|
|
|
|
ifneq ($(USE_LDOPT),)
|
|
|
|
LDOPT := $(LDOPT),$(USE_LDOPT)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Link time optimizations
|
|
|
|
ifeq ($(USE_LTO),yes)
|
|
|
|
OPT += -flto
|
|
|
|
endif
|
|
|
|
|
2014-05-14 08:56:55 +00:00
|
|
|
# Undefined state stack size
|
|
|
|
ifeq ($(USE_UND_STACKSIZE),)
|
|
|
|
LDOPT := $(LDOPT),--defsym=__und_stack_size__=8
|
|
|
|
else
|
|
|
|
LDOPT := $(LDOPT),--defsym=__und_stack_size__=$(USE_UND_STACKSIZE)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Abort stack size
|
|
|
|
ifeq ($(USE_ABT_STACKSIZE),)
|
|
|
|
LDOPT := $(LDOPT),--defsym=__abt_stack_size__=8
|
|
|
|
else
|
|
|
|
LDOPT := $(LDOPT),--defsym=__abt_stack_size__=$(USE_ABT_STACKSIZE)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# FIQ stack size
|
|
|
|
ifeq ($(USE_FIQ_STACKSIZE),)
|
|
|
|
LDOPT := $(LDOPT),--defsym=__fiq_stack_size__=64
|
|
|
|
else
|
|
|
|
LDOPT := $(LDOPT),--defsym=__fiq_stack_size__=$(USE_FIQ_STACKSIZE)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# IRQ stack size
|
|
|
|
ifeq ($(USE_IRQ_STACKSIZE),)
|
|
|
|
LDOPT := $(LDOPT),--defsym=__irq_stack_size__=0x400
|
|
|
|
else
|
|
|
|
LDOPT := $(LDOPT),--defsym=__irq_stack_size__=$(USE_IRQ_STACKSIZE)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Supervisor stack size
|
|
|
|
ifeq ($(USE_SUPERVISOR_STACKSIZE),)
|
|
|
|
LDOPT := $(LDOPT),--defsym=__svc_stack_size__=8
|
|
|
|
else
|
|
|
|
LDOPT := $(LDOPT),--defsym=__svc_stack_size__=$(USE_SUPERVISOR_STACKSIZE)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# System stack size
|
|
|
|
ifeq ($(USE_SYSTEM_STACKSIZE),)
|
|
|
|
LDOPT := $(LDOPT),--defsym=__sys_stack_size__=0x400
|
|
|
|
else
|
|
|
|
LDOPT := $(LDOPT),--defsym=__sys_stack_size__=$(USE_SYSTEM_STACKSIZE)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Output directory and files
|
|
|
|
ifeq ($(BUILDDIR),)
|
|
|
|
BUILDDIR = build
|
|
|
|
endif
|
|
|
|
ifeq ($(BUILDDIR),.)
|
|
|
|
BUILDDIR = build
|
|
|
|
endif
|
|
|
|
OUTFILES = $(BUILDDIR)/$(PROJECT).elf $(BUILDDIR)/$(PROJECT).hex \
|
2014-10-27 13:26:32 +00:00
|
|
|
$(BUILDDIR)/$(PROJECT).bin $(BUILDDIR)/$(PROJECT).dmp \
|
|
|
|
$(BUILDDIR)/$(PROJECT).list
|
|
|
|
|
2014-05-14 08:56:55 +00:00
|
|
|
|
2014-05-14 08:49:13 +00:00
|
|
|
# Source files groups and paths
|
|
|
|
ifeq ($(USE_THUMB),yes)
|
|
|
|
TCSRC += $(CSRC)
|
|
|
|
TCPPSRC += $(CPPSRC)
|
|
|
|
else
|
|
|
|
ACSRC += $(CSRC)
|
|
|
|
ACPPSRC += $(CPPSRC)
|
|
|
|
endif
|
|
|
|
ASRC = $(ACSRC)$(ACPPSRC)
|
|
|
|
TSRC = $(TCSRC)$(TCPPSRC)
|
|
|
|
SRCPATHS = $(sort $(dir $(ASMXSRC)) $(dir $(ASMSRC)) $(dir $(ASRC)) $(dir $(TSRC)))
|
|
|
|
|
|
|
|
# Various directories
|
|
|
|
OBJDIR = $(BUILDDIR)/obj
|
|
|
|
LSTDIR = $(BUILDDIR)/lst
|
|
|
|
|
|
|
|
# Object files groups
|
|
|
|
ACOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACSRC:.c=.o)))
|
|
|
|
ACPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACPPSRC:.cpp=.o)))
|
|
|
|
TCOBJS = $(addprefix $(OBJDIR)/, $(notdir $(TCSRC:.c=.o)))
|
|
|
|
TCPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(TCPPSRC:.cpp=.o)))
|
|
|
|
ASMOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMSRC:.s=.o)))
|
|
|
|
ASMXOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMXSRC:.S=.o)))
|
|
|
|
OBJS = $(ASMXOBJS) $(ASMOBJS) $(ACOBJS) $(TCOBJS) $(ACPPOBJS) $(TCPPOBJS)
|
|
|
|
|
|
|
|
# Paths
|
|
|
|
IINCDIR = $(patsubst %,-I%,$(INCDIR) $(DINCDIR) $(UINCDIR))
|
|
|
|
LLIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
|
|
|
|
|
|
|
|
# Macros
|
|
|
|
DEFS = $(DDEFS) $(UDEFS)
|
|
|
|
ADEFS = $(DADEFS) $(UADEFS)
|
|
|
|
|
|
|
|
# Libs
|
|
|
|
LIBS = $(DLIBS) $(ULIBS)
|
|
|
|
|
|
|
|
# Various settings
|
|
|
|
MCFLAGS = -mcpu=$(MCU)
|
|
|
|
ODFLAGS = -x --syms
|
|
|
|
ASFLAGS = $(MCFLAGS) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.s=.lst)) $(ADEFS)
|
|
|
|
ASXFLAGS = $(MCFLAGS) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.S=.lst)) $(ADEFS)
|
|
|
|
CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.c=.lst)) $(DEFS)
|
|
|
|
CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.cpp=.lst)) $(DEFS)
|
|
|
|
LDFLAGS = $(MCFLAGS) $(OPT) -nostartfiles $(LLIBDIR) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--library-path=$(RULESPATH),--script=$(LDSCRIPT)$(LDOPT)
|
|
|
|
|
|
|
|
# Thumb interwork enabled only if needed because it kills performance.
|
|
|
|
ifneq ($(TSRC),)
|
|
|
|
CFLAGS += -DTHUMB_PRESENT
|
|
|
|
CPPFLAGS += -DTHUMB_PRESENT
|
|
|
|
ASFLAGS += -DTHUMB_PRESENT
|
|
|
|
ifneq ($(ASRC),)
|
|
|
|
# Mixed ARM and THUMB mode.
|
|
|
|
CFLAGS += -mthumb-interwork
|
|
|
|
CPPFLAGS += -mthumb-interwork
|
|
|
|
ASFLAGS += -mthumb-interwork
|
|
|
|
LDFLAGS += -mthumb-interwork
|
|
|
|
else
|
|
|
|
# Pure THUMB mode, THUMB C code cannot be called by ARM asm code directly.
|
|
|
|
CFLAGS += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING
|
|
|
|
CPPFLAGS += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING
|
|
|
|
ASFLAGS += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -mthumb
|
|
|
|
LDFLAGS += -mno-thumb-interwork -mthumb
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
# Pure ARM mode
|
|
|
|
CFLAGS += -mno-thumb-interwork
|
|
|
|
CPPFLAGS += -mno-thumb-interwork
|
|
|
|
ASFLAGS += -mno-thumb-interwork
|
|
|
|
LDFLAGS += -mno-thumb-interwork
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Generate dependency information
|
|
|
|
ASFLAGS += -MD -MP -MF .dep/$(@F).d
|
|
|
|
CFLAGS += -MD -MP -MF .dep/$(@F).d
|
|
|
|
CPPFLAGS += -MD -MP -MF .dep/$(@F).d
|
|
|
|
|
|
|
|
# Paths where to search for sources
|
|
|
|
VPATH = $(SRCPATHS)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Makefile rules
|
|
|
|
#
|
|
|
|
|
2015-04-19 08:13:55 +00:00
|
|
|
all: PRE_MAKE_ALL_RULE_HOOK $(OBJS) $(OUTFILES) POST_MAKE_ALL_RULE_HOOK
|
2014-05-14 08:49:13 +00:00
|
|
|
|
2015-04-19 08:13:55 +00:00
|
|
|
PRE_MAKE_ALL_RULE_HOOK:
|
|
|
|
|
|
|
|
POST_MAKE_ALL_RULE_HOOK:
|
2014-05-14 08:49:13 +00:00
|
|
|
|
2015-04-26 17:30:54 +00:00
|
|
|
$(OBJS): | $(BUILDDIR) $(OBJDIR) $(LSTDIR)
|
2014-05-14 08:49:13 +00:00
|
|
|
|
2015-04-26 17:30:54 +00:00
|
|
|
$(BUILDDIR):
|
2014-05-14 08:49:13 +00:00
|
|
|
ifneq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
@echo Compiler Options
|
|
|
|
@echo $(CC) -c $(CFLAGS) -I. $(IINCDIR) main.c -o main.o
|
|
|
|
@echo
|
|
|
|
endif
|
2015-04-26 17:30:54 +00:00
|
|
|
@mkdir -p $(BUILDDIR)
|
|
|
|
|
|
|
|
$(OBJDIR):
|
|
|
|
@mkdir -p $(OBJDIR)
|
|
|
|
|
|
|
|
$(LSTDIR):
|
|
|
|
@mkdir -p $(LSTDIR)
|
2014-05-14 08:49:13 +00:00
|
|
|
|
|
|
|
$(ACPPOBJS) : $(OBJDIR)/%.o : %.cpp Makefile
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
@echo
|
|
|
|
$(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
|
|
|
|
else
|
|
|
|
@echo Compiling $(<F)
|
|
|
|
@$(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(TCPPOBJS) : $(OBJDIR)/%.o : %.cpp Makefile
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
@echo
|
|
|
|
$(CPPC) -c $(CPPFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
|
|
|
|
else
|
|
|
|
@echo Compiling $(<F)
|
|
|
|
@$(CPPC) -c $(CPPFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(ACOBJS) : $(OBJDIR)/%.o : %.c Makefile
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
@echo
|
|
|
|
$(CC) -c $(CFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
|
|
|
|
else
|
|
|
|
@echo Compiling $(<F)
|
|
|
|
@$(CC) -c $(CFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(TCOBJS) : $(OBJDIR)/%.o : %.c Makefile
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
@echo
|
|
|
|
$(CC) -c $(CFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
|
|
|
|
else
|
|
|
|
@echo Compiling $(<F)
|
|
|
|
@$(CC) -c $(CFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(ASMOBJS) : $(OBJDIR)/%.o : %.s Makefile
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
@echo
|
|
|
|
$(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@
|
|
|
|
else
|
|
|
|
@echo Compiling $(<F)
|
|
|
|
@$(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(ASMXOBJS) : $(OBJDIR)/%.o : %.S Makefile
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
2014-05-14 08:56:55 +00:00
|
|
|
@echo
|
2014-05-14 08:49:13 +00:00
|
|
|
$(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
|
|
|
|
else
|
|
|
|
@echo Compiling $(<F)
|
|
|
|
@$(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
|
|
|
|
endif
|
|
|
|
|
2015-11-07 08:07:54 +00:00
|
|
|
$(BUILDDIR)/$(PROJECT).elf: $(OBJS) $(LDSCRIPT)
|
2014-05-14 08:49:13 +00:00
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
@echo
|
|
|
|
$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
|
|
|
|
else
|
|
|
|
@echo Linking $@
|
|
|
|
@$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
|
|
|
|
endif
|
|
|
|
|
2015-11-07 08:07:54 +00:00
|
|
|
%.hex: %.elf
|
2014-05-14 08:49:13 +00:00
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
$(HEX) $< $@
|
|
|
|
else
|
|
|
|
@echo Creating $@
|
|
|
|
@$(HEX) $< $@
|
|
|
|
endif
|
|
|
|
|
2015-11-07 08:07:54 +00:00
|
|
|
%.bin: %.elf
|
2014-05-14 08:49:13 +00:00
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
$(BIN) $< $@
|
|
|
|
else
|
|
|
|
@echo Creating $@
|
|
|
|
@$(BIN) $< $@
|
|
|
|
endif
|
|
|
|
|
2015-11-07 08:07:54 +00:00
|
|
|
%.dmp: %.elf
|
2014-05-14 08:49:13 +00:00
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
$(OD) $(ODFLAGS) $< > $@
|
2014-11-28 09:08:19 +00:00
|
|
|
$(SZ) $<
|
2014-05-14 08:49:13 +00:00
|
|
|
else
|
|
|
|
@echo Creating $@
|
|
|
|
@$(OD) $(ODFLAGS) $< > $@
|
|
|
|
@echo
|
|
|
|
@$(SZ) $<
|
|
|
|
endif
|
|
|
|
|
2015-11-07 08:07:54 +00:00
|
|
|
%.list: %.elf
|
2014-10-27 13:26:32 +00:00
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
$(OD) -S $< > $@
|
|
|
|
else
|
|
|
|
@echo Creating $@
|
|
|
|
@$(OD) -S $< > $@
|
2015-04-03 08:13:11 +00:00
|
|
|
@echo
|
2014-10-27 13:26:32 +00:00
|
|
|
@echo Done
|
|
|
|
endif
|
|
|
|
|
2014-08-01 07:19:47 +00:00
|
|
|
lib: $(OBJS) $(BUILDDIR)/lib$(PROJECT).a
|
|
|
|
|
|
|
|
$(BUILDDIR)/lib$(PROJECT).a: $(OBJS)
|
|
|
|
@$(AR) -r $@ $^
|
|
|
|
@echo
|
|
|
|
@echo Done
|
|
|
|
|
2014-05-14 08:49:13 +00:00
|
|
|
clean:
|
|
|
|
@echo Cleaning
|
|
|
|
-rm -fR .dep $(BUILDDIR)
|
|
|
|
@echo
|
|
|
|
@echo Done
|
|
|
|
|
|
|
|
#
|
|
|
|
# Include the dependency files, should be the last of the makefile
|
|
|
|
#
|
|
|
|
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
|
|
|
|
|
|
|
# *** EOF ***
|