ispprog/Makefile

69 lines
1.8 KiB
Makefile
Raw Normal View History

2014-10-05 14:27:03 +02:00
CC := avr-gcc
LD := avr-ld
OBJCOPY := avr-objcopy
OBJDUMP := avr-objdump
SIZE := avr-size
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
TARGET = ispprog
SOURCE = $(wildcard *.c)
2019-11-22 22:35:37 +01:00
BUILD_DIR = build
2006-05-05 19:02:04 +02:00
2014-10-12 11:13:30 +02:00
#CONFIG = ispprog
CONFIG = ispprog2
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
AVRDUDE_PROG := -c butterfly -b 19200 -P /dev/ttyUSB0
#AVRDUDE_PROG := -c dragon_isp -P usb
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
# ---------------------------------------------------------------------------
2006-05-05 19:02:04 +02:00
2014-10-12 11:13:30 +02:00
ifeq ($(CONFIG), ispprog)
# (7.3728MHz ext. crystal)
2014-10-05 14:27:03 +02:00
AVRDUDE_MCU=m16
AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xda:m
2014-10-12 11:13:30 +02:00
MCU=atmega16
endif
ifeq ($(CONFIG), ispprog2)
# (8MHz int. osc, 2.7V BOD)
AVRDUDE_MCU=m328p -F
AVRDUDE_FUSES=lfuse:w:0xe2:m hfuse:w:0xdc:m efuse:w:0x02:m
MCU = atmega328p
2014-10-05 14:27:03 +02:00
endif
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
# ---------------------------------------------------------------------------
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
2019-11-22 22:35:37 +01:00
CFLAGS += -Wa,-adhlns=$(BUILD_DIR)/$(*D)/$(*F).lst -MMD -MP -MF $(BUILD_DIR)/$(*D)/$(*F).d
CFLAGS += -DCONFIG_$(CONFIG)=1
2014-10-05 14:27:03 +02:00
LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
# ---------------------------------------------------------------------------
2006-05-05 19:02:04 +02:00
2019-11-22 22:35:37 +01:00
$(TARGET): $(BUILD_DIR)/$(TARGET).elf
2014-10-05 14:27:03 +02:00
@$(SIZE) -B -x --mcu=$(MCU) $<
2006-05-05 19:02:04 +02:00
2019-11-22 22:35:37 +01:00
$(BUILD_DIR)/$(TARGET).elf: $(patsubst %,$(BUILD_DIR)/%,$(SOURCE:.c=.o))
2014-10-05 14:27:03 +02:00
@echo " Linking file: $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
@$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
@$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
@$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
2006-05-05 19:02:04 +02:00
2019-11-22 22:35:37 +01:00
$(BUILD_DIR)/%.o: %.c $(MAKEFILE_LIST)
2014-10-05 14:27:03 +02:00
@echo " Building file: $<"
2019-11-22 22:35:37 +01:00
@$(shell test -d $(BUILD_DIR)/$(*D) || mkdir -p $(BUILD_DIR)/$(*D))
2014-10-05 14:27:03 +02:00
@$(CC) $(CFLAGS) -o $@ -c $<
2006-05-05 19:02:04 +02:00
2019-11-22 22:35:37 +01:00
include $(shell find $(BUILD_DIR) -name \*.d 2> /dev/null)
2014-10-05 14:27:03 +02:00
clean:
2019-11-22 22:35:37 +01:00
rm -rf $(BUILD_DIR)
2006-05-05 19:02:04 +02:00
2019-11-22 22:35:37 +01:00
install: $(BUILD_DIR)/$(TARGET).elf
2014-10-05 14:27:03 +02:00
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
2006-05-05 19:02:04 +02:00
2014-10-05 14:27:03 +02:00
fuses:
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))