################################### tell Emacs this is a -*- makefile-gmake -*-
#
# Copyright (c) 2018-2020, NVIDIA CORPORATION.  All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# tmake for SW Mobile component makefile
#
###############################################################################

NVGPU_UNIT_COMMON_SRCS		:= \
                                src/nvgpu.c \
                                src/args.c \
                                src/io.c \
                                src/module.c \
                                src/required_tests.c \
                                src/results.c \
                                src/exec.c \
                                src/utils.c
NVGPU_UNIT_COMMON_INCLUDES	:= \
                                ../nvsched/include \
                                include \
                                ../drivers/gpu/nvgpu \
                                ../drivers/gpu/nvgpu/include

ifdef NV_COMPONENT_FLAG_NVTEST_EXECUTABLE_SECTION
include $(NV_BUILD_START_COMPONENT)

NV_COMPONENT_NAME		:= nvgpu_unit
NV_COMPONENT_SOURCES		:= \
				src/unit_main.c \
				$(NVGPU_UNIT_COMMON_SRCS)

NV_COMPONENT_INCLUDES		:= \
				$(NVGPU_UNIT_COMMON_INCLUDES)

ifndef NVGPU_UNIT_GPU
NVGPU_UNIT_GPU			:= igpu
endif

NV_COMPONENT_NEEDED_INTERFACE_DIRS := ../libs/$(NVGPU_UNIT_GPU)

ifneq ($(NV_BUILD_CONFIGURATION_OS_IS_QNX),1)
NV_COMPONENT_SYSTEM_SHARED_LIBRARIES += pthread
NV_COMPONENT_SYSTEM_SHARED_LIBRARIES += dl
NV_COMPONENT_SYSTEM_SHARED_LIBRARIES += gcov
endif

_NV_TOOLCHAIN_CFLAGS            += -rdynamic

NV_UNIT_SH=unit.sh
NV_SUBMIT_UNIT_SH=nvgpu_submit_unit.sh
NV_TESTLIST_PY=testlist.py
NV_REQ_TESTS_INI=required_tests.ini
NV_COMPONENT_SYSTEMIMAGE_DIR    := $(NV_SYSTEMIMAGE_TEST_EXECUTABLE_DIR)/nvgpu_unit
systemimage:: $(NV_COMPONENT_SYSTEMIMAGE_DIR) $(NV_COMPONENT_SYSTEMIMAGE_DIR)/$(NV_UNIT_SH) \
	$(NV_SYSTEMIMAGE_TEST_EXECUTABLE_DIR)/$(NV_SUBMIT_UNIT_SH) \
	$(NV_COMPONENT_SYSTEMIMAGE_DIR)/$(NV_TESTLIST_PY) \
	$(NV_COMPONENT_SYSTEMIMAGE_DIR)/$(NV_REQ_TESTS_INI)

#make the output directory
$(NV_COMPONENT_SYSTEMIMAGE_DIR) : $(NV_SYSTEMIMAGE_TEST_EXECUTABLE_DIR)
	$(MKDIR_P) $@

#copy the test script
$(NV_COMPONENT_SYSTEMIMAGE_DIR)/$(NV_UNIT_SH) : $(NV_COMPONENT_DIR)/$(NV_UNIT_SH) $(NV_COMPONENT_SYSTEMIMAGE_DIR)
	$(CP) $< $@
#the submit script goes in the parent directory
$(NV_SYSTEMIMAGE_TEST_EXECUTABLE_DIR)/$(NV_SUBMIT_UNIT_SH) : $(NV_COMPONENT_DIR)/$(NV_SUBMIT_UNIT_SH) $(NV_COMPONENT_SYSTEMIMAGE_DIR)
	$(CP) $< $@
$(NV_COMPONENT_SYSTEMIMAGE_DIR)/$(NV_TESTLIST_PY) : $(NV_COMPONENT_DIR)/$(NV_TESTLIST_PY) $(NV_COMPONENT_SYSTEMIMAGE_DIR)
	$(CP) $< $@
$(NV_COMPONENT_SYSTEMIMAGE_DIR)/$(NV_REQ_TESTS_INI) : $(NV_COMPONENT_DIR)/$(NV_REQ_TESTS_INI) $(NV_COMPONENT_SYSTEMIMAGE_DIR)
	$(CP) $< $@

include $(NV_BUILD_NVTEST_EXECUTABLE)

endif

ifdef NV_COMPONENT_FLAG_SHARED_LIBRARY_SECTION
include $(NV_BUILD_START_COMPONENT)

NV_COMPONENT_NAME		:= nvgpu_unit-lib
NV_COMPONENT_OWN_INTERFACE_DIR	:= .

NV_COMPONENT_SOURCES		:= \
				$(NVGPU_UNIT_COMMON_SRCS)

NV_COMPONENT_INCLUDES		:= \
				$(NVGPU_UNIT_COMMON_INCLUDES)

ifneq ($(NV_BUILD_CONFIGURATION_OS_IS_QNX),1)
NV_COMPONENT_SYSTEM_SHARED_LIBRARIES += pthread
NV_COMPONENT_SYSTEM_SHARED_LIBRARIES += dl
NVGPU_FORCE_SAFETY_PROFILE	:= 1
NVGPU_FORCE_DEBUG_PROFILE	:= 1
endif

NV_COMPONENT_CFLAGS		+= \
	-D__NVGPU_POSIX__ \
	-DNVGPU_UNITTEST_FAULT_INJECTION_ENABLEMENT

-include ../drivers/gpu/nvgpu/Makefile.shared.configs
NV_COMPONENT_CFLAGS             += $(NVGPU_COMMON_CFLAGS)

NV_COMPONENT_SYSTEMIMAGE_DIR    := $(NV_SYSTEMIMAGE_TEST_EXECUTABLE_DIR)/nvgpu_unit/
systemimage:: $(NV_COMPONENT_SYSTEMIMAGE_DIR)
$(NV_COMPONENT_SYSTEMIMAGE_DIR) : $(NV_SYSTEMIMAGE_TEST_EXECUTABLE_DIR)
	$(MKDIR_P) $@
NV_COMPONENT_SYSTEMIMAGE_NAME	:= libnvgpu-unit.so

include $(NV_BUILD_SHARED_LIBRARY)

endif

# Local Variables:
# indent-tabs-mode: t
# tab-width: 8
# End:
# vi: set tabstop=8 noexpandtab:
