#
# Makefile for Pirate brand BBS
#
# Aug 30,1989
# 
# Additions for EBBS 1.1 by Ray Rocker
# September 1992
#
# Cleaned up big time for EBBS 2.1 by Ray Rocker
# November 1993
#
#############################################################################

# THIS IS THE PART YOU HAVE TO EDIT! Pick the line for your operating 
# system and uncomment it. If your OS isn't listed, take a guess,
# and modify install.sh accordingly!
# If you leave them all commented, you'll build for SunOS.

# Some of the systems listed below (Solaris, Irix, maybe AIX, others)
# have unsolved problems related to the chroot the bbsrf login shell does.
# As of version 2.11 you can put -DNO_CHROOT in the LOCALDEFS below and
# not do the chroot. WARNING: this is a security compromise! I highly 
# recommend you disable the Shell Escape on the Admin menu if you don't
# chroot. You have been warned. If you do forego the chroot much of the
# copying into ~bbs that goes on is unnecessary. Leave the stuff in 
# ~bbs/bin though, the bbs will be sure to find it there, except for the
# protocols. If you define NO_CHROOT you probably will have to set the
# correct paths for the protocols in files.c. See note there.

# This is for SunOS 4.1.3. The default. It works.
#SYSTEM = SUNOS
# This one for Linux SLS 1.03. It works.
#SYSTEM = LINUX
# This one for SunOS (Solaris) 5.2. Talk/chat had problems due to
# chroot, otherwise OK.
#SYSTEM = SOLARIS
# This one for OSF/1. Compile tested only! I don't have root on an OSF box.
#SYSTEM = OSF
# This one for Intergraph CLIX (System V Release 3.1)
#SYSTEM = CLIX
# This one for SGI IRIX 5.1. Gives a Trace/BPT Trap if you try to exec 
# while chrooted. *shrug*. Works with -DNO_CHROOT if you dare (see above).
#SYSTEM = IRIX
# This will turn on John Salmi's AIX ifdefs. The install.sh has NOT been
# ported to AIX yet. That's a do-it-yourselfer for the time being.
#SYSTEM = AIX
# Ditto above for RISC/OS 4.52. 
#SYSTEM = RISCOS
# Ultrix ifdefs contributed by Alex Schubert. Again, these only apply to
# the bbs *.c files, not the install.sh.
#SYSTEM = ULTRIX
# NeXT 3.2 ifdefs contributed by Andre Schmidt. You may need to fix install.sh.
#SYSTEM = NEXT

# Shell to use for make installbbs and make installchatd
# Use csh for most systems, except Linux where you want bash.
# This shell will also be copied to ~bbs/bin by the install script, 
# so it's helpful if this is the same as ESCAPE_SHELL in config.h.
SH = csh
#SH = sh   # On Linux this is usually bash
#SH = ksh  # Nice if you have it

# What's your compiler?
CC       = cc
#CC       = gcc # Prefer gcc? Use this
#CC       = /usr/ucb/cc  # Be sure you use this cc for Solaris
#CC       = acc  # for CLIX Apogee C compiler

# If you have any site-specific defines, put them here.
# Also you may want these:
#
# -DINVISIBLE makes bbs users invisible to 'finger' and 'who'.
# Simply remove it if you don't want this feature.
# Note: don't use -DINVISIBLE on CLIX yet...it's broke.
#
# -DNO_CHROOT makes the bbs run without chrooting. This is a new feature
# in 2.2 so caveat emptor! Be sure to see the chroot note above before 
# you try it.
LOCALDEFS =

# Command-line options for the compiler.
CFLAG    = -O
#CFLAG   = -O -w              # if compiler is "noisy" with warnings (CLIX)
#CFLAG    = -systype bsd43    # Use for RISCOS

# Command-line options for the linker.
LDFLAG   =
#LDFLAG   = -systype posix    # Use for RISCOS

# Libraries to link with.
LIBS     = -ltermcap
#LIBS     = /usr/lib/libtermcap.a /bsd43/usr/lib/libc.a  # Use for RISCOS
#LIBS     = -ltermcap -lbsd  # Use for CLIX

############################################################################
# You probably don't have to mess with anything under here. ################
############################################################################

PROGNAME = bbs

CFILE    = bbs.c record.c delete.c main.c stuff.c mail.c files.c \
           xyz.c talk.c read.c comm_lists.c namecomplete.c chat.c \
           maintain.c edit.c more.c pass.c help.c bcache.c fastnew.c \
           screen.c io.c term.c
COBJS    = bbs.o record.o delete.o main.o stuff.o mail.o files.o \
           xyz.o talk.o read.o comm_lists.o namecomplete.o chat.o \
           maintain.o edit.o more.o pass.o help.o bcache.o fastnew.o \
           screen.o io.o term.o
LNFILES  = bbs.ln record.ln delete.ln main.ln stuff.ln mail.ln files.ln \
           xyz.ln talk.ln read.ln comm_lists.ln namecomplete.ln chat.ln \
           maintain.ln edit.ln more.ln pass.ln help.ln bcache.ln fastnew.ln \
           screen.ln io.ln term.ln
OTHERS   = Makefile bbs.h edit.h
GARBAGE  = a.out core installchatd bbs.chatd bbsrf passwdent

DEFINES  = -D$(SYSTEM) $(LOCALDEFS)

.SUFFIXES: .o .c .ln

.c.o:   ;   $(CC) $(CFLAG) $(DEFINES) -c $*.c
.c.ln:  ;   lint -abhi $*.c

$(PROGNAME): $(COBJS) $(OTHERS) bbs.chatd
	$(CC) -o $(PROGNAME) $(CFLAG) $(LDFLAG) $(COBJS) $(LIBS)

lint: $(LNFILES)
	lint -abh $(LNFILES)

passwdent: passwdent.c
	$(CC) -o passwdent passwdent.c

bbsrf: bbsrf.c passwdent
	$(CC) -o bbsrf $(CFLAG) $(DEFINES) -DBBSHOME=\"`./passwdent bbs homedir`\" -DBBSUID=`./passwdent bbs uid` bbsrf.c $(LIBS)

bbs.chatd: station.c chat.h
	$(CC) -o bbs.chatd $(CFLAG) $(DEFINES) station.c $(LIBS)

genlogin: genlogin.o pass.o
	$(CC) -o genlogin $(CFLAG) $(DEFINES) genlogin.o pass.o

vedit.o: edit.c bbs.h config.h modes.h permissions.h edit.h
	$(CC) $(CFLAG) $(DEFINES) -DMAKEVE -c -o vedit.o edit.c

ve: vedit.o term.o screen.o io.o editor.o
	$(CC) -o ve $(CFLAG) vedit.o term.o screen.o io.o editor.o $(LIBS)

installbbs: $(PROGNAME)
	$(SH) -c "mv -f ~bbs/bin/bbs ~bbs/bin/bbs.old; cp bbs ~bbs/bin"

installchatd: bbs.chatd
	$(SH) -c "mv -f ~bbs/bin/bbs.chatd ~bbs/bin/chatd.old; cp bbs.chatd ~bbs/bin"

install: $(PROGNAME) bbs.chatd bbsrf passwdent genlogin
	./install.sh $(SYSTEM) $(SH)

clean: /tmp
	rm -fr $(GARBAGE) $(COBJS) $(PROGNAME) $(LNFILES) *~

tags: /tmp
	etags $(CFILE)

# Dependencies and schtuff.

bbs.o: bbs.c bbs.h config.h modes.h permissions.h
record.o: record.c bbs.h config.h modes.h permissions.h
delete.o: delete.c bbs.h config.h modes.h permissions.h
main.o: main.c bbs.h config.h modes.h permissions.h
stuff.o: stuff.c bbs.h config.h modes.h permissions.h
mail.o: mail.c bbs.h config.h modes.h permissions.h
files.o: files.c bbs.h config.h modes.h permissions.h
xyz.o: xyz.c bbs.h config.h modes.h permissions.h
talk.o: talk.c bbs.h config.h modes.h permissions.h
read.o: read.c bbs.h config.h modes.h permissions.h
comm_lists.o: comm_lists.c bbs.h config.h modes.h permissions.h
namecomplete.o: namecomplete.c bbs.h config.h modes.h permissions.h
chat.o: chat.c bbs.h config.h modes.h permissions.h chat.h
maintain.o: maintain.c bbs.h config.h modes.h permissions.h
edit.o: edit.c bbs.h config.h modes.h permissions.h edit.h
more.o: more.c bbs.h config.h modes.h permissions.h
help.o: help.c bbs.h config.h modes.h permissions.h
bcache.o: bcache.c bbs.h config.h modes.h permissions.h
fastnew.o: fastnew.c bbs.h config.h modes.h permissions.h
screen.o: screen.c bbs.h config.h modes.h permissions.h screen.h
io.o: io.c bbs.h config.h modes.h permissions.h
term.o: term.c bbs.h config.h modes.h permissions.h
editor.o: editor.c bbs.h config.h modes.h permissions.h
genlogin.o: genlogin.c bbs.h config.h modes.h permissions.h
