# RTU_ALL_AI — 公共编译选项
# 模块 makefile 通过 include 本文件获取 CC/CXX/C_FLAGS 等变量

# ------ x86 默认 ------
CROSS_COMPILE :=
GCCLIB_PATH   := /usr/bin
ARCH          := x86
BUILD_TYPE    := x86

# ------ ARM 交叉编译 ------
ifeq ($(CROSS), arm)
$(info ===> ARM 交叉编译)
CROSS_COMPILE := aarch64-buildroot-linux-gnu-
GCCLIB_PATH   := /opt/atk-dlrk356x-toolchain/bin
ARCH          := arm
BUILD_TYPE    := arm
endif

# ------ 工具链 ------
CC  := $(GCCLIB_PATH)/$(CROSS_COMPILE)gcc
CXX := $(GCCLIB_PATH)/$(CROSS_COMPILE)g++
LD  := $(GCCLIB_PATH)/$(CROSS_COMPILE)ld
AR  := $(GCCLIB_PATH)/$(CROSS_COMPILE)ar

# ------ 路径（模块 makefile 位于 release/src/layer/module/，上溯4级到根）------
ROOT_DIR     := $(realpath $(CURDIR)/../../../../)
REL_ROOT_DIR := $(ROOT_DIR)/release/$(BUILD_TYPE)
SRC_ROOT_DIR := $(ROOT_DIR)/src
REL_INC      := -I$(ROOT_DIR)/release/inc

# ------ 编译选项 ------
C_FLAGS   := $(REL_INC) -Wall -g
CXX_FLAGS := $(REL_INC) -std=c++11 -Wall -g

# ------ Debug 编译 (make DEBUG=1) ------
ifeq ($(DEBUG), 1)
$(info ===> DEBUG mode: -O0)
C_FLAGS   += -O0 -DDEBUG
CXX_FLAGS += -O0 -DDEBUG
else
C_FLAGS   += -O2
CXX_FLAGS += -O2
endif

ifeq ($(CROSS), arm)
C_FLAGS   += -DRK356x -mno-outline-atomics
CXX_FLAGS += -DRK356x -mno-outline-atomics -fno-threadsafe-statics
endif

# ------ 产物路径 ------
LIB_REL := $(REL_ROOT_DIR)/lib
EXE_REL := $(REL_ROOT_DIR)/exe

export CC CXX LD AR ARCH C_FLAGS CXX_FLAGS
export ROOT_DIR REL_ROOT_DIR SRC_ROOT_DIR REL_INC LIB_REL EXE_REL
