############################################################################### 
# --- Makefile ---  Copyright (C) 1994 by T. Weidenfeller
#
# File ID:
#	$Id: Makefile,v 1.3 1994/10/27 19:51:43 root Exp $
#
# Purpose:
# 	Makefile to perform various manangement tasks for the BiTronics
#	device driver, including distribution generation and file installation.
#
# Copyright:
#	Copyright (C) 1994 by T. Weidenfeller. All rights reserved
#	
#	You are free to copy, modify and distribute this software as you
#	see fit, and to use it for any purpose, provided this copyright
#	notice and the warranty disclaimer are included without any
#	modification in all copies and modifications. You have to mark all
#	modifications clearly and you are also commited to give propper
#	acknowledgment of the original source if you include this software
#	or parts of it in another software.
#	
# Warranty:
#	The BiTronics device driver and the accompaning material is a free
#	sample of no commercial value. It comes without any warranty:
#	
#	THERE IS NO WARRANTY OF ANY KIND WITH REGARDS TO THIS MATERIAL,
#	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#	MECHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The author
#	shall not be liable for errors contained in the material or for
#	incidental or consequental damage in connection with the
#	furnishing, performance, or use of this material.
#	
# Revisions: $Log: Makefile,v $
#	Revision 1.3  1994/10/27  19:51:43  root
#	Auto conversion of announce msg added.
#
#	Revision 1.2  1994/10/26  18:23:46  root
#	General harmonisation (prep 1. ALPHA release).
#
#	Revision 1.1  1994/10/16  07:56:00  root
#	Initial revision
#
###############################################################################

# management information
VERSION	= $(shell sed -n '/bt_version/s/[^"]*"\([^"]*\).*/\1/p' < bt_version.h)
DVERSION= $(shell sed -n '/bt_version/s/[^0-9]//gp' < bt_version.h)
BT	= bt
LABEL	= $(BT)-$(VERSION)

# where to create the tmp directory
TMP	= /tmp
DIR	= $(LABEL)
TMPDIR	= $(TMP)/$(DIR)

# target information
KSRCDIR	= /usr/src/linux
KINCDIR	= $(KSRCDIR)/include/linux
KDCDIR	= $(KSRCDIR)/drivers/char
MANDIR	= /usr/man
MANEXT	= 4

# output
TARFILE	= $(LABEL).tar.gz
DOSTARF	= $(BT)$(DVERSION).tgz
DOSANN	= announce.txt

# input files
PATCHFILE = kernel-patch.$(LABEL)
INFOFILES = README WARRANTY COPYRIGHT
# SRCS: C code AND private headers!
SRCS	= $(BT).c $(BT)_io.h $(BT)_error.h $(BT)_config.h \
	  $(BT)_trace.h $(BT)_version.h
HDRS	= $(BT).h				# Public headers
MAN	= $(BT).man
TSTPRGS	= tst1
SETUPPRG= bt-setup Makefile
FILES	= $(INFOFILES) $(PATCHFILE) $(SRCS) $(HDRS) $(MAN) $(TSTPRGS) $(SETUPPRG)
ANNOUNCE=ANNOUNCE

default: zdisk

dist $(TARFILE): $(FILES)
	rm -f -r $(TMPDIR)
	mkdir $(TMPDIR)
	cp $(FILES) $(TMPDIR)
	tar cfz $(TARFILE) -C $(TMP) $(DIR)
	rm -f -r $(TMPDIR)

dist.dos $(DOSTARF) $(DOSANN): $(TARFILE) $(ANNOUNCE)
	cp $(TARFILE) $(DOSTARF)
	gawk '{ sub("$$", "\015") }' $(ANNOUNCE) > $(DOSANN)
	

$(PATCHFILE):
	mksrcpatch > $@

##############################################################################
# Software installation by copying
# (choose between soft- or hard installation)
install:	install.full

install.full:	install.src apply.patch install.doc

install.src:	install.src.soft

install.src.hard: $(SRCS) $(HDRS) FORCE
	@for i in $(SRCS) ; do			\
		echo cp $$i $(KDCDIR)/$$i ;	\
		cp $$i $(KDCDIR)/$$i ;		\
	done
	@for i in $(HDRS) ; do			\
		echo cp $$i $(KINCDIR)/$$i ;	\
		cp $$i $(KINCDIR)/$$i ;		\
	done
	
install.src.soft: $(SRCS) $(HDRS) FORCE
	@for i in $(SRCS) ; do				\
		echo ln -f -s `pwd`/$$i $(KDCDIR)/$$i ;	\
		ln -f -s `pwd`/$$i $(KDCDIR)/$$i ;	\
	done
	@for i in $(HDRS) ; do				\
		echo ln -f -s `pwd`/$$i $(KINCDIR)/$$i ;\
		ln -f -s `pwd`/$$i $(KINCDIR)/$$i ;	\
	done

apply.patch: $(PATCHFILE) FORCE
	@if [ -e .bt_development ] ; then			\
		echo "Automatic patching skiped" ;		\
	else							\
		patch -d $(KSRCDIR) -l < $(PATCHFILE);	\
	fi

install.doc install.man: $(MAN)
	install -o root -g root -m 644 $(MAN) $(MANDIR)/man$(MANEXT)/$(BT).$(MANEXT)

	
##############################################################################
# compile the kernel
zdisk: install
	(cd $(KSRCDIR); make $@)

##############################################################################
clean:
	rm -f $(PATCHFILE) $(TARFILE) $(DOSTARF)
	rm -f -r $(TMPDIR)

FORCE:	# empty
