CC = avr-gcc OBJCOPY = avr-objcopy OBJDUMP = avr-objdump SIZE = avr-size NM = avr-nm AVRDUDE = avrdude RM = rm -f COPY = cp # Define all object files. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) # Compiler flags to generate dependency files. GENDEPFLAGS = -MMD -MP -MF .dep/$(@F:%.o=%.d) # Combine all necessary flags and optional flags. # Add target processor to flags. ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS) 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 .PHONY: elf hex lss sym size elf: $(TARGET).elf hex: $(TARGET).hex lss: $(TARGET).lss sym: $(TARGET).sym size: $(TARGET).elf @$(QP)printf " SIZE $(TARGET).elf\n" $(Q)$(SIZE) $(TARGET).elf # Program the device. .PHONY: flash fuses flash: $(TARGET).hex $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) 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" $(Q)$(OBJDUMP) -h -S $< > $@ # Create a symbol table from ELF output file. %.sym: %.elf @$(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) # Compile: create object files from C source files. %.o: %.c @$(QP)printf " CC $<\n" $(Q)$(CC) -c $(ALL_CFLAGS) $< -o $@ # Target: clean project. .PHONY: clean distclean clean: @$(QP)printf " CLEAN\n" $(Q)$(RM) $(TARGET).elf $(TARGET).lss $(TARGET).map $(TARGET).sym \ $(OBJ) $(SRC:.c=.s) .dep/* distclean: clean @$(QP)printf " DISTCLEAN\n" $(Q)$(RM) $(TARGET).hex $(TARGET).tar.gz .PHONY: dist dist: build tar cvfz $(TARGET).tar.gz \ $(SRC) \ $(TARGET).hex $(TARGET).eep # Include the dependency files. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)