2019-03-07 14:34:52 +08:00
|
|
|
$(if $(strip $(TARGET)),,$(error TARGET not defined))
|
|
|
|
$(if $(strip $(SRC_FILES)),,$(error No source files))
|
|
|
|
$(if $(strip $(BSP_ROOT)),,$(error BSP_ROOT not defined))
|
|
|
|
|
|
|
|
ifneq ($(MAKE_LIB),1)
|
|
|
|
BUILD_DIR := $(BSP_ROOT)/build
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(if $(strip $(BUILD_DIR)),,$(error BUILD_DIR not defined))
|
|
|
|
|
2019-03-23 19:36:40 +08:00
|
|
|
RTT_BUILD_DIR := .
|
|
|
|
BSP_BUILD_DIR := bsp
|
2019-03-07 14:34:52 +08:00
|
|
|
|
|
|
|
#################
|
|
|
|
|
|
|
|
define add_c_file
|
2019-03-23 19:36:40 +08:00
|
|
|
$(eval C_SRC := $(1:$(BSP_ROOT)/%=%)) \
|
|
|
|
$(eval C_SRC := $(C_SRC:$(RTT_ROOT)/%=%)) \
|
2019-03-07 14:34:52 +08:00
|
|
|
$(eval COBJ := $(1:%.c=%.o)) \
|
|
|
|
$(eval COBJ := $(COBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \
|
2019-03-23 19:36:40 +08:00
|
|
|
$(eval COBJ := $(COBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \
|
2019-03-07 14:34:52 +08:00
|
|
|
$(eval LOCALC := $(addprefix $(BUILD_DIR)/,$(COBJ))) \
|
|
|
|
$(eval OBJS += $(LOCALC)) \
|
2019-03-23 19:36:40 +08:00
|
|
|
$(if $(strip $(LOCALC)),$(eval $(LOCALC): $(C_SRC)
|
2019-03-07 14:34:52 +08:00
|
|
|
@if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi
|
2019-03-23 19:36:40 +08:00
|
|
|
@echo cc $$<
|
2019-03-07 14:34:52 +08:00
|
|
|
@$(CROSS_COMPILE)gcc $$(CFLAGS) -c $$< -o $$@))
|
|
|
|
endef
|
|
|
|
|
|
|
|
define add_cxx_file
|
2019-03-23 19:36:40 +08:00
|
|
|
$(eval CXX_SRC := $(1:$(BSP_ROOT)/%=%)) \
|
|
|
|
$(eval CXX_SRC := $(CXX_SRC:$(RTT_ROOT)/%=%)) \
|
2019-03-07 14:34:52 +08:00
|
|
|
$(eval CXXOBJ := $(1:%.cpp=%.o)) \
|
|
|
|
$(eval CXXOBJ := $(CXXOBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \
|
2019-03-23 19:36:40 +08:00
|
|
|
$(eval CXXOBJ := $(CXXOBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \
|
2019-03-07 14:34:52 +08:00
|
|
|
$(eval LOCALCXX := $(addprefix $(BUILD_DIR)/,$(CXXOBJ))) \
|
|
|
|
$(eval OBJS += $(LOCALCXX)) \
|
2019-03-23 19:36:40 +08:00
|
|
|
$(if $(strip $(LOCALCXX)),$(eval $(LOCALCXX): $(CXX_SRC)
|
2019-03-07 14:34:52 +08:00
|
|
|
@if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi
|
2019-03-23 19:36:40 +08:00
|
|
|
@echo cc $$<
|
2019-03-07 14:34:52 +08:00
|
|
|
@$(CROSS_COMPILE)g++ $$(CXXFLAGS) -c $$< -o $$@))
|
|
|
|
endef
|
|
|
|
|
|
|
|
define add_S_file
|
2019-03-23 19:36:40 +08:00
|
|
|
$(eval S_SRC := $(1:$(BSP_ROOT)/%=%)) \
|
|
|
|
$(eval S_SRC := $(S_SRC:$(RTT_ROOT)/%=%)) \
|
2019-03-07 14:34:52 +08:00
|
|
|
$(eval SOBJ := $(1:%.S=%.o)) \
|
|
|
|
$(eval SOBJ := $(SOBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \
|
2019-03-23 19:36:40 +08:00
|
|
|
$(eval SOBJ := $(SOBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \
|
2019-03-07 14:34:52 +08:00
|
|
|
$(eval LOCALS := $(addprefix $(BUILD_DIR)/,$(SOBJ))) \
|
|
|
|
$(eval OBJS += $(LOCALS)) \
|
2019-03-23 19:36:40 +08:00
|
|
|
$(if $(strip $(LOCALS)),$(eval $(LOCALS): $(S_SRC)
|
2019-03-07 14:34:52 +08:00
|
|
|
@if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi
|
2019-03-23 19:36:40 +08:00
|
|
|
@echo cc $$<
|
2019-03-07 14:34:52 +08:00
|
|
|
@$(CROSS_COMPILE)gcc $$(AFLAGS) -c $$< -o $$@))
|
|
|
|
endef
|
|
|
|
|
2020-07-16 22:25:09 +08:00
|
|
|
define add_s_file
|
|
|
|
$(eval S_SRC := $(1:$(BSP_ROOT)/%=%)) \
|
|
|
|
$(eval S_SRC := $(S_SRC:$(RTT_ROOT)/%=%)) \
|
|
|
|
$(eval SOBJ := $(1:%.s=%.o)) \
|
|
|
|
$(eval SOBJ := $(SOBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \
|
|
|
|
$(eval SOBJ := $(SOBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \
|
|
|
|
$(eval LOCALS := $(addprefix $(BUILD_DIR)/,$(SOBJ))) \
|
|
|
|
$(eval OBJS += $(LOCALS)) \
|
|
|
|
$(if $(strip $(LOCALS)),$(eval $(LOCALS): $(S_SRC)
|
|
|
|
@if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi
|
|
|
|
@echo cc $$<
|
|
|
|
@$(CROSS_COMPILE)gcc $$(AFLAGS) -c $$< -o $$@))
|
|
|
|
endef
|
|
|
|
|
2019-03-07 14:34:52 +08:00
|
|
|
add_flg = $(eval CFLAGS += $1) \
|
|
|
|
$(eval AFLAGS += $1) \
|
|
|
|
$(eval CXXFLAGS += $1)
|
|
|
|
|
|
|
|
add_inc = $(eval CFLAGS += -I$1) \
|
|
|
|
$(eval AFLAGS += -I$1) \
|
|
|
|
$(eval CXXFLAGS += -I$1)
|
|
|
|
|
|
|
|
add_def = $(eval CFLAGS += -D$1) \
|
|
|
|
$(eval AFLAGS += -D$1) \
|
|
|
|
$(eval CXXFLAGS += -D$1)
|
|
|
|
|
|
|
|
OBJS :=
|
2019-03-23 19:36:40 +08:00
|
|
|
#VPATH := $(BSP_ROOT) $(RTT_ROOT)
|
|
|
|
VPATH := $(RTT_ROOT)
|
2019-03-07 14:34:52 +08:00
|
|
|
|
|
|
|
CONFIG_FLG := $(strip $(EXTERN_FLAGS))
|
|
|
|
$(if $(CONFIG_FLG),$(foreach f,$(CONFIG_FLG),$(call add_flg,$(f))))
|
|
|
|
|
|
|
|
CONFIG_DEF := $(strip $(PROJECT_DEFS))
|
|
|
|
$(if $(CONFIG_DEF),$(foreach d,$(CONFIG_DEF),$(call add_def,$(d))))
|
|
|
|
|
|
|
|
CONFIG_INC := $(strip $(INCLUDE_PATH))
|
|
|
|
$(if $(CONFIG_INC),$(foreach i,$(CONFIG_INC),$(call add_inc,$(i))))
|
|
|
|
|
|
|
|
SRCS := $(strip $(filter %.c,$(SRC_FILES)))
|
|
|
|
$(if $(SRCS),$(foreach f,$(SRCS),$(call add_c_file,$(f))))
|
|
|
|
|
|
|
|
SRCS := $(strip $(filter %.cpp,$(SRC_FILES)))
|
|
|
|
$(if $(SRCS),$(foreach f,$(SRCS),$(call add_cxx_file,$(f))))
|
|
|
|
|
|
|
|
SRCS := $(strip $(filter %.S,$(SRC_FILES)))
|
|
|
|
$(if $(SRCS),$(foreach f,$(SRCS),$(call add_S_file,$(f))))
|
|
|
|
|
2020-07-16 22:25:09 +08:00
|
|
|
SRCS := $(strip $(filter %.s,$(SRC_FILES)))
|
|
|
|
$(if $(SRCS),$(foreach f,$(SRCS),$(call add_s_file,$(f))))
|
|
|
|
|
2019-03-07 14:34:52 +08:00
|
|
|
CFLAGS += $(CPPPATHS)
|
|
|
|
CXXFLAGS += $(CPPPATHS)
|
|
|
|
AFLAGS += $(CPPPATHS)
|
|
|
|
|
|
|
|
CFLAGS += $(DEFINES)
|
|
|
|
CXXFLAGS += $(DEFINES)
|
|
|
|
AFLAGS += $(DEFINES)
|
|
|
|
|
|
|
|
all: $(TARGET)
|
|
|
|
|
|
|
|
ifeq ($(MAKE_LIB),1)
|
|
|
|
$(TARGET): $(OBJS)
|
|
|
|
@echo ------------------------------------------------
|
|
|
|
@echo ar $(TARGET)
|
|
|
|
@$(CROSS_COMPILE)ar -rv $@ $(OBJS)
|
|
|
|
else
|
2021-06-04 23:53:29 +08:00
|
|
|
$(TARGET): $(OBJS)
|
2019-03-07 14:34:52 +08:00
|
|
|
@echo ------------------------------------------------
|
|
|
|
@echo link $(TARGET)
|
2021-06-04 23:53:29 +08:00
|
|
|
@$(CROSS_COMPILE)g++ -o $@ $(LFLAGS) $(OBJS) $(EXTERN_LIB)
|
2019-03-07 14:34:52 +08:00
|
|
|
@echo ------------------------------------------------
|
|
|
|
@$(CROSS_COMPILE)objcopy -O binary $@ rtthread.bin
|
|
|
|
@$(CROSS_COMPILE)size $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
phony += clean
|
|
|
|
clean:
|
|
|
|
@echo clean
|
|
|
|
@rm -rf $(TARGET) $(BUILD_DIR)
|
|
|
|
|
|
|
|
.PHONY: $(phony)
|