# $Id: Makefile-in,v 1.1 1997/07/06 14:34:49 eilts Exp eilts $
SHELL = /bin/sh

CC = X_CC

CFLAGS = X_CFLAGS
#
# NNTPNEWS    enable NetNews over NNTP
#
# NO_TV_USEC  disables automatic Z-Modem Uploads, which wants a timer with a
#             high resolution (subroutine microtime with gettimeofday)
# NO_REGCOMP  if your system has no regcomp()
# NO_RZ_BFLAG if rz has no option '-b'
# NO_MMAP     if your system has no mmap()
# NO_SETSID   if your system has no setsid()
# NO_PUTENV   if yuor system has no putenv()
# NO_USLEEP   if your system has no usleep()
# NO_MEMSET   if your system has no memset()
# NO_RANDOM   if your system has no random()
# NO_LRAND48  if your system has no lrand48()
# NO_CRYPT    if your system has no crypt()
# NO_NCURSES  if your system has no ncurses but (old) curses
# NO_DBOPEN   if your system has no dbopen (Berkeley new db)
#
# NeXT wants -posix and forbidds -ansi -pedantic
#

# for make depend
MKDEPFLAG = X_MKDEPFLAG

# directory to install
INSTALLDIR = X_INSTALLDIR

# chroot-directory for clients
CHROOTDIR = X_CHROOTDIR

# owner and group of clients
BBS_OWNER = X_BBS_OWNER
BBS_GROUP = X_BBS_GROUP
# owner and group of daemon
BBSD_OWNER = X_BBSD_OWNER
BBSD_GROUP = X_BBSD_GROUP
# SUID of daemon
BBSD_SUID = X_BBSD_SUID

# Table of terminal types
TERMTABLE = X_TERMTABLE
TERMTABPATH = X_TERMTABPATH

OBJ_COM = stringstuff.o msg.o filesys.o sysstuff.o bbsdstuff-com.o nntp-com.o \
          mailstuff.o
OBJ_BBS = bbs.o execute.o tliste.o talk.o userrw.o signal.o do.o menue.o \
          windowstuff.o edit.o bbsdstuff.o errorstuff.o mail.o news.o nntp.o
OBJ_BBSD = bbsdaemon.o daction.o dbase.o errorstuff_d.o
OBJ_MAIL = bbsmail.o errorstuff_m.o

LIBSC = X_LIBSC
LIBSD = X_LIBSD

REV=
RCSFILES = bbs.c do.c menue.c sysstuff.c windowstuff.c bbsdaemon.c bbsmail.c \
           errorstuff.c msg.c talk.c bbsdstuff.c bbsdstuff-com.c execute.c \
	   signal.c tliste.c daction.c filesys.c stringstuff.c userrw.c \
	   dbase.c mail.c mailstuff.c edit.c \
           bbs.h bbs_charcodes.h bbs_decl.h bbs_types.h bbskeys.h edit.h \
	   nntp.h bbssetproctitle.h \
           Configure \
	   conf/templates/Makefile-in conf/templates/local-in.h \
           conf/templates/bbs.conf-in conf/templates/users-in \
           conf/templates/kermrc-in conf/templates/bbsmail.m4-in

all: bbs bbsd bbsmail

bbs: $(OBJ_BBS) $(OBJ_COM)
	$(CC) $(CFLAGS) -o $@ $(OBJ_BBS) $(OBJ_COM) $(LIBSC)

bbsd: $(OBJ_BBSD) $(OBJ_COM)
	$(CC) $(CFLAGS) -o $@ $(OBJ_BBSD) $(OBJ_COM) $(LIBSD)

bbsmail: $(OBJ_MAIL) $(OBJ_COM)
	$(CC) $(CFLAGS) -o $@ $(OBJ_MAIL) $(OBJ_COM) $(LIBSD)

errorstuff_d.o: errorstuff.c
	$(CC) $(CFLAGS) -c -o $@ -DBBSD_SOURCE $?
errorstuff_m.o: errorstuff.c
	$(CC) $(CFLAGS) -c -o $@ -DBBSMAIL_SOURCE $?

