Created
January 30, 2021 22:16
-
-
Save ndomx/c1a95128c35bde4e3b31f6679047029e to your computer and use it in GitHub Desktop.
Makefile for simple ATmega C projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MCU = atmega328p | |
DUDEMCU = m328p | |
PROG = usbasp | |
OPT = s | |
CPPFLAGS = -DF_CPU=16000000 -O$(OPT) | |
CFLAGS = -mmcu=$(MCU) | |
TARGET = main | |
CC = avr-gcc | |
DUDE = avrdude | |
OBJCOPY = avr-objcopy | |
.PHONY: build | |
build: $(TARGET).hex | |
$(TARGET).hex: $(TARGET).elf | |
$(OBJCOPY) -O ihex $< $@ | |
$(TARGET).elf: $(TARGET).o | |
$(CC) $(CFLAGS) $< -o $@ | |
$(TARGET).o: $(TARGET).c | |
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ | |
.PHONY: upload | |
upload: $(TARGET).hex | |
$(DUDE) -c $(PROG) -p $(DUDEMCU) -v -U flash:w:$(TARGET).hex:i | |
.PHONY: clean | |
clean: | |
rm -f $(TARGET).o $(TARGET).elf $(TARGET).hex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment