include $(AQROOT)/makefile.linux.def

INCLUDE += -I$(VIVANTE_SDK_INC) -I$(VIVANTE_SDK_INC)/HAL -I$(AQROOT)/sdk/inc
INCLUDE += -I../include/ops -I../include/utils -I../include/inference
INCLUDE += -I../include/client -I../include -I../include/libnnext

CFLAGS += $(INCLUDE)
CFLAGS += -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Werror
CFLAGS += -fvisibility=hidden -D'OVXLIB_API=__attribute__((visibility("default")))'

################################################################################
# Supply necessary libraries.
ifeq ($(USE_VXC_BINARY)$(USE_VSC_LITE),11)
LIBS += -L$(VIVANTE_SDK_LIB) -l OpenVX -l OpenVXU -l CLC -l VSC_Lite -lGAL
else
LIBS += -L$(VIVANTE_SDK_LIB) -l OpenVX -l OpenVXU -l CLC -l VSC -lGAL
endif
LIBS += -lm -ldl

#############################################################################
# Macros.
ifeq ($(gcdSTATIC_LINK), 1)
STATIC=1
TARGET_NAME  = libovxlib.a
else
CFLAGS += -fPIC
DYNAMIC      := 1
TARGET_NAME  = libovxlib.so
endif

ifneq ("$(OVXLIB_CONFIG)", "")
    CFLAGS += -D$(OVXLIB_CONFIG)
endif

ifneq ($(gcdSTATIC_LINK), 1)
    ifeq ($(VSI_GPERF_DEBUG), 1)
        TCMALLOC_DIR = $(OVXLIB_DIR)/third-party/gperftools
        CFLAGS += -I$(TCMALLOC_DIR)/src
        CFLAGS += -I$(TCMALLOC_DIR)/src/gperftools
        CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
        CFLAGS += -g
        LIBS += -L$(TCMALLOC_DIR)/.libs -ltcmalloc
    endif
endif
#############################################################################
# Objects.
OBJECTS =   $(OBJ_DIR)/vsi_nn_context.o \
            $(OBJ_DIR)/vsi_nn_client_op.o \
            $(OBJ_DIR)/vsi_nn_graph.o  \
            $(OBJ_DIR)/vsi_nn_node_attr_template.o  \
            $(OBJ_DIR)/vsi_nn_node.o  \
            $(OBJ_DIR)/vsi_nn_ops.o  \
            $(OBJ_DIR)/vsi_nn_daemon.o  \
            $(OBJ_DIR)/vsi_nn_tensor.o \
            $(OBJ_DIR)/vsi_nn_version.o \
            $(OBJ_DIR)/vsi_nn_rnn.o \
            $(OBJ_DIR)/vsi_nn_rnn_helper.o \
            $(OBJ_DIR)/vsi_nn_internal_node.o \
            $(OBJ_DIR)/vsi_nn_log.o \
            $(OBJ_DIR)/vsi_nn_graph_optimization.o \
            $(OBJ_DIR)/vsi_nn_pre_post_process.o

vpath %.c client
OBJECTS +=   $(OBJ_DIR)/vsi_nn_vxkernel.o

vpath %.c utils
OBJECTS +=   $(OBJ_DIR)/vsi_nn_code_generator.o   \
             $(OBJ_DIR)/vsi_nn_binary_tree.o   \
             $(OBJ_DIR)/vsi_nn_map.o   \
             $(OBJ_DIR)/vsi_nn_link_list.o   \
             $(OBJ_DIR)/vsi_nn_math.o   \
             $(OBJ_DIR)/vsi_nn_dtype_util.o   \
             $(OBJ_DIR)/vsi_nn_shape_util.o   \
             $(OBJ_DIR)/vsi_nn_dtype.o   \
             $(OBJ_DIR)/vsi_nn_limits.o   \
             $(OBJ_DIR)/vsi_nn_vdata.o   \
             $(OBJ_DIR)/vsi_nn_util.o    \
             $(OBJ_DIR)/vsi_nn_constraint_check.o    \
             $(OBJ_DIR)/vsi_nn_hashmap.o   \
             $(OBJ_DIR)/vsi_nn_tensor_op.o

vpath %.c quantization
OBJECTS +=   $(OBJ_DIR)/vsi_nn_dynamic_fixed_point.o   \
             $(OBJ_DIR)/vsi_nn_asymmetric_affine.o   \
             $(OBJ_DIR)/vsi_nn_perchannel_symmetric_affine.o

vpath %.c pycc
OBJECTS +=      $(OBJ_DIR)/vsi_pycc_interface.o

vpath %.c post
OBJECTS +=      $(OBJ_DIR)/vsi_nn_post_fasterrcnn.o \
                $(OBJ_DIR)/vsi_nn_post_cmupose.o

vpath %.c libnnext
OBJECTS += $(OBJ_DIR)/vsi_nn_libnnext_resource.o

vpath %.c libnnext/ops/kernel
SRCS += ${notdir ${wildcard libnnext/ops/kernel/*.c}}

vpath %.c ops
SRCS += ${notdir ${wildcard ops/*.c}}

vpath %.c kernel
SRCS += ${notdir ${wildcard kernel/*.c}}

vpath %.c kernel/cl
SRCS += ${notdir ${wildcard kernel/cl/*.c}}

vpath %.c kernel/cpu
SRCS += ${notdir ${wildcard kernel/cpu/*.c}}

vpath %.c kernel/evis
SRCS += ${notdir ${wildcard kernel/evis/*.c}}

vpath %.c kernel/vx
SRCS += ${notdir ${wildcard kernel/vx/*.c}}

vpath %.c custom/ops
SRCS += ${notdir ${wildcard custom/ops/*.c}}

vpath %.c custom/ops/kernel
SRCS += ${notdir ${wildcard custom/ops/kernel/*.c}}

OBJECTS +=  ${patsubst %.c, $(OBJ_DIR)/%.o, $(SRCS)}

# installation directory
INSTALL_DIR := $(VIVANTE_SDK_LIB)

################################################################################
# Include the common makefile.

include $(AQROOT)/common.target
