#
#       Copyright (C) 1993 Bas Laarhoven.
#
# 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; 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; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# $Source: /home/bas/distr/ftape-2.02/RCS/Makefile,v $
# $Author: bas $
#
# $Revision: 1.43 $
# $Date: 1995/01/15 13:19:55 $
# $State: Beta $
#
#      Makefile for the QIC-40/80 floppy-tape driver for Linux.
#
#  Valid ftape options are:
#       NO_TRACE        - if defined, only information and errors show up.
#       NO_TRACE_AT_ALL - if defined, no trace output shows up.
#       GCC_2_4_5_BUG   - must be set if using gcc-2.4.5 to prevent
#                         bad assembler-code for the dma handling.
#       VERIFY_HEADERS  - if set the headers segments are verified after
#                         being written.
#       PROBE_FC10      - if defined will look for a FC-10 card at specified
#                         settings (FDC_BASE,FDC_IRQ,FDC_DMA) before using
#                         the standard fd controller.
#       FDC_BASE        - set base address (only!) if using non-standard fdc
#       FDC_IRQ         - set interrupt if FDC_BASE defined
#       FDC_DMA         - set dma channel if FDC_BASE defined
#       MACH2           - (experimental) support for Mountain MACH-2 contoller
#                         at either 1E0 or 3E0, don't forget the FDC_OPT's !
#	TESTING		- Guess what ? Never use this for normal use !!!
#
FTAPE_OPT       = -DVERIFY_HEADERS
# enable if tape drive on CMS FC-10 controller:
#FDC_OPT         = -DMACH2 -DFDC_BASE=0x1E0 -DFDC_IRQ=6 -DFDC_DMA=2
# enable if tape drive on CMS FC-10 controller:
#FDC_OPT         = -DPROBE_FC10 -DFDC_BASE=0x180 -DFDC_IRQ=9 -DFDC_DMA=3
# enable if tape drive on secondary floppy disk controller:
#FDC_OPT         = -DFDC_BASE=0x370 -DFDC_IRQ=9 -DFDC_DMA=3

KERNEL_OPT      = -D__KERNEL__ -DKERNEL -DLINUX
WARNINGS        = -Wall -Wstrict-prototypes
COMPILE         = -pipe -fomit-frame-pointer -m486 -O6
DEBUG           = -g

CFLAGS = $(DEBUG) $(WARNINGS) $(COMPILE) $(FTAPE_OPT) $(FDC_OPT) $(KERNEL_OPT)
SFLAGS = -fverbose-asm $(WARNINGS) $(COMPILE) $(FTAPE_OPT) $(FDC_OPT) $(KERNEL_OPT)

.c.o:
	$(CC) $(CFLAGS) -c $<

.c.s:
	$(CC) $(SFLAGS) -S $<

SRCS  = kernel-interface.c fdc-io.c fdc-isr.c ftape-rw.c tracing.c \
        ftape-read.c ftape-write.c ftape-io.c ftape-eof.c calibr.c \
        ecc.c fc-10.c ftape-bsm.c ftape-ctl.c

OBJS  = $(SRCS:.c=.o)

TST_SRCS = tecc.c ecc.c
TST_OBJS = tecc.o tst-ecc.o

driver: dep ftape.o Makefile

test:   tecc Makefile
	sync
	tecc -a

depend: dep

dep:	kernel-version.h .depend

.depend:	
	$(CPP) -M $(SRCS) > .depend

clean:
	- rm -f a.out *.o core *~ gen_test tecc kernel-version.h .depend

all:    driver test

ftape.o: $(OBJS) Makefile .depend
	ld -r -o $@ $(OBJS)
	sync

tst-ecc.o: ecc.c ecc.h ftape.h Makefile
	$(CC) $(CFLAGS) -DTEST -c -o $@ ecc.c

tecc:   tecc.c tst-ecc.o ftape.h Makefile
	$(CC) $(CFLAGS) -DTEST -o $@ tecc.c tst-ecc.o

kernel-version.h: Makefile
	echo "#define KERNEL_VERSION \"`cat /proc/version | \
	cut -d" " -f3`\"" >kernel-version.h
	cat /proc/version | cut -d" " -f3 | \
	awk -F\. '{ if ($$1 < 1 || ($$1 == 1 && \
			($$2 < 1 || ($$2 == 1 && $$3 < 23)))) \
		print "#define FLOPPY_HACK" ; \
		else print "#undef FLOPPY_HACK" }' >>kernel-version.h
	cat /proc/version | cut -d" " -f3 | \
	awk -F\. '{ if ($$1 < 1 || ($$1 == 1 && \
			($$2 < 1 || ($$2 == 1 && $$3 < 43)))) \
		print "#define OLD_IRQ_REQUEST" ; \
		else print "#undef OLD_IRQ_REQUEST" }' >>kernel-version.h
	cat /proc/version | cut -d" " -f3 | \
	awk -F\. '{ if ($$1 < 1 || ($$1 == 1 && \
			($$2 < 1 || ($$2 == 1 && $$3 < 48)))) \
		print "#define OLD_DMA_REQUEST" ; \
		else print "#undef OLD_DMA_REQUEST" }' >>kernel-version.h

#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif
