#
#	@(#)%M%  %I%  Teemu Torma %H%
#
#	Makefile for FidoNet routines
#
#	@(#)Copyright (C) Teemu Torma 1987
#
ENA	=	
SHELL	=	/bin/sh
INCLUDE	=	/usr/include
#
# Use cp if you want sources and lib dir to be on another file system
#
MOVER	=	echo
#
# Add -DSAFE_STDIO_ROUTINES to not to use macros for several stdio routines
# Use -g for debugging, -O for optimizer
#
CFLAGS	=	-g -DSAFE_STDIO_ROUTINES
#
# Define -s to strip
#
LDFLAGS	=
LNFLAGS	=

FUNPACK	=	funpack.o funcs.o nodelist.o gethostname.o address.o \
		getdate.o ftime.o sprintfs.o strempty.o \
		config.o tempfile.o bsearch.o vsprintf.o vfprintf.o

LFUNPACK=	funpack.ln funcs.ln nodelist.ln gethostname.ln address.ln \
		ftime.ln sprintfs.ln strempty.ln config.ln tempfile.ln \
		bsearch.ln vsprintf.ln vfprintf.ln

RMAIL	=	rmail.o address.o funcs.o sprintfs.o config.o nodelist.o \
		bsearch.o vsprintf.o vfprintf.o

LRMAIL	=	rmail.ln address.ln funcs.ln sprintfs.ln config.ln \
		nodelist.ln bsearch.ln vsprintf.ln vfprintf.ln

RFMAIL	=	rfmail.o funcs.o nodelist.o gethostname.o address.o getdate.o \
		ftime.o sprintfs.o strempty.o config.o bsearch.o \
		vsprintf.o vfprintf.o

LRFMAIL	=	rfmail.ln funcs.ln nodelist.ln gethostname.ln address.ln \
		ftime.ln sprintfs.ln strempty.ln config.ln bsearch.ln \
		vsprintf.ln vfprintf.ln

RFNEWS	=	rfnews.o funcs.o nodelist.o address.o sprintfs.o config.o \
		tempfile.o bsearch.o vsprintf.o vfprintf.o

LRFNEWS	=	rfnews.ln funcs.ln nodelist.ln address.ln sprintfs.ln \
		config.ln tempfile.ln bsearch.ln vsprintf.ln vfprintf.ln

FPACK	=	fpack.o funcs.o nodelist.o address.o sprintfs.o config.o \
		bsearch.o vsprintf.o vfprintf.o

LFPACK	=	fpack.ln funcs.ln nodelist.ln address.ln sprintfs.ln \
		config.ln bsearch.ln vsprintf.ln vfprintf.ln

FCALL	=	fcall.o funcs.o fio.o xtsend.o xtrec.o crc.o nodelist.o \
		address.o sprintfs.o config.o bsearch.o vsprintf.o vfprintf.o \
		dial.o createlock.o removelock.o

LFCALL	=	fcall.ln funcs.ln fio.ln xtsend.ln xtrec.ln crc.ln \
		nodelist.ln address.ln sprintfs.ln config.ln bsearch.ln \
		vsprintf.ln vfprintf.ln dial.ln

RFCONFIG	=	rfconfig.o funcs.o config.o sprintfs.o nodelist.o \
			address.o bsearch.o vsprintf.o vfprintf.o

LRFCONFIG	=	rfconfig.ln funcs.ln config.ln sprintfs.ln \
			nodelist.ln address.ln bsearch.ln \
			vsprintf.ln vfprintf.ln

CFILES	=	rfmail.c funcs.c rfnews.c rmail.c fpack.c funpack.c fcall.c \
                fio.c xtsend.c xtrec.c nodelist.c gethostname.c dateconv.c \
                address.c crc.c lintlib.c sprintfs.c config.c rfconfig.c \
		strempty.c ftime.c tempfile.c bsearch.c vsprintf.c \
		vfprintf.c dial.c createlock.c removelock.c

HFILES	=	fnet.h config.h fpack.h rmail.h fio.h crc.h hsu.h shuffle.h \
		sysexits.h nodelist.h fnews.h longnames.h unistd.h \
		directory.h configs.h

OTHERFILES	=	README HISTORY INSTALL LICENCE NOTES PROBLEMS \
			TODO THANKS Alias rfmail.cf fcaller Makefile \
			getdate.y packer fnetdemon.day alloca.s

# Add -lbsd or ndir or whatever to include posix-compatible scandir
LIBS	=
# Add rmail to build rmail
ALL	=	funpack fcall fpack rfmail rfnews rmail rfconfig
OWNER	=	hsu
GROUP	=	other

