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.

Makefile 1.4 KiB

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