# Makefile for iflib - part of ifmail FidoNet package
# Copyright (c) 1993-1997 by Eugene G. Crosser

INCDIR = .

include ../CONFIG

DEFINES =	-DDEBUGFILE=\"${DEBUGFILE}\" \
		-DLOGFILE=\"${LOGFILE}\" \
		-DCONFIGFILE=\"${CONFIGFILE}\" \
		-DMAPTABDIR=\"${MAPTABDIR}\" \
		-DLOCKDIR=\"${LOCKDIR}\" \
		-DPUBDIR=\"${PUBDIR}\" \
		-DFAKEDIR=\"${FAKEDIR}\" \
		-DMAILLOG=${MAILLOG} \
		-DNEWSLOG=${NEWSLOG} \
		-DCICOLOG=${CICOLOG} \
		${OPTS}

OBJS = lutil.o xutil.o ulock.o rfcdate.o sequencer.o ftnmsg.o hdr.o \
		crc.o parsedate.o gettime.o execute.o execsh.o \
		rdconfig.o ftn.o packet.o pktname.o bwrite.o \
		bread.o getheader.o scanout.o matchaka.o atoul.o \
		nodelock.o trap.o rfcaddr.o expipe.o callstat.o \
		cspace.o setprocn.o \
		charset.o mime.o \
		lhash.o hash.o falists.o ${NEEDED}

SRCS = lutil.c xutil.c ulock.c rfcdate.c sequencer.c ftnmsg.c hdr.c \
		crc.c strcasestr.c strncasecmp.c strcasecmp.c \
		rename.c mkdir.c parsedate.y gettime.c \
		rdconfig.c ftn.c packet.c pktname.c bwrite.c \
		bread.c getheader.c scanout.c matchaka.c usleep.c \
		execute.c execsh.c signal.c regexpr.c atoul.c \
		nodelock.c trap.c rfcaddr.c expipe.c callstat.c \
		cspace.c setprocn.c ref.c \
		charset.c mime.c \
		cleanup_ref.c make_new_ref.c tmpfile.c \
		dirent.c lhash.c hash.c falists.c

HDRS = lutil.h xutil.h ulock.h libinn.h macros.h configdata.h clibrary.h \
		config.h ftn.h bwrite.h bread.h getheader.h getopt.h \
		scanout.h trap.h rfcaddr.h ftnmsg.h rfcmsg.h callstat.h \
		cspace.h charset.h mime.h \
		crc.h strcasestr.h strncasecmp.h strcasecmp.h rename.h \
		mkdir.h usleep.h ref_interface.h tmpfile.h \
		version.h directory.h lhash.h hash.h falists.h

OTHER = Makefile README parsedate.3 cleanup_ref.8 make_new_ref.8

ifdef REFERENCES_MSC96
OBJS += ref.o
#REF_FILES=cleanup_ref make_new_ref
REF_FILES=make_new_ref
REF_MAN=man_ref
REF_INSTALL=install_ref
endif

#############################################################################

ifeq (yes,${SHARED})
.c.o:
	${CC} ${CFLAGS} -fPIC ${INCLUDES} ${DEFINES} -c $<

all:		needed.h libifmail.so.${SHVER} ${REF_FILES}

else
.c.o:
	${CC} ${CFLAGS} ${INCLUDES} ${DEFINES} -c $<

all:		needed.h utlib.a ${REF_FILES}
endif

parsedate.c:	parsedate.y
	@echo expect 6 shift/reduce conflicts
	${YACC} parsedate.y
	mv y.tab.c parsedate.c
	@echo expect 4 warnings compiling parsedate.c

libifmail.so.${SHVER}: ${OBJS}
	${CC} -o libifmail.so.${SHVER} -shared -Wl,-soname,libifmail.so.${SHVER} ${OBJS}
	ln -s libifmail.so.${SHVER} libifmail.so

utlib.a:	${OBJS}
	${AR} r $@ $?
	${RANLIB} $@

