#
# This Makefile was automatically generated; do not edit.
# Generated on 'swio-display-x64-rhel04-15' on Wed Oct 30 17:17:25 PDT 2013.
#

#
# 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)
#

.PHONY: all install suser-sanity-check rmmod-sanity-check build-sanity-checks \
module module-sign module-install package-install clean print-module-filename \
conftest-compile-test

# avoid ld.gold, see #626279
LD=ld.bfd

all: install
install: package-install

#
# The NVIDIA kernel module base name and static file names. KBUILD will go
# ahead and append ".o" or ".ko" to form the final module name.
#

MODULE_NAME := nvidia
VERSION_HEADER := nv_compiler.h

#
# List of object files to link into NVIDIA kernel module; make sure KBUILD
# understands that we want a module.
#

CORE_OBJS := nv-kernel.o
RESMAN_GLUE_OBJS := $(patsubst %.c,%.o, nv.c nv-acpi.c nv-chrdev.c nv-cray.c nv-drm.c nv-gvi.c nv-i2c.c nv-mempool.c nv-mlock.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-pci.c os-registry.c os-smp.c os-usermap.c)

$(MODULE_NAME)-y		 = $(RESMAN_GLUE_OBJS)
$(MODULE_NAME)-$(CONFIG_X86_32)	+= nv-kernel-i386.o_shipped
$(MODULE_NAME)-$(CONFIG_X86_64)	+= nv-kernel-amd64.o_shipped
$(MODULE_NAME)-$(CONFIG_ARM)	+= nv-kernel-armhf.o_shipped

#
# The precompiled kernel module build process requires a separation of the
# closed source and open source object files.
#

KERNEL_GLUE_NAME := nv-linux.o
KERNEL_GLUE_OBJS := $(RESMAN_GLUE_OBJS) $(MODULE_NAME).mod.o

obj-m := $(MODULE_NAME).o

#
# Include local source directory in $(CC)'s include path and set disable any
# warning types that are of little interest to us.
#

EXTRA_CFLAGS += -I$(src)
EXTRA_CFLAGS += -Wall -MD $(DEFINES) $(INCLUDES) -Wsign-compare -Wno-cast-qual -Wno-error

#
# We rely on these two definitions below; if they aren't set, we set them to
# reasonable defaults (e.g. for top-level passes).
#

src ?= .
obj ?= .

#
# Determine location of the Linux kernel source tree. Allow users to override
# the default (i.e. automatically determined) kernel source location with the
# SYSSRC directive; this new directive replaces NVIDIA's SYSINCLUDE.
#

ifdef SYSSRC
 KERNEL_SOURCES := $(SYSSRC)
 KERNEL_HEADERS := $(KERNEL_SOURCES)/include
else
 KERNEL_UNAME ?= $(shell uname -r)
 KERNEL_MODLIB := /lib/modules/$(KERNEL_UNAME)
 KERNEL_SOURCES := $(shell test -d $(KERNEL_MODLIB)/source && echo $(KERNEL_MODLIB)/source || echo $(KERNEL_MODLIB)/build)
 KERNEL_HEADERS := $(KERNEL_SOURCES)/include
endif

KERNEL_OUTPUT := $(KERNEL_SOURCES)
KBUILD_PARAMS :=

ifdef SYSOUT
 ifneq ($(SYSOUT), $(KERNEL_SOURCES))
 KERNEL_OUTPUT := $(SYSOUT)
 KBUILD_PARAMS := KBUILD_OUTPUT=$(KERNEL_OUTPUT)
 endif
else
 KERNEL_UNAME ?= $(shell uname -r)
 KERNEL_MODLIB := /lib/modules/$(KERNEL_UNAME)
 ifeq ($(KERNEL_SOURCES), $(KERNEL_MODLIB)/source)
 KERNEL_OUTPUT := $(KERNEL_MODLIB)/build
 KBUILD_PARAMS := KBUILD_OUTPUT=$(KERNEL_OUTPUT)
 endif
endif

CC ?= cc
HOST_CC ?= $(CC)
LD ?= ld

ifndef ARCH
 ARCH := $(shell uname -m | sed -e 's/i.86/i386/' -e 's/armv[0-9]\w\+/arm/')
endif

CONFTEST := /bin/sh $(src)/conftest.sh "$(CC)" "$(HOST_CC)" $(ARCH) $(KERNEL_SOURCES) $(KERNEL_OUTPUT)

