-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
70 lines (50 loc) · 1.24 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
# AVR project Makefile
# Microcontroller
MCU = atmega328p
# F_CPU (in Hz)
F_CPU = 16000000UL
# Programmer
PROGRAMMER = -c arduino -P /dev/ttyACM0 -b 115200
# Compiler
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AVRDUDE = avrdude
# Compiler flags
CFLAGS = -g -Wall -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU) -fexceptions
# Source directory
SRC_DIR = src
# Build directory
BUILD_DIR = build
# Source files
SRCS = main.c $(wildcard $(SRC_DIR)/libs/**/*.c)
# Object files
OBJS = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS))
# Output files
TARGET = main
ELF = $(TARGET).elf
HEX = $(TARGET).hex
MAP = $(TARGET).map
EEP = $(TARGET).eep
# Rules
all: $(HEX)
$(HEX): $(ELF)
$(OBJCOPY) -O ihex -R .eeprom $(ELF) $(HEX)
$(ELF): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(ELF)
$(OBJDUMP) -h -S $(ELF) > $(MAP)
$(SIZE) --format=avr --mcu=$(MCU) $(ELF)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR) $(dir $(OBJS))
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(dir $(OBJS)):
mkdir -p $@
flash: $(HEX)
$(AVRDUDE) $(PROGRAMMER) -p $(MCU) -U flash:w:$(HEX):i
eeprom: $(EEP)
$(AVRDUDE) $(PROGRAMMER) -p $(MCU) -U eeprom:w:$(EEP):i
clean:
rm -rf $(BUILD_DIR) $(ELF) $(HEX) $(MAP) $(EEP)
.PHONY: all flash eeprom clean