#!/bin/make -f
# @(#)pd/Makefile	1.9 9/20/92 16:44:58
# Makefile for items that are in the public domain
#
# This file is in the public domain

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

# IMPORTANT NOTE:  Due to potential problems with installing binmail,
#		   the binmail sub directory is NOT called from this
#		   makefile.  Read LMAIL comments in EDITME-dist
#		   and build/install binmail by hand if you want to.
MAKE_SUB_DIRS=getopt pathalias uuwho
MISC_SUB_DIRS=binmail sdbm strlib
SUB_DIRS=${MAKE_SUB_DIRS} ${MISC_SUB_DIRS}
ROOT=..
MISCSRC=Makefile README
SRC=${MISCSRC}

all:	build_util

build_util: ${DEFS_SH}
	@if [ -f ${DEFS_SH} ]; then \
	   . ./${DEFS_SH}; \
	   case "$$DBM_LIB" in \
	   */pd/sdbm/*) \
		echo "Build targets under ${SRC_PREFIX}sdbm ..."; \
		(cd sdbm; ${MK} SRC_PREFIX=${SRC_PREFIX}sdbm/); \
	   esac; fi	# $(MAKE)
	@for i in ${MAKE_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}; do \
		echo "Get sources under ${SRC_PREFIX}$$i ..."; \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/ sources); \
	 done	# $(MAKE)

${SRC}:
	${GET} $@

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

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

install:
	@for i in ${MAKE_SUB_DIRS}; do \
		echo "Install targets under ${SRC_PREFIX}$$i ..."; \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/ install); \
	 done	# $(MAKE)

depend: local_depend subdir_depend

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

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

subdir_depend:
	@for i in ${MAKE_SUB_DIRS} strlib; do \
		echo "Make dependencies under ${SRC_PREFIX}$$i ..."; \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/ depend); \
	 done	# $(MAKE)
	@if [ -f ${DEFS_SH} ]; then \
	   . ./${DEFS_SH}; \
	   case "$$DBM_LIB" in \
	   */pd/sdbm/*) \
		echo "Make dependencies under ${SRC_PREFIX}sdbm ..."; \
		(cd sdbm; ${MK} SRC_PREFIX=${SRC_PREFIX}sdbm/ depend); \
	   esac; fi	# $(MAKE)

clean: local_clean
	@for i in ${SUB_DIRS}; do \
		echo "Clean under ${SRC_PREFIX}$$i ..."; \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/ clean); \
	 done	# $(MAKE)

clobber: local_clean
	@for i in ${SUB_DIRS}; do \
		echo "Clobber under ${SRC_PREFIX}$$i ..."; \
		(cd $$i; ${MK} SRC_PREFIX=${SRC_PREFIX}$$i/ clobber); \
	 done	# $(MAKE)

local_clean:
	rm -f ${DEFS_SH} ${DEFS_H} ${DEFS_SED}
	rm -f .${DEFS_SH} .${DEFS_H} .${DEFS_SED} .Makefile

nuke:
	-${CLEAN}
	-${GET} Makefile
	@for i in ${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
