yb_arm/driver/tfu/makefile
2025-05-20 01:20:32 +08:00

168 lines
5.0 KiB
Makefile
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#========================================================================================================
# 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
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))
DEFINES ?= TFU_VER=\"commit_id:$(git_id),commit_time:$(commit_time)\"
ifeq ($(adj_freq),yes)
DEFINES += SL_ADJ_FREQ
endif
board ?= EVMYFT
#ifeq ($(board),evb)
#DEFINES += EVB
#else
#DEFINES += EVMYFT
#endif
DEFINES += $(board)
#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
SRC_DIRS ?= ./main/src
LIB_SRC_DIRS ?= ./stc/src
ifeq ($(gps),lc98s)
SRC_DIRS += ./lc98s/src
else
SRC_DIRS += ./ublox/src
endif
INCLUDE_DIRS ?= ./main/inc
INCLUDE_DIRS += ./stc/inc
INCLUDE_DIRS += ./ublox/inc
LD_FLAGS ?= -lgcc -lc
LD_FLAGS += -lm -ldl -Wl,-rpath=./
LD_FLAGS += -lpthread
LD_FLAGS += -lstc
LD_FLAGS += -rdynamic -funwind-tables -ffunction-sections
$(info "DEFINES=" $(DEFINES))
#$(info "lib src =" $(LIB_SRC_DIRS))
#Flatten files and remove the duplicate by sort
ABS_SRC_DIRS := $(foreach d,$(SRC_DIRS),$(abspath $(d)))
#$(info "abs src =" $(ABS_SRC_DIRS))
ABS_LIB_SRC_DIRS := $(foreach d,$(LIB_SRC_DIRS),$(abspath $(d)))
#$(info "abs lib =" $(ABS_LIB_SRC_DIRS))
SRC_FILES := $(foreach d,$(ABS_SRC_DIRS),$(wildcard $(d)/*.c))
#$(info "src files =" $(SRC_FILES))
LIB_SRC_FILES := $(foreach d,$(ABS_LIB_SRC_DIRS),$(wildcard $(d)/*.c))
#$(info "lib files =" $(LIB_SRC_FILES))
#main.c
MAIN_DIR := ./main/src
MAIN_FILE := ./main/src/main.c
# Allow certain files to be excluded from the build
#EXCL_SRCS ?= $(MAIN_FILE)
# 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
# ==============================================================================
BUILD_DIR := ./build
LIB_DIRS ?= $(BUILD_DIR)
OBJ_MAIN_DIR := $(BUILD_DIR)/main
OBJ_DIR := $(BUILD_DIR)/obj
#BIN_DIR := $(BUILD_DIR)/bin
#LIB_DIR := $(BUILD_DIR)/lib
#ELF_FILE := $(BIN_DIR)/test.elf
BIN_FILE := $(BUILD_DIR)/tfu.out
LIB_FILE := $(BUILD_DIR)/libstc.a
OBJ_FILES += $(foreach f,$(FINAL_SRCS_FILES),$(OBJ_DIR)/$(patsubst %.c,%.o,$(notdir $(f))))
#$(info "obj files =" $(OBJ_FILES))
LIB_OBJ_FILES += $(foreach f,$(LIB_SRC_FILES),$(OBJ_DIR)/$(patsubst %.c,%.o,$(notdir $(f))))
#$(info "lib obj files =" $(LIB_OBJ_FILES))
OBJ_MAIN_FILES += $(foreach f,$(MAIN_FILE),$(OBJ_MAIN_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)))
$(eval $(call DO_BUILD,$(OBJ_DIR),$(ABS_LIB_SRC_DIRS)))
$(eval $(call DO_BUILD,$(OBJ_MAIN_DIR), $(abspath $(MAIN_DIR))))
#$(BIN_FILE):$(OBJ_FILES) $(OBJ_MAIN_FILES)
$(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)
$(LIB_FILE):$(LIB_OBJ_FILES)
# @echo "# Creating lib directory $(LIB_DIR)"
# mkdir -p $(LIB_DIR)
# $(info "lib obj =" $(LIB_OBJ_FILES))
@echo "# Linking objects to form $@"
$(AR) -rcs $@ $^
# $(CC) -shared -o $@ $^ $(LD_FLAGS)
# ==============================================================================
# Rules: Targets
# ==============================================================================
.DEFAULT_GOAL := all
.PHONY: build lib clean
all: lib build
build: $(BIN_FILE)
lib: $(LIB_FILE)
clean:
@echo "deleted all files"
rm -rf $(BUILD_DIR)