You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

46 lines
1.3 KiB

  1. CC := avr-gcc
  2. LD := avr-ld
  3. OBJCOPY := avr-objcopy
  4. OBJDUMP := avr-objdump
  5. SIZE := avr-size
  6. TARGET = funkbridge
  7. SOURCE = $(wildcard *.c)
  8. BUILD_DIR = build
  9. AVRDUDE_PROG := -c butterfly -b 19200 -P /dev/funkbridge
  10. MCU = atmega328p
  11. AVRDUDE_MCU=m328p -F
  12. # ---------------------------------------------------------------------------
  13. CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
  14. CFLAGS += -Wa,-adhlns=$(BUILD_DIR)/$(*D)/$(*F).lst -MMD -MP -MF $(BUILD_DIR)/$(*D)/$(*F).d
  15. LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections
  16. # ---------------------------------------------------------------------------
  17. $(TARGET): $(BUILD_DIR)/$(TARGET).elf
  18. @$(SIZE) -B -x --mcu=$(MCU) $<
  19. $(BUILD_DIR)/$(TARGET).elf: $(patsubst %,$(BUILD_DIR)/%,$(SOURCE:.c=.o))
  20. @echo " Linking file: $@"
  21. @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
  22. @$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
  23. @$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
  24. @$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
  25. $(BUILD_DIR)/%.o: %.c $(MAKEFILE_LIST)
  26. @echo " Building file: $<"
  27. @$(shell test -d $(BUILD_DIR)/$(*D) || mkdir -p $(BUILD_DIR)/$(*D))
  28. @$(CC) $(CFLAGS) -o $@ -c $<
  29. include $(shell find $(BUILD_DIR) -name \*.d 2> /dev/null)
  30. clean:
  31. rm -rf $(BUILD_DIR)
  32. install: $(BUILD_DIR)/$(TARGET).elf
  33. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)