#	$Source: /afs/sipb.mit.edu/project/sipbsrc/src/RCS/Makefile,v $
#	$Id: Makefile,v 1.22 91/06/11 14:01:28 jtkohl Exp $
#
MACHINE=linux
DESTDIR=
TOPDIR=		/usr/sipb
BINDIR=		${TOPDIR}/${MACHINE}bin
LIBDIRS=	${TOPDIR}/lib ${TOPDIR}/${MACHINE}lib \
		${TOPDIR}/lib/discuss ${TOPDIR}/lib/app-defaults
INCDIR=		${TOPDIR}/include
ETCDIRS=	${TOPDIR}/etc ${TOPDIR}/${MACHINE}etc
CFLAGS=		-O
CC=		cc
ECHO=		/bin/echo

# Programs that live in subdirectories, and have makefiles of their own.
#
# Right now, the following directories are not correct in the sources
# and live elsewhere in reality, and are therefore deleted from the
# SUBDIR variable and should be installed by hand:

BROKEN_SUBDIR= 

# We don't install these anywhere.
UNUSED_SUBDIR= \
	conference \
	dvi2ps.old \
	macdump \
	go \
	irc \
	nethack \
	nn \
	psdvi \
	world

# Don't compile these at all, because they don't get installed in the
# sipb locker.
SPECIAL_SUBDIR = \
	dialup \
	gameserver

SUBDIR= \
	Pps \
	arc5.21 \
	chat \
	cookbook \
	discuss \
	dvi2ps \
	dvi2tty \
	dyn \
	et \
	fortune \
	freeze \
	hearts \
	inews \
	kaleid \
	latexindex \
	macps \
	mboggle \
	memo \
	micrognu \
	pbmplus \
	pfrom \
	ptoc \
	qedx \
	rolodex \
	rrn \
	sc \
	splot \
	ss \
	starchart \
	tek2ps \
	template \
	tex \
	tgrind \
	transfig \
	vcal \
	web2c \
	webster \
	xdvi \
	xfig \
	xfish.x11 \
	xfroot \
	xmoire \
	xphoon \
	xrn \
	xscreensaver \
	xspaceout \
	xyzmodem \
	xzwrite \
	zmail \
	zoo \
	zpunt

# xman needs -lSx for X10, oh well.
NOTANYMORE= xman.x10
#
# Directories which get copied to the locker
COPYDIRS= bitmaps doc man prototype etc bitmaps.x11

# C programs that live in the current directory and do not need
# explicit make lines.
#
STD=	anyone cal char copy die have_mail new_plans nol owner \
	print_lw remotehost where tmodem phony
STDSRC= anyone.c cal.c char.c copy.c die.c have_mail.c new_plans.c \
	nol.c owner.c print_lw.c remotehost.c where.c tmodem.c
#not used anymore
OLDSTD= print_x9700

# C programs needing to be linked with the X10 library
#STDX10=	showfont.x10 xconfigure.x10
STDX10=
STDX10SRC=

# We don't want those anymore because we're doing X11 now!

# C programs that live in the current directory and need explicit make lines.
#
NSTD=
NSTDSRC=

# sources for all the things that live in this directory
SRCS= anyone.c bm.sh cal.c char.c copy.c \
	die.c ds.sh have_mail.c new_plans.c nol.c owner.c print_lw.c \
	remotehost.c showfont.c sipb.emacs \
	sman.sh where.c xconfigure.c apropos.sh man.sh whatis.sh
# no longer used
OLDSRC= print_x9700.c

# shell scripts in the current directory which just get copied
SCRIPTS= bm ds man dsc_notify apropos whatis

all:	${SUBDIR} ${STD} ${STDX10} ${NSTD}

${SUBDIR}: FRC
	(cd $@; make ${MFLAGS} MACHINE=${MACHINE} DESTDIR=${DESTDIR})

FRC:

links: dlinks llinks

dlinks:
	-for i in ${SUBDIR}; do \
		(cd $$i; make ${MFLAGS} links); done

llinks:
	-for i in ${SRCS}; do \
		(ln -s ../vs2/$$i); done

