2020-03-10 05:56:43 +00:00
|
|
|
.DEFAULT_GOAL := all
|
2020-03-08 06:38:24 +00:00
|
|
|
|
2020-03-10 05:56:43 +00:00
|
|
|
PLATFORM ?= posix
|
|
|
|
|
|
|
|
TARGET_FILE ?= firmware.elf
|
2020-03-08 06:38:24 +00:00
|
|
|
|
|
|
|
CC = $(CROSS_COMPILE)gcc
|
|
|
|
CPP = $(CROSS_COMPILE)cpp
|
|
|
|
OBJCOPY = $(CROSS_COMPILE)objcopy
|
|
|
|
|
|
|
|
SRC_DIR = src
|
|
|
|
OBJ_DIR = obj
|
|
|
|
BIN_DIR = bin
|
|
|
|
|
|
|
|
CPP_FLAGS += $(addprefix -I, $(INCLUDES))
|
|
|
|
|
|
|
|
C_SRCS = $(wildcard $(SRC_DIR)/*.c)
|
2020-03-10 05:56:43 +00:00
|
|
|
C_SRCS += $(wildcard $(SRC_DIR)/platform/$(PLATFORM)/*.c)
|
2020-03-08 06:38:24 +00:00
|
|
|
C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS)))
|
|
|
|
OBJS = $(NRF_A_OBJS) $(NRF_C_OBJS) $(C_OBJS)
|
|
|
|
|
|
|
|
TARGET = $(BIN_DIR)/$(TARGET_FILE)
|
|
|
|
TARGET_HEX = $(patsubst %.elf,%.hex,$(TARGET))
|
|
|
|
TARGET_PACKAGE = $(patsubst %.hex,%.zip,$(TARGET_HEX))
|
|
|
|
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
|
|
|
|
2020-03-10 05:56:43 +00:00
|
|
|
INCLUDES += include/
|
|
|
|
|
2020-03-08 06:38:24 +00:00
|
|
|
OPT = 3
|
|
|
|
C_FLAGS += -O$(OPT) -g$(OPT)
|
|
|
|
C_FLAGS += -Wall -Werror
|
|
|
|
C_FLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
|
2020-03-10 05:56:43 +00:00
|
|
|
|
2020-03-08 06:38:24 +00:00
|
|
|
LIBS += c nosys m
|
|
|
|
|
2020-03-10 05:56:43 +00:00
|
|
|
include Makefile.$(PLATFORM)
|
|
|
|
|
|
|
|
.PHONY: all install uninstall clean distclean debug
|
2020-03-08 06:38:24 +00:00
|
|
|
all: $(TARGET)
|
|
|
|
|
|
|
|
debug:
|
|
|
|
@echo $(TARGET_HEX)
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -f $(TARGET) $(TARGET_HEX) $(TARGET_PACKAGE)
|
|
|
|
rm -f $(OBJS) $(patsubst %.o,%.d,$(OBJS))
|
|
|
|
|
|
|
|
distclean:
|
|
|
|
rm -rf $(OBJ_DIR) $(BIN_DIR)
|
|
|
|
|
|
|
|
$(TARGET): $(OBJS) $(THIS_MAKEFILE)
|
2020-03-10 05:56:43 +00:00
|
|
|
@mkdir -p $(dir $@)
|
2020-03-08 06:38:24 +00:00
|
|
|
$(CC) $(CC_FLAGS) $(LD_FLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -o $@
|
|
|
|
|
|
|
|
$(TARGET_HEX): $(TARGET) $(THIS_MAKEFILE)
|
|
|
|
$(OBJCOPY) -O ihex $(TARGET) $(TARGET_HEX)
|
|
|
|
|
|
|
|
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.c
|
2020-03-10 05:56:43 +00:00
|
|
|
@mkdir -p $(dir $@)
|
2020-03-08 06:38:24 +00:00
|
|
|
$(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(C_FLAGS) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(SRC_DIR)/%.c,$@)
|
|
|
|
|
|
|
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
|
|
|
@mkdir -p $(dir $@)
|
2020-03-10 05:56:43 +00:00
|
|
|
$(CC) -c $(CPP_FLAGS) $(C_FLAGS) $< -o $@
|
2020-03-08 06:38:24 +00:00
|
|
|
|
|
|
|
ifneq ($(MAKECMDGOALS),clean)
|
|
|
|
-include $(patsubst %.o,%.d,$(OBJS))
|
|
|
|
endif
|