This repository has been archived by the owner on Nov 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
58 lines (39 loc) · 1.55 KB
/
Makefile
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
50
51
52
53
54
55
56
57
#Check the boards.txt file for the correct arduino version
ARDUINO_VERSION=mhvboard
TARGET=$(shell basename `pwd`)
AVRDUDE_PORT=usb
SRC = $(TARGET).c
SRC += ht1632.c lpd8806.c colour.c
# you shouldn't need to change anything below here
AVRDUDE=avrdude
CC=avr-gcc
OBJ2HEX=avr-objcopy
MCU := $(shell grep $(ARDUINO_VERSION).build.mcu boards.txt | cut -d= -f2)
F_CPU := $(shell grep $(ARDUINO_VERSION).build.f_cpu boards.txt | cut -d= -f2)
AVRDUDE_PROGRAMER := $(shell grep $(ARDUINO_VERSION).upload.protocol boards.txt | cut -d= -f2)
# dirty hack to accomidate the arduino boards.txt file being wrong.
# can you believe they do this in the code rather than fixing their config file?
ifeq ($(AVRDUDE_PROGRAMER),stk500)
AVRDUDE_PROGRAMER=stk500v1
endif
AVRDUDE_SPEED := $(shell grep $(ARDUINO_VERSION).upload.speed boards.txt | cut -d= -f2)
AVRDUDE_MAXSIZE := $(shell grep $(ARDUINO_VERSION).upload.max_size boards.txt | cut -d= -f2)
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMER) -b $(AVRDUDE_SPEED)
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
CFLAGS := -g -Os -Wall -mcall-prologues -mmcu=$(MCU) -DF_CPU=$(F_CPU)
# deafult is to compile to the hex file
ALL : $(TARGET).hex
%.d: %.c
set -e; $(CC) -MM $(ALL_CFLAGS) $< \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
[ -s $@ ] || rm -f $@
-include $(SRC:.c=.d)
ODEPS=$(SRC:.c=.o)
%.obj : $(ODEPS)
$(CC) $(CFLAGS) $? -o $@ -lm
%.hex : %.obj
$(OBJ2HEX) -R .eeprom -O ihex $< $@
clean :
rm -f *.hex *.obj *.o *.d
program: $(TARGET).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)