#
#	dgdm driver Makefile
#
#	$Id: Makefile24,v 1.9 2003/11/28 20:41:54 scottk Exp $
#

#Grab version and other important stuff
include ../Makefile.inc

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

# Compiler and flags to use when compiling the driver itself.
KCC = @KGCC@
CC = @KGCC@
KCFLAGS = @KCFLAGS@
KINC = @KINC@
LINUXSRC = @KERNEL_HEADERS@
SMP = @SMP@
MODDIR = $(shell echo $(BUILDROOT)@MODDIR@/misc)
LSMOD = @LSMOD@
RMMOD = @RMMOD@
INSMOD = @INSMOD@
MANDIR=@mandir@

#
# Set TRACING equal to "ON" in order to compile in tracing support.
#
TRACING=ON


ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)

KCFLAGS := $(KCFLAGS) -D__KERNEL__ @KINC@ -Wall -Wstrict-prototypes -pipe -fno-strength-reduce

VERFILE=@KERNEL_HEADERS@/include/linux/modversions.h
MODVERSIONS=$(shell [ -f $(VERFILE) ] && echo -DMODVERSIONS -include $(VERFILE) )

KCFLAGS += \
	-I. \
	-Iinclude \
	-Ilibdxb \
	-Itriboot \
	-I../fep_include \
	-DMODULE\
	$(MODVERSIONS)\
	-D@DISTRO@

KCFLAGS += -DSBINDIR=\"$(SBINDIR)\" -DLINUX
KCFLAGS += -DDG_NAME=\"$(RPMNAME)\" -DDG_PART=\"$(PARTNUM)\"

ifeq ($(SMP),SMP)
	ifeq ($(ARCH),i386)
		KCFLAGS += -D__SMP__ -DCONFIG_X86_LOCAL_APIC
	else
		KCFLAGS += -D__SMP__
	endif
endif


MODULES=	dgdm.o

OBJECTS=dgdm_audiotap.o	dgdm_driver.o	dgdm_eqm.o\
	dgdm_fileio.o	dgdm_isdn.o	dgdm_mgmt.o\
	dgdm_proc.o	dgdm_tty.o	libdxb/dxblib.o\
	triboot.o

ifeq ($(TRACING),ON)
	OBJECTS += dgdm_trace.o
	KCFLAGS += -DDGDM_TRACER -DDGDM_PARANOIA_CHECK
	KCFLAGS += -DTRC_TO_CONSOLE
endif


all: $(MODULES)

#
#	Link all the driver objects into one .o
#
dgdm.o: $(OBJECTS)

ifeq ($(ARCH),sparc64)
	$(LD) -r -m elf64_sparc -o $@ $(OBJECTS)
else
	$(LD) -r -nostartfiles -o $@ $(OBJECTS) -L$(GCCDIR) -lgcc
endif

#
# Link all of the triboot stuff together
#
triboot.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/tribl.h triboot/s2k_hw.o
ifeq ($(ARCH),sparc64)
	$(LD) -r -m elf64_sparc -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
else
	$(LD) -r -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
endif

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

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

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


clean:
	rm -f *.o
	rm -f *.ko
	rm -f dgdm.mod.c
	rm -f .*.cmd
	rm -f .*.flags
	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
	rm -f depend.mk
	rm -f .rpmrc

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


distclean: clobber


dgdm_driver.o: dgdm_driver.c include/dgdm_driver.h include/dxbtypes.h 
	$(KCC) $(KCFLAGS) -c dgdm_driver.c -o dgdm_driver.o

dgdm_tty.o: dgdm_tty.c include/dgdm_driver.h include/dxbtypes.h 
	$(KCC) $(KCFLAGS) -c dgdm_tty.c -o dgdm_tty.o

dgdm_isdn.o: dgdm_isdn.c include/dgdm_driver.h include/dxbtypes.h 
	$(KCC) $(KCFLAGS) -c dgdm_isdn.c -o dgdm_isdn.o

dgdm_audiotap.o: dgdm_audiotap.c include/dgdm_driver.h include/dxbtypes.h 
	$(KCC) $(KCFLAGS) -c dgdm_audiotap.c -o dgdm_audiotap.o

dgdm_mgmt.o: dgdm_mgmt.c include/dgdm_driver.h include/dxbtypes.h 
	$(KCC) $(KCFLAGS) -c dgdm_mgmt.c -o dgdm_mgmt.o

dgdm_proc.o: dgdm_proc.c include/dgdm_driver.h include/dxbtypes.h 
	$(KCC) $(KCFLAGS) -c dgdm_proc.c -o dgdm_proc.o

dgdm_eqm.o: dgdm_eqm.c include/dgdm_driver.h include/dxbtypes.h 
	$(KCC) $(KCFLAGS) -c dgdm_eqm.c -o dgdm_eqm.o

dgdm_fileio.o: dgdm_fileio.c include/dgdm_driver.h include/dxbtypes.h 
	$(KCC) $(KCFLAGS) -c dgdm_fileio.c -o dgdm_fileio.o

libdxb/dxblib.o: libdxb/dxblib.c include/dgdm_driver.h include/dxbtypes.h libdxb/dxblib.h
	$(KCC) $(KCFLAGS) -c libdxb/dxblib.c -o libdxb/dxblib.o

ifeq ($(TRACING),ON)
dgdm_trace.o: dgdm_trace.c include/dgdm_driver.h include/dxbtypes.h 
	$(KCC) $(KCFLAGS) -c dgdm_trace.c -o dgdm_trace.o
endif

#
# build the triboot library
#
triboot/tribl.o: triboot/tribl.c triboot/tribl.h 
	$(KCC) $(KCFLAGS) -c triboot/tribl.c -o triboot/tribl.o

triboot/hlc_hw.o: triboot/hlc_hw.c triboot/tribl.h 
	$(KCC) $(KCFLAGS) -c triboot/hlc_hw.c -o triboot/hlc_hw.o

triboot/rap_hw.o: triboot/rap_hw.c triboot/tribl.h 
	$(KCC) $(KCFLAGS) -c triboot/rap_hw.c -o triboot/rap_hw.o

triboot/tb_dl.o: triboot/tb_dl.c triboot/tribl.h 
	$(KCC) $(KCFLAGS) -c triboot/tb_dl.c -o triboot/tb_dl.o

triboot/tb_mdone.o: triboot/tb_mdone.c triboot/tribl.h 
	$(KCC) $(KCFLAGS) -c triboot/tb_mdone.c -o triboot/tb_mdone.o

triboot/tb_reg.o: triboot/tb_reg.c triboot/tribl.h 
	$(KCC) $(KCFLAGS) -c triboot/tb_reg.c -o triboot/tb_reg.o

triboot/tb_wdone.o: triboot/tb_wdone.c triboot/tribl.h 
	$(KCC) $(KCFLAGS) -c triboot/tb_wdone.c -o triboot/tb_wdone.o

triboot/s2k_hw.o: triboot/s2k_hw.c triboot/tribl.h 
	$(KCC) $(KCFLAGS) -c triboot/s2k_hw.c -o triboot/s2k_hw.o
