2014-02-26 08:54:48 +00:00
|
|
|
# e200z common makefile scripts and rules.
|
2013-11-18 10:52:55 +00:00
|
|
|
|
2014-02-26 08:54:48 +00:00
|
|
|
##############################################################################
|
|
|
|
# Processing options coming from the upper Makefile.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Compiler options
|
2013-11-18 10:52:55 +00:00
|
|
|
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
|
2014-07-17 10:03:21 +00:00
|
|
|
LDOPT := --no-gc-sections
|
2013-11-18 10:52:55 +00:00
|
|
|
endif
|
|
|
|
|
2014-02-26 09:25:35 +00:00
|
|
|
# Linker extra options
|
|
|
|
ifneq ($(USE_LDOPT),)
|
|
|
|
LDOPT := $(LDOPT),$(USE_LDOPT)
|
|
|
|
endif
|
|
|
|
|
2013-11-18 10:52:55 +00:00
|
|
|
# Link time optimizations
|
|
|
|
ifeq ($(USE_LTO),yes)
|
|
|
|
OPT += -flto
|
|
|
|
endif
|
|
|
|
|
|
|
|
# VLE option handling.
|
|
|
|
ifeq ($(USE_VLE),yes)
|
|
|
|
DDEFS += -DPPC_USE_VLE=1
|
|
|
|
DADEFS += -DPPC_USE_VLE=1
|
|
|
|
MCU += -mvle
|
|
|
|
else
|
|
|
|
DDEFS += -DPPC_USE_VLE=0
|
|
|
|
DADEFS += -DPPC_USE_VLE=0
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Process stack size
|
|
|
|
ifeq ($(USE_PROCESS_STACKSIZE),)
|
|
|
|
LDOPT := $(LDOPT),--defsym=__process_stack_size__=0x400
|
|
|
|
else
|
|
|
|
LDOPT := $(LDOPT),--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Exceptions stack size
|
|
|
|
ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
|
2013-11-19 13:59:52 +00:00
|
|
|
LDOPT := $(LDOPT),--defsym=__irq_stack_size__=0x400
|
2013-11-18 10:52:55 +00:00
|
|
|
else
|
2013-11-19 13:59:52 +00:00
|
|
|
LDOPT := $(LDOPT),--defsym=__irq_stack_size__=$(USE_EXCEPTIONS_STACKSIZE)
|
2013-11-18 10:52:55 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
# Output directory and files
|
|
|
|
ifeq ($(BUILDDIR),)
|
|
|
|
BUILDDIR = build
|
|
|
|
endif
|
|
|
|
ifeq ($(BUILDDIR),.)
|
|
|
|
BUILDDIR = build
|
|
|
|
endif
|
|
|
|
OUTFILES = $(BUILDDIR)/$(PROJECT).elf $(BUILDDIR)/$(PROJECT).hex \
|
|
|
|
$(BUILDDIR)/$(PROJECT).mot $(BUILDDIR)/$(PROJECT).bin \
|
2014-10-27 13:26:32 +00:00
|
|
|
$(BUILDDIR)/$(PROJECT).dmp $(BUILDDIR)/$(PROJECT).list
|
|
|
|
|
2013-11-18 10:52:55 +00:00
|
|
|
|
|
|
|
# Source files groups and paths
|
|
|
|
SRC = $(CSRC)$(CPPSRC)
|
|
|
|
SRCPATHS = $(sort $(dir $(ASMXSRC)) $(dir $(ASMSRC)) $(dir $(SRC)))
|
|
|
|
|
|
|
|
# Various directories
|
|
|
|
OBJDIR = $(BUILDDIR)/obj
|
|
|
|
LSTDIR = $(BUILDDIR)/lst
|
|
|
|
|
|
|
|
# Object files groups
|
|
|
|
COBJS = $(addprefix $(OBJDIR)/, $(notdir $(CSRC:.c=.o)))
|
|
|
|
CPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(CPPSRC:.cpp=.o)))
|
|
|
|
ASMOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMSRC:.s=.o)))
|
|
|
|
ASMXOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMXSRC:.S=.o)))
|
|
|
|
OBJS = $(ASMXOBJS) $(ASMOBJS) $(COBJS) $(CPPOBJS)
|
|
|
|
|
|
|
|
# Paths
|
2014-02-26 08:54:48 +00:00
|
|
|
IINCDIR = $(patsubst %,-I%,$(INCDIR) $(DINCDIR) $(UINCDIR))
|
|
|
|
LLIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
|
2013-11-18 10:52:55 +00:00
|
|
|
|
|
|
|
# Macros
|
2014-02-26 08:54:48 +00:00
|
|
|
DEFS = $(DDEFS) $(UDEFS)
|
|
|
|
ADEFS = $(DADEFS) $(UADEFS)
|
2013-11-18 10:52:55 +00:00
|
|
|
|
|
|
|
# Libs
|
2014-02-26 08:54:48 +00:00
|
|
|
LIBS = $(DLIBS) $(ULIBS)
|
2013-11-18 10:52:55 +00:00
|
|
|
|
|
|
|
# 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)
|
2014-02-26 09:01:20 +00:00
|
|
|
LDFLAGS = $(MCFLAGS) $(OPT) -nostartfiles $(LLIBDIR) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--library-path=$(RULESPATH),$(LDOPT),--script=$(LDSCRIPT)
|
2013-11-18 10:52:55 +00:00
|
|
|
|
|
|
|
# Generate dependency information
|
2014-05-11 07:44:38 +00:00
|
|
|
ASFLAGS += -MD -MP -MF .dep/$(@F).d
|
2013-11-18 10:52:55 +00:00
|
|
|
CFLAGS += -MD -MP -MF .dep/$(@F).d
|
|
|
|
CPPFLAGS += -MD -MP -MF .dep/$(@F).d
|
|
|
|
|
|
|
|
# Paths where to search for sources
|
|
|
|
VPATH = $(SRCPATHS)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Makefile rules
|
|
|
|
#
|
|
|
|
|
|
|
|
all: $(OBJS) $(OUTFILES) MAKE_ALL_RULE_HOOK
|
|
|
|
|
|
|
|
MAKE_ALL_RULE_HOOK:
|
|
|
|
|
|
|
|
$(OBJS): | $(BUILDDIR)
|
|
|
|
|
|
|
|
$(BUILDDIR) $(OBJDIR) $(LSTDIR):
|
|
|
|
ifneq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
@echo Compiler Options
|
|
|
|
@echo $(CC) -c $(CFLAGS) -I. $(IINCDIR) main.c -o main.o
|
|
|
|
@echo
|
|
|
|
endif
|
|
|
|
mkdir -p $(OBJDIR)
|
|
|
|
mkdir -p $(LSTDIR)
|
|
|
|
|
|
|
|
$(CPPOBJS) : $(OBJDIR)/%.o : %.cpp Makefile
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
@echo
|
|
|
|
$(CPPC) -c $(CPPFLAGS) -I. $(IINCDIR) $< -o $@
|
|
|
|
else
|
|
|
|
@echo Compiling $(<F)
|
|
|
|
@$(CPPC) -c $(CPPFLAGS) -I. $(IINCDIR) $< -o $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(COBJS) : $(OBJDIR)/%.o : %.c Makefile
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
@echo
|
|
|
|
$(CC) -c $(CFLAGS) -I. $(IINCDIR) $< -o $@
|
|
|
|
else
|
|
|
|
@echo Compiling $(<F)
|
|
|
|
@$(CC) -c $(CFLAGS) -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-02-26 08:54:48 +00:00
|
|
|
@echo
|
2013-11-18 10:52:55 +00:00
|
|
|
$(CC) -c $(ASXFLAGS) -I. $(IINCDIR) $< -o $@
|
|
|
|
else
|
|
|
|
@echo Compiling $(<F)
|
|
|
|
@$(CC) -c $(ASXFLAGS) -I. $(IINCDIR) $< -o $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
%.elf: $(OBJS) $(LDSCRIPT)
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
@echo
|
|
|
|
$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
|
|
|
|
else
|
|
|
|
@echo Linking $@
|
|
|
|
@$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
%.hex: %.elf $(LDSCRIPT)
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
$(HEX) $< $@
|
|
|
|
else
|
|
|
|
@echo Creating $@
|
|
|
|
@$(HEX) $< $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
%.mot: %.elf $(LDSCRIPT)
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
$(MOT) $< $@
|
|
|
|
else
|
|
|
|
@echo Creating $@
|
|
|
|
@$(MOT) $< $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
%.bin: %.elf $(LDSCRIPT)
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
$(BIN) $< $@
|
|
|
|
else
|
|
|
|
@echo Creating $@
|
|
|
|
@$(BIN) $< $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
%.dmp: %.elf $(LDSCRIPT)
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
$(OD) $(ODFLAGS) $< > $@
|
2014-11-28 09:08:19 +00:00
|
|
|
$(SZ) $<
|
2013-11-18 10:52:55 +00:00
|
|
|
else
|
|
|
|
@echo Creating $@
|
|
|
|
@$(OD) $(ODFLAGS) $< > $@
|
|
|
|
@echo
|
|
|
|
@$(SZ) $<
|
|
|
|
@echo
|
|
|
|
@echo Done
|
|
|
|
endif
|
|
|
|
|
2014-10-27 13:26:32 +00:00
|
|
|
%.list: %.elf $(LDSCRIPT)
|
|
|
|
ifeq ($(USE_VERBOSE_COMPILE),yes)
|
|
|
|
$(OD) -S $< > $@
|
|
|
|
else
|
|
|
|
@echo Creating $@
|
|
|
|
@$(OD) -S $< > $@
|
|
|
|
@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
|
|
|
|
|
2013-11-18 10:52:55 +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 ***
|