##############################################################################

## This file is a shell script fragment that supplies the information
## necessary to tailor a template configure script into the configure
## script appropriate for this directory.  For more information, check
## any existing configure script.  

## Be warned, there are two types of configure.in files.  There are those
## used by Autoconf, which are macros which are expanded into a configure
## script by autoconf.  The other sort, of which this is one, is executed
## by Cygnus configure.  

## For more information on these two systems, check out the documentation
## for 'Autoconf' (autoconf.texi) and 'Configure' (configure.texi).  


################################################################################


################################################################################

configdirs="util util/et util/makedepend util/ss include lib lib/acl \
lib/des lib/kadm lib/kdb lib/krb lib/kstream POP admin appl \
appl/bsd appl/sample appl/tftp appl/tftp/doc appl/x5dm \
kadmin kuser man movemail pfrom server slave tests"
configdirs=""
x11subdirs="appl/x5dm"
utilsubdirs="util util/makedepend util/et util/ss"
libsubdirs="include lib lib/des lib/krb lib/kdb lib/kadm lib/acl lib/kstream"
othersubdirs="kuser kadmin server slave admin appl appl/bsd man tests appl/tftp appl/sample appl/telnet appl/telnet/libtelnet appl/telnet/telnet appl/telnet/telnetd appl/ftp appl/ftp/ftp appl/ftp/ftpd"
emailsubdirs="email email/movemail email/pfrom email/POP"
subdirs="$utilsubdirs $libsubdirs $othersubdirs $emailsubdirs"

# for makefile substitution
extrasubdirs=

winsubdirs="include lib/des lib/krb kuser"
macsubdirs="include lib/des lib/krb kuser"

srctrigger=Makefile.in
srcname="kerberos"

package_makefile_frag=config/common

# per-host:

