#
#	Main dgdm Makefile for Linux
#
#	$Id: Makefile.installed,v 1.43 2002/06/25 14:06:56 dickl Exp $
#
#		CHANGE LOG
#	$Log: Makefile.installed,v $
#	Revision 1.43  2002/06/25 14:06:56  dickl
#	Added test for tcl.h to Makefile to catch the case where the package
#	is installed via tgz rather than rpm
#	
#	Revision 1.42  2002/04/23 12:37:04  sethb
#	Fix for vantive 8409 (GE Medical).  Also cleaned up debugging.  Everything works as it should now, with no messages printed twice.  Console tracing has been tested, kmem tracing has not been tested.  I also cleaned up some tracing related compiler warnings.
#	
#	Revision 1.41  2001/05/01 14:57:55  randall
#	- Updated makefile variables to be more linux
#	  generic.  DMBIN -> BINDIR, etc
#	
#	Revision 1.40  2001/04/24 16:56:18  randall
#	- Make sure we're using the right RCDIR
#	
#	Revision 1.39  2001/04/05 15:46:33  randall
#	- Updates to support Linux 2.4
#	
#	Revision 1.38  2001/01/05 08:17:19  dickl
#	Added s2k_hw.c/o to the makefile for triboot
#	
#	Revision 1.37  2000/10/20 16:14:53  randall
#	- Change the permissions on the module from 0755 to 0644
#	  so that Redhat 7.0 doesn't strip all the symbols out
#	  of it (blargh!)
#	
#	Revision 1.36  2000/08/03 16:45:47  randall
#	- Change how libgcc.a is located
#	
#	Revision 1.35  2000/06/12 21:24:03  randall
#	- Updates to version numbers returned by the shim.
#	
#	Revision 1.34  2000/05/11 20:51:41  randall
#	- Updates to be able to build true SRPM and RPM with 'make srpm'
#	  Note: 'make rpm' still makes the old-style hybrid RPM.
#	
#	Revision 1.33  2000/05/03 18:58:45  randall
#	- Install and uninstall ditty and dtrc in $(DMBIN)
#	
#	Revision 1.32  2000/05/03 18:46:45  randall
#	- Updates to compile ditty upon RPM install
#	
#	Revision 1.31  2000/04/12 17:33:30  randall
#	- Update the shim to return the driver version to PAM
#	
#	Revision 1.30  2000/04/11 22:36:15  randall
#	- Update install to kill dgdm_agent before rmmod
#	
#	Revision 1.29  2000/03/23 16:48:50  randall
#	- update SMP detection to check if kernel was compiled for SMP
#	
#	Revision 1.28  2000/03/06 21:38:31  randall
#	- Fix the logic to unload the driver if it's loaded
#	  in the uninstall targets.
#	
#	Revision 1.27  2000/01/30 16:48:33  dickl
#	Migrated dm_ utilities to the ras_trace cvs module
#	
#	Revision 1.26  2000/01/11 13:12:10  dickl
#	Corrected SMP detection to operate correctly on machines with
#	AMD processors
#	
#	Revision 1.25  1999/12/17 21:50:02  erics
#	remove omit-frame-pointer for easier field debugging
#	
#	Revision 1.24  1999/12/15 15:57:01  dickl
#	Insured that all "install" commands specify an appropriate -m
#	Do a chown -R root:0 on an install-src
#	
#	Revision 1.23  1999/12/11 00:31:22  randall
#	- Fix two typos.
#	
#	Revision 1.22  1999/12/11 00:00:01  randall
#	- Complete code cleanup:
#	  - All functions prototyped.
#	  - Global includes, #defines, and structs all moved to the new
#	    dgdm_driver.h
#	  - eqm.c, audiotap.c and mgmt.c renamed with dgdm_ prefixes
#	  - Global functions renamed to have dgdm_ prefixes.
#	  - Unused functions removed.
#	  - #if 0 code also removed.
#	  - Corrected all instances of #include "file.c"
#	  - Makefile modified to stop including libc.a in final linking
#	  - Makefile modified to link in the tracing only when tracing
#	    enabled in the Makefile.
#	- Tracebuffer changed to use dynamically allocated memory, thus
#	  allowing arbitrary sizes without recompilation.
#	- Fastbaud functionality removed from the ioctls in dgdm_tty.c
#	  as per Functional Specification changes.
#	
#	Revision 1.21  1999/12/09 15:48:17  dickl
#	Added rmmod dgdm to uninstall target
#	Removed clobber dependency from unistall for Makefile (not installed)
#	
#	Revision 1.20  1999/12/09 13:41:42  dickl
#	Cause versioning info and Digi part number to be displayed at load time
#	
#	Revision 1.19  1999/12/08 18:26:00  dickl
#	Changed debug flag to #-DDGDM_PARANOIA_CHECK
#	
#	Revision 1.18  1999/11/29 21:07:48  randall
#	- Update the Makefiles to reflect the new pam structure
#	
#	Revision 1.17  1999/11/19 20:59:27  randall
#	- Makefile changes to build the shim, dpa, and pam agent into the RPM
#	
#	Revision 1.16  1999/10/29 12:40:31  dickl
#	Reworked SMP detection for 2.0 kernels
#	
#	
#

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




