Skip to content

Instantly share code, notes, and snippets.

@MatthaeusHarris
Created February 18, 2019 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthaeusHarris/c0da1e572c7053e8562e88ff1233ee64 to your computer and use it in GitHub Desktop.
Save MatthaeusHarris/c0da1e572c7053e8562e88ff1233ee64 to your computer and use it in GitHub Desktop.
Working, hack-ish makefile
PRG = binaryclock
MCU_TARGET = atmega328p
PROGRAMMER = usbtiny
PFLAGS = #-P /dev/ttyUSB0
OPTIMIZE = -Os
DEFS = -DF_CPU=1000000UL
LIBS =
HEADERS =
CC = avr-gcc
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
override LDFLAGS = -W1,-Map,$(PRG).map
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
FLASH = avrdude
all: $(PRG).hex
$(PRG).hex: $(PRG).elf
$(OBJCOPY) -O ihex -R .eeprom $(PRG).elf $(PRG).hex
$(PRG).elf: $(PRG)_linked.o
$(CC) $(PRG)_linked.o -o $(PRG).elf
$(PRG)_linked.o: $(PRG).o twimaster.o
$(CC) $(CFLAGS) $(PRG).o twimaster.o -o $(PRG)_linked.o
$(PRG).o: $(PRG).c $(HEADERS)
$(CC) $(CFLAGS) -c $(PRG).c -o $(PRG).o
twimaster.o: twimaster.c
$(CC) $(CFLAGS) -c twimaster.c -o twimaster.o
flash:
$(FLASH) -c $(PROGRAMMER) $(PFLAGS) -p $(MCU_TARGET) -U flash:w:$(PRG).hex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment