#
#       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.
#
#
# /home/cvs/zftape/Makefile,v
# root
#
# 1.1.1.1
# 1995/11/15 16:55:45
# Exp
#
#      Makefile for the QIC-40/80 floppy-tape driver for Linux.
#

.EXPORT_ALL_VARIABLES:

#
# change the next line to point to the root of your kernel sources
# If you don't have the kernel-sources (why don't you have them?)
# but have the directories "/usr/include/linux" and "/usr/include/asm"
# then set the variable to /usr
#
# I used this variable simply for compiling zftape with different 
# kernel versions without having to reboot and to adjust the
# symbolic link /usr/src/linux all the time
#
# LINUX_SRC_DIR = /usr
LINUX_SRC_DIR = /usr/src/linux

#  Valid ftape options are (for the vaiable FTAPE_OPT):
#       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        - sets base address (only!) if using non-standard fdc
#       FDC_IRQ         - sets interrupt if FDC_BASE is defined
#       FDC_DMA         - sets dma channel if FDC_BASE is 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_MEM_FLAGS:
#       DYN_ALLOC       - allocate all buffers dynamically, especially the dma-buffer
#                 

#
# set this to -DDYN_ALLOC to enable dynamic memory alloction of the dma buffer
# this feature will automatically be disabled if the kernel version is less
# than 1.1.72.
#
# FTAPE_MEM_FLAGS   = 
FTAPE_MEM_FLAGS   = -DDYN_ALLOC

#
# set FTAPE_TRACE_FLAGS to NO_TRACE to reduce debugging output
# use NO_TRACE_AT_ALL to disable all debugging ouput and to
# reduce the size of the driver (reduces the size a lot!)
#
# FTAPE_TRACE_FLAGS = -DNO_TRACE
# FTAPE_TRACE_FLAGS = -DNO_TRACE_AT_ALL
FTAPE_TRACE_FLAGS =

#
# set VERIFY_HEADERS to enable verification of header segments, the volume
# table segment and the compression map segment. If set, the segments are
# read back from the tape after being written and the result is compared 
# with the data they should contain. Slows updating of the header 
# segments down, but is strongly recommended because the tape gets 
# unreadable if the header segments contain wrong data.
#
# FTAPE_OPT       = $(FTAPE_MEM_FLAGS) $(FTAPE_TRACE_FLAGS)
FTAPE_OPT       = -DVERIFY_HEADERS $(FTAPE_MEM_FLAGS) $(FTAPE_TRACE_FLAGS)

#  If you're using a non-standard floppy disk controller for the
#  tape drive, enable one (only!) of the following lines and set
#  the FDC_BASE, FDC_IRQ and FDC_DMA parameters to the actual values.
#  Note1: Don't change the values on the FC-10 line but reconfigure
#         the FC-10/20 to the supplied values. Otherwise it won't work!
#  Note2: IRQ 2 and IRQ 9 can be considered the same. When using IRQ 2
#         on a controller you must specify IRQ 9 here!
#
# enable the next line for a Mountain MACH-2 controller:
#
#FDC_OPT         = -DMACH2 -DFDC_BASE=0x1E0 -DFDC_IRQ=6 -DFDC_DMA=2
#
# enable the next line for a CMS FC-10 or FC-20 controller:
#
#FDC_OPT         = -DPROBE_FC10 -DFDC_BASE=0x180 -DFDC_IRQ=9 -DFDC_DMA=3
#
# enable the next line for a secondary floppy disk controller:
#
# FDC_OPT = -DFDC_BASE=0x370 -DFDC_IRQ=6 -DFDC_DMA=2

#
#  Don't change anything below this point!
#
KERNEL_OPT      = -I$(LINUX_SRC_DIR)/include -D__KERNEL__ -DKERNEL -DLINUX $(MODFLAGS)
WARNINGS        = -Wall -Wstrict-prototypes
COMPILE         = -pipe -fomit-frame-pointer -m486 -O2
#DEBUG		= -g
LD_OPT		= -r -S
LD              = ld
SHELL           = /bin/bash

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

COMPRESS_DIR = compress
COMPRESS_OBJ = lzrw3.o

CC=gcc

.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 qic80-vtbl.c qic80-compress.c \
        ftape-dynmem.c

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

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

driver: dep ftape.o Makefile

module: driver
	sync
	- rmmod ftape
	insmod -x ftape.o

modules: driver

test:   tecc Makefile
	sync
	tecc -a

depend: dep

dep:	kernel-version.h .depend

.depend:
	$(CPP) $(CFLAGS) -M $(SRCS) > .depend
	set -e;test ! -d $(COMPRESS_DIR) || $(MAKE) -C $(COMPRESS_DIR) dep

clean:
	- rm -f a.out *.o core *~ gen_test tecc kernel-version.h .depend
	- make -C $(COMPRESS_DIR) clean

all:    driver test

compact: ftape.o
	strip ftape.o

ftape.o: $(OBJS) compression Makefile .depend
	$(LD) $(LD_OPT) -o $@ $(OBJS) $(COMPRESS_DIR)/$(COMPRESS_OBJ)
	sync

compression:
	make -C $(COMPRESS_DIR) $(COMPRESS_OBJ)

FTAPE_MAJOR = 27

#
# the mknod rule really requires bash.  I should change it to
# use the "expr" program one day
#
mknod:
	@echo Creating device-special file in /dev ...
	for i in 0 1 2 3; do                                               \
		rm -f /dev/rft$$i;                                         \
		rm -f /dev/nrft$$i;                                        \
		rm -f /dev/qft$$i;                                         \
		rm -f /dev/nqft$$i;                                        \
		rm -f /dev/zqft$$i;                                        \
		rm -f /dev/nzqft$$i;                                       \
		mknod /dev/rft$$i  c $(FTAPE_MAJOR) $$i;                     \
		mknod /dev/nrft$$i c $(FTAPE_MAJOR) $$[ $$i + 4 ];           \
		mknod /dev/qft$$i c $(FTAPE_MAJOR) $$[ $$i + 8 ];            \
		mknod /dev/nqft$$i c $(FTAPE_MAJOR) $$[ $$i + 4 + 8 ];       \
		mknod /dev/zqft$$i c $(FTAPE_MAJOR) $$[ $$i + 8 + 16 ];      \
		mknod /dev/nzqft$$i c $(FTAPE_MAJOR) $$[ $$i + 4 + 8 + 16 ]; \
	done

kernel-version.h:
	./Configure $(LINUX_SRC_DIR)
  
#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif



