summaryrefslogtreecommitdiff
path: root/zumo/makefile
blob: 1a7ad36d38fb1375e3500b94b4555e2204fa7997 (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
PORT = /dev/ttyUSB0

C++ = avr-g++
CC = avr-gcc
LD = avr-ld
RM = rm -f

MCU = atmega32u4
TARGET = main
SRCS += main.cpp

CFLAGS += -mcall-prologues
CFLAGS += -mmcu=$(MCU)
CFLAGS += -Os
CFLAGS += -g
CFLAGS += -Wl,-gc-sections
CFLAGS += -Wl,-relax

include zumo.mk

OBJS := $(patsubst %.c,%.o, $(SRCS))
OBJS := $(patsubst %.cpp,%.o, $(OBJS))

MAKEFLAGS += -j4

.PHONY: all clean flash

all: $(TARGET).hex

%.o: %.cpp
	$(C++) -c $(CFLAGS) $< -o $@

%.o: %.c
	$(CC) -c $(CFLAGS) $< -o $@

$(TARGET): $(OBJS)
	$(LD) $^ $(LFLAGS) -o $@

$(TARGET).hex: $(TARGET)
	avr-objcopy -R .eeprom -O ihex $< $@

flash: $(TARGET).hex
	avrdude -p $(MCU) -c avr109 -P $(PORT) -U flash:w:$(TARGET).hex

clean:
	$(RM) $(TARGET) $(TARGET).hex $(OBJS)

compile_commands.json: makefile
	compiledb make -Bn