#
# Makefile for kerberos
#

# These may be overridden by a host specific Makefile fragment
# Directory syntax: R=root, C=current, S=Separator, U=Up one level
R=/
C=.
S=/
U=../

# The default system to build
WHAT=unix

srcdir = $(C)

prefix = $(R)usr$(S)kerberos

exec_prefix = $(prefix)

SHELL = /bin/sh

SUBDIRS="this is set by configure"

# Not plain GZIP, since gzip looks there for extra command-line options.
GZIPPROG = gzip -v --best
GZIPEXT = gz

MAKEOVERRIDES=

#### Host, target, and site specific Makefile fragments come in here.
###

# These are roughly topologically sorted in order to make porting more
# streamlined.
FLAGS_TO_PASS = \
	"prefix=$(prefix)" \
	"exec_prefix=$(exec_prefix)" \
	"CC=$(CC)" \
	"DBG=$(DBG)" \
	"DESTDIR=$(DESTDIR)"

all: all-$(WHAT)

all-unix:
	@for dir in .. ${SUBDIRS}; do \
	  if [ x$${dir} != x.. ]; then \
	    if [ -d $$dir ]; then \
	      if (cd $$dir; $(MAKE) $(FLAGS_TO_PASS) all); then \
		true; \
	      else \
		exit 1; \
	      fi; \
	    else true; fi; \
	  else true; fi; \
	done

all-: all-windows
all-windows:
	cd src
	$(MAKE)

depend install check:
	@for dir in .. ${SUBDIRS}; do \
	  if [ x$${dir} != x.. ]; then \
	    if [ -d $$dir ]; then \
	      if (cd $$dir; $(MAKE) $(FLAGS_TO_PASS) $@); then \
		true; \
	      else \
		exit 1; \
	      fi; \
	    else true; fi; \
	  else true; fi; \
	done

svr4-pkg: svr4-pkg-bin svr4-pkg-src

version=cns-`date +%Y%m%d`
asrcdir=`cd $(srcdir)&&pwd`

PKGDIR=`pwd`/pkgdir
INSTSUBDIR=$(PKGDIR)/install/usr/kerberos/install
pkgdir:
	if test ! -d $(PKGDIR); then mkdir $(PKGDIR); else true; fi
svr4-pkg-bin: pkgdir
	rm -rf $(PKGDIR)/install
	mkdir $(PKGDIR)/install
	$(MAKE) install DESTDIR=$(PKGDIR)/install
	$(PKGDIR)/install/usr/kerberos/install/fixprot $(PKGDIR)/install
	echo i pkginfo=$(asrcdir)/pkginfo.bin			>  $(PKGDIR)/proto.bin
	echo i request=$(INSTSUBDIR)/svr4-request		>> $(PKGDIR)/proto.bin
	echo i postinstall=$(INSTSUBDIR)/svr4-postinst		>> $(PKGDIR)/proto.bin
	pkgproto $(PKGDIR)/install/usr/kerberos=/usr/kerberos	>> $(PKGDIR)/proto.bin
	pkgmk -f $(PKGDIR)/proto.bin -v $(version) -o -d $(PKGDIR) CNS4
	rm -rf $(PKGDIR)/install
	pkgtrans -s -o $(PKGDIR) CNS4.pkg CNS4
	rm -rf $(PKGDIR)/CNS4

# THIS TARGET DOESN'T WORK YET.
# The sed commend after pkgproto is to filter out CVS subdirectories and
# the Mac directories that contain files with spaces in their names.
svr4-pkg-src: pkgdir
	if test $(srcdir) = . ; then \
	  echo "" ; \
	  echo "*** Cannot build a source package from a locally configured tree." ; \
	  echo "" ; \
	  exit 1 ; \
	else true; fi
	echo i pkginfo=$(asrcdir)/pkginfo.src				>  $(PKGDIR)/proto.src
	pkgproto $(asrcdir)=/usr/kerberos/src \
		| sed -e '/\/CVS/d' -e '/src\/driver/d' -e '/src\/mactelnet/d' \
									>> $(PKGDIR)/proto.src
	pkgmk -f $(PKGDIR)/proto.src -v $(version) -o -d $(PKGDIR) CNS4-SRC
	pkgtrans -s -o $(PKGDIR) CNS4-SRC.pkg CNS4-SRC
	rm -rf $(PKGDIR)/CNS4-SRC

