#
# Makefile for Hypermail
#
@SET_MAKE@

prefix=@prefix@
datarootdir = @datarootdir@
datadir = @datadir@
exec_prefix=@exec_prefix@
 
# This is where you want hypermail to be installed
bindir=@bindir@
 
# This is where the man page goes
mandir=@mandir@

# This is where your CGI programs live
cgidir=@cgidir@

# Executable program suffix (.exe for windows, null for Unix systems)
SUFFIX=@suffix@

# Compiler to use
CC=@CC@

# Installation program to use
INSTALL_PROG=@INSTALL@ 

SPLINTFLAGS=@INCLUDES@ -Itrio

PCRE_DEP=@PCRE_DEP@
FNV_DEP=@FNV_DEP@

#WNOERROR=-Werror
#WARNINGS=$(WNOERROR) -ansi -pedantic -Wall -Wtraditional -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Dlint

CFLAGS=@CFLAGS@ $(WARNINGS)
CPPFLAGS=@CPPFLAGS@ @INCLUDES@ -Itrio -DTRIO_MINIMAL
YACC=@YACC@
NETLIBS=@LIBS@
LDFLAGS=@LDFLAGS@ -Ltrio
MISC_LIBS= -lm -lpcre -ltrio
OPT_LIBS=@EXTRA_LIBS@

INCS=		domains.h hypermail.h lang.h proto.h \
		../config.h ../patchlevel.h dsprintf.h threadprint.h \
		getdate.h getname.h finelink.h txt2html.h search.h

SRCS=		base64.c date.c domains.c file.c hypermail.c lang.c lock.c \
		mem.c parse.c print.c printfile.c string.c struct.c uudecode.c\
		dmatch.c setup.c threadprint.c getdate.c getname.c\
		finelink.c txt2html.c search.c quotes.c

OBJS=		base64.o date.o domains.o file.o hypermail.o lang.o lock.o \
		mem.o parse.o print.o printfile.o string.o struct.o uudecode.o\
		dmatch.o setup.o threadprint.o getdate.o getname.o\
		finelink.o txt2html.o search.o quotes.o

MAILOBJS=	mail.o ../libcgi/libcgi.a

.c.o:
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $<

all:    @PCRE_DEP@ trio/libtrio.a @FNV_DEP@ hypermail$(SUFFIX) mail$(SUFFIX) lang$(SUFFIX)

pcre/.libs/libpcre.a:
	@cd pcre; $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" ; rm -f .libs/lib*.so*

trio/libtrio.a:
	@cd trio; $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)"

fnv/libfnv.a:
	@cd fnv; $(MAKE) libfnv.a CC="$(CC)" CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)"

hypermail$(SUFFIX): $(OBJS) 
	$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(OBJS) $(OPT_LIBS) $(MISC_LIBS)
	chmod 0755 $@

mail$(SUFFIX):	$(MAILOBJS)
	$(CC) -o $@ $(CFLAGS) $(MAILOBJS) $(NETLIBS) -lm
	chmod 0755 $@

lang$(SUFFIX): lang.c lang.h
	$(CC) -DLANG_PROG $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ lang.c $(MISC_LIBS)

../libcgi/libcgi.a:
	@cd ../libcgi; $(MAKE) all CC="$(CC)" CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)"

getdate.c: getdate.y getdate.h
	@echo "Expect 13 shift/reduce conflicts."
	$(YACC) getdate.y
	@mv -f y.tab.c getdate.c

install: all
	@if [ ! -d $(bindir) ]; then mkdir -p $(bindir); fi
	$(INSTALL_PROG) -s -c -m 0755 hypermail$(SUFFIX) $(bindir)

mail.install:
	@if [ ! -d $(cgidir) ]; then mkdir -p $(cgidir); fi
	$(INSTALL_PROG) -s -c -m 0755 mail$(SUFFIX) $(cgidir)

uninstall:
	rm -f $(bindir)/hypermail$(SUFFIX)
	rm -f $(cgidir)/mail$(SUFFIX)

insight:
	$(MAKE) CC="insight" 

pure:
	$(MAKE) CFLAGS="-g" $(OBJS)  
	purify $(CC) -o hypermail -g $(CFLAGS) $(CPPFLAGS) $(OBJS) 

