### Makefile for kerberos tree -- maximal passed arguments
srcdir = $(C)

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

program_transform_name =

##

SHELL = /bin/sh

SUBDIRS = "this is set via configure, don't edit this"
OTHERS = 

INSTALL_TARGET = install

RUNTEST = runtest
RUNTESTFLAGS =

##DOS!include config\common
##DOS!include config\mt-win
#### host and target specific makefile fragments come in here.
###


# The first rule in the file had better be this one.  Don't put any above it.
all: all-$(WHAT)

all-unix:
	@for i in $(SUBDIRS); do \
	  if (cd $$i; $(MAKE) $(MFLAGS) "CC=$(CC)" "DBG=$(DBG)" \
		RESOLV=$(RESOLV) all) ; then \
	    true; \
	  else \
	    exit 1; \
	  fi; \
	done

# Windows nmake is too stupid to be able to iterate over a list, use
# semicolons, or keep track of anything but the current directory.
# unix configure will make all-unix the default in config/common
all-: all-windows
all-windows: makefile-windows
	cd include
	$(MAKE)
	cd ..\lib\des
	$(MAKE)
	cd ..\kadm
	$(MAKE)
	cd ..\kstream
	$(MAKE)
	cd ..\krb
	$(MAKE)
	cd ..\..\kwin
	$(MAKE)
	cd ..\wintel
	$(MAKE)
	cd ..

#
# cygin
#
# The all-in-one program that logs you in to a remote Kerberos site
# in one operation.
#
# These rules are sufficient to build this from a working tree, but don't have
# enough dependencies, so don't use for development!
cygin: appl/bsd/cygin
	 rm -f cygin
	 ln appl/bsd/cygin .

install-cygin:
	$(INSTALLPROG) appl/bsd/cygin $(DESTDIR)$(PROGDIR)/cygin

appl/bsd/cygin: include/krb.h lib/kstream/libkstream.a lib/krb/libkrb.a lib/des/libdes.a
	(cd appl/bsd; $(MAKE) $(MFLAGS) "CC=$(CC)" "DBG=$(DBG)" RESOLV=$(RESOLV) cygin)

include/krb.h:
	(cd include; $(MAKE) $(MFLAGS) "CC=$(CC)" "DBG=$(DBG)" RESOLV=$(RESOLV) all)

lib/kstream/libkstream.a:
	(cd lib/kstream; $(MAKE) $(MFLAGS) "CC=$(CC)" "DBG=$(DBG)" RESOLV=$(RESOLV) all)

lib/krb/libkrb.a:
	(cd lib/krb; $(MAKE) $(MFLAGS) "CC=$(CC)" "DBG=$(DBG)" RESOLV=$(RESOLV) all)

lib/des/libdes.a:
	(cd lib/des; $(MAKE) $(MFLAGS) "CC=$(CC)" "DBG=$(DBG)" RESOLV=$(RESOLV) all)

roll:
	for i in $(SUBDIRS); do \
	(cd $$i; $(MAKE) $(MFLAGS) "CC=$(CC)" "DBG=$(DBG)" RESOLV=$(RESOLV) all);\
	(cd $$i; $(RM) *.o);\
	done

depend:
	for i in $(SUBDIRS); do \
	(cd $$i; $(MAKE) $(MFLAGS) "CC=$(CC)" "DBG=$(DBG)" depend)\
	done

install:: install-$(WHAT)

install-unix:
	@for i in $(SUBDIRS); do \
	  if (cd $$i; $(MAKE) $(MFLAGS) "CC=$(CC)" "DBG=$(DBG)" \
		DESTDIR=$(DESTDIR) install); \
	    then true; \
	  else \
	    exit 1; \
	  fi; \
	done
	if test -d $(DESTDIR)$(S)$(KDBDIR); then \
	  true; \
	else \
	  mkdir $(DESTDIR)$(S)$(KDBDIR); \
	fi

install-windows:
	copy doc\*.txt floppy
	copy doc\*.htm floppy
	cd include
	$(MAKE) install
	cd ..\lib\des
	$(MAKE) install
	cd ..\kadm
	$(MAKE) install
	cd ..\kstream
	$(MAKE) install
	cd ..\krb
	$(MAKE) install
	cd ..\..\kwin
	$(MAKE) install
	cd ..\wintel
	$(MAKE) install
	cd ..

