# This Makefile is automatically generated; do not edit
#   Generated on 'builder3' on Tue May 14 07:41:43 PDT 2002

LINUX_MODULE=Module-linux
DEFINES=-D__KERNEL__ -DMODULE -D_LOOSE_KERNEL_NAMES -D_X86=1 -Di386=1 -DUNIX -DLINUX -DNV4_HW -DNTRM -DRM20 -D_GNU_SOURCE -DRM_HEAPMGR -D_LOOSE_KERNEL_NAMES -D__KERNEL__ -DMODULE  -DNV_MAJOR_VERSION=1 -DNV_MINOR_VERSION=0 -DNV_PATCHLEVEL=2960 
INCLUDES=-I.

OBJECTS=nv.o os-interface.o os-registry.o 
HEADERS=os-interface.h nv-linux.h nv.h  nvrm.h nvtypes.h $(VERSION_HDR)

CFLAGS=-Wall -Wimplicit -Wreturn-type -Wswitch -Wformat -Wchar-subscripts -Wparentheses -Wpointer-arith -Wcast-qual -Wno-multichar  -O -MD $(DEFINES) $(INCLUDES) -Wno-cast-qual

RESMAN_KERNEL_MODULE=Module-nvkernel

KERNDIR=/lib/modules/$(shell uname -r)

# check for newer paths. if found, use them, otherwise use old paths
# these wouldn't work with the gnu make included with rh6.2
# KERNINC=$(if -d $(KERNDIR)/build, $(KERNDIR)/build/include, /usr/src/linux/include)
# INSTALLDIR=$(if -d $(KERNDIR)/kernel, $(KERNDIR)/kernel/drivers/video, $(KERNDIR)/video)

# this is slightly more brain-dead, but works..
ifeq ($(shell if test -d $(KERNDIR)/build; then echo yes; fi),yes)
KERNINC=$(KERNDIR)/build/include
else
KERNINC=/usr/src/linux/include
endif

ifeq ($(shell if test -d $(KERNDIR)/kernel; then echo yes; fi),yes)
INSTALLDIR=$(KERNDIR)/kernel/drivers/video
else
INSTALLDIR=$(KERNDIR)/video
endif

ifeq ($(shell echo $(NVDEBUG)),1)
  ifeq ($(shell test -z $(RMDEBUG) && echo yes),yes)
    RMDEBUG=1
  endif
endif

ifeq ($(shell echo $(RMDEBUG)),1)
CFLAGS += -DDEBUG -g -fno-common
endif

# this is just plain wrong, get rid of it
BROKENDIR=$(KERNDIR)/kernel/video

INSTALL=$(shell which install)

# determine gcc versions used (kernel, NVdriver)
module_cc:=$(shell $(CC) -v 2>&1 | tail -1)
version="^Linux version [^(]* (.*@.*) (\(.*\)) .*"
kernel_cc:=$(shell cat /proc/version | sed "s/"$(version)"/\1/")

module_cc:=$(shell echo "$(module_cc)" | cut -d ' ' -f 3)
kernel_cc:=$(shell echo "$(kernel_cc)" | cut -d ' ' -f 3)

# allow specification of alternate include file tree on command line and extra defines
ifdef SYSINCLUDE
INCLUDES += -I$(SYSINCLUDE)
else
INCLUDES += -I$(KERNINC)
endif

DEFINES+=$(EXTRA_DEFINES)

# allow build parameters to be passed in through the environment
ifdef BUILD_PARAMS
    DEFINES+=-D$(BUILD_PARAMS)
endif

VERSION_HDR=nv_compiler.h

all: install

install: package-install

package-install: NVdriver
	@if [ `id -ur` != 0 ]; then \
		echo Please run \"make install\" as root.; \
	else \
		if [ -d $(BROKENDIR) ]; then \
			rm -f $(BROKENDIR)/NVdriver; \
			rmdir --ignore-fail-on-non-empty $(BROKENDIR); \
		fi && \
		mkdir -p $(INSTALLDIR) && \
		$(INSTALL) -m 0664 -o root -g root NVdriver $(INSTALLDIR)/NVdriver$(O) && \
		/sbin/depmod -a && \
		/sbin/modprobe NVdriver && \
		sh makedevices.sh && \
		echo "NVdriver installed successfully."; \
	fi

gcc-check:
	@if [ -z $(IGNORE_CC_MISMATCH) ]; then \
	 if [ $(kernel_cc) != $(module_cc) ]; then \
	echo "                                                           "; \
	echo "You appear to be compiling the NVdriver kernel module with "; \
	echo "a compiler different from the one that was used to compile "; \
	echo "the running kernel. This may be perfectly fine, but there  "; \
	echo "are 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 compile the kernel.  "; \
	echo "                                                           "; \
	echo -en "\033[1;31m"; \
	echo -e  "*** Failed cc sanity check. Bailing out! ***"; \
	echo -en "\033[0m"; \
	exit 1; \
	 fi \
	fi

NVdriver: gcc-check $(LINUX_MODULE) $(RESMAN_KERNEL_MODULE) 
	ld -r -o $@ $(LINUX_MODULE) $(RESMAN_KERNEL_MODULE)
	size $@

$(VERSION_HDR): 
	echo \#define NV_COMPILER \"`$(CC) -v 2>&1 | tail -1`\" > $@

$(LINUX_MODULE): $(OBJECTS)
	ld -r -o $@ $(OBJECTS)

%.o: %.c $(HEADERS)
	$(CC) -c $(CFLAGS) $<

# debug tool to preprocess the file and leave .i to make it easier to untangle #defines
%.i: %.c
	$(CC) $(CFLAGS) -E $< > $@

%.s: %.c
	$(CC) $(CFLAGS) -S $< > $@


clean:
	$(RM) $(OBJECTS) $(LINUX_MODULE) $(VERSION_HDR) *.d NVdriver


-include $(OBJECTS:%.o=%.d)