# These should be those in "config.h", helps in installing the stuff
# (jari@krkct)

LIBDIR	=	/usr/lib/fnet
SPOOLDIR=	/usr/spool/fnet
DIRS	=	$(LIBDIR) $(SPOOLDIR) $(SPOOLDIR)/unpacked \
		$(SPOOLDIR)/sentbundles $(SPOOLDIR)/bad

# This should be where real rmail is (see "rmail.h")
RMAIL_LIB = 	/usr/lib

OTHERS	= 	d de fcaller fnetdemon.day Alias rfmail.cf

.c.ln: $<
	lint -c $(LNFLAGS) $<

.SUFFIXES: .ln

all:		${ALL}
	touch all

getdate.o: getdate.y
	@echo "expect 8 shift/reduce conflicts"
	yacc getdate.y
	mv y.tab.c getdate.c
	$(CC) $(CFLAGS) -c getdate.c
	-rm -f getdate.c

funpack:	${FUNPACK}
	cc ${LDFLAGS} -o funpack ${FUNPACK} ${LIBS}

rfmail:		${RFMAIL}
	cc ${LDFLAGS} -o rfmail ${RFMAIL} ${LIBS}

rfnews:		${RFNEWS}
	cc ${LDFLAGS} -o rfnews ${RFNEWS} ${LIBS}

fpack:		${FPACK}
	cc ${LDFLAGS} -o fpack ${FPACK} ${LIBS}

fcall:		${FCALL}
	cc ${LDFLAGS} -o fcall ${FCALL} ${LIBS}

rmail:		${RMAIL}
	cc ${LDFLAGS} -o rmail ${RMAIL} ${LIBS}

rfconfig:	$(RFCONFIG)
	cc $(LDFLAGS) -o rfconfig $(RFCONFIG) $(LIBS)

# The following is more shell independent with older dumb make preprocessors
# jari@krkct

install:	all
	@for i in $(DIRS); \
	do \
		if [ ! -d $$i ] ; then echo "Creating directory $$i ... \c"; \
			$(ENA) mkdir $$i; \
			$(ENA) chown ${OWNER} $$i; \
			$(ENA) chgrp ${GROUP} $$i; \
			$(ENA) chmod 750 $$i; \
			echo "done."; \
		fi; \
	done
	@echo "Moving ${ALL} into ${LIBDIR}
	-$(ENA) $(MOVER) ${ALL} ${LIBDIR} > /dev/null
	@echo "Changing ownerships and modes"
	@cd ${LIBDIR} ; chown ${OWNER} ${ALL}; chgrp ${GROUP} ${ALL}; \
		chmod 4111 ${ALL}
	@echo "Moving ${OTHERS} into ${LIBDIR}
	-$(ENA) $(MOVER) ${OTHERS} ${LIBDIR} > /dev/null
	@echo "Changing ownerships"
	@cd ${LIBDIR} ; chown ${OWNER} ${OTHERS}; chgrp ${GROUP} ${OTHERS}
	@echo "\nGet a nodelist, remove ^M:s and ^Z:s and move it to ${LIBDIR}."
	@echo "\nDONE."

# jari@krkct

testaus:	all
	@echo "TESTAUS"
	@for i in ${ALL}; \
	do \
		echo "Moving $$i into ${LIBDIR} ... \c"; \
		$(ENA) $(MOVER) $$i ${LIBDIR} > /dev/null; \
		$(ENA) chown ${OWNER} ${LIBDIR}/$$i; \
		$(ENA) chgrp ${GROUP} ${LIBDIR}/$$i; \
		$(ENA) chmod 4111 ${LIBDIR}/$$i; \
		echo "done."; \
	done
	@echo "END TESTAUS"

# Use this if you don't have a proper mailer (see rmail.c)

rmail-install:	rmail
	@if [ ! -f $(RMAIL_LIB)/rmail ]; then \
		echo "Changing /bin/rmail ... \c"; \
		$(ENA) ln /bin/rmail $(RMAIL_LIB)/rmail; \
		$(ENA) rm /bin/rmail; \
		$(ENA) cp rmail /bin; \
		$(ENA) chmod 2755 /bin/rmail; \
		$(ENA) chown bin /bin/rmail; $(ENA) chgrp mail /bin/rmail; \
		echo "done."; \
	else echo "$(RMAIL_LIB)/rmail exists, updating /bin/rmail ... \c"; \
		$(ENA) cp rmail /bin; \
		$(ENA) chmod 2755 /bin/rmail; \
		$(ENA) chown bin /bin/rmail; $(ENA) chgrp mail /bin/rmail; \
		echo "done."; \
	fi

