# To make correct module for 2.5 and up:
# make -C path/to/kernel/src SUBDIRS=$PWD modules

ifndef MYPWD
MYPWD = $(shell pwd)
endif

# Grab version and other important stuff
include ${MYPWD}/../Makefile.inc

RPMNAME := $(PACKAGE)-$(TRUE_VERSION)
PARTNUM := $(DGDM_PART_NUM)
RELNOTES := $(DGNC_REL_NOTE)

MODDIR = $(shell echo $(BUILDROOT)@MODDIR@/misc)
LSMOD = @LSMOD@
RMMOD = @RMMOD@
INSMOD = @INSMOD@
MANDIR=@mandir@

# Send in some extra things...
EXTRA_CFLAGS += -I${MYPWD}/libdxb -I${MYPWD}/triboot -I${MYPWD}/../fep_include\
	-I${MYPWD} -I${MYPWD}/include -I${MYPWD}/../commoninc\
	-DLINUX	-DDG_NAME=\"$(RPMNAME)\" -DDG_PART=\"$(PARTNUM)\"\
	-DSBINDIR=\"$(SBINDIR)\"\
	-DDGDM_TRACER -DDGDM_PARANOIA_CHECK\
	-D@DISTRO@


# Conform to correct kbuild conventions...

obj-m += dgdm.o

dgdm-objs := dgdm_driver.o	dgdm_fileio.o	dgdm_mgmt.o	dgdm_trace.o\
	     dgdm_audiotap.o	dgdm_eqm.o	dgdm_isdn.o	dgdm_proc.o\
	     dgdm_tty.o\
	     libdxb/dxblib.o\
	     triboot/tribl.o	triboot/rap_hw.o		triboot/hlc_hw.o\
	     triboot/tb_dl.o	triboot/tb_mdone.o		triboot/tb_reg.o\
	     triboot/tb_wdone.o triboot/s2k_hw.o

all:  build

build:
	make -C @KERNEL_HEADERS@ SUBDIRS=$$PWD modules MYPWD=${MYPWD}

clean:
	rm -f *.o
	rm -f *.ko
	rm -f dgdm.mod.c
	rm -f .*.cmd
	rm -f .*.flags
	rm -rf .tmp_versions
	rm -f triboot/*.o
	rm -f triboot/*.ko
	rm -f triboot/.*.cmd
	rm -f triboot/.*.flags
	rm -f libdxb/*.o
	rm -f libdxb/*.ko
	rm -f libdxb/.*.cmd
	rm -f libdxb/.*.flags


clobber: clean
	rm -f *.i *.s 
	rm -f Makefile Makefile.in
	rm -f include/config.h


distclean: clobber


install: all
	install -d $(BUILDROOT)$(MANDIR)/man4
	install -m 0755 -d $(MODDIR)
	install -m 0644 dgdm.ko $(MODDIR)
	install -m 0644 dm_driver.4 $(BUILDROOT)$(MANDIR)/man4/dm_driver.4.$(PACKAGE)

copymod:
	install -m 0644 dgdm.ko $(MODDIR)

unload: 
	if [ "`$(LSMOD) | grep -c dgdm`" -gt "0" ] ; then \
		$(RMMOD) dgdm; \
	fi

uninstall:  unload
	-rm -f $(MODDIR)/dgdm.ko