#############################################################################
#
# You should not need to modify anything below.
#
include Makefile.inc

RPMNAME := $(shell /bin/sh ./rpmname < dgdm.info)
PARTNUM := $(shell /bin/sh ./partnum < dgdm.info)

VPATH=.:libdxb

RCDIR= $(shell if [ -d /etc/rc.d/init.d ]; then echo "$(BUILDROOT)/etc/rc.d/init.d"; else echo "$(BUILDROOT)/etc/init.d"; fi)

POSXDIR= $(shell if [ -f /usr/include/bits/posix_opt.h ]; then echo bits; else echo; fi)

CURSES= $(shell if [ -f /usr/lib/libncurses.a ]; then echo ncurses; else echo curses; fi)

GCCDIR= $(shell $(CC) --print-libgcc | xargs dirname)

ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
  
SMP= $(shell if [ "`uname -v | grep -c SMP`" -gt "0" ]; then echo "SMP"; else echo "UP"; fi)

KCFLAGS := -D__KERNEL__ -I$(LINUXSRC)/include \
	-Wall -Wstrict-prototypes -O2 -pipe -fno-strength-reduce

ifneq ($(PACKAGEEXT), "")
        PACKAGEEXT=.$(PACKAGE)
endif

ifeq ($(ARCH),i386)
	CC=$(shell which kgcc | grep -v no 2> /dev/null > /tmp/kgcc-test; if [ -s /tmp/kgcc-test ]; then echo "kgcc"; else echo "gcc"; fi; rm /tmp/kgcc-test)
	KCFLAGS := $(KCFLAGS) -m486 -malign-loops=2 -malign-jumps=2 \
		-malign-functions=2 -DCPU=586
endif
ifeq ($(ARCH),sparc64)
	CC=sparc64-linux-gcc
	KCFLAGS := $(KCFLAGS) -m64 -pipe -mno-fpu -mcpu=ultrasparc \
		-mcmodel=medlow -ffixed-g4 -fcall-used-g5 -fcall-used-g7 \
		-Wno-sign-compare
endif

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

KCFLAGS := $(KCFLAGS) \
	-I. \
	-Ilibdxb \
	-Itriboot \
	-Ifep_include \
	-DMODULE \
	$(MODVERSIONS)

CFLAGS= $(KCFLAGS)

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

ifeq ($(POSXDIR),bits)
	CFLAGS += -DPOSXDIR
endif
 
ifeq ($(SMP),SMP)
	ifeq ($(ARCH),i386)
		CFLAGS += -D__SMP__ -DCONFIG_X86_LOCAL_APIC
	else
		CFLAGS += -D__SMP__
	endif
endif


MODULES=	dgdm.o

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

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


PUBHDRS=	rascon.h

all: Tcl_test $(MODULES) dtrc ditty
	cd trace/dm_gui && make $@;
	cd trace/dm_admin && make $@;
	cd trace/dm_eqm && make $@;
	cd trace/dm_listen && make $@;
	cd trace && make -f Makefile.linux $@;
	cd shim && make -f Makefile.linux $@;
	cd pam/LINUX && make $@;
	cd dpa && make -f dpalinux.mk $@;

Tcl_test:
	if [ ! -f /usr/include/tcl.h ] ; then \
		echo This package requires the file \"/usr/include/tcl.h\" ; \
		echo which does not exist on your system.  Some Linux ; \
		echo distributions are shipped with Tcl packages that ; \
		echo do not include tcl.h.  Please replace ; \
		echo your current version of Tcl with a version that ; \
		echo includes tcl.h ; \
		exit 1 ; \
	fi


#
#	Link all the driver objects into one .o
#

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

dxblib.o: dxblib.h

dgdm_version.h:	dgdm.info
	rm -f dgdm_version.h
	echo "#define DG_PART	\"$(PARTNUM)\"" > dgdm_version.h
	echo "#define DG_NAME   \"$(RPMNAME)\"" >> dgdm_version.h


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