install: all
	if [ ! -d $(INSTALLDIR) ]; then X_MKDIR $(INSTALLDIR); fi
	if [ ! -d $(INSTALLDIR)/mail ]; then X_MKDIR $(INSTALLDIR)/mail; fi
	if [ ! -d $(INSTALLDIR)/help ]; then X_MKDIR $(INSTALLDIR)/help; fi
	if [ ! -d $(INSTALLDIR)/etc ]; then X_MKDIR $(INSTALLDIR)/etc; fi
	if [ ! -d $(INSTALLDIR)/scratch ]; then X_MKDIR $(INSTALLDIR)/scratch; fi
	X_INSTALL -c -m 111 -o $(BBS_OWNER) -g $(BBS_GROUP) bbs $(INSTALLDIR)
	X_INSTALL -c -m 555 -o $(BBS_OWNER) -g $(BBS_GROUP) bbs-guest $(INSTALLDIR)
	X_INSTALL -c -m 111 -o $(BBSD_OWNER) -g $(BBSD_GROUP) bbsmail $(INSTALLDIR)
	if [ -z "$(BBSD_SUID)" ]; then\
	  X_INSTALL -c -m 111 -o $(BBSD_OWNER) -g $(BBSD_GROUP) bbsd $(INSTALLDIR);\
 	else\
	  X_INSTALL -c -m 4111 -o $(BBSD_OWNER) -g $(BBSD_GROUP) bbsd $(INSTALLDIR);\
	fi
	if [ -n "$(TERMTABLE)" ]; then\
	  X_INSTALL -c -m 444 -o $(BBSD_OWNER) -g $(BBSD_GROUP) conf/term/$(TERMTABLE) $(TERMTABPATH);\
	fi
	X_INSTALL -c -m 444 -o $(BBSD_OWNER) -g $(BBSD_GROUP) bbs.conf $(INSTALLDIR)
	X_INSTALL -c -m 444 -o $(BBSD_OWNER) -g $(BBSD_GROUP) kermrc $(INSTALLDIR)/etc
	X_INSTALL -c -m 444 -o $(BBSD_OWNER) -g $(BBSD_GROUP) users $(INSTALLDIR)/etc
	X_CP help/* $(INSTALLDIR)/help
	X_CHOWN $(BBS_OWNER) $(INSTALLDIR) $(INSTALLDIR)/help
	X_CHGRP $(BBS_GROUP) $(INSTALLDIR) $(INSTALLDIR)/help
	X_CHOWN $(BBSD_OWNER) $(INSTALLDIR)/mail
	X_CHGRP $(BBSD_GROUP) $(INSTALLDIR)/mail
	X_CHOWN $(BBSD_OWNER) $(INSTALLDIR)/etc
	X_CHGRP $(BBSD_GROUP) $(INSTALLDIR)/etc
	X_CHOWN $(BBS_OWNER) $(INSTALLDIR) $(INSTALLDIR)/scratch
	X_CHGRP $(BBS_GROUP) $(INSTALLDIR) $(INSTALLDIR)/scratch
	X_CHMOD 555 $(INSTALLDIR) $(INSTALLDIR)/help
	X_CHMOD 755 $(INSTALLDIR)/etc
	X_CHMOD 755 $(INSTALLDIR)/mail
	X_CHMOD 777 $(INSTALLDIR)/scratch
	X_CHOWN $(BBS_OWNER) $(INSTALLDIR)/help/*
	X_CHGRP $(BBS_GROUP) $(INSTALLDIR)/help/*
	X_CHMOD 444 $(INSTALLDIR)/help/*
	if [ ! -d $(CHROOTDIR) ]; then\
	  X_MKDIR $(CHROOTDIR); \
	  X_CHOWN $(BBS_OWNER) $(CHROOTDIR); \
	  X_CHGRP $(BBS_GROUP) $(CHROOTDIR); \
	  X_CHMOD -R 555 $(CHROOTDIR); \
	fi
	@echo "NOW CHANGE PASSWORDS"

test-install: all
	if [ ! -d $(INSTALLDIR) ]; then X_MKDIR $(INSTALLDIR); fi
	if [ ! -d $(INSTALLDIR)/mail ]; then X_MKDIR $(INSTALLDIR)/mail; fi
	if [ ! -d $(INSTALLDIR)/help ]; then X_MKDIR $(INSTALLDIR)/help; fi
	if [ ! -d $(INSTALLDIR)/etc ]; then X_MKDIR $(INSTALLDIR)/etc; fi
	if [ ! -d $(INSTALLDIR)/scratch ]; then X_MKDIR $(INSTALLDIR)/scratch; fi
	X_INSTALL -c -m 711 -o $(BBS_OWNER) -g $(BBS_GROUP) bbs $(INSTALLDIR)
	X_INSTALL -c -m 755 -o $(BBS_OWNER) -g $(BBS_GROUP) bbs-guest $(INSTALLDIR)
	X_INSTALL -c -m 711 -o $(BBSD_OWNER) -g $(BBSD_GROUP) bbsmail $(INSTALLDIR)
	if [ -z "$(BBSD_SUID)" ]; then\
	  X_INSTALL -c -m 711 -o $(BBSD_OWNER) -g $(BBSD_GROUP) bbsd $(INSTALLDIR);\
	else\
	  X_INSTALL -c -m 4711 -o $(BBSD_OWNER) -g $(BBSD_GROUP) bbsd $(INSTALLDIR);\
	fi
	if [ -n "$(TERMTABLE)" ]; then\
	  X_INSTALL -c -m 644 -o $(BBSD_OWNER) -g $(BBSD_GROUP) conf/term/$(TERMTABLE) $(TERMTABPATH);\
	fi
	X_INSTALL -c -m 644 -o $(BBSD_OWNER) -g $(BBSD_GROUP) bbs.conf $(INSTALLDIR)
	X_INSTALL -c -m 644 -o $(BBSD_OWNER) -g $(BBSD_GROUP) kermrc $(INSTALLDIR)/etc
	X_INSTALL -c -m 644 -o $(BBSD_OWNER) -g $(BBSD_GROUP) users $(INSTALLDIR)/etc
	X_CP help/* $(INSTALLDIR)/help
	X_CHOWN $(BBS_OWNER) $(INSTALLDIR) $(INSTALLDIR)/help
	X_CHGRP $(BBS_GROUP) $(INSTALLDIR) $(INSTALLDIR)/help
	X_CHOWN $(BBSD_OWNER) $(INSTALLDIR)/mail
	X_CHGRP $(BBSD_GROUP) $(INSTALLDIR)/mail
	X_CHOWN $(BBSD_OWNER) $(INSTALLDIR)/etc
	X_CHGRP $(BBSD_GROUP) $(INSTALLDIR)/etc
	X_CHOWN $(BBS_OWNER) $(INSTALLDIR) $(INSTALLDIR)/scratch
	X_CHGRP $(BBS_GROUP) $(INSTALLDIR) $(INSTALLDIR)/scratch
	X_CHMOD 755 $(INSTALLDIR) $(INSTALLDIR)/help
	X_CHMOD 755 $(INSTALLDIR)/mail
	X_CHMOD 755 $(INSTALLDIR)/etc
	X_CHMOD 777 $(INSTALLDIR)/scratch
	X_CHOWN $(BBS_OWNER) $(INSTALLDIR)/help/*
	X_CHGRP $(BBS_GROUP) $(INSTALLDIR)/help/*
	X_CHMOD 644 $(INSTALLDIR)/help/*
	if [ ! -d $(CHROOTDIR) ]; then\
	  X_MKDIR $(CHROOTDIR); \
	  X_CHOWN $(BBS_OWNER) $(CHROOTDIR); \
	  X_CHGRP $(BBS_GROUP) $(CHROOTDIR); \
	  X_CHMOD -R 755 $(CHROOTDIR); \
	fi

tags:   $(RCSFILES)
	X_RM tags
	X_CTAGS -t *.[hc]

delta:  $(RCSFILES)
	ci -l $(RCSFILES)

clean:
	X_RM -f $(OBJ_BBS) $(OBJ_BBSD) $(OBJ_COM) $(OBJ_MAIL) bbs bbsd bbsmail\
         *.core
	X_FIND . -name '.nfs' -print | X_XARGS X_RM -f
	X_RM -rf conf/tmp

distclean:
	X_RM -f $(OBJ_BBS) $(OBJ_BBSD) $(OBJ_COM) $(OBJ_MAIL) bbs bbsd bbsmail\
	  *.core tags Makefile* users* local.h* bbs.conf* kermrc*  bbsmail.m4 RCS\
     conf/local.conf conf/test-*.sys
	X_FIND . -name '*~' -print | X_XARGS X_RM -f
	X_FIND . -name '#*#' -print | X_XARGS X_RM -f
	X_FIND . -name '.nfs' -print | X_XARGS X_RM -f
	X_RM -rf conf/tmp