KERNEL_UNAME ?= $(shell $(CONFTEST) get_uname)
MODULE_ROOT := /lib/modules/$(KERNEL_UNAME)/kernel/drivers

#
# Sets any internal variables left unset by KBUILD (e.g. this happens during
# a top-level run).
#

TOPDIR ?= $(KERNEL_SOURCES)

#
# Linux 2.6 uses the .ko module extension.
#

MODULE_OBJECT := $(MODULE_NAME).ko

#
# NVIDIA specific CFLAGS and #define's.
#

EXTRA_CFLAGS += -D__KERNEL__ -DMODULE -DNVRM -DNV_VERSION_STRING=\"319.72\" -Wno-unused-function -Wuninitialized -mno-red-zone -mcmodel=kernel -UDEBUG -U_DEBUG -DNDEBUG -D__linux__

COMPILE_TESTS = \
	remap_page_range \
	remap_pfn_range \
	vmap \
	set_pages_uc \
	set_memory_uc \
	set_memory_array_uc \
	change_page_attr \
	i2c_adapter \
	pci_get_class \
	pm_message_t \
	irq_handler_t \
	pci_choose_state \
	vm_insert_page \
	acpi_device_ops \
	acpi_device_id \
	acquire_console_sem \
	kmem_cache_create \
	outer_flush_all \
	on_each_cpu \
	smp_call_function \
	vmm_support \
	nvmap_support \
	acpi_evaluate_integer \
	ioremap_cache \
	ioremap_wc \
	proc_dir_entry \
	INIT_WORK \
	acpi_walk_namespace \
	acpi_os_wait_events_complete \
	scatterlist \
	pci_domain_nr \
	pci_dma_mapping_error \
	file_operations \
	sg_init_table \
	pci_get_domain_bus_and_slot \
	get_num_physpages \
	efi_enabled \
	drm_available \
	proc_create_data \
	pde_data \
	proc_remove

#
# Command for signing kernel modules
#

MOD_SIGN_CMD ?= $(KERNEL_SOURCES)/scripts/sign-file

#
# Miscellaneous NVIDIA kernel module build support targets. They are needed
# to satisfy KBUILD requirements and to support NVIDIA specifics.
#

$(obj)/$(CORE_OBJS):
	$(NVQ)cp $(src)/$(CORE_OBJS) $(obj)/$(CORE_OBJS)

$(obj)/$(VERSION_HEADER):
	$(NVQ)echo \#define NV_COMPILER \"`$(CC) -v 2>&1 | tail -n 1`\" > $@

CONFTEST_COMPILE_TEST_HEADERS := $(obj)/conftest/macros.h \
$(obj)/conftest/functions.h $(obj)/conftest/symbols.h $(obj)/conftest/types.h \
$(obj)/conftest/generic.h

CONFTEST_HEADERS := $(obj)/conftest.h $(obj)/conftest/headers.h \
$(CONFTEST_COMPILE_TEST_HEADERS) $(obj)/conftest/patches.h

$(obj)/conftest.h $(CONFTEST_COMPILE_TEST_HEADERS): conftest-compile-test

$(obj)/conftest/headers.h: build-sanity-checks

conftest-compile-test: $(src)/conftest.sh
	$(NVQ)$(CONFTEST) compile_tests $(COMPILE_TESTS)

$(obj)/conftest/patches.h:
	$(NVQ)$(CONFTEST) patch_check

RESMAN_GLUE_TARGETS = $(addprefix $(obj)/,$(RESMAN_GLUE_OBJS))

$(RESMAN_GLUE_TARGETS): $(CONFTEST_HEADERS)

$(obj)/nv.o: $(obj)/$(VERSION_HEADER)

#
# KBUILD build parameters.
#

ifndef NV_VERBOSE
 ifneq ($(strip $(QUIET)),1)
 NV_VERBOSE=1
 else
 NV_VERBOSE=0
 endif
endif

KBUILD_PARAMS += KBUILD_VERBOSE=$(NV_VERBOSE)
KBUILD_PARAMS += -C $(KERNEL_SOURCES) SUBDIRS=$(PWD)
KBUILD_PARAMS += ARCH=$(ARCH)

#
# NVIDIA sanity checks.
#

suser-sanity-check:
	$(NVQ)$(CONFTEST) suser_sanity_check

rmmod-sanity-check:
	$(NVQ)$(CONFTEST) rmmod_sanity_check

build-sanity-checks:
	$(NVQ)$(CONFTEST) cc_version_check 		full_output
	$(NVQ)$(CONFTEST) rivafb_sanity_check 	full_output
	$(NVQ)$(CONFTEST) nvidiafb_sanity_check full_output
	$(NVQ)$(CONFTEST) xen_sanity_check 		full_output

