#
# Makefile for `problem'
#
# Makefile Makefile 1.34   Delta'd: 15:20:39 11/1/92   Mike Lijewski, CNSF
#

# Your C++ compiler goes here.
CC = g++

#
# Flags for CFLAGS:
#
#
# Add -DSIGINTERRUPT if you both have it and NEED it to ensure that signals
# interrupt slow system calls.  This is primarily for 4.3 BSD-based systems.
# Otherwise, your system most certaily does the right thing already.
#
# Add -DOLDDELETE if your compiler can't handle the 'delete []' form
# of the delete operator for deleting arrays of objects allocated
# via new.  If you don't know whether you compiler can handle it or
# not, just don't define it and see what happens.  If your compiler
# doesn't choke, it'll do the right thing.
#
# You must indicate where the GDBM header file 'gdbm.h' is to be found
# using a flag of the form: -I/usr/local/include.
#
# If you have the BSD 4.3 signal mechanism, in particular, sigblock(2) and
# sigsetmask(2), add -DBSDSIGS.  Else if you have POSIX signals, in
# particular sigprocmask(2), add -DPOSIXSIGS.  Otherwise I'll use
# the usually ANSI C signal mechanism when I need to block SIGTSTP and
# SIGWINCH.  This can lead to some lost signals in very rare
# circumstances, but what can you do with a braindead signal mechanism.
#
# The default locking is done using the POSIX "lockf".  If you don't
# have "lockf" but have the BSD "flock", add -DFLOCK.  If you don't
# have either, scream bloody murder to your vendor; you really need
# one or the other.
#
# By default, we assume that you have version of mail that accepts the
# "-s" flag to indicate a subject line.  If your mailer doesn't
# recognize the "-s" flag, add -DNOSUBJECT.
#
# If you don't have the pager "less" or just don't want to force its use as
# the pager, add -DNOLESS.  We'll then use the pager in the PAGER
# environment variable, or "more" by default.  Use "less" if you have it.
#
# If you're running on ESIX, add -DESIX
#
# Add -O if you trust your optimizer.
#
CFLAGS = -O -I/home/xtelab/lijewski/include -DBSDSIGS -DSIGINTERRUPT

#
# Those flags needed to compile in the type of terminal
# control you have:
#
#   Use -DTERMIOS if you have <termios.h>, the POSIX terminal control.
#   Use -DTERMIO if you have <termio.h>, the SYSV terminal control.
#   Otherwise, we assume you have <sgtty.h>, the BSD terminal control.
#
# If you choose to use -DTERMIOS and have problems, try -DTERMIO.  On
# at least two systems I've tried, the vendor hasn't had all the
# include files set up correctly to include <unistd.h> together with
# <osfcn.h>, among others.
#
# On RS/6000s, AIX/370 and recent Suns, -DTERMIO works well.
#
TERMFLAGS = -DTERMIO

#
# You must indicate where the GDBM library 'libgdbm.a' is to be found
# using a flag of the form: -L/usr/local/lib.
#
# On ESIX you might also need -lgen and -lbsd
#
LDFLAGS = -L/home/xtelab/lijewski/lib

#
# The needed libraries.  You need Termcap(3) and GDBM
#
LIBS = -lgdbm -ltermcap

#
# Directory is which the databases, AREA file (this is the file, with
# one area per line, listing the valid problem areas), SEQUENCE file
# (this is the file used to keep the unique problem #), and
# MAILLIST.* files (which contains the names of interested parties)
# will be stored.
#
HOMEBASE = /home/xtelab/lijewski/src/c++/problem

#
# MAILPROG -- a version of mail.  If you didn't specify -DNOSUBJEC
# above, then this should be a mailer which accepts  the "-s" flag to
# indicate indicate a "Subject:" line.  This must be a full pathname.
#
MAILPROG = /usr/ucb/mail

#
# MAXFILESIZE is the largest size file you'll allow for logs, appends
# and closes.  If the file is larger than that only the first
# MAXFILESIZE bytes are stored in the database.
#
MAXFILESIZE = 16000

##############################################################################
# nothing should need to be changed below here.
##############################################################################

SHELL     = /bin/sh
MAKESHELL = /bin/sh

HDR   = classes.h display.h help.h lister.h keys.h problem.h regexp.h \
        version.h utilities.h
MISC1 = AREAS.template ChangeLog INSTALL MANIFEST
MISC2 = Makefile README THANKS gdbm.h-proto problem.1 problem.lpr
MISC  = $(MISC1) $(MISC2)
OBJ   = classes.o display.o lister.o problem.o regexp.o utilities.o
SRC   = classes.C display.C lister.C problem1.C problem2.C regexp.C utilities.C

problem: $(OBJ) SEQUENCE AREAS
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)

display.o: display.C display.h
	$(CC) $(CFLAGS) $(TERMFLAGS) -c display.C

problem.o: problem.C
	$(CC) -c $(CFLAGS) -DHOMEBASE=\"$(HOMEBASE)\"                 \
              -DMAILPROG=\"$(MAILPROG)\" -DMAXFILESIZE=$(MAXFILESIZE) \
              problem.C

#
# problem.C is built from .C and command2.C the first time
# it is needed.  This is so that the shar files don't get too big.
#
problem.C: problem1.C problem2.C
	cat problem1.C problem2.C > problem.C

SEQUENCE:
	@if [ ! -f "$(HOMEBASE)/SEQUENCE" ]; then           \
            echo "making $(HOMEBASE)/SEQUENCE ...";         \
            echo "problems will be numbered starting at 1"; \
            echo -n "0" > $(HOMEBASE)/SEQUENCE;             \
	    chmod 644 $(HOMEBASE)/SEQUENCE;                 \
        else                                                \
            true;                                           \
        fi

AREAS:
	@if [ ! -f "$(HOMEBASE)/AREAS" ]; then                   \
            echo "Creating $(HOMEBASE)/AREAS ...";               \
            cp AREAS.template $(HOMEBASE)/AREAS;                 \
            chmod 644 $(HOMEBASE)/AREAS;                         \
        fi

clean:
	-rm -f core *.o *..c problem

realclean:
	-rm -f core *.o *..c problem *~ problem.C

#
# This depends on Rich Salz' cshar program.
#
shar: $(SRC) $(HDR) $(MISC)
	cshar -n1 -e7 -o problem-01 $(HDR) $(MISC1)
	cshar -n2 -e7 -o problem-02 $(MISC2)
	cshar -n3 -e7 -o problem-03 display.C regexp.C
	cshar -n4 -e7 -o problem-04 classes.C lister.C
	cshar -n5 -e7 -o problem-05 problem1.C
	cshar -n6 -e7 -o problem-06 problem2.C
	cshar -n7 -e7 -o problem-07 utilities.C

tar:
	tar cf problem.tar $(SRC) $(HDR) $(MISC)
	compress -f problem.tar

classes.o   : classes.h problem.h utilities.h
display.o   : display.h utilities.h
lister.o    : classes.h display.h help.h keys.h lister.h \
			  problem.h utilities.h version.h
problem.o   : classes.h display.h lister.h problem.h utilities.h
utilities.o : classes.h display.h lister.h problem.h utilities.h

.SUFFIXES: .C .o

.C.o:
	$(CC) $(CFLAGS) -c $*.C
