#!/bin/make -f
# @(#) $Id: Makefile,v 1.10 1992/09/20 17:10:17 tron 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
MAKE=make
GET=sccs get
AR=ar
LINT=lint
CLEAN=sccs clean
MK=${MAKE} -${MAKEFLAGS} SHELL=${SHELL}
SRC_PREFIX=
MKDEPEND=${ROOT}/conf/lib/mkdepend.sh
MKDEFS=${ROOT}/conf/lib/mkdefs.sh
CHECKDEFS=${ROOT}/conf/lib/checkdefs.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=contrib guide NOTES
MISCSRC=Makefile level patchnum README CHANGES COPYING
SRC=${MISCSRC}

all:	build_smail

build_smail: ${DEFS_H} ${DEFS_SH} ${DEFS_SED}
	@for i in ${SUB_DIRS}; do \
		echo "Build targets under ${SRC_PREFIX}$$i ..."; \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/); \
	 done	# $(MAKE)

sources: ${SRC}
	@for i in ${SUB_DIRS} ${MORE_SUB_DIRS}; do \
		echo "Get sources under ${SRC_PREFIX}$$i ..."; \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/ sources); \
	 done	# $(MAKE)

${SRC}:
	${GET} $@

${DEFS_H} ${DEFS_SH} ${DEFS_SED}:
	ROOT=${ROOT} ${SHELL} ${MKDEFS}

names:
	@for i in ${SRC}; do echo ${SRC_PREFIX}$$i; done
	@for i in ${SUB_DIRS} ${MORE_SUB_DIRS}; do \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/ names); \
	 done	# $(MAKE)

depend:	local_depend subdir_depend

local_depend: check_defs
	${SHELL} ${MKDEPEND} Makefile
	. ./${DEFS_SH}; echo "$$DEFS_DEPEND" >> Makefile
	chmod -w Makefile

subdir_depend:
	@for i in ${SUB_DIRS}; do \
		echo "Make dependencies under ${SRC_PREFIX}$$i ..."; \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/ depend); \
	 done	# $(MAKE)

check_defs:
	SHELL=${SHELL} ROOT=${ROOT} ${SHELL} ${CHECKDEFS}

install: ${DEFS_SH}
	@. ./${DEFS_SH}; \
	   case "$$DONT_INSTALL" in \
	   ?*)	echo Testing ... install ignored; exit 0;; \
	   esac
	   for i in ${SUB_DIRS}; do \
		echo "Install targets under ${SRC_PREFIX}$$i ..."; \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/ install); \
	   done # $(MAKE)

installman:
	@echo "Install man pages under ${SRC_PREFIX}man ..."
	cd man; ${MK} SRC_PREFIX=${SRC_PREFIX}man/ installman # $(MAKE)

clean:
	rm -f ${DEFS_SH} ${DEFS_H} ${DEFS_SED}
	@for i in ${SUB_DIRS} ${MORE_SUB_DIRS}; do \
		echo "Clean under ${SRC_PREFIX}$$i ..."; \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/ clean); \
	 done	# $(MAKE)

clobber:
	rm -f ${DEFS_SH} ${DEFS_H} ${DEFS_SED}
	rm -f .${DEFS_SH} .${DEFS_H} .${DEFS_SED} .Makefile
	@for i in ${SUB_DIRS} ${MORE_SUB_DIRS}; do \
		echo "Clobber under ${SRC_PREFIX}$$i ..."; \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/ clobber); \
	 done	# $(MAKE)

nuke:
	rm -f ${DEFS_SH} ${DEFS_H} ${DEFS_SED}
	rm -f .${DEFS_SH} .${DEFS_H} .${DEFS_SED} .Makefile
	-${CLEAN}
	-${GET} Makefile
	@for i in ${SUB_DIRS} ${MORE_SUB_DIRS}; do \
		echo "Nuke under ${SRC_PREFIX}$$i ..."; \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/ nuke); \
	 done	# $(MAKE)

# DO NOT REMOVE THIS LINE, OR "make depend" WILL NOT WORK
