# Generic makefile for Parallax Propeller chips # To be included into project-specific makefile # Watch out: work in progress! # (c) 2012 Stefan Brantschen # Propeller GCC installation location # ------------------------------------ PROPELLER_PATH := /opt/parallax/ PROPELLER_TOOL_PATH := $(PROPELLER_PATH)bin/ # Configuration # ------------- # Define MEMORY_MODEL and BOARD in the project-specific makefile, or use the make # command line options "mm=xxx" and "b=xxx". Defs in the project-specific makefile # supersede the command line options. # Memory model, default is lmm ifeq ($(MEMORY_MODEL),) mm = lmm MEMORY_MODEL = $(mm) endif # Board, default is ASC ifeq ($(BOARD),) b = ASC BOARD = $(b) endif # Build flags/options # ------------------- # Common flags COMMON_FLAGS := $(DEFS) COMMON_FLAGS += -Wall COMMON_FLAGS += -ffreestanding #COMMON_FLAGS += -funsigned-char #COMMON_FLAGS += -funsigned-bitfields COMMON_FLAGS += -I. COMMON_FLAGS += $(addprefix -I, $(SOURCE_DIRS)) COMMON_FLAGS += -b$(BOARD) C_CC_FLAGS = $(COMMON_FLAGS) C_CC_FLAGS += -ffunction-sections -fdata-sections C_CC_FLAGS += -m$(MEMORY_MODEL) # Resulting flags CFLAGS := $(C_CC_FLAGS) -std=gnu99 -Wstrict-prototypes -pedantic $(CFLAGS) CXXFLAGS := $(C_CC_FLAGS) -fno-exceptions -fno-rtti $(CXXFLAGS) COGCFLAGS := $(COMMON_FLAGS) -std=gnu99 $(COGCFLAGS) # Linker flags # ------------ #LDFLAGS := --gc-sections $(LDFLAGS) LDFLAGS := $(LDFLAGS) ifneq ($(LIBDIRS),) LDFLAGS += -L $(LIBDIRS) endif # Load flags # ------------ LOADFLAGS += -b $(BOARD) LOADFLAGS += -S1 # Dependency checking flags # ------------------------- # -M means includes system files DEPFLAGS = -M #DEPFLAGS = -MM # Build directory # --------------- BUILDDIRNAME := buildir BUILDDIR := $(BUILDDIRNAME)/ # Source files: collect the sources # --------------------------------- # C CDIRS := $(SOURCE_DIRS) CDIRS := *.c $(addsuffix *.c, $(CDIRS)) CSRC := $(shell ls $(CDIRS) 2>/dev/null) # CPP CPPDIRS := $(SOURCE_DIRS) CPPDIRS := *.cpp $(addsuffix *.cpp, $(CPPDIRS)) CPPSRC := $(shell ls $(CPPDIRS) 2>/dev/null) # CC CCDIRS := $(SOURCE_DIRS) CCDIRS := *.cc $(addsuffix *.cc, $(CCDIRS)) CCSRC := $(shell ls $(CCDIRS) 2>/dev/null) # Cog C COGCDIRS := $(SOURCE_DIRS) COGCDIRS := *.cogc $(addsuffix *.cogc, $(COGCDIRS)) COGCSRC := $(shell ls $(COGCDIRS) 2>/dev/null) # E-Cog C ECOGCDIRS := $(SOURCE_DIRS) ECOGCDIRS := *.ecogc $(addsuffix *.ecogc, $(ECOGCDIRS)) ECOGCSRC := $(shell ls $(ECOGCDIRS) 2>/dev/null) # Object files # ------------ COBJ := $(CSRC:.c=.o) CPPOBJ := $(CPPSRC:.cpp=.o) CCOBJ := $(CCSRC:.cc=.o) COGCOBJ := $(COGCSRC:.cogc=.cog) ECOGCOBJ := $(ECOGCSRC:.ecogc=.ecog) OBJS := $(COBJ) $(CPPOBJ) $(CCOBJ) $(COGCOBJ) $(ECOGCOBJ) OBJDIRS := $(dir $(OBJS)) # Target files # ------------ ELFNAME := $(TARGETNAME).elf LIBNAME := $(TARGETNAME).a # Dependency files # ----------------- CDEP := $(COBJ:.o=.d) CPPDEP := $(CPPOBJ:.o=.d) CCDEP := $(CCOBJ:.o=.d) COGCDEP := $(COGCOBJ:.cog=.dc) ECOGCDEP := $(ECOGCOBJ:.ecog=.de) DEPS := $(CDEP) $(CPPDEP) $(CCDEP) $(COGCDEP) $(ECOGCDEP) # Tools and commands # ------------------ CC := $(PROPELLER_TOOL_PATH)propeller-elf-gcc CXX := $(PROPELLER_TOOL_PATH)propeller-elf-g++ LD := $(PROPELLER_TOOL_PATH)propeller-elf-ld AS := $(PROPELLER_TOOL_PATH)propeller-elf-as OBJCOPY := $(PROPELLER_TOOL_PATH)propeller-elf-objcopy LOAD := $(PROPELLER_TOOL_PATH)propeller-load SIZE := $(PROPELLER_TOOL_PATH)propeller-elf-size -A AR := $(PROPELLER_TOOL_PATH)propeller-elf-ar RM := rm -rf MKDIR := mkdir -p TESTDIR := test -d # Build rules # ----------- # We need an elf file for uploading # Plain file version $(BUILDDIR)$(ELFNAME): $(addprefix $(BUILDDIR), $(OBJS)) $(CC) $(LDFLAGS) -o $@ $(addprefix $(BUILDDIR), $(OBJS)) $(LIBS) -s # version using a library #$(BUILDDIR)(ELFNAME): $(LIBNAME)($(addprefix $(BUILDDIR), $(OBJS))) # $(CC) $(LDFLAGS) -o $@ $(LIBNAME) $(LIBS) -s $(BUILDDIR)%.o: %.c $(CC) $(CFLAGS) -o $@ -c $< $(BUILDDIR)%.o: %.cc $(CC) $(CXXFLAGS) -o $@ -c $< $(BUILDDIR)%.o: %.cpp $(CC) $(CXXFLAGS) -o $@ -c $< $(BUILDDIR)%.cog: %.cogc $(CC) -r $(COGCFLAGS) -mcog -o $@ -xc $< $(OBJCOPY) --rename-section .text=$@ --localize-text $@ $(BUILDDIR)%.ecog: %.ecogc $(CC) -r $(COGCFLAGS) -mcog -o $@ -xc $< $(OBJCOPY) --rename-section .text=$@ --localize-text $@ # Create a library for the object files $(LIBNAME)(): $(addprefix $(BUILDDIR), $(OBJS)) # Our phonies # ----------- .PHONY: obj obj: $(addprefix $(BUILDDIR), $(OBJS)) .PHONY: lib lib: $(LIBNAME)($(OBJS)) $(AR) -t $(LIBNAME) .PHONY: elf elf: $(BUILDDIR)$(ELFNAME) $(SIZE) $(BUILDDIR)$(ELFNAME) .PHONY: clean clean: $(RM) $(BUILDDIR) # $(RM) *.o *.elf *.cog *.ecog *.binary *.a *.d *.dc *.de .PHONY: run run: $(BUILDDIR)$(ELFNAME) $(LOAD) $(LOADFLAGS) $(BUILDDIR)$(ELFNAME) -r -t # Dependency Rules/Files Creation and Inclusion # --------------------------------------------- # Recipe, using $(CC) -MM for its magic (see make man page and make manual section 4.14) CREATE_DEP_FILE = $(MKDIR) $(addprefix $(BUILDDIR),$(OBJDIRS)); \ set -e; $(RM) $@;\ $(CC) $(DEPFLAGS) $(C_CC_FLAGS) $< > $@.$$$$;\ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@;\ $(RM) $@.$$$$ CREATE_DEP_FILE2 = $(MKDIR) $(addprefix $(BUILDDIR),$(OBJDIRS)); \ set -e; $(RM) $@;\ $(CC) $(DEPFLAGS) $(COGCFLAGS) -xc $< > $@.$$$$;\ sed 's,\($*\)\.o[ :]*,\1.cog $@ : ,g' < $@.$$$$ > $@;\ $(RM) $@.$$$$ CREATE_DEP_FILE3 = $(MKDIR) $(addprefix $(BUILDDIR),$(OBJDIRS)); \ set -e; $(RM) $@;\ $(CC) $(DEPFLAGS) $(COGCFLAGS) -xc $< > $@.$$$$;\ sed 's,\($*\)\.o[ :]*,\1.ecog $@ : ,g' < $@.$$$$ > $@;\ $(RM) $@.$$$$ # Rules for dep files $(BUILDDIR)%.d: %.c @$(CREATE_DEP_FILE) $(BUILDDIR)%.d: %.cc @$(CREATE_DEP_FILE) $(BUILDDIR)%.d: %.cpp @$(CREATE_DEP_FILE) $(BUILDDIR)%.dc: %.cogc @$(CREATE_DEP_FILE2) $(BUILDDIR)%.de: %.ecogc @$(CREATE_DEP_FILE3) # Include all dependency files -include $(addprefix $(BUILDDIR), $(DEPS))