-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
168 lines (120 loc) · 5.74 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# Configure here
ARDUINO_DIR = current-arduino
# You can set MESSAGE in the environment or just use the default
ifndef MESSAGE
MESSAGE=[red]TC[green] MAKER [orange]@ [yellow]HACK[purple] FACTORY
endif
# You can set MESSAGE in the environment or just use the default
ifndef OUTDIR
OUTDIR=.
endif
CC = avr-gcc
RM = rm
CXX = avr-g++
OBJCOPY = avr-objcopy
AVRDUDE = avrdude
TARGET_HEX = $(OUTDIR)/led.hex
ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries
ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
ARDUINO_VARIANT_PATH = $(ARDUINO_DIR)/hardware/arduino/variants/standard
MCU = atmega328
MCUPART = m328p
F_CPU = 16000000
ARDUINO_PORT = /dev/ttyUSB*
# Expand and pick the first port
ARD_PORT = $(firstword $(wildcard $(ARDUINO_PORT)))
AVRDUDE_ARD_PROGRAMMER = arduino
AVRDUDE_ARD_BAUDRATE = 57600
AVRDUDE_COM_OPTS = -q -V -p $(MCUPART)
AVRDUDE_ARD_OPTS = -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P $(ARD_PORT) $(AVRDUDE_ARD_EXTRAOPTS)
CPPFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) \
-I. -I$(OUTDIR) \
-I$(ARDUINO_CORE_PATH) -I$(ARDUINO_VARIANT_PATH) \
-g -Os -w -Wall \
-ffunction-sections -fdata-sections
CFLAGS = -std=gnu99
CXXFLAGS = -fno-exceptions
LDFLAGS = -mmcu=$(MCU) -lm -Wl,--gc-sections -Os
LIBCONFIGCFLAGS := $(shell pkg-config --cflags libconfig)
LIBCONFIGLDFLAGS := $(shell pkg-config --libs libconfig)
SIMCFLAGS := $(shell pkg-config --cflags xcb xcb-keysyms)
SIMLDFLAGS := $(shell pkg-config --libs xcb xcb-keysyms) -lpthread -L $(OUTDIR) -lledsim
FTCFLAGS := $(shell pkg-config --cflags freetype2)
FTLDFLAGS := $(shell pkg-config --libs freetype2)
$(OUTDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
$(OUTDIR)/%.o: $(ARDUINO_CORE_PATH)/%.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
$(OUTDIR)/%.o: %.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
$(OUTDIR)/%.hex: $(OUTDIR)/%.elf
$(OBJCOPY) -O ihex -R .eeprom $< $@
OBJECTS=$(OUTDIR)/generated_led.o $(OUTDIR)/Print.o $(OUTDIR)/HardwareSerial.o $(OUTDIR)/wiring.o $(OUTDIR)/main.o
all: $(TARGET_HEX) $(OUTDIR)/drive $(OUTDIR)/makemap \
$(OUTDIR)/ledscroll $(OUTDIR)/ledscrollsim \
$(OUTDIR)/war $(OUTDIR)/warsim \
$(OUTDIR)/tetris $(OUTDIR)/tetrissim \
$(OUTDIR)/showgif $(OUTDIR)/showgifsim
$(OUTDIR)/message.h: Makefile $(OUTDIR)/makemap
$(OUTDIR)/makemap 6x10.bdf "$(MESSAGE)" > $(OUTDIR)/message.h
$(OUTDIR)/generated_led.cpp: led.pde led.h $(OUTDIR)/message.h
@echo '#include <WProgram.h>' > $@
@cat $< >>$@
$(OUTDIR)/generated_led.o: $(OUTDIR)/generated_led.cpp
$(OUTDIR)/drive: drive.c led.h
gcc -Wall -I. -o $@ $<
$(OUTDIR)/libled.a: $(OUTDIR)/libled.o
ar r $@ $<
$(OUTDIR)/libled.o: libled.c led.h
gcc -g -Wall -c -I. $(LIBLEDCFLAGS) -o $@ $< $(LIBLEDLDFLAGS)
$(OUTDIR)/libledsim.a: $(OUTDIR)/ledsim.o
ar r $@ $<
$(OUTDIR)/ledsim.o: ledsim.c led.h Makefile
gcc -g $(SIMCFLAGS) -c -o $@ $<
$(OUTDIR)/fifo.o: fifo.c fifo.h led.h Makefile
gcc $(SIMCFLAGS) -c -o $@ $<
$(OUTDIR)/testlib: testlib.c led.h $(OUTDIR)/libled.a
gcc -g -Wall -I. -o $@ $< $(OUTDIR)/libled.a $(LIBCONFIGLDFLAGS)
$(OUTDIR)/testlibsim: testlib.c led.h $(OUTDIR)/libledsim.a
gcc -g -Wall -I. -DSIMULATOR $(SIMCFLAGS) -o $@ $< $(SIMLDFLAGS)
$(OUTDIR)/ledscroll: ledscroll.c led.h $(OUTDIR)/libled.a
gcc -g -Wall -I. $(FTCFLAGS) -o $@ $< $(OUTDIR)/libled.a $(LIBCONFIGLDFLAGS) $(FTLDFLAGS)
$(OUTDIR)/ledscrollsim: ledscroll.c led.h $(OUTDIR)/libledsim.a
gcc -g -Wall -I. -DSIMULATOR $(FTCFLAGS) $(SIMCFLAGS) -o $@ $< $(SIMLDFLAGS) $(FTLDFLAGS)
$(OUTDIR)/warsim: war.c led.h $(OUTDIR)/libledsim.a $(OUTDIR)/fifo.o
gcc -Wall -I. -DSIMULATOR $(SIMCFLAGS) -o $@ $< $(OUTDIR)/fifo.o $(SIMLDFLAGS) -lm
$(OUTDIR)/war: war.c led.h $(OUTDIR)/libled.a $(OUTDIR)/fifo.o
gcc -Wall -I. $(LIBLEDCFLAGS) -o $@ $< $(OUTDIR)/fifo.o $(LIBLEDLDFLAGS) -L$(OUTDIR) -lled -l pthread $(LIBCONFIGLDFLAGS) -lm
$(OUTDIR)/tetrissim: tetris.c tetris.h led.h $(OUTDIR)/libledsim.a $(OUTDIR)/fifo.o
gcc -Wall -I. -DSIMULATOR $(SIMCFLAGS) -o $@ $< $(OUTDIR)/fifo.o $(SIMLDFLAGS) -lm
$(OUTDIR)/tetris: tetris.c tetris.h led.h $(OUTDIR)/libled.a $(OUTDIR)/fifo.o
gcc -Wall -I. $(LIBLEDCFLAGS) -o $@ $< $(OUTDIR)/fifo.o $(LIBLEDLDFLAGS) -L$(OUTDIR) -lled -l pthread $(LIBCONFIGLDFLAGS) -lm
$(OUTDIR)/showgifsim: showgif.c led.h $(OUTDIR)/libledsim.a $(OUTDIR)/fifo.o
gcc -g -Wall -I. -DSIMULATOR $(SIMCFLAGS) -o $@ $< $(OUTDIR)/fifo.o $(SIMLDFLAGS) -lgif
$(OUTDIR)/showgif: showgif.c led.h $(OUTDIR)/libled.a $(OUTDIR)/fifo.o
gcc -g -Wall -I. $(LIBLEDCFLAGS) -o $@ $< $(OUTDIR)/fifo.o $(LIBLEDLDFLAGS) -L$(OUTDIR) -lled -l pthread $(LIBCONFIGLDFLAGS) -lgif
$(OUTDIR)/makemap: makemap.c led.h
gcc -Wall -o $@ -I. -I $(OUTDIR) -I /usr/include/freetype2 $< -lfreetype -lm
$(OUTDIR)/led.elf: $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $(OBJECTS)
$(OUTDIR)/led.hex: $(OUTDIR)/led.elf
$(OUTDIR)/Print.o: $(ARDUINO_CORE_PATH)/Print.cpp
$(OUTDIR)/HardwareSerial.o: $(ARDUINO_CORE_PATH)/HardwareSerial.cpp
$(OUTDIR)/wiring.o: $(ARDUINO_CORE_PATH)/wiring.c
$(OUTDIR)/main.o: $(ARDUINO_CORE_PATH)/main.cpp
upload: reset raw_upload
raw_upload: $(TARGET_HEX)
$(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
-U flash:w:$(TARGET_HEX):i
# BSD stty likes -F, but GNU stty likes -f/--file. Redirecting
# stdin/out appears to work but generates a spurious error on MacOS at
# least. Perhaps it would be better to just do it in perl ?
reset:
stty --file $(ARD_PORT) hupcl ; \
(sleep 0.1 2>/dev/null || sleep 1) ; \
stty --file $(ARD_PORT) -hupcl
clean:
$(RM) $(OBJECTS) $(TARGET_HEX) $(OUTDIR)/led.elf $(OUTDIR)/generated_led.cpp $(OUTDIR)/drive $(OUTDIR)/makemap $(OUTDIR)/message.h \
$(OUTDIR)/ledscroll $(OUTDIR)/ledscrollsim \
$(OUTDIR)/war $(OUTDIR)/warsim \
$(OUTDIR)/tetris $(OUTDIR)/tetrissim