#
# Copyright 1999 by Digi International (www.digi.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
# PURPOSE.  See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#	Main Makefile for PCI DataFire RAS/AccelePort RAS/AccelePort 2000 driver
#	for Linux
#
#	$Id: Makefile24,v 1.1 2003/07/15 21:10:25 scottk Exp $
#
include ../Makefile.inc

# Compiler and flags to use when compiling the driver itself.
CC = @KGCC@
KCFLAGS = @KCFLAGS@
KINC = @KINC@
MODDIR = @MODDIR@

VPATH=.:./include

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

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

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

KCFLAGS := -D__KERNEL__ -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer $(KINC)


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

KCFLAGS := $(KCFLAGS) \
	-I. \
	-Iinclude \
	-I../commoninc \
	-DMODULE\
	$(MODVERSIONS)

CFLAGS= $(KCFLAGS)

MODULE=	dgrp.o

CFLAGS += -DSBINDIR=\"$(SBINDIR)\" -DDGRP_TRACER -DLINUX #-DDEBUG
CFLAGS += -DDIGI_VERSION=\"$(TRUE_VERSION)\"

ifeq ($(POSXDIR),bits)
	CFLAGS += -DPOSXDIR
endif

# all: $(MODULE)
# 	cd utility && make $@;

all: $(MODULE)
	echo "complete."

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

dgrp.o: dgrp_driver.o dgrp_proc.o dgrp_specproc.o dgrp_net_ops.o dgrp_mon_ops.o dgrp_common.o dgrp_tty.o dgrp_ports_ops.o
ifeq ($(ARCH),sparc64)
	$(LD) -r -m elf64_sparc -o $@ dgrp_driver.o dgrp_proc.o dgrp_specproc.o dgrp_net_ops.o dgrp_mon_ops.o dgrp_common.o dgrp_tty.o dgrp_ports_ops.o
else
	$(LD) -r -nostartfiles -o $@ dgrp_driver.o dgrp_proc.o dgrp_specproc.o dgrp_net_ops.o dgrp_mon_ops.o dgrp_common.o  dgrp_tty.o dgrp_ports_ops.o -L$(GCCDIR) -lgcc
endif

dgrp_common.o: dgrp_common.h

dgrp_driver.o: dgrp_proc.h

dgrp_mon_ops.o: dgrp_mon_ops.h drp.h

dgrp_net_ops.o: dgrp_net_ops.h drp.h

dgrp_ports_ops.o: dgrp_ports_ops.h drp.h

dgrp_specproc.o: dgrp_specproc.h

dgrp_tty.o: dgrp_tty.h

.PHONY: all install uninstall postinstall preuninstall

install: 
	install -d  $(DGRPBIN)
	install -d  $(DGRPMAN)
	install -m 644 $(MODULE) $(DGRPBIN)/
	install -m 644 dgrp.man $(DGRPMAN)/dgrp.8

postinstall: $(MODDIR)
	ln -sf /usr/bin/dgrp/dgrp.o $(MODDIR)/dgrp.o
	/sbin/depmod -a

preuninstall:
	-rm -f $(MODDIR)/dgrp.o
	
uninstall: 
	-rm -f $(DGRPBIN)/$(MODULE)
	-rm -f $(DGRPMAN)/dgrp.8*
	-rm -f /var/catman/cat8/dgrp.8*

$(MODDIR):
	mkdir -p $@

clean:
	-rm -f *.o depend.mk

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

FORCE:

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

include depend.mk
