aboutsummaryrefslogtreecommitdiff
path: root/dev/arduino-terminal/Makefile
blob: d60dafb89983b161e9d138d95446cb39b4ce7721 (plain) (blame)
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
##
## Makefile to create firmware image including arduino sources
##
##


# Arduino variant
#
VARIANT=mega


# CPU model
#
MCU=atmega2560


# CPU Frequency
#
F_CPU=16000000L


# Serial port used for uploading and monitoring
#
SERIAL=/dev/ttyACM0
BAUD=115200


# Name of image to produce (can be arbitrary)
#
TARGET=firmware


# Toolchain and flags
#
CC=avr-gcc
CFLAGS=-Os -Wall -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(F_CPU) -MMD -DUSB_VID=0x2341 -DUSB_PID=0x8037 -DARDUINO=106

CXX=avr-g++
CXXFLAGS=$(CFLAGS)

LD=avr-gcc
LDFLAGS= -Os -Wl,--gc-sections -mmcu=$(MCU)

AR=avr-ar

AS=avr-as
ASFLAGS=-mmcu=$(MCU)

OC=avr-objcopy
OCFLAGS=

OD=avr-objdump
AVRDUDE=avrdude
AVRDUDEFLAGS= -DV -p $(MCU) -P $(SERIAL) -c stk500v2 -b 115200

AVRSIZE=avr-size

# Derived variables
SOURCEDIRS=\
	src \
	ext/arduino/core \
	$(wildcard ext/arduino/lib/*)

INCLUDES=\
	include \
	ext/arduino/core \
	ext/arduino/variants/$(VARIANT) \
	$(wildcard ext/arduino/lib/*)

SOURCES=\
	$(foreach dir,$(SOURCEDIRS),$(wildcard $(dir)/*.c)) \
	$(foreach dir,$(SOURCEDIRS),$(wildcard $(dir)/*.cpp))
	
OBJECTS=$(addsuffix .o, $(basename $(SOURCES)))

# Rules
all: $(TARGET).hex

$(TARGET).hex: $(TARGET).elf
	$(OC) $(OCFLAGS) -O ihex -R .eeprom $< $@

$(TARGET).elf: $(OBJECTS)
	$(LD) $(LDFLAGS) -o $@ $^
	
# Sources
%.o: %.c
	$(CC) $(CFLAGS) -I$(dir $<) $(addprefix -I, $(INCLUDES)) -o $@ -c $<

%.o: %.cpp
	$(CXX) $(CXXFLAGS) -I$(dir $<) $(addprefix -I, $(INCLUDES)) -o $@ -c $<

# Utility rules
size: $(TARGET).hex
	$(AVRSIZE) --format=avr --mcu=$(MCU) $(TARGET).elf

upload: $(TARGET).hex
	$(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(TARGET).hex:i
	
monitor:
	cu -l $(SERIAL) -s $(BAUD) --parity=none -h

clean:
	@rm -f *.o
	@for dir in $(SOURCEDIRS); do \
		rm -f $$dir/*.o; \
		rm -f $$dir/*.d; \
	done
	@rm -f $(TARGET).hex
	@rm -f $(TARGET).elf
	@rm -f $(GDBINITFILE)
	
.PHONY: clean