#
# This Makefile was automatically generated; do not edit.
# Generated on 'swio-display-x64-rhel04-19' on Tue May 5 16:45:42 PDT 2015.
#

#
# KBUILD Makefile for the NVIDIA Linux 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.
#
# kbuild Makefile originally developed by:
#
# Alistair J Strachan (alistair@devzero.co.uk) (first pass, enhancements)
# Christian Zander (zander@mail.minion.de) (enhancements)
#

#
# The NVIDIA kernel module base name. The names of additional kernel modules
# will be variants on this name.
#

MODULE_NAME := nvidia

VERSION_HEADER := nv_compiler.h

#
# List of targets to build in case of multiple NVIDIA kernel module builds.
#

ifdef NV_BUILD_MODULE_INSTANCES
 MODULE_INSTANCE_NUMBERS := $(shell seq 0 `expr $(NV_BUILD_MODULE_INSTANCES) - 1`)
 FRONTEND_MODULE_NAME := $(MODULE_NAME)-frontend
 ifndef BUILD_MODULES_LIST
 BUILD_MODULES_LIST := $(addprefix $(MODULE_NAME),$(MODULE_INSTANCE_NUMBERS)) $(FRONTEND_MODULE_NAME)
 endif
endif

#
# List of object files to link into NVIDIA kernel module(s):
#
# - The core object file, shared by the single kernel module build, and each
# instance module in a multiple kernel module build.
# - The frontend object files, used by the single kernel module build, and by
# the frontend module in a multiple kernel module build.
# - The common glue object files, shared by the interface layer of the single
# kernel module build, and the interface layers for each instance module in
# a multiple kernel module build.
# - The instance object file, used by the interface layer of the single kernel
# module build, and unique to the interface layers of each instance module
# in a multiple kernel module build.
#
# Make sure KBUILD understands that we want a module.
#

CORE_OBJS := nv-kernel.o

FRONTEND_GLUE_OBJS := $(patsubst %.c,%.o,nv-frontend.c)
INSTANCE_GLUE_OBJS := $(patsubst %.c,%.o,nv-instance.c)

#
# Make each instance module depend upon its respective
# unique-per-instance object file.
#
# $(1): the module instance number for which to assign dependencies
#

define INSTANCE_DEPENDENCIES
 $(MODULE_NAME)$(strip $(1))-objs := $(CORE_OBJS) $(MODULE_GLUE_OBJS) \
 $(subst nv-instance,nv-instance-$(strip $(1)),$(INSTANCE_GLUE_OBJS))
endef

#
# Multi-module builds require GNU Make v3.81 or later, due to a bug in earlier
# versions of GNU Make that prevents the use of $(eval) within a $(foreach):
#
# http://savannah.gnu.org/bugs/?func=detailitem&item_id=1517
#

ifdef NV_BUILD_MODULE_INSTANCES
 $(FRONTEND_MODULE_NAME)-objs := $(FRONTEND_GLUE_OBJS)
 MODULE_GLUE_OBJS := $(patsubst %.c,%.o, nv.c nv-acpi.c nv-chrdev.c nv-cray.c nv-dma.c nv-drm.c nv-gvi.c nvlink.c nv-i2c.c nv-mempool.c nv-mmap.c nv-p2p.c nv-pat.c nv-procfs.c nv-usermap.c nv-vm.c nv-vtophys.c os-interface.c os-mlock.c os-pci.c os-registry.c os-smp.c os-usermap.c nv_uvm_interface.c)
 $(foreach instance,$(MODULE_INSTANCE_NUMBERS),$(eval $(call INSTANCE_DEPENDENCIES,$(instance))))
