#
# libraries.  You will want the bobm.a utility library, wherever
# you decided to put it, and the lex library.
#
LIBS = $(HOME)/lib/bobm.a -ll

#
# -d is needed to generate y.tab.h for the scanner, and for keycheck.c
#
YFLAGS = -d

#
# don't know what all you'll have to do for SYSV, other than
# -Dindex=strchr -Drindex=strrchr
#
# if you want to dink with the keywords recognized, maybe add special
# ones for your c compiler, see keycheck.c
#
CFLAGS = -O

#
# LOCAL CONFIGURATION
#
# These definitions also drive the making of a header file.  HATDIR is the
# directory you want the analyzer and parser placed in, BINDIR is the
# directory you want the command programs to be placed in.  PARSER and
# ANALYZER are the names you want to give those respective executables.
# CPPCMD is the c-preprocessor, and SHELLCMD a shell which will be
# execl'ed to execute the other PARSER | [CPPCMD] | ANALYZER pipe.
# MANDIR is where to put the manual pages.
#
# Some of the definitions will be placed in header file localnames.h, and
# moved to lastnames.h after compiling hat.c
#
MANDIR = .
HATDIR = $(HOME)/bin
BINDIR =  $(HOME)/bin
PARSER = hat_p
ANALYZER = hat_a
CPPCMD = "/lib/cpp"
SHELLCMD = "/bin/sh"

#
# object lists for the three executables - no remarks from the peanut gallery
# concerning the analyzer abbreviation :-).
#
ANALOBJ = amain.o anread.o table.o analyze.o topsort.o listsort.o
PARSOBJ = parse.o scan.o pmain.o keycheck.o
HATOBJ = hat.o

all: hat parser anal coat man

parser: $(PARSOBJ)
	cc -o $(PARSER) $(PARSOBJ) $(LIBS)
	mv $(PARSER) $(HATDIR)

anal:	$(ANALOBJ)
	cc -o $(ANALYZER) $(ANALOBJ) $(LIBS)
	mv $(ANALYZER) $(HATDIR)

hat:	$(HATOBJ)
	cc -o hat $(HATOBJ)
	mv hat $(BINDIR)

coat:
	sed -e "s,ANALYZER,$(HATDIR)/$(ANALYZER)," coat.tpl >coat
	chmod 755 coat
	mv coat $(BINDIR)

man:
	cp hat.1 $(MANDIR)
	cp coat.1 $(MANDIR)

hat.o:
	echo "#define HATDIR \"$(HATDIR)\"" >localnames.h
	echo "#define PARSER \"$(PARSER)\"" >>localnames.h
	echo "#define ANALYZER \"$(ANALYZER)\"" >>localnames.h
	echo "#define CPPCMD \"$(CPPCMD)\"" >>localnames.h
	echo "#define SHELLCMD \"$(SHELLCMD)\"" >>localnames.h
	cc $(CFLAGS) -c hat.c
	mv localnames.h lastnames.h
