#
# Makefile for Unix and CP/M-80 versions of Unquill
#
# Currently, without a DOS cross-compiler, I have to do the DOS version
# separately.
#
IQSRC  = IQRun/iqrun.inf IQRun/iqproc.h IQRun/linker.c IQRun/Makefile IQRun/COPYING.LIB
SRCS   = unquill.c   playgame.c tables.c   condact.c   inform.c   zcode.c unquill.h \
         Makefile chain.com fbmake.c xtables.c  $(IQSRC)
OBJS   = unquill.o   playgame.o   tables.o   condact.o   inform.o   zcode.o \
	 xtables.o
OBJS80 = unquill.obj playgame.obj tables.obj condact.obj inform.obj zcode.obj \
	 xtables.obj
DOCS   = COPYING unquill.txt unquill.1
#
# Directory for iqrun.z5. Note trailing slash!
#
LIBDIR = /usr/lib/games/zcode/
#
# Install locations
#
BINDIR = /usr/local/bin
MANDIR = /usr/local/man/man1


CC      = gcc
ZCC     = zxc	# Z80 cross-compiler (actually a native compiler running 
                #                     under emulation)
#CFLAGS  = -g -ansi -U__STRICT_ANSI__ -Wall -pedantic -DLIBDIR=\"$(LIBDIR)\"
CFLAGS  = -O2 -ansi -U__STRICT_ANSI__ -Wall -pedantic -DLIBDIR=\"$(LIBDIR)\"
ZCFLAGS = -DTINY
ZIP     = zip 

all:	unquill $(DOCS) iqrun.z5

iqrun.z5: $(IQSRC)
	cd IQRun;make;cd ..
	cp IQRun/iqrun.z5 .

%.obj:	%.c
	$(ZCC) $(ZCFLAGS) -c $<

unquill:	$(OBJS)
	$(CC) -o unquill $(OBJS)

fbmake:	fbmake.c
#
# This little trick is to make UNQUILL.COM "run" under DOS by passing its
# command tail to UNQUILL.EXE. Otherwise DOS users have to delete UNQUILL.COM
# before DOS will run UNQUILL.EXE.
#
# In theory, I could build UnQuill as a .COM file for DOS as well, and use
# FBMAKE to generate a single .COM file for both platforms; but that would 
# mean making a tiny-model UNQUILL for DOS, which can't do Inform output.
# Plus the combined file would be more than 64k so CP/M wouldn't load it.
#
unquill.com:	$(OBJS80) fbmake
	$(ZCC) $(OBJS80)
	mv unquill.com unquill.cpm
	./fbmake unquill.cpm chain.com unquill.com	

unquill.man:	unquill.1
	nroff -c -mandoc $< > $@

unquill.txt:	unquill.man
	col -b < $< > $@

install: unquill unquill.1 iqrun.z5
	install -m 755 unquill   $(BINDIR)
	install -m 644 unquill.1 $(MANDIR)
	install -m 644 iqrun.z5  $(LIBDIR)

tidy:
	rm -f $(OBJS) $(OBJS80) *~ *.bak unquill.man

clean:	tidy
	rm -f unquill.com unquill

$(OBJS):	unquill.h
$(OBJS80):	unquill.h

zip: unquill.com unquill.exe iqrun.z5 $(SRCS) $(DOCS)
	$(ZIP) unquill.zip $(SRCS) $(DOCS) iqrun.z5 unquill.com unquill.exe