else
 MODULE_GLUE_OBJS := $(patsubst %.c,%.o, nv.c nv-acpi.c nv-chrdev.c nv-cray.c nv-dma.c nv-drm.c nv-gvi.c nvlink.c nv-i2c.c nv-mempool.c nv-mmap.c nv-p2p.c nv-pat.c nv-procfs.c nv-usermap.c nv-vm.c nv-vtophys.c os-interface.c os-mlock.c os-pci.c os-registry.c os-smp.c os-usermap.c nv_uvm_interface.c nv-frontend.c) $(INSTANCE_GLUE_OBJS)
 $(MODULE_NAME)-objs := $(CORE_OBJS) $(MODULE_GLUE_OBJS)
endif

nv-instance-%.c: nv-instance.c
	sed -e 's/#define MODULE_INSTANCE_NUMBER 0/#define MODULE_INSTANCE_NUMBER $(notdir $*)/' \
	 -e 's/#define MULTIPLE_KERNEL_MODULES NV_FALSE/#define MULTIPLE_KERNEL_MODULES NV_TRUE/' \
	 -e 's/#define MODULE_INSTANCE_STRING ""/#define MODULE_INSTANCE_STRING "$(notdir $*)"/' $< > $@

FUNCTION_COMPILE_TESTS = \
	remap_pfn_range \
	follow_pfn \
	vmap \
	set_pages_uc \
	set_memory_uc \
	set_memory_array_uc \
	change_page_attr \
	pci_get_class \
	pci_choose_state \
	vm_insert_page \
	acpi_device_id \
	acquire_console_sem \
	console_lock \
	kmem_cache_create \
	on_each_cpu \
	smp_call_function \
	acpi_evaluate_integer \
	ioremap_cache \
	ioremap_wc \
	acpi_walk_namespace \
	pci_domain_nr \
	pci_dma_mapping_error \
	sg_alloc_table \
	sg_init_table \
	pci_get_domain_bus_and_slot \
	get_num_physpages \
	efi_enabled \
	proc_create_data \
	pde_data \
	proc_remove \
	pm_vt_switch_required \
	drm_pci_set_busid \
	write_cr4 \
	xen_ioemu_inject_msi

TYPE_COMPILE_TESTS = \
	i2c_adapter \
	pm_message_t \
	irq_handler_t \
	acpi_device_ops \
	acpi_op_remove \
	acpi_device_id \
	outer_flush_all \
	proc_dir_entry \
	scatterlist \
	sg_table \
	file_operations \
	vm_operations_struct \
	pci_save_state \
	file_inode

GENERIC_COMPILE_TESTS = \
	nvmap_support \
	dom0_kernel_present \
	drm_available

MACRO_COMPILE_TESTS = \
	INIT_WORK

#
# CFLAGS dependent on the type of builds (e.g. single/muliple module, debug)
#

ifdef NV_BUILD_MODULE_INSTANCES
 EXTRA_CFLAGS += -DNV_BUILD_MODULE_INSTANCES=1
else
 EXTRA_CFLAGS += -DNV_BUILD_MODULE_INSTANCES=0
endif

EXTRA_CFLAGS += -UDEBUG -U_DEBUG -DNDEBUG

#
# Include common definitions; we rely on the definition of the source path to
# find the file; set to a reasonable default if unset (e.g. for top-level
# passes). The source path is also used in the common file.
#

src ?= .
include $(src)/nvidia-modules-common.mk

$(addsuffix .ko,$(BUILD_MODULES_LIST)): module

#
# Rules for building precompiled interfaces for multiple kernel module builds.
#

$(PRECOMPILED_INTERFACE_STEM)-%.o: nvidia%.ko
	@$(LD) $(EXTRA_LDFLAGS) $(MODULE_COMMON_SCRIPT) -r -o $@ $(MODULE_GLUE_OBJS) nv-instance-$(notdir $*).o $(MODULE_NAME)$(notdir $*).mod.o

$(PRECOMPILED_INTERFACE_STEM)-frontend.o: nvidia-frontend.ko
	@$(LD) $(EXTRA_LDFLAGS) $(MODULE_COMMON_SCRIPT) -r -o $@ $(FRONTEND_GLUE_OBJS) $(MODULE_NAME)-frontend.mod.o