quant:
	$(MAKE) CFLAGS="-g" $(OBJS)
	quantify $(CC) -o hypermail -g $(CFLAGS) $(CPPFLAGS) $(OBJS)


splint: 
	splint $(SPLINTFLAGS) $(SRCS) 2>&1 | tee splint.out

lint:	
	lint $(SRCS) 2>&1 | tee lint.out

lint_mail:	
	lint mail.c 2>&1 | tee lint.out
	@(cd ../libcgi; $(MAKE) lint 2>&1 | tee -a ../lint.out)

clean:
	rm -f hypermail$(SUFFIX) mail$(SUFFIX) lang$(SUFFIX)
	rm -f *.o .pure *qx *qv *.ln core
	rm -f .inslog tca.map lint.out splint.out
	rm -f getdate.c
	@(if test "$(PCRE_DEP)" != "" ; then cd pcre; $(MAKE) clean; fi)
	@cd trio; $(MAKE) clean
	@(if test "$(FNV_DEP)" != "" ; then cd fnv; $(MAKE) clean; fi)
	@cd ../libcgi; $(MAKE) clean

clobber: clean
	@(if test "$(PCRE_DEP)" != "" ; then cd pcre; rm -f *.lock; fi)
	@cd trio; rm -f *.lock
	@(if test "$(FNV_DEP)" != "" ; then cd fnv; $(MAKE) clobber; fi)
	@cd ../libcgi; $(MAKE) clobber

distclean: clobber
	@(if test "$(PCRE_DEP)" != "" ; then cd pcre; $(MAKE) distclean; fi)
	@cd trio; $(MAKE) clean
	@(if test "$(FNV_DEP)" != "" ; then cd fnv; $(MAKE) distclean; fi)
	@cd ../libcgi; $(MAKE) distclean

#
# Regenerate this dependency list with gcc -MM *.c:
#

base64.o: base64.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h \
 base64.h
date.o: date.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h \
 setup.h
dmatch.o: dmatch.c dmatch.h ../config.h
domains.o: domains.c hypermail.h ../config.h ../patchlevel.h proto.h \
 lang.h domains.h
file.o: file.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h \
 setup.h struct.h
finelink.o: finelink.c hypermail.h ../config.h ../patchlevel.h proto.h \
 lang.h finelink.h setup.h print.h struct.h search.h
getname.o: getname.c hypermail.h ../config.h ../patchlevel.h proto.h \
 lang.h getname.h setup.h
hypermail.o: hypermail.c hypermail.h ../config.h ../patchlevel.h proto.h \
 lang.h defaults.h setup.h parse.h print.h finelink.h search.h struct.h
lang.o: lang.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h
lock.o: lock.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h \
 setup.h
mail.o: mail.c ../libcgi/cgi.h ../libcgi/../config.h ../config.h
mem.o: mem.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h
parse.o: parse.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h \
 setup.h struct.h uudecode.h base64.h search.h getname.h parse.h print.h
print.o: print.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h \
 setup.h struct.h printfile.h print.h parse.h txt2html.h finelink.h \
 threadprint.h
printfile.o: printfile.c hypermail.h ../config.h ../patchlevel.h proto.h \
 lang.h setup.h print.h printfile.h struct.h
quotes.o: quotes.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h \
 setup.h
search.o: search.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h \
 setup.h struct.h print.h search.h
setup.o: setup.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h \
 defaults.h setup.h struct.h print.h
string.o: string.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h \
 setup.h parse.h uconvert.h
struct.o: struct.c hypermail.h ../config.h ../patchlevel.h proto.h lang.h \
 dmatch.h setup.h struct.h parse.h getname.h
threadprint.o: threadprint.c hypermail.h ../config.h ../patchlevel.h \
 proto.h lang.h setup.h struct.h threadprint.h printfile.h print.h
txt2html.o: txt2html.c hypermail.h ../config.h ../patchlevel.h proto.h \
 lang.h setup.h print.h finelink.h txt2html.h
uudecode.o: uudecode.c hypermail.h ../config.h ../patchlevel.h proto.h \
 lang.h setup.h uudecode.h
