#
#ident	"@(#)smail:RELEASE-3_2_0_115:Makefile,v 1.25 2003/06/18 07:03:38 woods Exp"
#
# Top-level makefile for the smail source tree
#
#    Copyright (C) 1987, 1988 Ronald S. Karr and Landon Curt Noll
#    Copyright (C) 1992  Ronald S. Karr
# 
# See the file COPYING, distributed with smail, for restriction
# and warranty information.

SHELL=/bin/sh

MKDEPEND=${ROOT}/conf/lib/mkdepend.sh
MKDIRS=${ROOT}/conf/lib/mkdirs.sh
MKDEFS=${ROOT}/conf/lib/mkdefs.sh
CHECKDEFS=${ROOT}/conf/lib/checkdefs.sh
INST=${ROOT}/conf/lib/inst.sh
INSTM=${ROOT}/conf/lib/instm.sh
XEXEC=${SHELL} ${ROOT}/conf/lib/xexec.sh

DEFS_SH=defs.sh
DEFS_H=defs.h
DEFS_SED=defs.sed

ROOT=.
SUB_DIRS=conf compat pd util src man
MORE_SUB_DIRS=guide NOTES

all install clean clobber depend lint mkdefs tags TAGS: ${DEFS_H} ${DEFS_SH} ${DEFS_SED} .MAKE
	@for i in ${SUB_DIRS}; do			\
		echo "Making $@ under $$i ...";		\
		(cd $$i && { if [ -f .depend ] ; then	\
			DEPMKFILE="-f Makefile -f .depend"; \
		fi; ${MAKE} $$DEPMKFILE $@; } );	\
		rc=$$?;					\
		if [ $$rc -ne 0 ] ; then		\
			exit $$rc;			\
		fi;					\
	done

everything: all all-more-subdirs

all-more-subdirs: ${DEFS_H} ${DEFS_SH} ${DEFS_SED} .MAKE
	@for i in ${MORE_SUB_DIRS}; do			\
		echo "Making all under $$i ...";	\
		(cd $$i && { if [ -f .depend ] ; then	\
			DEPMKFILE="-f Makefile -f .depend"; \
		fi; ${MAKE} $$DEPMKFILE all; } );	\
		rc=$$?;					\
		if [ $$rc -ne 0 ] ; then		\
			exit $$rc;			\
		fi;					\
	done

${DEFS_H} ${DEFS_SH} ${DEFS_SED}: ${ROOT}/conf/EDITME
	ROOT=${ROOT} ${SHELL} ${MKDEFS}

${ROOT}/conf/EDITME: .MAKE # cannot depend on anything else!
	cd ${ROOT}/conf && ${MAKE} EDITME

depend:	local-depend

local-depend: check_defs
	@rm -f .depend
	. ./${DEFS_SH}; echo "$$DEFS_DEPEND" >> .depend

# Note: don't try to source DEFS_SH and thus don't use XEXEC
#
check_defs:
	SHELL=${SHELL} ROOT=${ROOT} ${SHELL} ${CHECKDEFS}

mkdefs: ${DEFS_H} ${DEFS_SH} ${DEFS_SED}

install: local-install

local-install: ${DEFS_SH}
	@. ./${DEFS_SH};					\
	   case "$$DONT_INSTALL" in				\
	   ?*)	echo Testing only ... $@ ignored; exit 0;;	\
	   esac;						\
	   ${XEXEC} ${SHELL} ${INSTM} -r -m 0444 $$LIB_DIR COPYING

install-everything: install install-more-subdirs

install-more-subdirs: ${DEFS_SH} .MAKE
	@for i in ${MORE_SUB_DIRS}; do			\
		echo "Install targets under $$i ...";	\
		(cd $$i && { if [ -f .depend ] ; then	\
			DEPMKFILE="-f Makefile -f .depend"; \
		fi; ${MAKE} $$DEPMKFILE install; } );	\
		rc=$$?;					\
		if [ $$rc -ne 0 ] ; then		\
			exit $$rc;			\
		fi;					\
	done

clobber: clobber-local

clobber-local:
	rm -f .depend
	rm -f ${DEFS_SH} ${DEFS_H} ${DEFS_SED}

.MAKE:

.PHONY: all install local-install clean local-clean clobber local-clobber depend local-depend lint mkdefs check_defs tags TAGS
.PHONY: everything all-more-subdirs install-everything install-more-subdirs installman install.man .MAKE
