-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
77 lines (61 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
PRJ=main
SRC=$(PRJ).cpp
CFLAGS=-c -Wall
LDFLAGS=
SOURCES=$(PRJ).cpp
EXT=./USART ./ADXL345 ./i2c ./TWI ./Motors ./Gyro
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=hello
MCU=atmega328p
CLK=16000000
PRG=Usbasp
AVRD = avrdude
CFLAGS = -Wall -Os -DF_CPU=$(CLK) -mmcu=$(MCU) $(INCLUDE) -std=c++11
# executables
SIM=simulavr
AVRDUDE = avrdude -c $(PRG) -p $(MCU)
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size --format=avr --mcu=$(MCU)
CC = avr-g++
# generate list of objects
CFILES = $(filter %.c, $(SRC))
EXTC := $(foreach dir, $(EXT), $(wildcard $(dir)/*.c))
CPPFILES = $(filter %.cpp, $(SRC))
EXTCPP := $(foreach dir, $(EXT), $(wildcard $(dir)/*.cpp))
OBJ = $(CFILES:.c=.o) $(EXTC:.c=.o) $(CPPFILES:.cpp=.o) $(EXTCPP:.cpp=.o)
#OBJ = "lalal"
# compile all files
all: $(PRJ).hex
# test programmer connectivity
test:
$(AVRDUDE) -v
# flash program to mcu
flash: all
$(AVRDUDE) -U flash:w:$(PRJ).hex:i
# write fuses to mcu
#fuse:
# $(AVRDUDE) -U lfuse:w:$(LFU):m -U hfuse:w:$(HFU):m -U efuse:w:$(EFU):m
# generate disassembly files for debugging
disasm: $(PRJ).elf
$(OBJDUMP) -d $(PRJ).elf
# remove compiled files
clean:
rm -f *.hex *.elf *.o
$(foreach dir, $(EXT), rm -f $(dir)/*.o;)
# other targets
# objects from c files
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# objects from c++ files
.cpp.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# elf file
$(PRJ).elf: $(OBJ)
@echo "Making elf file from objects: " $(OBJ)
$(CC) $(CFLAGS) -o $(PRJ).elf $(OBJ)
# hex file
$(PRJ).hex: $(PRJ).elf
rm -f $(PRJ).hex
$(OBJCOPY) -j .text -j .data -O ihex $(PRJ).elf $(PRJ).hex
# $(SIZE) $(PRJ).elf