#  
#  Step 1: The following are the target directories for the binary, header,
#	   documentation, and on-line manual files.  Set these for your
#	   filesystem layout.
#
BINDIR=/usr/local/bin
INCDIR=/usr/local/include/pccts
DOCDIR=/usr/local/doc/pccts
MANDIR=/usr/local/man


#
#  Step 2: Check the compiler configuration for your system.  This really
#	   should be automated at some point.  Set these for your compiler
#	   organization.
#
CC=gcc

#
#  Step 3: Indicate verbosity level you want.
#
PSss=

#
#  Step 4: Indicate the print command to use to print man pages.
#
PRINT=cat > /dev/null

#
#  Step 5: Save this file and exit the editor.
#

#									    #
# #############  DO NOT CHANGE ANYTHING BEYOND THIS POINT ################# #
#									    #
TOPDIR  := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
HPATH=$(TOPDIR)/h

BINS=antlr dlg genmk

INCS1=AParser.cpp ATokenBuffer.h SList.cpp config.h AParser.h ATokenStream.h
INCS2=$(INCS1) SList.h dlgauto.h ASTBase.cpp DLexer.cpp antlr.h dlgdef.h ASTBase.h
INCS3=$(INCS2) DLexerBase.cpp ast.c err.h ATokPtr.cpp DLexerBase.h ast.h int.h
INCS4=$(INCS3) ATokPtr.h PBlackBox.h charbuf.h pcnames.bat AToken.h PCCTSAST.cpp
INCS=$(INCS4) charptr.c ATokenBuffer.cpp PCCTSAST.h charptr.h

DOCS1=BOOK NOTES.OS2 history.ps pccts1.txt CHANGES_FROM_1.31 NOTES.watcom
DOCS2=$(DOCS1) history.txt unbag.c README install.mpw NOTES.BCC RIGHTS NOTES.MSVC
DOCS=$(DOCS2) SERVICES

MANS=pccts.1 antlr/antlr.1 dlg/dlg.1
MAN=pccts.1* antlr.1* dlg.1*

.SILENT:

all:	compile install print

compile:
	(cd antlr; make -s)
	(cd dlg; make -s)
	(cd support/genmk; make -s)

install: compile
	# Build the remove script
	echo "all:" | cat > remove.mk
	echo "	if [ -d $(BINDIR) ] ; then cd $(BINDIR); rm -f $(BINS) ; fi" | cat >> remove.mk
	echo "	if [ -d $(INCDIR) ] ; then cd $(INCDIR); rm -f $(INCS) ; fi" | cat >> remove.mk
	echo "	if [ -d $(DOCDIR) ] ; then cd $(DOCDIR); rm -f $(DOCS) ; fi" | cat >> remove.mk
	echo "	if [ -d $(MANDIR)/man1 ] ; then cd $(MANDIR)/man1; rm -f $(MAN) ; fi" | cat >> remove.mk
	echo "	if [ -d $(MANDIR)/cat1 ] ; then cd $(MANDIR)/cat1; rm -f $(MAN) ; fi" | cat >> remove.mk

	# Build the restore script
	echo "all:" | cat > restore.mk
	echo "	if [ -d $(BINDIR) ] ; then (cd $(BINDIR); cp -p $(BINS) $(TOPDIR)/bin) ; fi" | cat >> restore.mk
	echo "	if [ -d $(INCDIR) ] ; then (cd $(INCDIR); cp -p $(INCS) $(TOPDIR)/h) ; fi" | cat >> restore.mk
	echo "	if [ -d $(DOCDIR) ] ; then (cd $(DOCDIR); cp -p $(DOCS) $(TOPDIR)) ; fi" | cat >> restore.mk
	echo "	if [ -d $(MANDIR)/man1 ] ; then (cd $(MANDIR)/man1; cp -p $(MAN) $(TOPDIR)) ; fi" | cat >> restore.mk
	echo "	mv antlr.1* antlr; mv dlg.1* dlg; " | cat >> restore.mk

	if [ ! -d $(DOCDIR) ] ; then mkdir -p $(DOCDIR) ; fi
	cp -p $(DOCS) $(DOCDIR)

	if [ ! -d $(MANDIR) ] ; then mkdir -p $(MANDIR) ; fi
	cp -a $(MANS) $(MANDIR)/man1

	if [ ! -d $(INCDIR) ] ; then mkdir -p $(INCDIR) ; fi
	cp -p $(HPATH)/*.h $(INCDIR)
	cp -p $(HPATH)/*.cpp $(INCDIR)

	if [ ! -d $(BINDIR) ] ; then mkdir -p $(BINDIR) ; fi
	cp -p bin/antlr $(BINDIR)
	cp -p bin/dlg $(BINDIR)
	cp -p support/genmk/genmk $(BINDIR)

print:
	# Print (if possible) the man pages
	$(PRINT) pccts1.txt antlr/antlr1.txt dlg/dlg1.txt

clean:
	# Removing binaries, objects, and compiler remnants (core, etc)
	# from this source tree.  Used to make different versions from the
	# same source tree.
	rm -f core bin/*
	(cd antlr; rm -f *.[oas] )
	(cd dlg; rm -f *.[oas] )
	(cd support/genmk; rm -f *.[oas]; rm -f genmk )

distclean: clean
	# Make this source tree match the original distribution if it hasn't
	# been "archive"d.  (i.e. "clean" + remove the extra scripts.)
	rm -f remove.mk
	rm -f restore.mk

remove:
	#  FOR THE MOMENT, THIS ASSUMES THAT THIS SOURCE TREE IS LEFT INTACT.
	# Remove a prior installation of THIS distribution of PCCTS from this
	# machine.  Used to remove this distribution before installing a new
	# distribution of PCCTS.
	make -s -f remove.mk

restore:
	# Centralize the files distributed across this machine into this source
	# tree.  Used to collect the distribution after archiving it, because
	# "make archive" removes some of the files from this source tree to
	# minimize disk space used by this distribution of PCCTS.  Note, this
	# does not "remove" the files that are distributed.
	make -s -f restore.mk

archive: clean
	# Used to remove redundant files from your system, while leaving remove
	# and restore scripts which can completely remove this distribution from
	# your system, or restore this source tree from the files distributed
	# throughout your system.
	if [ -d h ] ; then (cd h; rm -f $(INCS)) ; fi
	- rm -f $(DOCS)
	- rm -f $(MANS)
	if [ -d bin ] ; then (cd bin; rm -f $(BINS)) ; fi

