yb_arm/rfic/makefile

130 lines
3.7 KiB
Makefile
Raw Normal View History

#========================================================================================================
# stc makefile
# #FileName: makefile
#Author: xianfeng.du
#Data 2022-08-10
#Description: top makefile
#========================================================================================================
VERSION = 1.00
OPTION ?=
ifeq ($(OPTION),GCC)
CROSS_CC ?=
else
# TOOLS ?= /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin
# CROSS_CC ?= $(TOOLS)/aarch64-linux-gnu-
CROSS_CC ?= aarch64-linux-gnu-
endif
2023-09-26 11:29:28 +08:00
AR := ar
CC := $(CROSS_CC)gcc
#$(info "CC=" $(CC))
git_id ?= $(shell git log -1 --format="%H")
commit_ts ?= $(shell git log -1 --format="%ct")
commit_time ?= $(shell date -d@$(commit_ts) +"%Y-%m-%d-%H:%M:%S")
#git_cmit ?= $(shell date +"%Y-%m-%d::%H:%M:%S")
$(info "commit_ts=" $(commit_ts))
$(info "commit_time=" $(commit_time))
2023-09-26 11:29:28 +08:00
#DEFINES ?= RFIC_VER=\"commit_id:$(git_id),commit_time:$(commit_time)\"
#optimization level -O2
C_OPT_FLAGS ?= -O2
CC_FLAGS ?= $(C_OPT_FLAGS) -Wall -g
CC_FLAGS += -Werror -Wno-unused-function
CC_FLAGS += $(foreach d,$(DEFINES),-D$(d))
CC_FLAGS += -fPIC
LIB_DIRS ?= ../lib
SRC_DIRS ?= ./src
INCLUDE_DIRS ?= ./inc
LD_FLAGS ?= -lgcc -lc
LD_FLAGS += -lm -ldl -Wl,-rpath=./
LD_FLAGS += -lpthread
2023-09-26 11:29:28 +08:00
LD_FLAGS += -lrfic
LD_FLAGS += -rdynamic -funwind-tables -ffunction-sections
#Flatten files and remove the duplicate by sort
ABS_SRC_DIRS := $(foreach d,$(SRC_DIRS),$(abspath $(d)))
SRC_FILES := $(foreach d,$(ABS_SRC_DIRS),$(wildcard $(d)/*.c))
# Allow certain files to be excluded from the build
2023-09-26 11:29:28 +08:00
EXCL_SRCS ?=
# Filter source files (allow files to be excluded)
FINAL_SRCS_FILES += $(foreach f,$(SRC_FILES),$(if $(findstring $(abspath $(f)),$(abspath $(EXCL_SRCS))),,$(f)))
#$(info "FINAL_SRCS_FILES=" $(FINAL_SRCS_FILES))
# ==============================================================================
# Variables: Output Files
# ==============================================================================
2023-09-26 11:29:28 +08:00
#BUILD_DIR := ./build
ifeq ($(BOARD_TYPE),EVB)
BIN_FILE_NAME := rfic_evb.out
2023-10-26 09:01:30 +08:00
else ifeq ($(BOARD_TYPE),EVMY)
2023-09-26 11:29:28 +08:00
BIN_FILE_NAME := rfic_evmy.out
2023-10-26 09:01:30 +08:00
else ifeq ($(BOARD_TYPE),EVMYF)
BIN_FILE_NAME := rfic_evmyf.out
else
BIN_FILE_NAME := rfic_evmyt.out
2023-09-26 11:29:28 +08:00
endif
#$(info "BUILD_DIR=" $(BUILD_DIR))
OBJ_DIR := $(BUILD_DIR)/rfic
BIN_FILE := $(BUILD_DIR)/$(BIN_FILE_NAME)
OBJ_FILES += $(foreach f,$(FINAL_SRCS_FILES),$(OBJ_DIR)/$(patsubst %.c,%.o,$(notdir $(f))))
# ==============================================================================
# Rules: Compilation
# ==============================================================================
define DO_BUILD_OBJ
$(2)/%.o: $(1)/%.c | $(2)
@echo "# Compiling $$< -> $$@"
$(CC) $(CC_FLAGS) -o $$@ -c $$< $(patsubst %,-I %,$(INCLUDE_DIRS))
#OBJ_TGTS += $(foreach f,$(wildcard $(1)/*.c),$(OBJ_DIR)/$(notdir $(basename $(1)))/$(patsubst %.c,%.o,$(notdir $(f))))
endef
define DO_BUILD_DIR
$(1):
@echo "# Creating directory $$@"
mkdir -p $$@
endef
define DO_BUILD
$(eval $(call DO_BUILD_DIR,$(1)))
$(foreach d,$(sort $(2)),$(eval $(call DO_BUILD_OBJ,$(d),$(1))))
endef
$(eval $(call DO_BUILD,$(OBJ_DIR),$(ABS_SRC_DIRS)))
2023-09-26 11:29:28 +08:00
$(BIN_FILE):$(OBJ_FILES)
# @echo "# Creating bin directory $(BIN_DIR)"
# mkdir -p $(BIN_DIR)
@echo "# Linking objects to form $@"
$(CC) -o $@ $^ $(LD_FLAGS) $(patsubst %,-L %,$(LIB_DIRS))
# $(CC) -o $@ $^ $(LD_FLAGS) -T$(LINK_FILE)
# ==============================================================================
# Rules: Targets
# ==============================================================================
.DEFAULT_GOAL := all
2023-09-26 11:29:28 +08:00
.PHONY: build clean
all: build
build: $(BIN_FILE)
clean:
@echo "deleted all files"
2023-09-26 11:29:28 +08:00
#rm -rf $(BUILD_DIR)