driverlib/Makefile

60 lines
1.1 KiB
Makefile
Raw Normal View History

2019-10-20 07:12:45 +00:00
CROSS_COMPILE ?= arm-none-eabi-
TARGET_FILE ?= driverlib.a
C_FLAGS += -Wall -Werror -fno-builtin -DGNU -D__GNU__ -D__GCC__ -D__CORTEX_M4__
C_FLAGS += -Os
C_FLAGS += -ffunction-sections
C_FLAGS += -fdata-sections
C_FLAGS += -std=c18
C_FLAGS += -pedantic
C_FLAGS += -pedantic-errors
C_FLAGS += -ggdb3
C_FLAGS += -Iinc
C_FLAGS += -I.
CCFLAGS += -mcpu=cortex-m4 -mthumb -mthumb-interwork
CC = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
OBJ_DIR := objs
BIN_DIR := lib
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)
$(AR) rcs $(TARGET) $(OBJS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
@$(call makedep,$<,$@,$(patsubst %.c,%.d,$(OBJ_DIR)/$(notdir $<)),$(C_FLAGS))
$(CC) -c $(C_FLAGS) $(CCFLAGS) -o $@ $<
.PHONY: clean
clean:
rm -rf \
$(OBJS) \
$(patsubst %.o,%.d,$(OBJS)) \
$(TARGET)
define makedep
$(CC) -MM -MF $3 -MP -MT $2 $4 $1
endef
ifneq ($(MAKECMDGOALS),clean)
-include $($(subst .o,.d,$(OBJS))
endif