########################################################################
# AtariSIO Makefile
# (c) 2002, 2003 by Matthias Reichl <hias@horus.com>
# http://www.horus.com/~hias/atari/
########################################################################


########################################################################
# location of your kernel header files
########################################################################

KERNEL_INCLUDES = /usr/src/linux/include
#KERNEL_INCLUDES = /usr/include
#KERNEL_INCLUDES = /data/hias/laptop/linux-2.2.19/include

########################################################################
# installation directory
# The executables will be installed in INST_DIR/bin,
# the header file atarisio.h will be installed in INST_DIR/include,
########################################################################

INST_DIR = /usr/local
#INST_DIR = /usr/local/atarisio

########################################################################
# installation directory for the kernel module atarisio.o
# (lib/modules/$KERNELVERSION/misc)
# please note: some RedHat versions ship with a nonstandard version.h
# file which causes grep to fail in getting the version information.
# In this case, uncomment either the 'uname' line below or set the
# version directory by hand.
########################################################################

VERSION = $(shell grep UTS_RELEASE $(KERNEL_INCLUDES)/linux/version.h | cut -d '"' -f2)
#VERSION = $(shell uname -r)
#VERSION = 2.4.18

MDIR = /lib/modules/$(VERSION)/misc

########################################################################
# if you don't have zlib installed on your system, please comment out
# the following two lines. With zlib enabled you will be able to
# directly load and save gzip-compressed image files (eg file.atr.gz)
########################################################################

ZLIB_CXX_FLAGS=-DUSE_ZLIB
ZLIB_LD_FLAGS=-lz

########################################################################
# gcc version to use for compiling the kernel module
# The (major) version number must match the version that was used
# when compiling the linux kernel, otherwise your system may crash!
# To find out which gcc version was used to compile the kernel
# just do a "cat /proc/version"
########################################################################

KERNEL_CC = gcc
#KERNEL_CC = gcc-2.95
#KERNEL_CC = kgcc

########################################################################
# gcc version for compiling the user space apps
# Usually you don't need to change this
########################################################################

CC = gcc
CXX = g++
#CC = gcc-3.0
#CXX = g++-3.0
#CC = /usr/local/gcc-3.2.2/bin/gcc
#CXX = /usr/local/gcc-3.2.2/bin/g++

########################################################################
# don't change anything below here
########################################################################

CXXFLAGS = -g -W -Wall -DATARI_DEBUG $(ZLIB_CXX_FLAGS)
CFLAGS = -g -W -Wall -DATARI_DEBUG 
MODFLAGS = -Wall -O2 -DMODULE -D__KERNEL__ -I$(KERNEL_INCLUDES)

LDFLAGS = 
LIBS = $(ZLIB_LD_FLAGS) -lreadline -lcurses

#LDFLAGS = -static
#LIBS = $(ZLIB_LD_FLAGS) -lreadline -lhistory -lncurses

ATARIXFER_OBJS = atarixfer.o DiskImage.o AtrImage.o AtrMemoryImage.o \
	SIOWrapper.o DCMCodec.o FileIO.o

ATARISERVER_OBJS = atariserver.o DiskManager.o DiskImage.o AtrImage.o \
	AtrMemoryImage.o SIOWrapper.o AbstractSIOHandler.o AtrSIOHandler.o \
	SIOManager.o SIOTracer.o HighSpeedSIOCode.o DCMCodec.o FileIO.o

EXECUTABLES = atarisio.o atarixfer atariserver

all: $(EXECUTABLES)

atarixfer: $(ATARIXFER_OBJS)
	$(CXX) $(LDFLAGS) -o atarixfer $(ATARIXFER_OBJS) $(LIBS)

atariserver: $(ATARISERVER_OBJS)
	$(CXX) $(LDFLAGS) -o atariserver $(ATARISERVER_OBJS) $(LIBS)

atarisio.o: atarisio.c atarisio.h ${KERNEL_INCLUDES}/linux/version.h
	$(KERNEL_CC) $(MODFLAGS) -c atarisio.c

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

.C.o:
	$(CXX) $(CXXFLAGS) -c $<

clean:
	rm -f *.o $(EXECUTABLES) *.65o dumphscode

