# # 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.5 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. # # Please report any problems you may be experiencing with this experimental # Makefile to either one (or, preferably, both) of us: # # Alistair J Strachan (alistair@devzero.co.uk) (first pass, enhancements) # Christian Zander (zander@email.minion.de) (enhancements) # 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. # RESMAN_CORE_OBJS := nv-kernel.o RESMAN_GLUE_OBJS := nv.o os-agp.o os-interface.o os-registry.o $(MODULE_NAME)-objs := $(RESMAN_CORE_OBJS) $(RESMAN_GLUE_OBJS) # # A bug in KBUILD 2.4 means that leaving obj-m set in top-level context # will cause Rules.make to call pathdown.sh, which is wrong. So, we only # set this conditional of a kernel-level instance. # ifdef TOPDIR obj-m += $(MODULE_NAME).o endif # # 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 += -Wno-cast-qual -Wno-strict-prototypes # # Determine location of the Linux kernel source tree. Allow users to override # the default (i.e. automatically determined) kernel source location with the # KERNDIR directive; this new directive replaces NVIDIA's SYSINCLUDE. # ifdef KERNDIR KERNEL_SOURCES := $(KERNDIR) KERNEL_HEADERS := -I$(KERNEL_SOURCES)/include MODULE_ROOT := /lib/modules/$(shell uname -r)/kernel/drivers # XXX else KERNEL_SOURCES := /lib/modules/$(shell uname -r)/build KERNEL_HEADERS := -I$(KERNEL_SOURCES)/include MODULE_ROOT := /lib/modules/$(shell uname -r)/kernel/drivers endif # # We rely on these two definitions below; if they aren't set, we set them to # reasonable defaults (Linux 2.4's KBUILD, and top-level passes will not set # these). # src ?= . obj ?= . # # Sets any internal variables left unset by KBUILD (e.g. this happens during # a top-level run). # TOPDIR ?= $(KERNEL_SOURCES) PATCHLEVEL ?= $(shell sh $(src)/conftest.sh kernel_patch_level $(TOPDIR)) # # Linux 2.4 uses the .o module extension. Linux 2.5, however, uses the .ko # module extension. Handle these gracefully. # ifeq ($(PATCHLEVEL), 4) MODULE_OBJECT := $(MODULE_NAME).o else MODULE_OBJECT := $(MODULE_NAME).ko endif # # NVIDIA specific CFLAGS and #define's. The remap_page_range check has become # necessary with the introduction of the five argument version to Linux 2.4 # distribution kernels; this conflicting change cannot be detected at compile # time. # EXTRA_CFLAGS += -DNTRM -D_LOOSE_KERNEL_NAMES -D__KERNEL__ -DMODULE -DNV_MAJOR_VERSION=1 -DNV_MINOR_VERSION=0 -DNV_PATCHLEVEL=4348 -DNV_UNIX -DNV_LINUX -DNV_INT64_OK -DNVCPU_X86 ifeq ($(shell echo $(NVDEBUG)),1) ifeq ($(shell test -z $(RMDEBUG) && echo yes),yes) RMDEBUG=1 endif endif ifeq ($(shell echo $(RMDEBUG)),1) EXTRA_CFLAGS += -DDEBUG -g -fno-common endif ifeq ($(shell sh $(src)/conftest.sh remap_page_range $(KERNEL_HEADERS)), 5) EXTRA_CFLAGS += -DREMAP_PAGE_RANGE_5 endif ifeq ($(shell sh $(src)/conftest.sh remap_page_range $(KERNEL_HEADERS)), 4) EXTRA_CFLAGS += -DREMAP_PAGE_RANGE_4 endif # # NVIDIA binary object file includes .common section. # EXTRA_LDFLAGS := -d # # Miscellaneous NVIDIA kernel module build support targets. They are needed # to satisfy KBUILD requirements and to support NVIDIA specifics. # $(obj)/nv-kernel.o: cp $(src)/$(RESMAN_CORE_OBJS) $(obj)/$(RESMAN_CORE_OBJS) $(obj)/$(VERSION_HEADER): echo \#define NV_COMPILER \"`$(CC) -v 2>&1 | tail -1`\" > $@ $(obj)/nv.o: $(obj)/$(VERSION_HEADER) # # More quirks for Linux 2.4 KBUILD, which doesn't link automatically. # ifeq ($(PATCHLEVEL), 4) $(obj)/$(MODULE_NAME).o: $($(MODULE_NAME)-objs) $(LD) $(EXTRA_LDFLAGS) -r -o $@ $($(MODULE_NAME)-objs) endif # # KBUILD build parameters. # KBUILD_PARAMS := -C $(KERNEL_SOURCES) SUBDIRS=$(PWD) # # NVIDIA sanity checks. # suser-sanity-check: @if ! sh conftest.sh suser_sanity_check; then \ echo; \ echo "You have insufficient privileges for this operation. Please "; \ echo "run \"make install\" as root! "; \ echo; \ exit 1; \ fi rmmod-sanity-check: @if ! sh conftest.sh rmmod_sanity_check $(MODULE_NAME); then \ echo; \ echo "Unable to unload the currently loaded NVIDIA kernel module! "; \ echo "Please be certain that you have exited X before attempting "; \ echo "to install this version. "; \ echo; \ exit 1; \ fi cc-sanity-check: @if ! sh conftest.sh cc_sanity_check $(CC); then \ echo; \ echo "You appear to be building the NVIDIA kernel module with a "; \ echo "compiler different from the one that was used to build the "; \ echo "running kernel. This may be perfectly fine, but there are "; \ echo "cases where this can lead to unexpected behaviour and "; \ echo "system crashes. "; \ echo; \ echo "If you know what you are doing and want to override this "; \ echo "check, you can do so by setting IGNORE_CC_MISMATCH. "; \ echo; \ echo "In any other case, set the CC environment variable to the "; \ echo "name of the compiler that was used to build the kernel. "; \ echo; \ exit 1; \ fi # # Build the NVIDIA kernel module using Linux KBUILD. This target is used by # the "package-install" target below. # module: cc-sanity-check @make $(KBUILD_PARAMS) modules; \ if ! [ -f $(MODULE_OBJECT) ]; then \ echo "$(MODULE_OBJECT) failed to build!"; \ exit 1; \ fi # # 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 @mkdir -p $(MODULE_ROOT)/video; \ install -m 0664 -o root -g root $(MODULE_OBJECT) $(MODULE_ROOT)/video; \ /sbin/depmod -ae; # # This target builds, then installs, then creates device nodes and inserts # the module, if successful. # package-install: module-install rmmod-sanity-check @sh makedevices.sh; \ /sbin/modprobe $(MODULE_NAME) && \ echo "$(MODULE_OBJECT) installed successfully."; # # Support hack, KBUILD isn't prepared to clean up after external modules. # clean: @rm -f $(RESMAN_GLUE_OBJS) .*.{cmd,flags} @rm -f $(MODULE_NAME).{o,ko,mod.{o,c}} built-in.o $(VERSION_HEADER) *~ # # Linux 2.4 KBUILD requires the inclusion of Rules.make; Linux 2.5's KBUILD # includes dependencies automatically. # ifeq ($(PATCHLEVEL), 4) include $(KERNEL_SOURCES)/Rules.make endif