${STD}:
	${CC} ${CFLAGS} -o $@ $@.c

#${STDX10}:
#	${CC} ${CFLAGS} -o $@ $@.c /usr/lib/X10/libX.a

install: install_msg dir_install copy_install
install: top_install script_install bin_install catman

install_msg:
	@${ECHO} Note: This will install the entire SIPB filesystem from scratch
	@${ECHO} It had better be mounted on ${DESTDIR}${TOPDIR}.
	@${ECHO} Binaries will be installed into ${DESTDIR}${BINDIR}.
	@${ECHO} Abort now if you aren\'t ready to do this.
	sleep 10
	@${ECHO} ""

dir_install:
	@${ECHO} Create directories if they do not exist.
	@${ECHO} ""
	-@for i in ${BINDIR} ${LIBDIRS} ${ETCDIRS} ${INCDIR}; do \
		if [ ! -d ${DESTDIR}$$i ]; then \
			${ECHO} "  " ${DESTDIR}$$i "..."; \
			mkdir ${DESTDIR}$$i; fi; done
	@${ECHO} ""

copy_install:
	@${ECHO} Copy some directories completely into the locker.
	@${ECHO} ""
	-@for i in ${COPYDIRS}; do \
		${ECHO} "  " $$i "..."; \
		if [ ! -d ${DESTDIR}${TOPDIR}/$$i ]; then \
			mkdir ${DESTDIR}${TOPDIR}/$$i; fi; \
		(cd $$i; tar cf - .) | \
			(cd ${DESTDIR}${TOPDIR}/$$i; tar xpBfv -); done
	@${ECHO} ""

top_install: dir_install ${STD} ${NSTD} ${STDX10}
	@${ECHO} "Top-level binaries."
	@${ECHO} ""
	-@for i in ${STD} ${STDX10} ${NSTD}; do \
		${ECHO} "  " $$i "..."; \
		install -c -s $$i ${DESTDIR}${BINDIR}; done
	@${ECHO} ""

script_install: dir_install
	@${ECHO} "Shell scripts."
	@${ECHO} ""
	-@for i in ${SCRIPTS}; do \
		${ECHO} "  " $$i "..."; \
		install -c $$i.sh ${DESTDIR}${BINDIR}/$$i; done
	@${ECHO} ""

bin_install: dir_install
	@${ECHO} "Sub-directory installations"
	@${ECHO} ""
	-@for i in ${SUBDIR}; do \
		${ECHO} "  " $$i "..."; \
		(cd $$i; make ${MFLAGS} DESTDIR=${DESTDIR} install); done
	@${ECHO} ""

catman: copy_install
	@${ECHO} "Build man directory database."
	@${ECHO} ""
	-catman -M ${DESTDIR}${TOPDIR}/man
	@${ECHO} ""
	@${ECHO} Installation complete.

clean:
	rm -f a.out core *.s *.o errs
	for i in ${SUBDIR}; do (cd $$i; make ${MFLAGS} clean); done
	rm -f ${STD} ${STDX10} ${NSTD}

depend:
	makedepend ${CFLAGS} -v ${STDSRC} ${STDX10SRC} ${NSTDSRC}
	for i in ${SUBDIR}; do \
		(cd $$i; make ${MFLAGS} DESTDIR=${DESTDIR} \
		MACHINE=${MACHINE} depend); done
#	for i in ${STD} ${STDX10} ${NSTD}; do \
#	    ${CC} -M ${INCPATH} $$i.c | sed 's/\.o//' | \
#	    awk ' { if ($$1 != prev) \
#		{ if (rec != "") print rec; rec = $$0; prev = $$1; } \
#	else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
#		else rec = rec " " $$2 } } \
#		END { print rec } ' >> makedep; done
#	${ECHO} '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
#	${ECHO} '$$r makedep' >>eddep
#	${ECHO} 'w' >>eddep
#	cp Makefile Makefile.bak
#	ed - Makefile < eddep
#	rm eddep makedep
#	${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

# Files listed in ${NSTD} have explicit make lines given below.

# DO NOT DELETE THIS LINE -- make depend depends on it.