lintlib.ln:	lintlib.c
	lint -c -x lintlib.c

lfunpack: $(LFUNPACK) lintlib.ln
	lint $(LFUNPACK) lintlib.ln $(LIBS)
	touch lfunpack

lrmail: $(LRMAIL) lintlib.ln
	lint $(LRMAIL) lintlib.ln $(LIBS)
	touch lrmail

lrfmail: $(LRFMAIL) lintlib.ln
	lint $(LRFMAIL) lintlib.ln $(LIBS)
	touch lrfmail

lrfnews: $(LRFNEWS) lintlib.ln
	lint $(LRFNEWS) lintlib.ln $(LIBS)
	touch lrfnews

lfpack: $(LFPACK) lintlib.ln
	lint $(LFPACK) lintlib.ln $(LIBS)
	touch lfpack

lfcall: $(LFCALL) lintlib.ln
	lint $(LFCALL) lintlib.ln $(LIBS)
	touch lfcall

lrfconfig: $(LRFCONFIG) lintlib.ln
	lint $(LRFCONFIG) lintlib.ln $(LIBS)
	touch lrfconfig

lint:	lfunpack lfcall lfpack lrfmail lrfnews lrfconfig lrmail

tar:
	tar cvf - $(OTHERFILES) $(CFILES) $(HFILES) | compress > fnet.tar.Z

initsccs:
	@if [ -d SCCS ];						\
	then								\
	  echo "Directory SCCS/ already exist.";			\
	  exit 1;							\
	fi;								\
	echo "Creating directory SCCS/...";				\
	mkdir SCCS;							\
	for file in ${SCCS};						\
	do								\
	  echo "Creating SCCS/s.$$file...";				\
	  admin -i$$file SCCS/s.$$file;					\
	  if [ $$? -eq 0 ];						\
	    then							\
	      echo "Getting file SCCS/s.$$file...";			\
	      rm -f $$file;						\
	      get SCCS/s.$$file;					\
	    fi;								\
	done

edit:
	get -e $(OTHERFILES) $(CFILES) $(HFILES)

look:
	get $(OTHERFILES) $(CFILES) $(HFILES)

delta:
	delta $(OTHERFILES) $(CFILES) $(HFILES)

shar:
	shar -vc -l60 -ofnetdist. $(OTHERFILES) ${CFILES} ${HFILES}

# change previous version number here
diff:
	diff -c $(OTHERFILES) $(CFILES) $(HFILES) fnetdist/0.3.3

clean:
	-rm lfunpack lrmail lrfmail lrfnews lfpack lfcall
	-rm funpack rfmail rfnews fpack fcall rmail
	-rm *.ln *.o .make .funpack .lint log loki
	-rm *.idx

depend:
	@echo '/^# DO NOT/+1,$$d\nw\nq' | ed - Makefile; \
	echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile; \
	for i in ${CFILES} ; \
	do \
		if [ -r $$i ]; \
		then \
			echo "Finding dependences for $$i ... \c"; \
			for j in `grep '^#[ 	]*include[ 	]*"[^"]*"' < $$i | \
				sed 's/^#[ 	]*include[ 	]*"\([^"]*\)".*/\1/'`; \
			do \
				if [ -r $$j ]; \
				then \
					echo "`basename $$i .c`.o: $$j" >> Makefile; \
					echo "`basename $$i .c`.ln: $$j" >> Makefile; \
				else \
					echo "`basename $$i .c`.o: ${HEADERS}/$$j" \
        					>> Makefile; \
					echo "`basename $$i .c`.ln: ${HEADERS}/$$j" \
						>> Makefile; \
				fi; \
			done; \
			echo "done."; \
		else \
			echo "Can not open $$i." 1>&2; \
		fi; \
	done; \
	echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile; \
	echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile; \
	echo '# see make depend above' >> Makefile

