#
# This Makefile was automatically generated; do not edit.
#   Generated on 'swio-display-x64-rhel04-11' on Sat Nov  7 20:27:37 PST 2015.
#

#
# KBUILD Makefile for NVIDIA UVM kernel module
#
# The motivation for replacing the original Makefile is the hope that this
# version will simplify the build and installation process. In the past,
# many architectural and cosmetic changes to the Linux kernel have made it
# difficult to maintain compatibility or required duplication of logic.
#
# Linux 2.6 introduces numerous such changes, many of which impact modules.
# Relying on KBUILD, some aspects of the build system otherwise difficult
# to support (for example, module versioning) are abstracted away and dealt
# with elsewhere, making life significantly easier here.
#
# The new approach currently has its own share of problems, some of which
# are architectural difficulties with KBUILD, others minor annoyances. For
# this reason, an improved version of the NVIDIA Makefile is available to
# those experiencing difficulties.
#

# The following UVM_BUILD_TYPEs are supported: debug, release, and develop.
# The first two are nearly self-explanatory, but "develop" deserves a little
# more explanation (below).
#
# Description of the UVM build types (UVM_BUILD_TYPE):
#
# debug builds: these get debug symbols, no optimization (in order to allow
# easier stepping through of functions), and debug printing.
#
# develop builds: these are "printing" builds, normally without debug symbols.
# These builds must run at close to normal speeds, so they are optimized, and
# do not have any debug symbols. However, they do have debug printing output.
# This allows a convenient way for QA (or anyone) to get a slightly deeper look
# at what the driver is doing, without the hassle of setting up kernel
# debugging.
#
# release builds: these are just the usual speed-optimized, no-debug,
# no-printing builds that you would expect most users to run.
#
UVM_BUILD_TYPE = release

ifeq ($(UVM_BUILD_TYPE),debug)
  EXTRA_CFLAGS += -DDEBUG -O0 -g
else
    ifeq ($(UVM_BUILD_TYPE),develop)
	  # -DDEBUG is required, in order to allow pr_devel() print statements to
	  # work:
      EXTRA_CFLAGS += -DDEBUG -O2
	else
      EXTRA_CFLAGS += -O2
    endif
endif

NV_HOST_OS := $(shell uname)
NV_HOST_ARCH := $(shell uname -m)

NV_TARGET_DEFINES ?=
NV_DEFINES=

# Enable Uvm kernel module
NV_DEFINES += -DNVIDIA_UVM_ENABLED

# UVM_NEXT is enabled if the driver supports fault-capable gpus.
UVM_NEXT = 0

ifneq ($(UVM_NEXT),0)
    NV_DEFINES += -DNVIDIA_UVM_NEXT_ENABLED
endif

# RM_ENABLED denotes whether the driver should be built with rm dependent code.
RM_ENABLED ?= 1

NV_DEFINES += -D$(NV_HOST_OS)

ifneq ($(findstring $(NV_HOST_OS),"Linux"),)
  NV_HOST_OS_FAMILY = Unix
  NV_HOST_OS_FAMILY_LOWER_CASE = unix
  NV_DEFINES+= -D__linux__
endif

ifneq ($(findstring $(NV_HOST_OS),"macosx"),)
  NV_HOST_OS_FAMILY = MacOSX
  NV_HOST_OS_FAMILY_LOWER_CASE = macosx
endif

ifeq ($(NV_HOST_OS_FAMILY),)
  $(error "Unrecognized NV_HOST_OS: $(NV_HOST_OS)")
endif

ifneq ($(findstring $(NV_HOST_OS_FAMILY),"Unix MacOSX"),)
  # For Unix and MacOS, use the host platform as the default target platform.
  NV_TARGET_OS ?= $(NV_HOST_OS)
  NV_TARGET_ARCH ?= $(NV_HOST_ARCH)
endif

#
# Determine NV_TARGET_OS_FAMILY
#
NV_TARGET_OS_FAMILY =

ifneq ($(findstring $(NV_TARGET_OS),"Linux"),)
  NV_TARGET_OS_FAMILY = Unix
  NV_TARGET_OS_FAMILY_LOWER_CASE = unix
endif

ifneq ($(findstring $(NV_TARGET_OS),"macosx"),)
  NV_TARGET_OS_FAMILY = MacOSX
  NV_TARGET_OS_FAMILY_LOWER_CASE = macosx
endif

ifeq ($(NV_TARGET_OS_FAMILY),)
  $(error "NV_TARGET_OS_FAMILY has not been set.")
endif

src ?= $(CURDIR)
obj ?= $(src)

# In both internal builds, and installation (public) builds, the UVM open-source
# files (that's all of them, for UVM) are in a subdirectory below the RM
# open-source files.
RM_OUT_DIR ?= $(src)/..

VERSION_HEADER := $(RM_OUT_DIR)/nv_compiler.h

FUNCTION_COMPILE_TESTS = \
	remap_page_range \
	remap_pfn_range \
	vm_insert_page \
	kmem_cache_create \
	address_space_init_once \
	kbasename \
	fatal_signal_pending \
	list_cut_position

TYPE_COMPILE_TESTS = \
	irq_handler_t \
	outer_flush_all \
	vm_operations_struct \
	file_operations \
	task_struct \
	kuid_t \
	fault_flags \
	atomic64_type \
	address_space \
	backing_dev_info

MODULE_NAME:= nvidia-uvm

NV_MODULE_SUFFIX := -uvm

include $(src)/nvidia-uvm-core-sources.mk
MODULE_GLUE_OBJS := $(patsubst %.c,%.o,$(NVIDIA_UVM_CORE_SOURCES))

NV_INCLUDES:= -I$(PWD) -I$(RM_OUT_DIR)

-include $(src)/uvmnext.mk

ifneq ($(RM_ENABLED),0)
  include $(src)/nvidia-uvm-rm-dep-sources.mk
  NV_DEFINES += -DNVIDIA_UVM_RM_ENABLED
  MODULE_GLUE_OBJS += $(patsubst %.c,%.o,$(NVIDIA_UVM_RM_DEP_SOURCES))
endif

EXTRA_CFLAGS += $(NV_DEFINES) $(NV_TARGET_DEFINES) $(NV_INCLUDES)

ccflags-y += $(EXTRA_CFLAGS)

RM_MODULE_SYMVERS:= $(RM_OUT_DIR)/Module.symvers
UVM_MODULE_SYMVERS:= $(obj)/Module.symvers

module $(MODULE_NAME).ko: $(UVM_MODULE_SYMVERS) debug_diagnostics_printing

$(MODULE_NAME)-y := $(MODULE_GLUE_OBJS)

include $(RM_OUT_DIR)/nvidia-modules-common.mk

$(RM_MODULE_SYMVERS):
	cd $(RM_OUT_DIR); make module SYSSRC=$(KERNEL_SOURCES) SYSOUT=$(KERNEL_OUTPUT) KBUILD_EXTMOD=$(RM_OUT_DIR)

$(UVM_MODULE_SYMVERS): $(RM_MODULE_SYMVERS)
	cp $< $@

debug_diagnostics_printing:
ifeq ($(NV_VERBOSE),1)
	@echo "NVIDIA UVM: CC=$(CC), HOST_CC=$(HOST_CC) NV_TARGET_ARCH=$(NV_TARGET_ARCH)"
	@echo "NVIDIA UVM: CONFTEST=$(CONFTEST)"
	@echo "KERNEL_SOURCES: $(KERNEL_SOURCES)"
	@echo "EXTRA_CFLAGS: $(EXTRA_CFLAGS)"
endif

.PHONY: debug_diagnostics_printing