svr4-zpkg-bin: svr4-pkg-bin
	$(GZIPPROG) $(PKGDIR)/CNS4.pkg
svr4-zpkg-src: svr4-pkg-src
	$(GZIPPROG) $(PKGDIR)/CNS4-SRC.pkg
svr4-zpkg: svr4-zpkg-bin svr4-zpkg-src

taz-bin: pkgdir
	rm -rf $(PKGDIR)/install cns4-bin.taz
	mkdir $(PKGDIR)/install
	$(MAKE) install DESTDIR=$(PKGDIR)/install
	(cd $(PKGDIR)/install && tar cf - usr/kerberos) | compress > cns4-bin.taz
	rm -rf $(PKGDIR)/install

tgz-bin: pkgdir
	rm -rf $(PKGDIR)/install cns4-bin.tgz
	mkdir $(PKGDIR)/install
	$(MAKE) install DESTDIR=$(PKGDIR)/install
	(cd $(PKGDIR)/install && tar cf - usr/kerberos) | $(GZIPPROG) > cns4-bin.tgz
	rm -rf $(PKGDIR)/install

# N.B.: Do *NOT* add "*.a" to the names to remove.  We do ship a couple of "source" files
# with such names, in the non-UNIXy configurations.
#
# The "touch" command is to ensure that there's at least one name passed to "rm".
taz-src: pkgdir
	rm -rf $(PKGDIR)/source
	mkdir $(PKGDIR)/source
	mkdir $(PKGDIR)/source/usr
	mkdir $(PKGDIR)/source/usr/kerberos
	mkdir $(PKGDIR)/source/usr/kerberos/src
	(cd $(srcdir) && tar cf - .) | (cd $(PKGDIR)/source/usr/kerberos/src && tar xf -)
	touch $(PKGDIR)/source/CVS
	find $(PKGDIR)/source \
		-name CVS -o -name RCS \
		-print | xargs rm -rf
	(cd $(PKGDIR)/source ; tar cf - usr/kerberos/src) | compress > $(PKGDIR)/cns4-src.taz
	rm -rf $(PKGDIR)/source
tgz-src: pkgdir
	rm -rf $(PKGDIR)/source
	mkdir $(PKGDIR)/source
	mkdir $(PKGDIR)/source/usr
	mkdir $(PKGDIR)/source/usr/kerberos
	mkdir $(PKGDIR)/source/usr/kerberos/src
	(cd $(srcdir) && tar cf - .) | (cd $(PKGDIR)/source/usr/kerberos/src && tar xf -)
	touch $(PKGDIR)/source/CVS
	find $(PKGDIR)/source \
		-name CVS -o -name RCS -o -name '*~' \
		-print | xargs rm -rf
	(cd $(PKGDIR)/source ; tar cf - usr/kerberos/src) | $(GZIPPROG) > $(PKGDIR)/cns4-src.taz
	rm -rf $(PKGDIR)/source

dist:
	@if [ x${DESTDIR} = x ]; then \
	  echo '***' Set DESTDIR before running make dist; \
	  false; \
	else true; fi
	${DESTDIR}/usr/kerberos/install/fixprot ${DESTDIR} tar
	cd ${DESTDIR}/.; tar cf - usr | $(GZIPPROG) > kerberos.tar.$(GZIPEXT)

clean mostlyclean:
	-rm -f *~ core *.o a.out
	-rm -rf $(PKGDIR)
	@for dir in .. ${SUBDIRS}; do \
	if [ x$${dir} != x.. ]; then \
	    if [ -d $$dir ]; then \
	      (cd $$dir; $(MAKE) $@); \
	    else true; fi; \
	  else true; fi; \
	done

distclean realclean: clean
	-rm -f *~ core
	-rm -f Makefile config.status 
	@for dir in .. ${SUBDIRS}; do \
	if [ x$${dir} != x.. ]; then \
	    if [ -d $$dir ]; then \
	      (cd $$dir; $(MAKE) $@); \
	    else true; fi; \
	  else true; fi; \
	done

info install-info clean-info dvi ps:
	if [ -d doc ]; then \
	  cd doc; $(MAKE) $(FLAGS_TO_PASS) $@; \
	else true; fi

unixmac:
	cd src; $(MAKE) $(FLAGS_TO_PASS) unixmac

Makefile: Makefile.in configure.in $(host_makefile_frag) $(target_makefile_frag)
	$(SHELL) config.status

.NOEXPORT:
