#:ts=8
#
#    $Id: Makefile,v 3.8.0.7 1994/10/04 07:04:45 mj Exp mj $
#
#    Makefile for FIDOGATE software
#
# OS2 = OS/2 with EMX GCC
#

# OS2: comment out
SHELL		= /bin/sh

#
# ----- Start configuration defines ------------------------------------------
#
BINDIR		= /usr/local/bin
LIBDIR		= /usr/local/lib/fidonet
SPOOLDIR	= /usr/spool/fidonet

OWNER		= news
GROUP		= news

PERM_PROG	= 755
PERM_DATA	= 644
PERM_SETUID	= 4755
PERM_DIR	= 755

#
# C compiler / flags
#
CC		= gcc
#YACC		= yacc					# Use yacc, not bison
YACC		= bison -y
AR		= ar
#RANLIB		= @echo >/dev/null			# No ranlib
RANLIB		= ranlib
#RANLIB		= ar s					# OS2

#CFLAGS		= -g -Wall -posix -DISC			# ISC 3.x
#CFLAGS		= -g -Wall -DOS2			# OS2
CFLAGS		= -g -Wall

#LFLAGS		= -Zexe -g -L.				# OS2
LFLAGS		= -g -L.

#LIBS		= -lfidogate -linet -lPW -lcposix	# ISC 3.x
LIBS		= -lfidogate

# ISC 3.x: use bsdinst
INSTALL_PROG	= install -g $(GROUP) -o $(OWNER) -m $(PERM_PROG)
INSTALL_DATA	= install -g $(GROUP) -o $(OWNER) -m $(PERM_DATA)
INSTALL_SETUID	= install -g $(GROUP) -o $(OWNER) -m $(PERM_SETUID)
INSTALL_DIR	= install -g $(GROUP) -o $(OWNER) -m $(PERM_DIR) -d

#LIB		= fidogate.a			# OS2
LIB		= libfidogate.a

#
# ----- End configuration defines --------------------------------------------
#
# Normally it should not be necessary to change anything below this line
#

OBJS		= address.o aliases.o areas.o areasbbs.o binkley.o\
		  bounce.o bufstring.o charset.o config.o crc16.o crc32.o\
		  date.o exit.o fopen.o getopt.o getopt1.o\
		  gettime.o hosts.o kludge.o lock.o log.o mail.o maus.o\
		  message.o misc.o msgid.o node.o outpkt.o packet.o passwd.o\
		  parsedate.o read.o rfcaddr.o rfcheader.o routing.o\
		  sequencer.o textlist.o version.o wildmat.o\
		  xalloc.o xstrtok.o


PROGS		= ftn2rfc rfc2ftn toaddr fidorun ftnin ftn2ftn\
		  out-attach pktdebug sumcrc mail2news\
		  ftnaf ftnbounce ftntoss ftnroute ftnpack ftnlock runtoss\
		  ffx ffxqt ffxbatch ffxmail ffxrun

#
# Compiling
#
.c.o:
	$(CC) $(CFLAGS) -c $<

.o:
	$(CC) $(LFLAGS) -o $* $*.o $(LIBS)


all:		paths.mak $(PROGS)


$(LIB):		$(OBJS)
	rm -f $(LIB)
	$(AR) r $(LIB) $(OBJS)
	$(RANLIB) $(LIB)

parsedate.c:	parsedate.y
	@echo "expect 6 shift/reduce conflicts"
	$(YACC) parsedate.y
	mv y.tab.c parsedate.c

paths.mak:	Makefile
	@echo '/*'                                          > paths.mak
	@echo ' * Automatically generated --- do not edit!' >>paths.mak
	@echo ' */'                                         >>paths.mak
	@echo '#define BINDIR   "$(BINDIR)"'                >>paths.mak
	@echo '#define LIBDIR   "$(LIBDIR)"'                >>paths.mak
	@echo '#define SPOOLDIR "$(SPOOLDIR)"'              >>paths.mak
	diff paths.mak paths.h || cp paths.mak paths.h


rfc2ftn:	$(LIB)
ftn2ftn:	$(LIB)
ftn2rfc:	$(LIB)
toaddr:		$(LIB)
ftnin:		$(LIB)
mail2news:	$(LIB)
out-attach:	$(LIB)
pktdebug:	$(LIB)
ffx:		$(LIB)
ffxqt:		$(LIB)
ffxbatch:	$(LIB)
sumcrc:		$(LIB)
ftnaf:		$(LIB)
ftnbounce:	$(LIB)
ftntoss:	$(LIB)
ftnroute:	$(LIB)
ftnpack:	$(LIB)
ftnlock:	$(LIB)


