-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
75 lines (57 loc) · 1.54 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
TARGET=$(build)
#NAME=$(notdir $(TARGET))
#$(info $$var is [${NAME}])
CC=avr-gcc
MCU=atmega16m1
PROGRAMMER=avrispmkII
PORT=usb
AVRDUDE=avrdude
OBJCOPY=avr-objcopy
##############
# Src Vars #
##############
SRCDIR=src
LIBDIR=lib
OBJDIR=obj
BUIDIR=build
SRCLIBS=$(wildcard $(LIBDIR)/*.c)
INTLIBS=$(wildcard $(LIBDIR)/*.h)
OBJLIBS=$(patsubst $(LIBDIR)/%.c,$(LIBDIR)/%.o,$(SRCLIBS))
SRCS=$(wildcard $(SRCDIR)/$(TARGET)/*.c)
OBJS=$(patsubst $(SRCDIR)/$(TARGET)/%.c, $(OBJDIR)/%.o, $(SRCS))
################
# Build Vars #
################
CFLAGS+=-mmcu=$(MCU) -g -Os -Wall -Wunused -I$(LIBDIR)/
LDFLAGS=-mmcu=$(MCU) -Wl,-Map=$(BUIDIR)/$(TARGET).map -lm
AVRFLAGS=-p $(MCU) -v -c $(PROGRAMMER) -P $(PORT)
#############
# Recipes #
#############
all: $(OBJLIBS) $(BUIDIR)/$(TARGET).elf $(BUIDIR)/$(TARGET).hex $(BUIDIR)/$(TARGET).srec
$(LIBDIR)/%.o: $(LIBDIR)/%.c $(LIBDIR)/%.h
$(CC) -c -o $@ $< $(CFLAGS)
$(OBJDIR)/%.o: $(SRCDIR)/$(TARGET)/%.c
$(CC) -c -o $@ $< $(CFLAGS)
$(BUIDIR)/%.elf: $(OBJS) $(OBJLIBS)
$(CC) $^ $(LDFLAGS) -o $@
$(BUIDIR)/%.srec: $(BUIDIR)/%.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
$(BUIDIR)/%.hex: $(BUIDIR)/%.elf
$(OBJCOPY) -O ihex -R .eeprom $< $@
$(OBJS): | $(OBJDIR)
$(OBJDIR):
mkdir -p $(OBJDIR)
mkdir -p $(BUIDIR)
.PHONY: flash
flash: $(BUIDIR)/$(TARGET).hex
sudo $(AVRDUDE) $(AVRFLAGS) -U flash:w:$<
.PHONY: verify
verify: $(BUIDIR)/$(TARGET).hex
sudo $(AVRDUDE) $(AVRFLAGS) -U flash:v:$<
.PHONY: fuse
fuse:
sudo $(AVRDUDE) $(AVRFLAGS) -U hfuse:w:0xDF:m
.PHONY: clean
clean:
rm -rf $(BUIDIR) $(OBJDIR) $(OBJLIBS)