forked from rsbohn/ArduinoISP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
60 lines (46 loc) · 1.58 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
TARGET=ArduinoISP
MCU=atmega32u4
F_CPU=16000000
# We are gonna build against TeensyCore, because of VID&PID.
# https://github.com/PaulStoffregen/cores
TEENSY=./TeensyCore/teensy
# You just need two files, SPI.cpp and SPI.h from ArduinoCore for AVR.
# https://github.com/arduino/ArduinoCore-avr
# https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/SPI/src
LIBSPI=./libraries/SPI
INO_PATH=$(TARGET)
SRC_PATH=$(TEENSY) $(LIBSPI)
DEFS=-DARDUINO=100 -DUSB_SERIAL -DF_CPU=$(F_CPU)UL
INCS=$(addprefix -I,$(SRC_PATH)) -Wp,-include,WProgram.h
FLAGS=-Os -mmcu=$(MCU)
CXXFLAGS=-std=c++11
SRCS=main.cpp usb.c usb_api.cpp pins_teensy.c SPI.cpp
OBJS=$(TARGET).o $(filter %.o,$(SRCS:.c=.o) $(SRCS:.cpp=.o))
OBJDIR=obj
default: hex
bin: $(TARGET).bin
hex: $(TARGET).hex
elf: $(TARGET).elf
submodule:
git submodule sync TeensyCore
git submodule update --init --progress TeensyCore
$(OBJDIR):
@mkdir -p $@
vpath %.ino $(INO_PATH)
vpath %.ino.h $(INO_PATH)
$(OBJDIR)/%.o: %.ino %.ino.h | $(OBJDIR)
avr-gcc -x c++ $(CXXFLAGS) $(FLAGS) $(DEFS) $(INCS) -Wp,-include,$(filter %.ino.h,$^) -c -o $@ $<
vpath %.c $(SRC_PATH)
$(OBJDIR)/%.o: %.c | $(OBJDIR)
avr-gcc $(FLAGS) $(DEFS) $(INCS) -c -o $@ $<
vpath %.cpp $(SRC_PATH)
$(OBJDIR)/%.o: %.cpp | $(OBJDIR)
avr-gcc $(CXXFLAGS) $(FLAGS) $(DEFS) $(INCS) -c -o $@ $<
$(TARGET).elf: $(addprefix $(OBJDIR)/,$(OBJS))
avr-gcc -mmcu=$(MCU) -Wl,--gc-sections --output $@ $^
%.hex: %.elf
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@
%.bin: %.hex
avr-objcopy -I ihex -O binary $< $@
clean:
rm -rf obj $(TARGET).elf $(TARGET).hex $(TARGET).bin