#  No Copyright
#
#  The person who associated a work with this deed has dedicated the work to the
#  public domain by waiving all of his or her rights to the work worldwide under
#  copyright law, including all related and neighboring rights, to the extent
#  allowed by law.
#
#  You can copy, modify, distribute and perform the work, even for commercial
#  purposes, all without asking permission.
#
#  See https://creativecommons.org/share-your-work/public-domain/cc0/ for more
#  information on the license.


#  This file is part of the clock sculpture project, made by
#  Maarten Tromp <maarten@geekabit.nl>.
#
#  More info on the project: https://www.geekabit.nl/projects/clock-sculpture/


MCU		:= attiny13a
F_CPU	:= 9600000L
AVRDUDE_PROGRAMMER := usbasp


# programs
CC		:= avr-gcc
LD		:= $(CC)
OBJCOPY	:= avr-objcopy
OBJDUMP	:= avr-objdump
AVRSIZE	:= avr-size
AVRDUDE	:= avrdude
LINT	:= splint


# flags
CFLAGS	:= -Wall -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU)
LDFLAGS	:= $(CFLAGS)
LIBS	:=
# avrdude does not recognize tiny13a -> use tiny13 instead.
AVRDUDEFLAGS := -p attiny13 -c $(AVRDUDE_PROGRAMMER)
LINTFLAGS	:= -I /usr/lib/avr/include/


# sources
HEADERS	:= 
SOURCES	:= main.c
OBJECTS	:= $(SOURCES:.c=.o)
TARGET	:= main.elf
ASM		:= $(TARGET:.elf=.asm)


# targets:
.PHONY: all prog fuses lint size clean
all: $(TARGET) size

prog: $(TARGET)
	$(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$<

fuses:
	$(AVRDUDE) $(AVRDUDEFLAGS) -U lfuse:w:0x7a:m -U hfuse:w:0xff:m

disasm:	$(TARGET)
	$(OBJDUMP) --disassemble $< > $(ASM)

lint: $(SOURCES)
	$(LINT) $(LINTFLAGS) $<

size: $(TARGET)
	$(AVRSIZE) $<

clean:
	- $(RM) $(TARGET) $(OBJECTS) $(ASM)

%.o: %.c
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

$(TARGET): $(OBJECTS)
	$(LD) $(LDFLAGS) $< -o $@


# end of file
