narf52/Makefile

114 lines
3.3 KiB
Makefile
Raw Normal View History

2020-03-10 05:56:43 +00:00
.DEFAULT_GOAL := all
2020-03-08 06:38:24 +00:00
2020-03-12 14:30:53 +00:00
APPLICATION ?= blinky
2020-03-10 05:56:43 +00:00
2020-03-12 14:30:53 +00:00
PLATFORM ?= nrf52
2020-04-09 07:39:53 +00:00
ifneq "$(findstring $(PLATFORM), nrf52)" ""
CORE = cm4
endif
2020-03-10 12:31:33 +00:00
TARGET_FILE ?= $(APPLICATION).elf
2020-03-08 06:38:24 +00:00
CC = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)cpp
2020-03-29 13:48:12 +00:00
CXX = $(CROSS_COMPILE)g++
2020-03-08 06:38:24 +00:00
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
2020-03-29 08:25:17 +00:00
SIZE = $(CROSS_COMPILE)size
2020-03-30 09:45:29 +00:00
CHECK = cppcheck
2020-03-08 06:38:24 +00:00
SRC_DIR = src
2020-03-10 12:31:33 +00:00
OBJ_DIR = obj/$(PLATFORM)
BIN_DIR = bin/$(PLATFORM)
2020-03-08 06:38:24 +00:00
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-10 12:31:33 +00:00
C_SRCS += $(wildcard $(SRC_DIR)/application/$(APPLICATION)/*.c)
2020-03-29 13:48:12 +00:00
C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.c.o,$(C_SRCS)))
CC_SRCS = $(wildcard $(SRC_DIR)/*.cc)
2020-04-09 07:39:53 +00:00
CC_SRCS += $(wildcard $(SRC_DIR)/platform/$(CORE)/*.cc)
2020-03-29 13:48:12 +00:00
CC_SRCS += $(wildcard $(SRC_DIR)/platform/$(PLATFORM)/*.cc)
CC_SRCS += $(wildcard $(SRC_DIR)/application/$(APPLICATION)/*.cc)
CC_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.cc,%.cc.o,$(CC_SRCS)))
OBJS = $(NRF_A_OBJS) $(NRF_C_OBJS) $(C_OBJS) $(CC_OBJS)
2020-03-08 06:38:24 +00:00
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-29 16:05:34 +00:00
INCLUDES += src/
INCLUDES += interfaces/
2020-03-10 05:56:43 +00:00
INCLUDES += include/
2020-03-30 09:45:29 +00:00
INCLUDES += include/platform/$(PLATFORM)
2020-03-10 05:56:43 +00:00
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
C_FLAGS += -DPLATFORM_$(PLATFORM)
2020-03-10 05:56:43 +00:00
2020-03-29 13:48:12 +00:00
CXX_FLAGS += -O$(OPT) -g$(OPT)
CXX_FLAGS += -Wall -Werror
CXX_FLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CXX_FLAGS += -DPLATFORM_$(PLATFORM)
2020-03-30 09:45:29 +00:00
CHECK_FLAGS = $(addprefix -I,$(INCLUDES))
CHECK_FLAGS += --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr --force --language=c++
2020-03-08 06:38:24 +00:00
2020-03-30 09:45:29 +00:00
include build_system/platform/$(PLATFORM)/Makefile.$(PLATFORM)
2020-03-10 05:56:43 +00:00
2020-03-30 09:45:29 +00:00
.PHONY: all install uninstall clean distclean debug check
2020-03-08 06:38:24 +00:00
all: $(TARGET)
debug:
2020-03-29 13:48:12 +00:00
@echo $(CC_OBJS)
2020-03-08 06:38:24 +00:00
clean:
rm -f $(TARGET) $(TARGET_HEX) $(TARGET_PACKAGE)
rm -f $(OBJS) $(patsubst %.o,%.d,$(OBJS))
distclean:
2020-03-10 12:31:33 +00:00
rm -rf bin obj
2020-03-08 06:38:24 +00:00
2020-03-30 09:45:29 +00:00
.PHONY:
check: $(C_SRCS)
$(CHECK) $(CHECK_FLAGS) $(CC_SRCS)
2020-03-08 06:38:24 +00:00
$(TARGET): $(OBJS) $(THIS_MAKEFILE)
2020-03-10 05:56:43 +00:00
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(LD_FLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -Wl,-Map=$@.map -o $@
$(OBJDUMP) --disassemble-all --section=.text --source -EL -C --wide --line-numbers --inlines $@ > $@.text.disassemble
2020-03-10 12:31:33 +00:00
ln -sf $(shell pwd)/$@ $(shell pwd)/bin/firmware.elf
$(SIZE) -x $@ > $@.size
@cat $@.size
2020-03-08 06:38:24 +00:00
$(TARGET_HEX): $(TARGET) $(THIS_MAKEFILE)
$(OBJCOPY) -O ihex $(TARGET) $(TARGET_HEX)
2020-03-10 12:31:33 +00:00
ln -sf $(shell pwd)/$@ $(shell pwd)/bin/firmware.hex
2020-03-08 06:38:24 +00:00
2020-03-12 14:30:53 +00:00
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.c $(THIS_MAKEFILE)
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,$@)
2020-03-29 13:48:12 +00:00
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.cc $(THIS_MAKEFILE)
@mkdir -p $(dir $@)
$(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(CXX_FLAGS) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(SRC_DIR)/%.cc,$@)
$(OBJ_DIR)/%.cc.o: $(SRC_DIR)/%.cc $(THIS_MAKEFILE)
@mkdir -p $(dir $@)
$(CXX) -c $(CPP_FLAGS) $(CXX_FLAGS) $< -o $@
$(OBJ_DIR)/%.c.o: $(SRC_DIR)/%.c $(THIS_MAKEFILE)
2020-03-08 06:38:24 +00:00
@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
2020-03-10 12:31:33 +00:00
ifeq "$(findstring $(MAKECMDGOALS), clean distclean)" ""
2020-03-08 06:38:24 +00:00
-include $(patsubst %.o,%.d,$(OBJS))
endif