# Configure appl/rdist subdirectory.  Simply setting configdirs doesn't help,
# because Cygnus configure assumes the subdirectory is only one level down,
# and it would get $newsrcdir wrong that way if $srcdir is relative.
case "${host}" in
  *-*-macos* | *-*-mpw* | \
  *-*-windows* )
    # Not supported, and probably never will be.
    ;;
  *-*-sco* | *-*-sysv3* | m68k-next-bsd* | i960-*-vxworks* | \
  *-*-ultrix3* | rs6000-ibm-aix4* | powerpc-ibm-aix4* | mips*-pyramid-osx*)
    # Not supported yet, but it probably wouldn't take much work.
    ;;
  *)
    if test -f $srcdir/appl/rdist/configure ; then
      extrasubdirs="$extrasubdirs appl/rdist"
      echo Configuring appl/rdist...
      for d in appl appl/rdist ; do
	if test -d $d || mkdir $d ; then true; else
	 echo "Can't create $d subdir." 1>&2 ; exit 1 ; fi
      done
      popdir=`pwd`
      case "${srcdir}" in
      .)	newsrcdir=. ;;
      /*)	newsrcdir=${srcdir}/appl/rdist ;;
      *)	newsrcdir=../../${srcdir}/appl/rdist ;;
      esac
      case "${newsrcdir}" in
      .)	srcdiroption= ;;
      *)	srcdiroption="--srcdir=$newsrcdir" ;;
      esac
      cd appl/rdist
      if eval ${config_shell} ${newsrcdir}/configure ${verbose} \
	    ${buildopt} --host=${host_alias} --target=${target_alias} \
	    ${prefixoption} ${tmpdiroption} ${exec_prefixoption} \
	    ${srcdiroption} ${site_option} ${withoptions} ${withoutoptions} \
	    ${enableoptions} ${disableoptions} ${other_options} ${redirect}
      then
	true
      else
	echo Configure in `pwd` failed, exiting. 1>&2
	exit 1
      fi
      cd $popdir
    fi
    ;;
esac

host_makefile_frag=config/host

# per-target:

# FIXME: This should actually be based on the host.  Kerberos does not
# have a target.  Its configury should be based on the host.

case "${target}" in
  sparc-sun-solaris2*)	target_makefile_frag=config/mt-spsol ;;
  sparc-sun-sunos4*)	target_makefile_frag=config/mt-sun ;;
  m68k-sun-sunos4*)	target_makefile_frag=config/mt-sun ;;
  mips*-dec-ultrix*)    target_makefile_frag=config/mt-decstation ;;
  mips*-sgi-irix4*)     target_makefile_frag=config/mt-irix4 ;;
  mips*-sgi-irix5*)	target_makefile_frag=config/mt-irix5 ;;
  i[345]86-*-sco*)      target_makefile_frag=config/mt-sco
			# subdirs="$subdirs appl/x5dm"
			;;
  i[345]86-*-sysv3.2*)	target_makefile_frag=config/mt-sco32 ;;
  i[345]86-*-linux*)    target_makefile_frag=config/mt-linux ;;
  i[345]86-*-bsd*)      target_makefile_frag=config/mt-386bsd ;;
  i[345]86-*-sysv4.2*)  target_makefile_frag=config/mt-386svr4 ;;
  rs6000-ibm-aix*)	target_makefile_frag=config/mt-rsaix ;;
  powerpc-ibm-aix*)	target_makefile_frag=config/mt-rsaix ;;
  hppa1.1-hp-hpux*)	target_makefile_frag=config/mt-snake ;;
  m68k-hp-hpux*)	target_makefile_frag=config/mt-hp300 ;;
  m68k-next-bsd*)	target_makefile_frag=config/mt-next ;;
  *-*-macos* | *-*-mpw*)	target_makefile_frag=config/mt-mac
			subdirs="$macsubdirs" ;;
  alpha-dec-osf*)	target_makefile_frag=config/mt-alpha ;;
  i[34]86-*-windows*)	target_makefile_frag=config/mt-win
			subdirs="$winsubdirs" ;;
  i960-*-vxworks*)	target_makefile_frag=config/mt-i960vx ;;
  mips*-pyramid-osx*)	target_makefile_frag=config/mt-pyramid ;;
  m88k-dg-dgux*)	target_makefile_frag=config/mt-dgux88k ;;
  *) echo "Target ${target} not supported yet"; exit 1;;
esac

# some tools are only suitable for building in a "native" situation.
# Those are added when we have a host==target configuration.  For cross
# toolchains, we add some directories that should only be useful in a
# cross-compiler.

if [ x"${host}" != x"${target}" ] ; then
	echo "Cross build not supported yet" ; exit 1
fi	

# post-target:

# Record ${subdirs} in the make variable SUBDIRS.
rm -f ${Makefile}.tem
sed -e "s:^SUBDIRS[ 	]*=.*$:SUBDIRS = $subdirs $extrasubdirs:" \
    ${Makefile} > ${Makefile}.tem
rm -f ${Makefile}
mv ${Makefile}.tem ${Makefile}

case ${with_x11r5_lib} in
  "") x11r5lib=
      ;;
  *)  x11r5lib="-L${with_x11r5_lib}"
      ;;
esac

case ${with_x11r5_include} in
  "") x11r5inc=
      ;;
  *)  x11r5inc="-I${with_x11r5_include}"
      ;;
esac

if grep '# USE X11R5' ${Makefile} >/dev/null ; then
	rm -f ${Makefile}.tem
	mv ${Makefile} ${Makefile}.tem
	echo XLD=${x11r5lib} > ${Makefile}
	echo INCLUDE_ARG=${x11r5inc} >> ${Makefile}
	cat ${Makefile}.tem >> ${Makefile}
	rm -f ${Makefile}.tem
	echo "modified ${Makefile} for x11 headers"
fi

postfix_makefile_frag=config/postfix
if [ ! -f ${postfix_makefile_frag} ] ; then
  postfix_makefile_frag=${srcdir}/${postfix_makefile_frag}
fi
if [ -f ${postfix_makefile_frag} ] ; then
  if grep '^# NOPOSTFIX' ${Makefile} >/dev/null ; then
    true
  else
    cat ${postfix_makefile_frag} >> ${Makefile}
  fi
fi

# Temporary hackery (gnu@cygnus.com May94) for Mac crud
# Move existing Makefile to Makefile.uni
# Figure out name of new (lowercase) makefile.
#  Turn { into ( in macro calls
#  Turn } into ) in macro calls
#  Turn / into \ except on lines that call sed (which needs fwd /)
#  Remove CC= lines.
#  Turn .o into .obj everywhere after alphabetics or @ ($@).
#  In the ORGANIZATION define, turn string '"'" into "\" for NMAKE.
#  In the ORGANIZATION define, turn string "'"' into \"" for NMAKE.
#    from Makefile.uni
#    into makefile
# Set the string that is used to print what we did, to use lowercase makefile.
case "${target_os}" in
  macos* | mpw*)
	mv ${Makefile} ${Makefile}.uni
	mf2=`echo ${Makefile} | sed 's,Makefile$,MakeFile,'`
	# Hack up the Unix makefile into an MPW Makefile.
	( cat ${srcdir}/mac-mf.frag; \
	  sed -f ${srcdir}/mac-mf.sed ${Makefile}.uni) >${mf2}.tmp
	(grep '^srcdir' ${mf2}.tmp; grep -v '^srcdir' ${mf2}.tmp) >${mf2}
	rm -f ${mf2}.tmp
	Makefile=${mf2}
	;;
esac
