forked from aedalzotto/avr-fat-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (50 loc) · 1.48 KB
/
Makefile
File metadata and controls
65 lines (50 loc) · 1.48 KB
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
BIN = air_drums
MCU = atmega2560
F_CPU = 16000000
BAUD = 57600
PORT = /dev/ttyACM0
SPEED = 115200
PROGRAMMER = wiring
CC = avr-g++
OBJCOPY = avr-objcopy
RM = rm
MK = mkdir
SRCDIR = src
BUILDDIR = build
BINDIR = bin
INCDIR = $(SRCDIR)/include
TARGET = $(BINDIR)/$(BIN)
CPP_SOURCES = $(wildcard $(SRCDIR)/*.cpp)
C_SOURCES = $(wildcard $(SRCDIR)/*.c)
CPP_OBJECTS = $(addprefix $(BUILDDIR)/,$(notdir $(CPP_SOURCES:.cpp=.o)))
C_OBJECTS = $(addprefix $(BUILDDIR)/,$(notdir $(C_SOURCES:.c=.o)))
CFLAGS = -g -Wall -mmcu=$(MCU) -Os
INCLUDES = -I$(INCDIR) -I$(LCDDIR)
LDFLAGS = -g -mmcu=$(MCU) -Wl,-u,vfprintf -lprintf_flt -lm
DEFINES = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -DDRV_MMC=0
all: $(TARGET).hex size
size:
@if [ -f $(TARGET).elf ]; then avr-size -C --mcu=$(MCU) $(TARGET).elf; fi
clean:
@echo "Cleaning..."
@$(RM) -rf $(BUILDDIR) $(BINDIR)
$(TARGET).hex: $(TARGET).elf
@echo "Generating hex..."
@$(RM) -f $(TARGET).hex
@$(OBJCOPY) -j .text -j .data -O ihex $< $@
$(TARGET).elf: $(CPP_OBJECTS) $(C_OBJECTS)
@echo "Linking..."
@$(MK) -p $(BINDIR)
@$(CC) $^ -o $@ $(LDFLAGS)
$(BUILDDIR)/%.o: $(SRCDIR)/%.c
@echo "Compiling $<"
@$(MK) -p $(BUILDDIR)
@$(CC) -c $< -o $@ $(INCLUDES) $(CFLAGS) $(DEFINES)
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
@echo "Compiling $<"
@$(MK) -p $(BUILDDIR)
@$(CC) -c $< -o $@ $(INCLUDES) $(CFLAGS) $(DEFINES)
flash:
@avrdude -c $(PROGRAMMER) -p $(MCU) -P $(PORT) -b $(SPEED) -U flash:w:$(TARGET).hex
monitor:
@screen $(PORT) $(BAUD)