dnl Process this file with autoconf to produce a configure script.
AC_INIT(00README.sdfred)

AC_PREFIX_DEFAULT(`pwd`)

if test -z "$MOSHOME"
then
MOSHOME=`pwd`/mosaic
fi

AC_ARG_WITH(neko,AC_HELP_STRING(--with-neko=PATH,nekosoft path)
, MOSHOME=$with_neko)
AC_SUBST(MOSHOME)

AC_CHECK_FILES($MOSHOME/00README.neko,
,AC_MSG_ERROR(nekosoft not found. Set \$MOSHOME or use --with-neko= option.))

SDFREDHOME=`pwd`

AC_ARG_WITH(sdfred,AC_HELP_STRING(--with-sdfred=PATH,sdfred home path)
, SDFREDHOME=$with_sdfred)

SDFREDSH=$SDFREDHOME/sdfredSH
SDFREDCL=$SDFREDHOME/clscripts

AC_SUBST(SDFREDHOME)
AC_SUBST(SDFREDSH)
AC_SUBST(SDFREDCL)

AC_PROG_MAKE_SET 
	
AC_PROG_RANLIB
AC_PROG_MAKE_SET
AC_PROG_AWK

###

AC_PATH_PROG(AWKPROG,$AWK)

AWK=$AWKPROG

AC_PATH_PROG(CSHELL,csh tcsh)
AC_SUBST(CSHELL)

AC_PATH_PROG(CSHELL,tcsh)
AC_SUBST(TCSHELL)

AC_PATH_PROG(SHELL,sh bash ksh)
AC_SUBST(SHELL)

AC_PATH_PROG(PERLPATH,perl)
AC_SUBST(PERLPATH)


#AC_ARG_WITH(sex,
#AC_HELP_STRING(--with-sex=PATH,SExtracror path),
#SEXPATH=$with_sex)

#if  test -n "$SEXPATH" 
#then
#AC_CHECK_FILE($SEXPATH/sex, SEXPROG=$SEXPROG/sex)
#else
#fi
AC_PATH_PROG(CLPROG,cl)
AC_PATH_PROG(MKIRAFPROG,mkiraf)
AC_PATH_PROG(SEXPROG,sex)

AC_PROG_CC

if test -z "$CC"; then
	GCC=""
fi

AC_CANONICAL_SYSTEM
SET_GCC=""

case "$host_os" in
hpux*)
    if test -z "$GCC"; then
      CFLAGS="$CFLAGS -Ae"
    fi
    ;;
sunos*|sol*)
    if test -n "$GCC" ; then
      SET_GCC="CC=$CC"
    fi
    ;;
*)
    :
    ;;
esac
AC_SUBST(SET_GCC)

CFLAGS="$CFLAGS "'-I$(IMC) '

AC_SUBST(CFLAGS)

## for randXY (XPG4) not needed?
#AC_CHECK_FUNCS(drand48)

## SEx VERSION CHECK  (not impl.)
##
#AC_CHECK_FILE($SEXPROG,,
#AC_MSG_WARN(SExtractor is not found. Set PATH or use --with-sex= option.))

## SEXPROG=/usr/local/bin/sex

#AC_SUBST(SEXPROG)

AC_CONFIG_SUBDIRS(mosaic)

AC_OUTPUT(Makefile sdfred/Makefile sdfredSH/Makefile
sdfredSH/blank/blank.csh                      
sdfredSH/distcorr/distcorr.csh                
sdfredSH/ffield/ffield.csh                    
sdfredSH/fwhmpsf/fwhmpsf.csh                  
sdfredSH/fwhmpsf_batch/fwhmpsf_batch.csh      
sdfredSH/limitmag/limitmag.csh
sdfredSH/makemos/makemos.csh                  
sdfredSH/mask_AGX/mask_AGX.csh            
sdfredSH/mask_mkflat_HA/mask_mkflat_HA.csh
sdfredSH/namechange/namechange.csh            
sdfredSH/overscansub/overscansub.csh      
sdfredSH/psfmatch/psfmatch.csh
sdfredSH/psfmatch_batch/psfmatch_batch.csh
sdfredSH/skysb/skysb.csh
sdfredSH/skysb_reg/skysb_reg.csh          
sdfredSH/starselect/starselect.csh
sdfredSH/spcamred/spcamred.csh

sdfredSH/mask_mkflat_HA/mask_mkflat_HA.sex
sdfredSH/fwhmpsf/fwhmpsf.sex
sdfredSH/psfmatch/psfmatch.sex
sdfredSH/skysb/skysb.sex
sdfredSH/skysb_reg/skysb_reg.sex
sdfredSH/starselect/starselect.sex

clscripts/Makefile
clscripts/SPCAMim2FOCASim/SPCAMim2FOCASim.csh
clscripts/geomatch/geomatch.cl
clscripts/geomatch/geomatch.sex
clscripts/limitmag/limitmag.cl
clscripts/limitmag/limitmag.sex

)

cat << END

configured as 
  sdfred home PATH  : $SDFREDHOME
  nekosoft PATH     : $MOSHOME
  sdfred shell PATH : $SDFREDSH
  awk(gawk)         : $AWK
END

if test -z "$SEXPROG"
then
echo
echo "Warning: SExtractor(sex) is not found in your PATH"
echo "         scripts in sdfredSH/... may not work correctly"
echo
fi

if test -z "$CLPROG"
then
echo
echo "Warning: IRAF(cl) is not found in your PATH"
echo "         scripts in clscripts/... may not work correctly"
echo
fi
#  

