# $Id: Makefile,v 35000.21 1998/07/28 06:44:28 hawkeye Exp $
########################################################################
#
#  TinyFugue - programmable mud client
#  Copyright (C) 1994 - 1998 Ken Keys
#
#  TinyFugue (aka "tf") is protected under the terms of the GNU
#  General Public Licence.  See the file "COPYING" for details.
#
#  DO NOT EDIT THIS FILE.  To change the default configuration,
#  see "README" and edit "Config".
#
########################################################################

# unix Makefile.
# This is invoked from unixmake, so the working directory is the root.

SHELL = /bin/sh

default: install
# If the next rule were first, a few strange versions of make would try
# to make "install", "all", AND "files", instead of just "install".

install all files: src/Makefile src/config.h _log
	cd ./src; { $(MAKE) $@ 2>&1; echo; cat exitmsg; } | \
	    { tee -a ../Build.log || cat; }

reconfigure:  unconfigure install

unconfigure:
	rm -f src/Makefile src/config.h

config src/Makefile src/config.h: Makefile unix/Config unix/tfconfig unix/unix.mak
	@rm -f ../src/Makefile ../src/config.h ../Build.log tfconfig.log
#	Use tfconfig to create config files.  If it fails, we don't exit
#	now, we want to create Build.log first.  Instead, we rm src/Makefile
#	but not src/config.h;  this lets 'install' continue on to '_log'.
#	('install' probably got here via the src/Makefile dependancy; if we
#	rm'd src/config.h, then 'install' would come back here again for the
#	src/config.h dependancy.)  Then, '_log' will create Build.log and,
#	if an error occured in this rule, '_log' will exit.
#	Note: tee eats exit code of tfconfig, so we couldn't use it anyway.
#	Note: some buggy versions of bash can't handle using descriptor 3 here.
	-@cd unix; \
		{ ./tfconfig $(TFVER) 2>&1 4>../src/config.h 5>vars.mak || \
		rm -f ../src/Makefile; } | \
			tee tfconfig.log

_log:
	-@{ cat unix/tfconfig.log; echo; } > Build.log
#	Exit now if there were errors in tfconfig.
	@test -f src/Makefile && test -f src/config.h
#	No errors.  Save info in Build.log, and continue.
	-@{ cat unix/vars.mak; echo; } >> Build.log
	-@{ cat src/config.h; echo; } >> Build.log

clean:
	cd ./src; rm -f *.o Makefile core* exitmsg config.h typescript*
	cd ./unix; rm -f vars.mak *.log functest* libtest* test.c a.out

distclean:  clean
	rm -f Build.log
#	cd ./tf-lib; rm -f tf-help.idx
	cd ./src; rm -f tf makehelp tags
	cd ./src; rm -f tf.pixie* tf.Addrs* tf.Counts*

spotless cleanest veryclean:  distclean
	cd ./src; rm -f tf.1.catman

uninstall:
	cd ./src; $(MAKE) uninstall

srcdist:
	cd ./src; $(MAKE) -f ../unix/unix.mak dist

help ./tf-lib/tf-help: _always_
	if cd ./help; then \
	    echo "Making help file..."; \
	    $(MAKE) && mv tf-help ../tf-lib; \
	else \
	    true; \
	fi

