-
Notifications
You must be signed in to change notification settings - Fork 1
/
Make_Senso
59 lines (45 loc) · 1.22 KB
/
Make_Senso
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
PROJ := Senso
TARGET_ELF := $(PROJ).elf
BUILD_DIR := ./bin/$(PROJ)
SRC_DIRS := ./src
FLASH_BAUDRATE := 57600
MCU_GCC := atmega328p
MCU_AVRDUDE := m328p
USB_DEVICE := /dev/ttyUSB0
INC := /usr/avr/include
CC := avr-gcc
LDFLAGS :=
CFLAGS := \
-DF_CPU=8000000 \
-O3 \
-MMD \
-MP \
-std=gnu99 \
$(addprefix -I,$(INC)) \
-mmcu=$(MCU_GCC) \
-Wall \
-Wextra \
-Werror
SRCS := $(shell find $(SRC_DIRS) -name "*.c" -o -name "*.S")
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
.PHONY: clean flash debug all
all: $(BUILD_DIR)/$(TARGET_ELF)
avr-size --mcu=$(MCU_GCC) -C $(BUILD_DIR)/$(TARGET_ELF)
flash: all
avr-objcopy -O ihex $(BUILD_DIR)/$(TARGET_ELF) $(BUILD_DIR)/$(PROJ).hex
avrdude -v -p $(MCU_AVRDUDE) -P $(USB_DEVICE) -c arduino -b $(FLASH_BAUDRATE) -U flash:w:$(BUILD_DIR)/$(PROJ).hex:i
$(BUILD_DIR)/$(TARGET_ELF): $(OBJS)
@$(CC) -mmcu=$(MCU_GCC) $(OBJS) -o $@ $(LDFLAGS)
@echo Done. Placed elf at $(BUILD_DIR)/$(TARGET_ELF)
$(BUILD_DIR)/%.c.o: %.c
@mkdir -p $(dir $@)
@echo Compiling $<
@$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/%.S.o: %.S
@mkdir -p $(dir $@)
@echo Compiling $<
@$(CC) $(CFLAGS) -c $< -o $@
clean:
$(RM) -r ./bin
-include $(DEPS)