42 lines
640 B
Makefile
42 lines
640 B
Makefile
|
.SUFFIXES:
|
||
|
|
||
|
MCU := atmega328p
|
||
|
PROGRAMMER := usbtiny
|
||
|
|
||
|
TARGET := main.hex
|
||
|
BIN := main.elf
|
||
|
OBJ := main.o
|
||
|
|
||
|
SHELL := sh
|
||
|
CC := avr-gcc
|
||
|
OBJCOPY := avr-objcopy
|
||
|
SIZE := avr-size
|
||
|
AVRDUDE := avrdude
|
||
|
|
||
|
CFLAGS := -mmcu=$(MCU) -Os -Wall -Werror -Wextra -Wpedantic
|
||
|
|
||
|
all: $(TARGET)
|
||
|
|
||
|
$(TARGET): $(BIN)
|
||
|
${OBJCOPY} -O ihex -j .text -j .data $< $@
|
||
|
|
||
|
$(BIN): $(OBJ)
|
||
|
$(CC) $(CFLAGS) $< -o $@
|
||
|
|
||
|
%.o: %.c
|
||
|
$(CC) $(CFLAGS) -Os -c $< -o $@
|
||
|
|
||
|
.PHONY: flash clean check size
|
||
|
|
||
|
flash: $(TARGET) size
|
||
|
$(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -U flash:w:$<:a
|
||
|
|
||
|
clean:
|
||
|
$(RM) main.o main.elf main.hex
|
||
|
|
||
|
check:
|
||
|
cppcheck main.c
|
||
|
|
||
|
size: $(BIN)
|
||
|
$(SIZE) --format=avr --mcu=$(MCU) $<
|