diff options
author | Leo C | 2019-05-30 20:32:16 +0200 |
---|---|---|
committer | Leo C | 2019-05-30 20:32:16 +0200 |
commit | 76c082ca2a2c560e660daca0a8294b73881423d8 (patch) | |
tree | ad5c6a6487dd47e8115b1772603630626ea8281b /mk | |
parent | f1e16f884308e8ef720a4ecbcdcc97af97dce4bd (diff) | |
download | z180-stamp-76c082ca2a2c560e660daca0a8294b73881423d8.zip |
Refactor makefiles
Diffstat (limited to 'mk')
-rw-r--r-- | mk/avr.rules.mk | 97 |
1 files changed, 60 insertions, 37 deletions
diff --git a/mk/avr.rules.mk b/mk/avr.rules.mk index 155397c..66fab58 100644 --- a/mk/avr.rules.mk +++ b/mk/avr.rules.mk @@ -1,37 +1,70 @@ +# Be silent per default, but 'make V=1' will show all compiler calls. +ifneq ($(V),1) +Q := @ +NULL := 2>/dev/null +else +QP := \# +endif -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -SIZE = avr-size -NM = avr-nm -AVRDUDE = avrdude -RM = rm -f -COPY = cp +############################################################################### +# Executables +CC = avr-gcc +LD = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +RM = rm -f +COPY = cp + +OPT := -Os +CSTD ?= -std=gnu11 + +############################################################################### # Define all object files. + OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) +############################################################################### +# C flags + +TGT_CFLAGS += -mmcu=$(MCU) $(OPT) $(CSTD) -g +TGT_CFLAGS += $(ARCH_FLAGS) +TGT_CFLAGS += -Wextra -Wshadow -Wimplicit-function-declaration +TGT_CFLAGS += -Wredundant-decls -Wstrict-prototypes +TGT_CFLAGS += -fshort-enums -funsigned-bitfields +TGT_CFLAGS += -fno-common -ffunction-sections -fdata-sections +TGT_CFLAGS += -mrelax -# Compiler flags to generate dependency files. -GENDEPFLAGS = -MMD -MP -MF .dep/$(@F:%.o=%.d) +############################################################################### +# C & C++ preprocessor common flags +TGT_CPPFLAGS += -MMD -MP -MF .dep/$(@F:%.o=%.d) +TGT_CPPFLAGS += -Wall -Wundef +TGT_CPPFLAGS += -DF_CPU=$(F_CPU)UL $(CDEFS) $(CINCS) -# Combine all necessary flags and optional flags. -# Add target processor to flags. -ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS) +############################################################################### +# Linker flags +TGT_LDFLAGS += $(ARCH_FLAGS) +TGT_LDFLAGS += -Wl,-Map=$(TARGET).map,--cref +TGT_LDFLAGS += -Wl,--gc-sections + +############################################################################### +# Avrdude + +AVRDUDE_PORT ?= usb AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) -# Be silent per default, but 'make V=1' will show all compiler calls. -ifneq ($(V),1) -Q := @ -NULL := 2>/dev/null -else -QP := \# -endif +############################################################################### + +.SUFFIXES: .elf .hex .lss .map .sym +.SECONDARY: .PHONY: elf hex lss sym size elf: $(TARGET).elf @@ -40,7 +73,7 @@ lss: $(TARGET).lss sym: $(TARGET).sym size: $(TARGET).elf - @$(QP)printf " SIZE $(TARGET).elf\n" + @#$(QP)printf " SIZE $(TARGET).elf\n" $(Q)$(SIZE) $(TARGET).elf # Program the device. @@ -51,14 +84,10 @@ flash: $(TARGET).hex fuses: $(AVRDUDE) $(AVRDUDE_FLAGS) -u -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m - -.SUFFIXES: .elf .hex .eep .lss .sym - %.hex: %.elf @$(QP)printf " OBJCOPY $(*).hex\n" $(Q)$(OBJCOPY) -Oihex -R .eeprom $< $@ - # Create extended listing file from ELF output file. %.lss: %.elf @$(QP)printf " OBJDUMP $@\n" @@ -69,34 +98,28 @@ fuses: @$(QP)printf " NM $@\n" $(Q)$(NM) -n $< > $@ - - # Link: create ELF output file from object files. -.SECONDARY : $(TARGET).elf -.PRECIOUS : $(OBJ) %.elf %.map: $(OBJ) @$(QP)printf " LD $@\n" - $(Q)$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) + $(Q)$(LD) $(TGT_CFLAGS) $(CFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ # Compile: create object files from C source files. %.o: %.c @$(QP)printf " CC $<\n" - $(Q)$(CC) -c $(ALL_CFLAGS) $< -o $@ - + $(Q)$(CC) $(TGT_CFLAGS) $(CFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $@ -c $< # Target: clean project. -.PHONY: clean distclean +.PHONY: clean distclean dist clean: @$(QP)printf " CLEAN\n" - $(Q)$(RM) $(TARGET).elf $(TARGET).lss $(TARGET).map $(TARGET).sym \ - $(OBJ) $(SRC:.c=.s) .dep/* + $(Q)$(RM) $(OBJ) $(SRC:.c=.s) .dep/* $(TARGET).elf \ + $(TARGET).hex $(TARGET).lss $(TARGET).map $(TARGET).sym distclean: clean @$(QP)printf " DISTCLEAN\n" - $(Q)$(RM) $(TARGET).hex $(TARGET).tar.gz + $(Q)$(RM) $(TARGET).tar.gz -.PHONY: dist dist: build tar cvfz $(TARGET).tar.gz \ $(SRC) \ |