needed.h:
	(for f in ${NEEDED} ;do BASE=`basename $$f .o`; BASE=\"$${BASE}.h\" ; \
	echo "#include $${BASE}"; done) > needed.h

cleanup_ref: cleanup_ref.o ref.o
	${CC} ${CFLAGS} cleanup_ref.o ref.o ${LIBS} -o cleanup_ref

make_new_ref: make_new_ref.o ref.o
	${CC} ${CFLAGS} make_new_ref.o ref.o ${LIBS} -o make_new_ref

clean:
	rm -f utlib.a libifmail.so* *.o getdate.c parsedate.c testscan \
	testconf testtrap testrfcaddr core filelist Makefile.bak needed.h \
	cleanup_ref make_new_ref

install:	all ${REF_INSTALL}
ifeq (1,${SHARED})
	${INSTALL} -o${OWNER} -g${GROUP} -m644 libifmail.so.${SHVER} ${LIBDIR}/libifmail.so.${SHVER}
endif

install_ref:
	#${INSTALL} -s -o ${OWNER} -g ${GROUP} -m ${MODE} cleanup_ref ${BINDIR}/cleanup_ref
	${INSTALL} -s -o ${OWNER} -g ${GROUP} -m ${MODE} make_new_ref ${BINDIR}/make_new_ref

tar:		utlib.tar.z

utlib.tar.z:	${SRCS} ${HDRS} ${OTHER}
	${TAR} cf - ${SRCS} ${HDRS} ${OTHER} \
	| gzip >$@

filelist:	Makefile
	BASE=`pwd`; \
	BASE=`basename $${BASE}`; \
	(for f in ${SRCS} ${HDRS} ${OTHER} ;do echo ifmail/$${BASE}/$$f; done) \
	>filelist

man:	${REF_MAN}
	${INSTALL} -o ${MANOWNER} -g ${MANGROUP} -m ${MANMODE} parsedate.3 ${MANDIR}/man3/parsedate.3

man_ref:
	${INSTALL} -o ${MANOWNER} -g ${MANGROUP} -m ${MANMODE} cleanup_ref.8 ${MANDIR}/man8/cleanup_ref.8
	${INSTALL} -o ${MANOWNER} -g ${MANGROUP} -m ${MANMODE} make_new_ref.8 ${MANDIR}/man8/make_new_ref.8

testconf:	rdconfig.c config.h utlib.a
	cc -g -Wall -DTESTING rdconfig.c utlib.a -o $@

tryconf: testconf
	./testconf ../misc/config

testscan:	scanout.c scanout.h utlib.a
	cc -g -Wall -DTESTING scanout.c utlib.a -o $@

tryscan: testscan
	./testscan ../misc/config

testtrap:	trap.c
	cc -g -Wall -DNEED_TRAP -DTESTING trap.c utlib.a -o $@

trytrap:	testtrap
	./testtrap

testrfcaddr:	rfcaddr.c rfcaddr.h
	cc -g -Wall -DTESTING rfcaddr.c utlib.a -o $@

tryrfcaddr:	testrfcaddr
	./testrfcaddr

depend:
	@rm -f Makefile.bak; \
	mv Makefile Makefile.bak; \
	sed -e '/^# DO NOT DELETE/,$$d' Makefile.bak >Makefile; \
	${ECHO} '# DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT' \
		>>Makefile; \
	${ECHO} '# Dependencies generated by make depend' >>Makefile; \
	for f in ${SRCS}; \
	do \
		${ECHO} "Dependencies for $$f:\c"; \
		${ECHO} "`basename $$f .c`.o:\c" >>Makefile; \
		for h in `sed -n -e \
			's/^#[ 	]*include[ 	]*"\([^"]*\)".*/\1/p' $$f`; \
		do \
			${ECHO} " $$h\c"; \
			${ECHO} " $$h\c" >>Makefile; \
		done; \
		${ECHO} " done."; \
		${ECHO} "" >>Makefile; \
	done; \
	${ECHO} '# End of generated dependencies' >>Makefile

# DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT
# Dependencies generated by make depend
lutil.o:
xutil.o: xutil.h lutil.h
ulock.o: lutil.h
rfcdate.o:
sequencer.o: lutil.h config.h
ftnmsg.o: lutil.h bwrite.h ftn.h ftnmsg.h
hdr.o: xutil.h lutil.h rfcmsg.h
crc.o:
strcasestr.o:
strncasecmp.o:
strcasecmp.o:
rename.o:
mkdir.o:
parsedate.y.o: configdata.h libinn.h macros.h
gettime.o: configdata.h clibrary.h libinn.h
rdconfig.o: xutil.h lutil.h ftn.h config.h charset.h
ftn.o: lutil.h xutil.h ftn.h rfcaddr.h config.h mime.h
packet.o: xutil.h lutil.h ftn.h config.h bwrite.h
pktname.o: directory.h lutil.h xutil.h ftn.h config.h
bwrite.o: bwrite.h config.h
bread.o: bread.h config.h
getheader.o: lutil.h xutil.h ftn.h bread.h config.h
scanout.o: directory.h xutil.h config.h ftn.h scanout.h lutil.h
matchaka.o: ftn.h lutil.h config.h
usleep.o:
execute.o: lutil.h
execsh.o: lutil.h
signal.o:
regexpr.o:
atoul.o:
nodelock.o: xutil.h lutil.h ftn.h
trap.o: lutil.h trap.h lutil.h
rfcaddr.o: xutil.h rfcaddr.h
expipe.o: lutil.h
callstat.o: lutil.h ftn.h callstat.h
setprocn.o:
ref.o: config.h ref_interface.h lutil.h
charset.o: lutil.h xutil.h rfcmsg.h needed.h config.h mime.h charset.h
mime.o: needed.h lutil.h xutil.h
cleanup_ref.o: config.h ref_interface.h
make_new_ref.o: config.h ref_interface.h
tmpfile.o:
dirent.o: directory.h
lhash.o: lhash.h
hash.o: hash.h lhash.h
falists.o: xutil.h lutil.h ftn.h falists.h
# End of generated dependencies