fidorun:	fidorun.sh
	sed -e 's+??SPOOL??+$(SPOOLDIR)+g' \
	    -e 's+??LIB??+$(LIBDIR)+g' fidorun.sh >fidorun
	chmod +x fidorun
ffxmail:	ffxmail.sh
	sed -e 's+??LIB??+$(LIBDIR)+g' ffxmail.sh >ffxmail
	chmod +x ffxmail
ffxrun:		ffxrun.sh
	sed -e 's+??LIB??+$(LIBDIR)+g' ffxrun.sh >ffxrun
	chmod +x ffxrun
runtoss:	runtoss.sh
	sed -e 's+??SPOOL??+$(SPOOLDIR)+g' \
	    -e 's+??LIB??+$(LIBDIR)+g' runtoss.sh >runtoss
	chmod +x runtoss


testdate:	$(LIB)
testdate.o:	parsedate.c
	$(CC) $(CFLAGS) -DTEST -c parsedate.c -o testdate.o
testrfc:	$(LIB)
testrfc.o:	rfcheader.c
	$(CC) $(CFLAGS) -DTEST -c rfcheader.c -o testrfc.o
testxx:		testxx.o $(LIB)
testcrc32:	crc32.c
	$(CC) $(LFLAGS) -DTEST -o testcrc32 crc32.c


install-gate:
	$(INSTALL_SETUID)  rfc2ftn    $(LIBDIR)
	$(INSTALL_PROG)   ftn2rfc    $(LIBDIR)
	$(INSTALL_PROG)   fidorun    $(LIBDIR)
	$(INSTALL_PROG)   toaddr     $(LIBDIR)
	$(INSTALL_PROG)   ftnin      $(LIBDIR)

install-ftngate:
	$(INSTALL_PROG)   ftn2ftn    $(LIBDIR)

install-ffx:
	$(INSTALL_SETUID)  ffx        $(LIBDIR)
	$(INSTALL_PROG)   ffxqt      $(LIBDIR)
	$(INSTALL_PROG)   ffxbatch   $(LIBDIR)
	$(INSTALL_PROG)   ffxmail    $(LIBDIR)
	$(INSTALL_PROG)   ffxrun     $(LIBDIR)

install-util:
	$(INSTALL_PROG)   mail2news  $(LIBDIR)
	$(INSTALL_PROG)   out-attach $(BINDIR)
	$(INSTALL_PROG)   pktdebug   $(BINDIR)
	$(INSTALL_PROG)   sumcrc     $(BINDIR)

install-ftnaf:
	$(INSTALL_SETUID)  ftnaf      $(LIBDIR)

install-tosser:
	$(INSTALL_PROG)   ftntoss    $(LIBDIR)
	$(INSTALL_PROG)   ftnroute   $(LIBDIR)
	$(INSTALL_PROG)   ftnpack    $(LIBDIR)
	$(INSTALL_PROG)   ftnlock    $(LIBDIR)
	$(INSTALL_PROG)   runtoss    $(LIBDIR)

install-dirs:
	$(INSTALL_DIR)    $(LIBDIR)
	$(INSTALL_DIR)    $(SPOOLDIR)
	$(INSTALL_DIR)    $(SPOOLDIR)/in
	$(INSTALL_DIR)    $(SPOOLDIR)/in/mail
	$(INSTALL_DIR)    $(SPOOLDIR)/in/news
	$(INSTALL_DIR)    $(SPOOLDIR)/in/bad
	$(INSTALL_DIR)    $(SPOOLDIR)/insecure
	$(INSTALL_DIR)    $(SPOOLDIR)/out
	$(INSTALL_DIR)    $(SPOOLDIR)/locks
	$(INSTALL_DIR)    $(SPOOLDIR)/toss
	$(INSTALL_DIR)    $(SPOOLDIR)/in
	$(INSTALL_DIR)    $(SPOOLDIR)/tmp
	$(INSTALL_DIR)    $(SPOOLDIR)/out

install:	install-gate install-ftngate install-ffx\
		install-util install-ftnaf   install-tosser
	

clean:
	rm -f testdate testdate.c testrfc testrfc.c testxx testcrc32
	rm -f $(PROGS) $(LIB)
	rm -f *~ *.bak *.o tags TAGS core paths.tmp


#
# Dependencies
#
depend:
	$(CC) -MM *.c >.depend

depend-all:
	$(CC) -M *.c >.depend
		
include .depend