install-mac:
	cp ../doc/*.txt $(DESTDIR)
	cp ../doc/*.html $(DESTDIR)
	(cd include; $(MAKE) -f Makefile.in DESTDIR=$(DESTDIR) install-mac)
	cp lib/krb/mac_stubs.c $(DESTDIR)
	cp driver/'%CNS Kerberos' $(DESTDIR)
	cp driver/'%Kerberos Client Preferences' $(DESTDIR)
	cp kconfig/kconfig/'%CNS Config' $(DESTDIR)
	cp mactelnet/'%CNS Telnet' $(DESTDIR)
	rm -f $(DESTDIR)/README
	echo "Cygnus Network Security release for Macintosh." > $(DESTDIR)/README
	echo "Full instructions are in mac.txt or mac.html." >> $(DESTDIR)/README

dist:: dist-$(WHAT)

dist-unix::

dist-windows::
	cd floppy
	pkzip ..\cns95q1.zip *.*

dist-mac:
	echo "Run StuffIt on the Mac, with the whole DESTDIR"
	

clean: clean-$(WHAT)

clean-:: clean-unix
clean-unix:
	rm -rf tmpdir
	for i in $(SUBDIRS); do \
	(cd $$i; $(MAKE) $(MFLAGS) clean)\
	done

clean-windows:
	cd lib\des
	$(MAKE) clean
	cd ..\kadm
	$(MAKE) clean
	cd ..\kstream
	$(MAKE) clean
	cd ..\krb
	$(MAKE) clean
	cd ..\..\kwin
	$(MAKE) clean
	cd ..\wintel
	$(MAKE) clean
	cd ..
	-del include\makefile
	-del lib\des\makefile
	-del lib\kadm\makefile
	-del lib\kstream\makefile
	-del lib\krb\makefile
	-del floppy\*.exe
	-del floppy\*.dll
	-del floppy\*.lib
	-del floppy\*.h
	-del floppy\*.txt
	-del floppy\*.htm
	-del makefile
	-del cns95q1.zip

uninstall:
	@echo "the uninstall target is not supported in this tree"

# Testsuite targets.
site.exp: config.status Makefile
	if [ -f site.exp ]; then \
	  mv site.exp site.bak; \
	else \
	  touch site.bak; \
	fi
	rm -f site.tmp
	echo "## variables are automatically generated by make ##" > site.tmp
	echo "# Do not edit here. If you wish to override these" >> site.tmp
	echo "# values, add them to the last section" >> site.tmp
	echo "set objdir `pwd`" >> site.tmp
	echo "## Variables generated by configure. Do Not Edit ##" >> site.tmp
	cat site.bak | \
	  sed -e '1,/^## Variables generated by.*##/ d' >> site.tmp
	mv site.tmp site.exp

check: site.exp
	$(RUNTEST) --tool krb --srcdir $(srcdir)/testsuite $(RUNTESTFLAGS)

#
# Part of building the Mac release has to be done on Unix at the moment.
# That's done by `make unixmac'.
#
unixmac:
	(cd include; $(MAKE) -f Makefile.uni unixmac S=/)
	(cd ../doc; $(MAKE) -f Makefile.in macdoc)

#
# Rename 8.3 truncated file names back to thier proper unix names
#
ren2long:
	-(cd config; sh ../lib/krb/ren2long.sh)
	-(cd include; sh ../lib/krb/ren2long.sh)
	-(cd kwin; sh ../lib/krb/ren2long.sh)
	-(cd lib/des; sh ../krb/ren2long.sh)
	-(cd lib/kadm; sh ../krb/ren2long.sh)
	-(cd lib/kstream; sh ../krb/ren2long.sh)
	-(cd lib/krb; sh ren2long.sh)
	-(sh lib/krb/ren2long.sh)

#
# Build the zip file that distributes Kerberos sources for DOS sites.
#
ZIPFILES=config include lib/des lib/krb lib/kadm lib/kstream kwin wintel \
	Makefile.in configure.in floppy \
	wconfig.c ren.msg util/et/et_h.awk util/et/et_c.awk ChangeLog
ZIPBINARYFILES=kwin/*.ico wintel/*.ico 
ZIPEXCLUDE=INCLUDE/.CVS LIB/DES/.CVS LIB/DES/%DESLIB- LIB/KRB/%KRBLIB- \
	CONFIG/CVS/* INCLUDE/CVS/* LIB/KRB/CVS/* LIB/DES/CVS/* \
	LIB/DES/DOC/CVS/* LIB/KADM/CVS/* LIB/KSTREAM/CVS/* KWIN/CVS/* \
	KWIN/*.ICO WINTEL/CVS/* WINTEL/*.ICO
kerbsrc.zip: force
	-rm -f kerbsrc.zip
	awk -f util/et/et_h.awk outfile=lib/krb/krb_err.h lib/krb/krb_err.et
	awk -f util/et/et_h.awk outfile=lib/kadm/kadm_err.h lib/kadm/kadm_err.et
	-mkdir floppy
	cp prototypes/etc.krb.realms floppy/krb.rea
	cp prototypes/etc.krb.conf floppy/krb.con
	(cd ../doc; $(MAKE) -f Makefile.in windoc)
	zip -lrk kerbsrc.zip $(ZIPFILES) -x $(ZIPEXCLUDE)
	zip -rk kerbsrc.zip $(ZIPBINARYFILES)
	(cd ..; zip -lrk src/kerbsrc.zip doc -x DOC/CVS/*)
	rm lib/krb/krb_err.h lib/kadm/kadm_err.h
	rm -r floppy

force:

# with the gnu make, this is done automatically.

Makefile: $(srcdir)$(S)Makefile.in $(host_makefile_frag) $(target_makefile_frag) $(package_makefile_frag)
	$(SHELL) ./config.status

makefile-windows: wconfig.c makefile.in config\common config\mt-win \
	config\host config\postfix lib\des\makefile.in lib\kadm\makefile.in \
	lib\kstream\makefile.in lib\krb\makefile.in include\makefile.in
	SET CL=
	$(CC) /AL /Iinclude wconfig.c
	.\wconfig <makefile.in >makefile
	.\wconfig <include\makefile.in >include\makefile
	.\wconfig <lib\des\makefile.in >lib\des\makefile
	.\wconfig <lib\kadm\makefile.in >lib\kadm\makefile
	.\wconfig <lib\kstream\makefile.in >lib\kstream\makefile
	.\wconfig <lib\krb\makefile.in >lib\krb\makefile
	del wconfig.obj
	del wconfig.exe

# end of Makefile.in
# NOPOSTFIX