#
# build the triboot library
#
triboot/tribl.o: triboot/tribl.c triboot/tribl.h
triboot/hlc_hw.o: triboot/hlc_hw.c triboot/tribl.h
triboot/rap_hw.o: triboot/rap_hw.c triboot/tribl.h
triboot/tb_dl.o: triboot/tb_dl.c triboot/tribl.h
triboot/tb_mdone.o: triboot/tb_mdone.c triboot/tribl.h
triboot/tb_reg.o: triboot/tb_reg.c triboot/tribl.h
triboot/tb_wdone.o: triboot/tb_wdone.c triboot/tribl.h
triboot/s2k_hw.o: triboot/s2k_hw.c triboot/tribl.h

dtrc: dtrc.c
	$(CC) -o dtrc dtrc.c

ditty: ditty.c
	$(CC) -o ditty ditty.c -l$(CURSES)

install: all $(MODDIR)
	install -m 0755 -d $(MODDIR)
	install -m 0755 -d $(INCLUDEDIR)
	install -m 0755 -d $(SBINDIR)
	install -m 0755 -d $(RCDIR)
	install -m 0755 -d $(BINDIR)
	install -m 0755 -d $(DRVLIBDIR)
	install -m 0755 -d $(DEVDIR)
	install -m 0755 -d $(MANDIR)/man4
	install -m 0755 -d $(MANDIR)/man8
	install -m 0644 $(MODULES) $(MODDIR)
	/sbin/depmod -a
	install -m 0644 $(PUBHDRS) $(INCLUDEDIR)
	install -m 755 dgdm_mknod $(SBINDIR)
	install -m 755 dgdm.rc $(RCDIR)/dgdm
	install -m 0644 dm_driver.4 $(MANDIR)/man4
	install -m 0755 ditty $(BINDIR)/ditty$(PACKAGEEXT)
	install -m 0755 dtrc $(BINDIR)
	install -m 0755 -d $(DRVLIBDIR)
	install -m 0755 -d $(DEVDIR)
	install -m 0644 fep_bins/* $(DRVLIBDIR)
	cd trace/dm_gui && make $@;
	cd trace/dm_admin && make $@;
	cd trace/dm_eqm && make $@;
	cd trace/dm_listen && make $@;
	cd trace && make -f Makefile.linux $@;
	cd shim && make -f Makefile.linux $@;
	cd pam/LINUX && make $@;
	cd dpa && make -f dpalinux.mk $@;
	touch .lastinstall

uninstall: clobber
	if [ "`lsmod | grep -c dgdm`" -gt "0" ] ; then \
		$(RCDIR)/dgdm stop ; \
	fi
	rm -f $(MODDIR)/$(MODULES)
	rm -f /usr/include/linux/$(PUBHDRS)
	rm -f $(SBINDIR)/dgdm_mknod
	rm -f $(RCDIR)/dgdm
	rm -f $(MANDIR)/man4/dm_driver.4
	rm -f $(BINDIR)/dtrc $(BINDIR)/ditty$(PACKAGEEXT)
	rm -rf $(DRVLIBDIR)
	rm -rf $(DEVDIR)
	cd trace/dm_gui && make $@;
	cd trace/dm_admin && make $@;
	cd trace/dm_eqm && make $@;
	cd trace/dm_listen && make $@;
	cd shim && make -f Makefile.linux $@;
	cd pam/LINUX && make $@;
	cd dpa && make -f dpalinux.mk $@;
	cd trace && make -f Makefile.linux $@;

$(MODDIR):
	mkdir -p $@

clean:
	-rm -f *.o depend.mk
	-rm -f triboot/*.o
	rm -f dgdm_version.h
	rm -f dtrc ditty
	cd trace/dm_gui && make $@;
	cd trace/dm_admin && make $@;
	cd trace/dm_eqm && make $@;
	cd trace/dm_listen && make $@;
	cd trace && make -f Makefile.linux $@;
	cd shim && make -f Makefile.linux $@;
	cd pam/LINUX && make $@;
	cd dpa && make -f dpalinux.mk $@;

clobber: clean
	rm -f .lastinstall
	cd trace/dm_gui && make $@;
	cd trace/dm_admin && make $@;
	cd trace/dm_eqm && make $@;
	cd trace/dm_listen && make $@;
	cd trace && make -f Makefile.linux $@;
	cd shim && make -f Makefile.linux $@;
	cd pam/LINUX && make $@;
	cd dpa && make -f dpalinux.mk $@;

TAGS: FORCE
	find . libdxb fep_include \
		\( -name \*.c -o -name \*.cc -o -name \*.h -o -name \*.hh \) \
		-print | etags -

FORCE:

#
#	Website population
#
web:
	cd utility && make $@;

.lastinstall:
	touch .lastinstall

depend.mk:
	for i in *.[cS] ;\
	do \
		$(CC) -MM $(CFLAGS)  $$i ;\
	done > depend.mk

-include depend.mk
