#!/usr/bin/make -f
# Makefile for TAiL 1.3/Adventure System 1.2 (ANSI-C/Unix)
#
# Sources already include the Smarticles and NewParser patches and a
# few minor modifications, like the prompt character and higher
# compiler limits (see README).

# TAiL 1.3 as modified and used by Valerie Winter (me)
RELEASE=tail_advsys-1.3


# default directories for the compiler where library files and
# binaries reside.
# Note: the path to includes needs only to be given in a source file
# if the included file NEITHER resides in $LIBDIR nor in the current
# directory.
LIBDIR=/usr/local/share/advsys
BINDIR=/usr/local/bin

# default directory where the interpreter looks for story files
# (asides from current directory)
STORYDIR=/usr/share/games/if/advsys


# the curses library that is available on your system
#CURSESLIB=curses
CURSESLIB=ncurses

#--------------------------------------------------------------------

CC=gcc
CFLAGS=-g -O2 -DLIBDIR=\"${LIBDIR}/lib\" -DSTORYDIR=\"${STORYDIR}\"

COMPILER_OBJ=src/compiler/compiler.o \
	src/compiler/functions.o \
	src/compiler/lexscan.o \
	src/compiler/expressions.o \
	src/compiler/avltree.o \
	src/compiler/fileio.o

INTERPR_OBJ=src/interpreter/messages.o \
	src/interpreter/parser.o \
	src/shared/dbaccess.o \
	src/interpreter/engine.o

INT_CURS_OBJ=src/interpreter/messages.o \
	src/interpreter/parser.o \
	src/shared/dbaccess.o \
	src/interpreter/engine.o

DISTFILES=doc/advsys-manual.txt \
	doc/advsys-errors.txt \
	doc/advsys-limits.txt \
	lib/objects.adi \
	lib/standard.adi \
	lib/osample.adv \
	advsys-compiler advcom \
	advsys-interpreter-dumb dadvint \
	advsys-interpreter-curses advint

BINARIES=advsys-compiler advcom \
	advsys-interpreter-dumb dadvint \
	advsys-interpreter-curses advint


default: compiler interpreter

all:	compiler interpreter samples

world:  install archive

compiler advcom: $(COMPILER_OBJ)
	${CC} -o advsys-compiler $(COMPILER_OBJ)
	test -e advcom || ln -s advsys-compiler advcom

interpreter advint: dumb curses

dumbint dumb: $(INTERPR_OBJ) term_dumb.o
	${CC} -o advsys-interpreter-dumb $(INTERPR_OBJ) src/interpreter/interpreter.o src/interpreter/term_dumb.o
	test -e advint || ln -s advsys-interpreter-dumb dadvint

cursesint curses: $(INT_CURS_OBJ) term_curses.o
	${CC} -o advsys-interpreter-curses $(INT_CURS_OBJ) \
	 src/interpreter/interpreter.o src/interpreter/term_curses.o -l$(CURSESLIB)
	test -e advint || ln -s advsys-interpreter-curses advint

samples: compiler lib/osample.adv lib/objects.adi lib/sample2.adv lib/standard.adi
	cd lib;	../advsys-compiler osample.adv; cd ..
	cd lib; ../advsys-compiler sample2.adv; cd ..

install: all
	test -d $(LIBDIR) && echo || mkdir $(LIBDIR)
	$(INSTALL) $(DISTFILES) $(LIBDIR)
	pushd $(BINDIR)
	ln -s $(LIBDIR)/advcom advcom
	ln -s $(LIBDIR)/dadvint dadvint
	ln -s $(LIBDIR)/advint advint
	popd

archive: all
	test -d $(RELEASE) && echo || mkdir $(RELEASE)
	cp $(DISTFILES) $(RELEASE)
	test -r standard.adi && cp standard.adi $(RELEASE) || echo
	tar cjlpvf $(RELEASE)-`uname -s`-`uname -p`-bin.tar.bz2 $(RELEASE)
	rm -Rf $(RELEASE)

backup src-archive srcarchive: clean
	cd ..; tar cjlpvf $(RELEASE)-src-`date +%d%b%Y`.tar.bz2 $(RELEASE);\
	cd $(RELEASE)

clean-obj:
	for file in src/interpreter/*.o src/compiler/*.o src/shared/*.o; do \
	test -e $$file && rm $$file || echo >/dev/null; done

clean: clean-obj
	rm -Rf $(BINARIES)

term_dumb.o:
	${CC} $(CFLAGS) -DDUMB -c -o src/interpreter/interpreter.o src/interpreter/interpreter.c
	${CC} $(CFLAGS) -DDUMB -c -o src/interpreter/term_dumb.o src/interpreter/term_dumb.c

term_curses.o:
	${CC} $(CFLAGS) -DCURSES -c -o src/interpreter/interpreter.o src/interpreter/interpreter.c
	${CC} $(CFLAGS) -DCURSES -c -o src/interpreter/term_curses.o src/interpreter/term_curses.c