tar ../tf-$(TFVER).tar: ./src/*.[ch] srcdist distclean
	@-cd ./src; echo Possible garbage in src: \
	    `ls *in *out *err *foo* *bar* *.new *.old *.ok *.c.* *.tf *[0-9] \
	    2>/dev/null`
	@-echo Possible garbage in top: \
	    `ls *.gz *.Z *.zip 2>/dev/null`
	@wd=`pwd`; [ "`basename $$wd`" = "work" ] || \
	    echo 'WARNING: You are not in the "work" directory.'
	@echo 'Press return to archive tf-$(TFVER).'
	@read foo
	rm -rf ../tf-$(TFVER)
	-for dir in "/" /src/ /src/regexp/ /tf-lib/ /unix/ /os2/ /win32/; do \
	    mkdir ../tf-$(TFVER)$${dir}; \
	    cp .$${dir}* ../tf-$(TFVER)$${dir}; \
	    chmod ugo+r ../tf-$(TFVER)$${dir}*; \
	done
	chmod ugo+r ../tf-$(TFVER)
	rm -f ../tf-$(TFVER)/src/dmalloc.c
	cd ..; tar -cf tf-$(TFVER).tar tf-$(TFVER)

dist: ./tf-lib/tf-help ../tf-$(TFVER).tar ../tf-$(TFVER)-help.tar
	cd ..; gzip tf-$(TFVER).tar
	cd ..; zip -qlr tf-$(TFVER).zip tf-$(TFVER)
	cd ..; chmod ugo+r tf-$(TFVER).tar.gz tf-$(TFVER).zip
	cd ..; gzip tf-$(TFVER)-help.tar
	@echo ""; echo "### Don't forget to assign a cvs tag."

gzdist: ./tf-lib/tf-help ../tf-$(TFVER).tar
	cd ..; gzip tf-$(TFVER).tar

tarhelp ../tf-$(TFVER)-help.tar: help
	@wd=`pwd`; [ "`basename $$wd`" = "work" ] || \
	    echo 'WARNING: You are not in the "work" directory.'
	@echo 'Press return to archive tf-$(TFVER)-help.'
	@read foo
	rm -rf ../tf-$(TFVER)-help;
	for dir in "/" /commands/ /topics/; do \
	    mkdir ../tf-$(TFVER)-help$${dir}; \
	    cp help/$${dir}*.html ../tf-$(TFVER)-help$${dir}; \
	    chmod ugo+r ../tf-$(TFVER)-help$${dir}*; \
	done
	chmod ugo+r ../tf-$(TFVER)-help
	cd ..; tar -cf tf-$(TFVER)-help.tar tf-$(TFVER)-help

tcp.com:
	cd ..; scp tf-$(TFVER).tar.gz tf-$(TFVER).zip tf-$(TFVER)-help.tar.gz \
	    tcp.com:

local:
	TFDEV_TF='/usr/local/bin/tf-$(TFVER)' \
	    TFDEV_LIBDIR='/usr/local/lib/tf-$(TFVER)-lib' \
	    TFDEV_SYMLINK='/usr/local/bin/tf' ./unixmake config

devlocal:
	CC=tfcc TFDEV_CCFLAGS='-g -DLOCALITY' TFDEV_STRIP=':' \
	    TFDEV_TF='/usr/local/bin/tf-$(TFVER)' \
	    TFDEV_LIBDIR='/usr/local/lib/tf-$(TFVER)-lib' \
	    TFDEV_SYMLINK='/usr/local/bin/tf' ./unixmake config

devhome:
	CC=tfcc TFDEV_CCFLAGS='-g' TFDEV_TF="$$HOME/bin/tf-$(TFVER)" \
	    TFDEV_LIBDIR="$$HOME/lib/tf-$(TFVER)-lib" TFDEV_STRIP=':' \
	    TFDEV_SYMLINK="$$HOME/bin/tf" \
	    TFDEV_QUIET=yes TFDEV_DMALLOC=0 ./unixmake config

dev:
	CC=tfcc TFDEV_CCFLAGS='-g' TFDEV_TF="$$HOME/bin/tf-$(TFVER)" \
	    TFDEV_LIBDIR="$$HOME/lib/tf-$(TFVER)-lib" TFDEV_STRIP=':' \
	    TFDEV_QUIET=yes TFDEV_DMALLOC=0 ./unixmake config

laurel: devhome files
	cp CHANGES $$HOME/www/tf/

_always_:

# hack to get around a bug in BSDi (and FreeBSD?) make.
make:

