#########################################################
#
# Makefile for  webble project
#
# MAKEFILE OPTIONS:
# 
# make all - compile webble and man page
# make webble - compile webble
# make install - install webble, man page and webblerc
# make uninstall - removes webble, man page and webblerc
# make clean - remove unnecessary files
#
#########################################################
#
# Executable name and manual section
# for manual page
#
EXEC=webble
SECTION=6

#
# BINPATH - Indicates where to put the
#	    binary executable
# MANPATH - Where to put the manual file
#
BINPATH=/usr/games
MANPATH=/usr/man/man$(SECTION)

#
# You can set the global resource file
# here - DONT REMOVE THE BACKSLASHES!
# Remember, you'll need to change both
# lines...
#
WRC=webblerc
SCRFILE=\"/usr/games/webblerc\"

#
# Compilation flags
#
FLAGS=-Wall
CFLAGS=$(FLAGS) -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_ALLOCA_H=1
CXXFLAGS=$(FLAGS) -DSCRFILE=$(SCRFILE)
LDFLAGS=$(FLAGS)

#
# Compilers, code generators, and the like
#
CXX=gcc

LEX=flex
#LEX=lex

YACC=bison -y
#YACC=yacc

ROFF=groff

INSTALL=install

MV=mv

################################
# YOU SHOULDN'T HAVE TO CHANGE #
# ANYTHING BELOW THIS LINE     #
################################
MAN=$(EXEC).$(SECTION)
OBJECTS=regex.o curs.o tkn.o parser.o lex.o main.o
LIBS=-lm -lncurses -lmenu -lform -lstdc++ -lshhopt

all: $(EXEC) $(MAN).gz

$(EXEC) : $(OBJECTS)
	$(CXX) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBS)

%.o : %.y
	$(YACC) -d $<
	$(MV) y.tab.c $*.cxx
	$(MV) y.tab.h $*.hxx
	$(CXX) $(CXXFLAGS) -c $*.cxx

%.o : %.l
	$(LEX) -i -o$*.cxx $<
	$(CXX) $(CXXFLAGS) -c $*.cxx

%.o : %.cxx
	$(CXX) $(CXXFLAGS) -c $<

%.o : %.c
	$(CXX) $(CFLAGS) $(DEFS) -c $<

$(MAN).gz: $(MAN)
	$(ROFF) -man -Tascii $(MAN) | gzip > $(MAN).gz

install: all
	$(INSTALL) -s -m 755 -o root -g root $(EXEC) $(BINPATH)/$(EXEC)
	$(INSTALL) -m 644 -o root -g root $(MAN).gz $(MANPATH)/$(MAN).gz
	$(INSTALL) -m 644 -o root -g root $(WRC) $(BINPATH)/$(WRC)

uninstall:
	rm -f $(BINPATH)/$(EXEC)
	rm -f $(BINPATH)/$(WRC)
	rm -f $(MANPATH)/$(MAN).gz

clean :
	rm -f $(OBJECTS) $(EXEC) *~ webble.6.gz 
	rm -f core lex.cxx parser.cxx parser.hxx
	rm -f *.dbg

# DO NOT DELETE
curs.o: curs.hxx tkn.hxx regex.h
lex.o: tkn.hxx parser.hxx
main.o: tkn.hxx curs.hxx tkn.hxx regex.h
parser.o: curs.hxx tkn.hxx regex.h
tkn.o: tkn.hxx
