rgb16mpm/Makefile
2012-03-02 17:35:35 +01:00

60 lines
1.6 KiB
Makefile

# ############################
PRG = rgb16mpm
MCU_TARGET = atmega32
# ############################
BUILD_DIR = build
SRC = $(wildcard *.c)
OUTPUTS = .hex .bin _eeprom.hex _eeprom.bin
CFLAGS = -Os -g -Wall -mmcu=$(MCU_TARGET)
CFLAGS += -pipe -MMD -MP -MG -MF $(BUILD_DIR)/$(*D)/$(*F).d
LDFLAGS = -Wl,-Map,$(BUILD_DIR)/$(*D)/$(*F).map,--cref
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
# ############################
.PHONY: all clean install
all: $(patsubst %,$(BUILD_DIR)/$(PRG)%, .elf $(OUTPUTS))
@$(SIZE) -x -A $<
.SECONDARY: $(patsubst %,$(BUILD_DIR)/%, $(SRC:.c=.o))
$(BUILD_DIR)/%.elf: $(patsubst %,$(BUILD_DIR)/%, $(SRC:.c=.o))
@echo " Linking file: $@"
@$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
@$(OBJDUMP) -h -S $@ > $(subst elf,lst,$@)
$(BUILD_DIR)/%.o: %.c $(MAKEFILE_LIST)
@echo " Building file: $<"
@$(shell test -d $(BUILD_DIR)/$(*D) || mkdir -p $(BUILD_DIR)/$(*D))
@$(CC) $(CFLAGS) -o $@ -c $<
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf
@$(OBJCOPY) -j .text -j .data -O ihex $< $@
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf
@$(OBJCOPY) -j .text -j .data -O binary $< $@
$(BUILD_DIR)/%_eeprom.hex: $(BUILD_DIR)/%.elf
@$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
$(BUILD_DIR)/%_eeprom.bin: $(BUILD_DIR)/%.elf
@$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
include $(shell find $(BUILD_DIR) -name \*.d 2> /dev/null)
# ############################
clean:
rm -rf $(BUILD_DIR)
install: $(BUILD_DIR)/$(PRG).hex
# avrdude -p m32 -c dragon_isp -P usb -U flash:w:$(PRG).hex
mpmboot -d /dev/ttyUSB0 -a 0x11 -w flash:$<