backup:
	tar zcf bak/SIO-`date '+%y%m%d-%H%M'`.tgz *.c *.C *.h *.src Makefile modutils* Changelog README* LICENSE

install: atarisio.o atariserver atarixfer
	if test ! -d $(MDIR) ; then mkdir -p $(MDIR) ; fi
	install -m 644 atarisio.o $(MDIR)/atarisio.o
	depmod -a
	if test ! -d $(INST_DIR)/bin ; then \
		mkdir -p -m 755 $(INST_DIR)/bin ; \
	fi
	install -o root -m 4755 atariserver $(INST_DIR)/bin/atariserver
	install -o root -m 4755 atarixfer $(INST_DIR)/bin/atarixfer
	if test ! -d $(INST_DIR)/include ; then \
		mkdir -p -m 755 $(INST_DIR)/include ; \
	fi
	install -o root -m 644 atarisio.h $(INST_DIR)/include/atarisio.h

/dev/atarisio:
	mknod -m 666 /dev/atarisio c 10 240

uninstall:
	rm -f $(MDIR)/atarisio.o 
	rm -f $(INST_DIR)/bin/atariserver 
	rm -f $(INST_DIR)/bin/atarixfer
	rm -f $(INST_DIR)/include/atarisio.h
	rm -f /dev/atarisio

# manually entered dependency information

dumphscode: dumphscode.o
	$(CC) -o dumphscode dumphscode.o

highspeedcode.65o: highspeedcode.src
	atasm $<

highspeedcode: highspeedcode.65o dumphscode
	./dumphscode

# dependency information

atarisio.o: atarisio.c atarisio.h
dumphscode.o: dumphscode.c
highspeedcode.o: highspeedcode.c
AbstractSIOHandler.o: AbstractSIOHandler.C AbstractSIOHandler.h \
 atarisio.h SIOWrapper.h
AtrImage.o: AtrImage.C AtrImage.h DiskImage.h
AtrMemoryImage.o: AtrMemoryImage.C AtrMemoryImage.h AtrImage.h \
 DiskImage.h DCMCodec.h FileIO.h AtariDebug.h
AtrSIOHandler.o: AtrSIOHandler.C AtrSIOHandler.h AbstractSIOHandler.h \
 atarisio.h SIOWrapper.h AtrImage.h DiskImage.h SIOTracer.h \
 AtariDebug.h HighSpeedSIOCode.h highspeedcode.h
DCMCodec.o: DCMCodec.C DCMCodec.h AtrMemoryImage.h AtrImage.h \
 DiskImage.h FileIO.h AtariDebug.h
DiskImage.o: DiskImage.C DiskImage.h
DiskManager.o: DiskManager.C DiskManager.h SIOManager.h \
 AbstractSIOHandler.h atarisio.h SIOWrapper.h AtrImage.h DiskImage.h \
 AtrMemoryImage.h AtrSIOHandler.h SIOTracer.h AtariDebug.h
DiskSlot.o: DiskSlot.C DiskSlot.h AtrImage.h DiskImage.h \
 AtrSIOHandler.h AbstractSIOHandler.h atarisio.h SIOWrapper.h \
 SIOTracer.h AtrMemoryImage.h AtariDebug.h
FileIO.o: FileIO.C FileIO.h AtariDebug.h
HighSpeedSIOCode.o: HighSpeedSIOCode.C HighSpeedSIOCode.h \
 highspeedcode.h AtariDebug.h highspeedcode.c
SIOManager.o: SIOManager.C SIOManager.h AbstractSIOHandler.h \
 atarisio.h SIOWrapper.h AtariDebug.h SIOTracer.h
SIOTracer.o: SIOTracer.C SIOTracer.h atarisio.h AbstractSIOHandler.h \
 SIOWrapper.h
SIOWrapper.o: SIOWrapper.C SIOWrapper.h atarisio.h AtariDebug.h
atariserver.o: atariserver.C AtrSIOHandler.h AbstractSIOHandler.h \
 atarisio.h SIOWrapper.h AtrImage.h DiskImage.h SIOTracer.h \
 AtrMemoryImage.h SIOManager.h DiskManager.h
atarixfer.o: atarixfer.C atarisio.h AtrMemoryImage.h AtrImage.h \
 DiskImage.h SIOWrapper.h
