summaryrefslogtreecommitdiff
path: root/dice/firmware/Makefile
blob: 80cffce69aa79de8e13545938e0a498fa9a9138f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
MAKEFLAGS += --no-builtin-rules --no-builtin-variables

# This variable can be overwritten to show executed commands
Q ?= @

# TODO use CC instead of GCC but at the moment --no-builtin-variables seems to
# break somehow detection of not defined variable.
TARGET ?= avr-
GCC ?= $(TARGET)gcc
OBJCOPY ?= $(TARGET)objcopy
AVRDUDE ?= avrdude

MCU ?= attiny85
F_CPU ?= 16000000L
CFLAGS ?= -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU)
LDFLAGS ?= -Os -mmcu=$(MCU)

#####################
SRC := main.c
#####################
OBJ := $(patsubst %.c,%.o,$(SRC))

.PHONY: all
all: firmware.hex

$(OBJ): %.o: %.c
	@echo "CC	$@"
	$(Q)$(GCC) -c $(CFLAGS) $< -o $@

firmware.elf: $(OBJ)
	@echo "LD	$@"
	$(Q)$(GCC) $(LDFLAGS) $< -o $@

firmware.hex: firmware.elf
	@echo "OBJCOPY	$@"
	$(Q)$(OBJCOPY) -O ihex -R .eeprom $< $@


.PHONY: install
install: firmware.hex
	@echo "AVRDUDE	$@"
	$(Q)$(AVRDUDE) -p$(MCU) -cusbasp -D -Uflash:w:$<:a

# TODO probably configure fuses

.PHONY: clean
clean:
	rm -f $(OBJ)
	rm -f firmware.elf firmware.hex