# DO NOT DELETE THIS LINE -- make depend uses it
# DEPENDENCIES MUST END AT END OF FILE
rfmail.o: hsu.h
rfmail.ln: hsu.h
rfmail.o: config.h
rfmail.ln: config.h
rfmail.o: fnet.h
rfmail.ln: fnet.h
rfmail.o: nodelist.h
rfmail.ln: nodelist.h
rfmail.o: configs.h
rfmail.ln: configs.h
funcs.o: hsu.h
funcs.ln: hsu.h
funcs.o: config.h
funcs.ln: config.h
funcs.o: fnet.h
funcs.ln: fnet.h
funcs.o: sysexits.h
funcs.ln: sysexits.h
funcs.o: nodelist.h
funcs.ln: nodelist.h
funcs.o: shuffle.h
funcs.ln: shuffle.h
funcs.o: configs.h
funcs.ln: configs.h
rfnews.o: hsu.h
rfnews.ln: hsu.h
rfnews.o: config.h
rfnews.ln: config.h
rfnews.o: fnet.h
rfnews.ln: fnet.h
rfnews.o: fnews.h
rfnews.ln: fnews.h
rfnews.o: nodelist.h
rfnews.ln: nodelist.h
rfnews.o: configs.h
rfnews.ln: configs.h
rmail.o: hsu.h
rmail.ln: hsu.h
rmail.o: rmail.h
rmail.ln: rmail.h
rmail.o: config.h
rmail.ln: config.h
rmail.o: sysexits.h
rmail.ln: sysexits.h
rmail.o: nodelist.h
rmail.ln: nodelist.h
rmail.o: fnet.h
rmail.ln: fnet.h
fpack.o: hsu.h
fpack.ln: hsu.h
fpack.o: config.h
fpack.ln: config.h
fpack.o: directory.h
fpack.ln: directory.h
fpack.o: fnet.h
fpack.ln: fnet.h
fpack.o: fpack.h
fpack.ln: fpack.h
fpack.o: nodelist.h
fpack.ln: nodelist.h
fpack.o: configs.h
fpack.ln: configs.h
funpack.o: hsu.h
funpack.ln: hsu.h
funpack.o: config.h
funpack.ln: config.h
funpack.o: directory.h
funpack.ln: directory.h
funpack.o: fnet.h
funpack.ln: fnet.h
funpack.o: fpack.h
funpack.ln: fpack.h
funpack.o: nodelist.h
funpack.ln: nodelist.h
funpack.o: sysexits.h
funpack.ln: sysexits.h
funpack.o: fnews.h
funpack.ln: fnews.h
funpack.o: configs.h
funpack.ln: configs.h
fcall.o: hsu.h
fcall.ln: hsu.h
fcall.o: config.h
fcall.ln: config.h
fcall.o: directory.h
fcall.ln: directory.h
fcall.o: fnet.h
fcall.ln: fnet.h
fcall.o: fio.h
fcall.ln: fio.h
fcall.o: nodelist.h
fcall.ln: nodelist.h
fcall.o: configs.h
fcall.ln: configs.h
fio.o: hsu.h
fio.ln: hsu.h
fio.o: fnet.h
fio.ln: fnet.h
fio.o: fio.h
fio.ln: fio.h
xtsend.o: hsu.h
xtsend.ln: hsu.h
xtsend.o: fnet.h
xtsend.ln: fnet.h
xtsend.o: fio.h
xtsend.ln: fio.h
xtsend.o: crc.h
xtsend.ln: crc.h
xtrec.o: hsu.h
xtrec.ln: hsu.h
xtrec.o: fnet.h
xtrec.ln: fnet.h
xtrec.o: fio.h
xtrec.ln: fio.h
xtrec.o: crc.h
xtrec.ln: crc.h
nodelist.o: hsu.h
nodelist.ln: hsu.h
nodelist.o: config.h
nodelist.ln: config.h
nodelist.o: fnet.h
nodelist.ln: fnet.h
nodelist.o: nodelist.h
nodelist.ln: nodelist.h
nodelist.o: configs.h
nodelist.ln: configs.h
dateconv.o: fnet.h
dateconv.ln: fnet.h
address.o: hsu.h
address.ln: hsu.h
address.o: config.h
address.ln: config.h
address.o: fnet.h
address.ln: fnet.h
address.o: nodelist.h
address.ln: nodelist.h
address.o: shuffle.h
address.ln: shuffle.h
address.o: configs.h
address.ln: configs.h
lintlib.o: hsu.h
lintlib.ln: hsu.h
lintlib.o: config.h
lintlib.ln: config.h
sprintfs.o: hsu.h
sprintfs.ln: hsu.h
config.o: hsu.h
config.ln: hsu.h
config.o: config.h
config.ln: config.h
config.o: fnet.h
config.ln: fnet.h
config.o: nodelist.h
config.ln: nodelist.h
config.o: configs.h
config.ln: configs.h
rfconfig.o: hsu.h
rfconfig.ln: hsu.h
rfconfig.o: config.h
rfconfig.ln: config.h
strempty.o: hsu.h
strempty.ln: hsu.h
ftime.o: hsu.h
ftime.ln: hsu.h
# DEPENDENCIES MUST END AT END OF FILE
# IF YOU PUT STUFF HERE IT WILL GO AWAY
# see make depend above
