rc5switch/Makefile

54 lines
1.8 KiB
Makefile
Raw Permalink Normal View History

2015-06-03 21:46:53 +02:00
CC := avr-gcc
LD := avr-ld
OBJCOPY := avr-objcopy
OBJDUMP := avr-objdump
SIZE := avr-size
2011-04-09 17:14:14 +02:00
2015-06-03 21:46:53 +02:00
TARGET = rc5switch
SOURCE = $(wildcard *.c)
BUILD_DIR = build
2011-04-09 17:14:14 +02:00
2015-06-03 21:46:53 +02:00
AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ispprog
#AVRDUDE_PROG := -c dragon_isp -P usb
2011-04-09 17:14:14 +02:00
2015-06-03 21:46:53 +02:00
MCU = attiny24
AVRDUDE_MCU=t24
# no self programming, 2.7V BOD, 8MHz internal RC Osz.
AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xff:m
2011-04-09 17:14:14 +02:00
2015-06-03 21:46:53 +02:00
# ---------------------------------------------------------------------------
2011-04-09 17:14:14 +02:00
2015-06-03 21:46:53 +02:00
CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
CFLAGS += -Wa,-adhlns=$(BUILD_DIR)/$(*D)/$(*F).lst -MMD -MP -MF $(BUILD_DIR)/$(*D)/$(*F).d
LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections
2011-04-09 17:14:14 +02:00
2015-06-03 21:46:53 +02:00
# ---------------------------------------------------------------------------
2011-04-09 17:14:14 +02:00
2015-06-03 21:46:53 +02:00
$(TARGET): $(BUILD_DIR)/$(TARGET).elf
@$(SIZE) -B -x --mcu=$(MCU) $<
2011-04-09 17:14:14 +02:00
2015-06-03 21:46:53 +02:00
$(BUILD_DIR)/$(TARGET).elf: $(patsubst %,$(BUILD_DIR)/%,$(SOURCE:.c=.o))
2011-04-09 17:14:14 +02:00
@echo " Linking file: $@"
2015-06-03 21:46:53 +02:00
@$(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)
@$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $@ $(@:.elf=_eeprom.hex)
@$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $@ $(@:.elf=_eeprom.bin)
$(BUILD_DIR)/%.o: %.c $(MAKEFILE_LIST)
2011-04-09 17:14:14 +02:00
@echo " Building file: $<"
2015-06-03 21:46:53 +02:00
@$(shell test -d $(BUILD_DIR)/$(*D) || mkdir -p $(BUILD_DIR)/$(*D))
@$(CC) $(CFLAGS) -o $@ -c $<
include $(shell find $(BUILD_DIR) -name \*.d 2> /dev/null)
2011-04-09 17:14:14 +02:00
clean:
2015-06-03 21:46:53 +02:00
rm -rf $(BUILD_DIR)
2011-04-09 17:14:14 +02:00
2015-06-03 21:46:53 +02:00
install: $(BUILD_DIR)/$(TARGET).elf
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex) -U eeprom:w:$(<:.elf=_eeprom.hex)
2011-04-09 17:14:14 +02:00
fuses:
2015-06-03 21:46:53 +02:00
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))