ignition_monitor/Makefile

77 lines
1.5 KiB
Makefile
Raw Permalink Normal View History

CROSS_COMPILE ?= avr-
TARGET_FILE ?= avr.elf
MCU = attiny85
2019-12-26 09:15:25 +00:00
C_FLAGS += -Wall -Werror
C_FLAGS += -Os
C_FLAGS += -mmcu=$(MCU)
2019-12-26 09:15:25 +00:00
C_FLAGS += -ffunction-sections
C_FLAGS += -fdata-sections
C_FLAGS += -std=c11
C_FLAGS += -pedantic
C_FLAGS += -pedantic-errors
C_FLAGS += -Iinclude
2019-12-22 20:27:17 +00:00
LD_FLAGS += -mmcu=$(MCU)
DUDE_FLAGS = -p $(MCU)
DUDE_FLAGS += -P /dev/spidev0.0
DUDE_FLAGS += -c linuxspi
DUDE_FLAGS += -b 10000
CC = $(CROSS_COMPILE)gcc
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
AVRDUDE = avrdude
OBJ_DIR := objs
BIN_DIR := bin
SRC_DIR := src
C_SRCS = $(wildcard $(SRC_DIR)/*.c)
C_OBJS = $(patsubst %.c,$(OBJ_DIR)/%.o,$(notdir $(C_SRCS)))
OBJS = $(C_OBJS)
TARGET = $(BIN_DIR)/$(TARGET_FILE)
.PHONY: all
all: $(TARGET)
$(TARGET): $(OBJS) Makefile
@mkdir -p $(BIN_DIR)
$(CC) $(LD_FLAGS) $(LINKER_SCRIPT) $(OBJS) $(LD_LIBS) -o $@ -Wl,-Map=$(BIN_DIR)/$(notdir $(basename $@)).map
$(OBJCOPY) -O ihex $(TARGET) $(subst .elf,.hex,$(TARGET))
$(SIZE) $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
@$(call makedep,$<,$@,$(patsubst %.c,%.d,$(OBJ_DIR)/$(notdir $<)),$(C_FLAGS))
2019-12-22 20:27:17 +00:00
$(CC) -c $(C_FLAGS) -o $@ $<
.PHONY: clean
clean:
rm -rf \
$(OBJS) \
$(patsubst %.o,%.d,$(OBJS)) \
$(TARGET) \
$(subst .elf,.map,$(TARGET)) \
$(subst .elf,.hex,$(TARGET))
.PHONY: flash
flash: $(TARGET)
gpio 22 off
$(AVRDUDE) $(DUDE_FLAGS) -U flash:w:$(subst .elf,.hex,$(TARGET))
gpio 22 on
define makedep
$(CC) -MM -MF $3 -MP -MT $2 $4 $1
endef
ifneq ($(MAKECMDGOALS),clean)
-include $($(subst .o,.d,$(OBJS))
endif