#
# Build the NVIDIA kernel module using Linux KBUILD. This target is used by
# the "package-install" target below.
#

module: build-sanity-checks
	@echo "NVIDIA: calling KBUILD..."
	$(NVQ)$(MAKE) "CC=$(CC)" $(KBUILD_PARAMS) modules
	@echo "NVIDIA: left KBUILD."
	$(NVQ)if ! [ -f $(MODULE_OBJECT) ]; then \
	 echo "$(MODULE_OBJECT) failed to build!"; \
	 exit 1; \
	elif [ -f split-object-file.sh ]; then \
	 /bin/sh split-object-file.sh $(MODULE_OBJECT); \
	fi

#
# Sign the NVIDIA kernel module with the provided key
#

module-sign: module
	$(NVQ)if [ -z "$(MODSECKEY)" ] || [ -z "$(MODPUBKEY)" ]; then \
	 echo "ERROR: MODSECKEY and MODPUBKEY must be set to sign modules!"; \
	 exit 1; \
	elif ! [ -f "$(MODSECKEY)" ]; then \
	 echo "ERROR: cant find MODSECKEY \"$(MODSECKEY)\""; \
	 exit 1; \
	elif ! [ -f "$(MODPUBKEY)" ]; then \
	 echo "ERROR: can't find MODPUBKEY \"$(MODPUBKEY)\""; \
	 exit 1; \
	elif ! [ -x "$(MOD_SIGN_CMD)" ]; then \
	 echo "ERROR: \"$(MOD_SIGN_CMD)\" not executable!"; \
	 exit 1; \
	fi
	HASH=$(CONFIG_MODULE_SIG_HASH); \
 if [ -z "$$HASH" ]; then \
	 HASH=$$($(CONFTEST) guess_module_signing_hash | sed s/\"//g); \
	fi; \
	if [ $$? -eq 0 ] && [ -n $$HASH ]; then \
	 "$(MOD_SIGN_CMD)" $$HASH "$(MODSECKEY)" "$(MODPUBKEY)" \
 "$(MODULE_OBJECT)"; \
	 if [ $$? -eq 0 ]; then \
	 exit 0; \
	 fi; \
	fi; \
	"$(MOD_SIGN_CMD)" "$(MODSECKEY)" "$(MODPUBKEY)" $(MODULE_OBJECT)

#
# Build the NVIDIA kernel module with KBUILD. Verify that the user posesses
# sufficient privileges. Rebuild the module dependency file.
#

module-install: suser-sanity-check module
	$(NVQ)mkdir -p $(MODULE_ROOT)/video; \
	install -m 0664 -o root -g root $(MODULE_OBJECT) $(MODULE_ROOT)/video; \
	PATH="$(PATH):/bin:/sbin" depmod -a

#
# This target builds, then installs, then creates device nodes and inserts
# the module, if successful.
#

package-install: module-install rmmod-sanity-check
	$(NVQ)PATH="$(PATH):/bin:/sbin" modprobe $(MODULE_NAME) && \
	echo "$(MODULE_OBJECT) installed successfully.";

#
# Build an object file suitable for further processing by the installer
# and inclusion as a precompiled kernel interface file. Note the
# dependency on 'module', and not just the input object files. This is
# because we rely on KBUILD to produce the latter as part of the
# full kernel module build.
#

$(KERNEL_GLUE_NAME): module
	$(NVQ)$(LD) $(EXTRA_LDFLAGS) -r -o $(KERNEL_GLUE_NAME) $(KERNEL_GLUE_OBJS)

#
# Support hack, KBUILD isn't prepared to clean up after external modules.
#

clean:
	$(NVQ)$(RM) -f $(RESMAN_GLUE_OBJS) $(KERNEL_GLUE_OBJS)
	$(NVQ)$(RM) -f build-in.o nv-linux.o *.d .*.{cmd,flags}
	$(NVQ)$(RM) -f $(MODULE_NAME).{o,ko{,.dbg},mod.{o,c}} $(VERSION_HEADER) *~
	$(NVQ)$(RM) -f conftest*.c conftest.h
	$(NVQ)$(RM) -rf conftest
	$(NVQ)$(RM) -rf Modules.symvers .tmp_versions

#
# This target just prints the kernel module filename (for use by the
# installer)
#

print-module-filename:
	@echo $(MODULE_OBJECT)
