dnl $Id: configure.in,v 1.238 2006/09/29 16:37:40 nlopess Exp $

dnl autoconf initialisation
AC_INIT()
SRCDIR=$srcdir
WORKDIR=`pwd`
AC_SUBST(SRCDIR)
AC_SUBST(WORKDIR)

dnl debug output
echo "file versions"
for file in $srcdir/*.in; do
  fgrep '$Id' $file | head -n1 | sed -e"s/^.*: //g" | sed -e"s/200.\/.*$//g"
done
echo "configure options: $@" 
echo "source directory: $srcdir"
echo "working directory: $WORKDIR"
echo

dnl {{{ check for support programs

dnl {{{   check for PHP

dnl use given argument, if any, else search in path 
AC_ARG_WITH(php,
[  --with-php=PATH         look for PHP executable needed for helper scripts],
[
  if test $withval != "yes"; then
    AC_MSG_CHECKING([for php])
    if test -x $withval; then
      PHP=$withval
      AC_MSG_RESULT($PHP)
    else
      PHP=no
      AC_MSG_RESULT(no)
      AC_MSG_ERROR([$withval: not an executable file])
    fi
  else
    if test -e ../phpdoc-tools/php.bat ; then
      AC_MSG_CHECKING([for php])
      PHP=../phpdoc-tools/php.bat
      AC_MSG_RESULT($PHP)
    else
      if test -e "$PHP_PEAR_BIN_DIR/cli/php" ; then
        AC_MSG_CHECKING([for php])
        PHP=`echo $PHP_PEAR_BIN_DIR/cli/php | tr '\\\\' '/'`
        AC_MSG_RESULT($PHP)
      else 
        AC_PATH_PROGS(PHP,"php php4",no)
      fi
    fi
  fi
],[
  if test -e ../phpdoc-tools/php.bat ; then
    AC_MSG_CHECKING([for php])
    PHP=../phpdoc-tools/php.bat
    AC_MSG_RESULT($PHP)
  else
    if test -e "$PHP_PEAR_BIN_DIR/cli/php" ; then
      AC_MSG_CHECKING([for php])
      PHP=`echo $PHP_PEAR_BIN_DIR/cli/php | tr '\\\\' '/'`
      AC_MSG_RESULT($PHP)
    else 
      AC_PATH_PROGS(PHP,"php php4",no)
    fi
  fi
]
)
if test $PHP = "no"; then
  AC_MSG_ERROR([no PHP binary found])
else
  AC_MSG_CHECKING([php version])
  PHPVERSION=`$PHP -q -f $srcdir/scripts/version.php`

  if test "yes" = `echo '<?php echo phpversion()>3?"yes":"no"; ?>' | $PHP -q`; then
    AC_MSG_RESULT($PHPVERSION)
  else
    AC_MSG_RESULT($PHPVERSION)
    AC_MSG_ERROR([PHP version 4.0.0 or newer needed])
    PHP=no
  fi
fi
AC_SUBST(PHP)

dnl }}}

dnl {{{
AC_MSG_CHECKING(for php.ini path)
AC_ARG_WITH(inipath,
[  --with-inipath=PATH     specify path to php.ini file (default: ./scripts)],
[
    AC_MSG_RESULT([$withval])
    INIPATH="$withval"
],[
    AC_MSG_RESULT([./scripts])
        INIPATH="./scripts"
])

AC_SUBST(INIPATH)

dnl }}}

dnl {{{   check for the Jade or OpenJade DSSSL parser

dnl use given argument, if any, else search in path 

AC_ARG_WITH(jade,
[  --with-jade=PATH        look for jade or openjade executable],[
  if test $withval != "yes"; then
    AC_MSG_CHECKING([for jade])
    if test -x $withval; then
      JADE=$withval
      AC_MSG_RESULT($JADE)
    else
      JADE=no
      AC_MSG_RESULT(no)
      AC_MSG_ERROR([$withval: not an executable file])
    fi
  else
    if test -e ../phpdoc-tools/jade/jade.exe ; then
      AC_MSG_CHECKING([for jade])
      JADE=../phpdoc-tools/jade/jade.exe
      AC_MSG_RESULT($JADE)
    else
      if test -e ../phpdoc-tools/openjade/openjade.exe ; then
        AC_MSG_CHECKING([for jade])
        JADE=../phpdoc-tools/openjade/openjade.exe
        AC_MSG_RESULT($JADE)
      else
        AC_PATH_PROGS(JADE,"openjade jade",no)
      fi
    fi
  fi
],[
  if test -e ../phpdoc-tools/jade/jade.exe ; then
    AC_MSG_CHECKING([for jade])
    JADE=../phpdoc-tools/jade/jade.exe
    AC_MSG_RESULT($JADE)
  else
    if test -e ../phpdoc-tools/openjade/openjade.exe ; then
      AC_MSG_CHECKING([for jade])
      JADE=../phpdoc-tools/openjade/openjade.exe
      AC_MSG_RESULT($JADE)
    else
      AC_PATH_PROGS(JADE,"openjade jade",no)
    fi
  fi
]
)
if test $JADE = "no"; then
  AC_MSG_ERROR([can't find jade or openjade])
fi
if test `expr $JADE : ../phpdoc-tools` -ne 0; then
  WINJADE=1
else
  WINJADE=0
fi
AC_SUBST(JADE)
AC_SUBST(WINJADE)

dnl }}}

dnl {{{   check for nsgmls or onsgmls

AC_ARG_WITH(nsgmls,
[  --with-nsgmls=PATH      look for nsgmls or onsgmls executable],[
  if test $withval != "yes"; then
    AC_MSG_CHECKING([for nsgmls])
    if test -x $withval; then
      NSGMLS=$withval
      AC_MSG_RESULT($NSGMLS)
    else
      NSGMLS=no
      AC_MSG_RESULT(no)
      AC_MSG_ERROR([$withval: not an executable file])
    fi
  else
    if test -e ../phpdoc-tools/jade/nsgmls.exe ; then
      AC_MSG_CHECKING([for nsgmls])
      NSGMLS=../phpdoc-tools/jade/nsgmls.exe
      AC_MSG_RESULT($NSGMLS)
    else
      if test -e ../phpdoc-tools/openjade/onsgmls.exe ; then
        AC_MSG_CHECKING([for nsgmls])
        NSGMLS=../phpdoc-tools/openjade/onsgmls.exe
        AC_MSG_RESULT($NSGMLS)
      else
        AC_PATH_PROGS(NSGMLS,"onsgmls nsgmls",no)
      fi
    fi
  fi
],[
  if test -e ../phpdoc-tools/jade/nsgmls.exe ; then
    AC_MSG_CHECKING([for nsgmls])
    NSGMLS=../phpdoc-tools/jade/nsgmls.exe
    AC_MSG_RESULT($NSGMLS)
  else
    if test -e ../phpdoc-tools/openjade/onsgmls.exe ; then
      AC_MSG_CHECKING([for nsgmls])
      NSGMLS=../phpdoc-tools/openjade/onsgmls.exe
      AC_MSG_RESULT($NSGMLS)
    else
      AC_PATH_PROGS(NSGMLS,"onsgmls nsgmls",no)
    fi
  fi
]
)
if test $NSGMLS = "no"; then
  AC_MSG_ERROR([can't find nsgmls or onsgmls])
fi
AC_SUBST(NSGMLS)

dnl }}}

dnl {{{   check for xsltproc
dnl use given argument, if any, else search in path

AC_ARG_WITH(xsltproc,
[  --with-xsltproc=PATH    look for xsltproc],
[
  if test $withval != "yes"; then
    AC_MSG_CHECKING([for xsltproc])
    if test -x $withval -a -f $withval
    then
      XSLTPROC=$withval
      AC_MSG_RESULT($XSLTPROC)
    else
      XSLTPROC=no
      AC_MSG_RESULT(no)
      AC_MSG_ERROR([$withval: not an executable file])
    fi
  else
    if test -e ../phpdoc-tools/libxml/xsltproc.exe ; then
      AC_MSG_CHECKING([for xsltproc])
      XSLTPROC=../phpdoc-tools/libxml/xsltproc.exe
      AC_MSG_RESULT($XSLTPROC)
    else
      AC_PATH_PROG(XSLTPROC,"xsltproc",no)
    fi
  fi
],[
  if test -e ../phpdoc-tools/libxml/xsltproc.exe ; then
    AC_MSG_CHECKING([for xsltproc])
    XSLTPROC=../phpdoc-tools/libxml/xsltproc.exe
    AC_MSG_RESULT($XSLTPROC)
  else
    AC_PATH_PROG(XSLTPROC,"xsltproc",no)
  fi
]
)
if test $XSLTPROC = "no"; then
  AC_MSG_WARN([no xsltproc binary found, XSL Transformations won't work])
fi
AC_SUBST(XSLTPROC)

dnl }}}

dnl {{{   check for xmllint
dnl use given argument, if any, else search in path

AC_ARG_WITH(xmllint,
[  --with-xmllint=PATH     check for xmllint],
[
  if test $withval != "yes"; then
    AC_MSG_CHECKING([for xmllint])
    if test -x $withval -a -f $withval
    then
      XMLLINT=$withval
      AC_MSG_RESULT($XMLLINT)
    else
      XMLLINT=no
      AC_MSG_RESULT(no)
      AC_MSG_ERROR([$withval: no xmllint binary found])
    fi
  else
    if test -e ../phpdoc-tools/libxml/xmllint.exe ; then
      AC_MSG_CHECKING([for xmllint])
      XSLTPROC=../phpdoc-tools/libxml/xmllint.exe
      AC_MSG_RESULT($XMLLINT)
    else
      AC_PATH_PROG(XMLLINT,"xmllint",no)
    fi
  fi
],[
  if test -e ../phpdoc-tools/libxml/xmllint.exe ; then
    AC_MSG_CHECKING([for xmllint])
    XMLLINT=../phpdoc-tools/libxml/xmllint.exe
    AC_MSG_RESULT($XMLLINT)
  else
    AC_PATH_PROG(XMLLINT,"xmllint",no)
  fi
]
)
if test $XMLLINT = "no"; then
  AC_MSG_WARN([no xmllint binary found, XML Validation won't work])
fi
AC_SUBST(XMLLINT)

dnl }}}

dnl }}}

dnl {{{ check for DocBook stuff

dnl {{{   check for DSSSL stylesheets

AC_MSG_CHECKING(for docbook.dsl)

AC_ARG_WITH(dsssl,
[  --with-dsssl=[DIR]        look for DSSSL stylesheets in the specified directory],
[
  if test -f "$withval/html/docbook.dsl" ; then
    DOCBOOK_HTML=$withval/html/docbook.dsl
    DOCBOOK_PRINT=$withval/print/docbook.dsl
    AC_MSG_RESULT(in $withval)
  fi
],[
  DOCBOOK_HTML="$srcdir/dsssl/docbook/html/docbook.dsl"
  DOCBOOK_PRINT="$srcdir/dsssl/docbook/print/docbook.dsl"
  AC_MSG_RESULT([$srcdir/dsssl/docbook (default)])
])
if test -z "$DOCBOOK_HTML"; then
    AC_MSG_RESULT(not found)
fi

AC_SUBST(DOCBOOK_HTML)
AC_SUBST(DOCBOOK_PRINT)

dnl }}}

dnl {{{   check for catalog files

dnl Do something smart to find catalog-files
CATALOG=""


dnl iso-ents catalog file
dnl The 4.1.2 DocBook DTD also includes entity files, but they cannot be used with Jade!
if test -e $srcdir/entities/ISO/catalog
then
  CATALOG="$CATALOG -c $srcdir/entities/ISO/catalog"
fi

dnl DSSSL catalog file
if test -e $srcdir/dsssl/docbook/catalog
then
  CATALOG="$CATALOG -c $srcdir/dsssl/docbook/catalog"
fi

dnl For windows (and maybe *nix too?) users lacking catalog-files

dnl jade catalog file
# how about using JADEPATH? You should replace the last 4 chars ('jade') with catalog
# !! JADEPATH may not properly be set on windows, so do not use it !!
if test -e ../phpdoc-tools/jade/catalog
then
  CATALOG="$CATALOG -c ../phpdoc-tools/jade/catalog"
fi
dnl SuSE openjade setup
if test -e /usr/share/sgml/CATALOG.docbk41
then
  CATALOG="$CATALOG -c /usr/share/sgml/CATALOG.docbk41"
fi
if test -e /usr/share/sgml/CATALOG.jade_dsl
then
  CATALOG="$CATALOG -c /usr/share/sgml/CATALOG.jade_dsl"
fi

dnl As a very last option, include default catalog files from phpdoc
dnl (imported from the openjade distribution)
if test -e $srcdir/dsssl/defaults/catalog
then
  CATALOG="$CATALOG -c $srcdir/dsssl/defaults/catalog"
fi

AC_SUBST(CATALOG)

dnl }}}

dnl }}}

dnl {{{ check for additional docs and sources

dnl {{{ check for PHP sourcecode

AC_MSG_CHECKING(for PHP source path)
AC_ARG_WITH(source,
[  --with-source=[DIR]       look at the specified source directory],
[
  if test -d "$withval" ; then
    PHP_SOURCE=$withval
  else
    for PHP_SOURCE in \
	$srcdir/../php-src \
	$srcdir/../php5 \
	$srcdir/../php4
    do
	if test -d $PHP_SOURCE; then
            break
	fi
    done
  fi
],[
  for PHP_SOURCE in \
      $srcdir/../php-src \
      $srcdir/../php5 \
      $srcdir/../php4
  do
      if test -d $PHP_SOURCE; then
          break
      fi
  done
])
if test ! -d $PHP_SOURCE; then
    PHP_SOURCE=no
fi
AC_MSG_RESULT($PHP_SOURCE)
AC_SUBST(PHP_SOURCE)

dnl }}}

dnl {{{ check for PEAR sources

AC_MSG_CHECKING(for PEAR source path)
AC_ARG_WITH(pear-source,
[  --with-pear-source=[DIR]  look at the specified PEAR directory],
[
  if test "$withval" = "yes"; then
    PEAR_SOURCE=$srcdir/../pear
    if test ! -d $PEAR_SOURCE; then
      PEAR_SOURCE=no
    fi  
  else
    PEAR_SOURCE=$withval
    if test ! -d $PEAR_SOURCE; then
      AC_MSG_ERROR(['$withval' is not a valid directory']) 
    fi
  fi
],[
  PEAR_SOURCE=no
])
AC_MSG_RESULT($PEAR_SOURCE)
AC_SUBST(PEAR_SOURCE)

dnl }}}

dnl {{{ check for PECL sources

AC_MSG_CHECKING(for PECL source path)
AC_ARG_WITH(pecl-source,
[  --with-pecl-source=[DIR]  look at the specified PECL directory],
[
  if test "$withval" = "yes"; then
    PECL_SOURCE=$srcdir/../pecl
    if test ! -d $PECL_SOURCE; then
      PECL_SOURCE=no
    fi  
  else
    PECL_SOURCE=$withval
    if test ! -d $PECL_SOURCE; then
      AC_MSG_ERROR(['$withval' is not a valid directory']) 
    fi
  fi
],[
  PECL_SOURCE=no
])
AC_MSG_RESULT($PECL_SOURCE)
AC_SUBST(PECL_SOURCE)

dnl }}}

dnl {{{ check for additional extension sources

AC_MSG_CHECKING(for additional PHP extensions)
AC_ARG_WITH(extension,
[  --with-extension=[DIR]    look at the specified extension directory],
[
  AC_MSG_RESULT($withval)
  list=`echo "$withval" | sed -e"s/,/ /g"`
  EXT_SOURCE="";
  for dir in $list; do
    if test -d "$dir/manual"; then
    AC_MSG_RESULT([  extension '$dir' ok])
      EXT_SOURCE="$EXT_SOURCE:$dir"
    else
      AC_MSG_WARN([  extension '$dir' ignored])
    fi
  done
])
if test "$EXT_SOURCE" = ""; then
  AC_MSG_RESULT([no])
fi
dnl }}}
AC_SUBST(EXT_SOURCE)

dnl {{{
AC_MSG_CHECKING(for CSS to use for html docs)
AC_ARG_WITH(htmlcss,
[  --with-htmlcss=URL      specify a CSS file to include in html docs],
[
    AC_MSG_RESULT([$withval])
    HTMLCSS="(define %stylesheet% \"$withval\")"
],[
    HTMLCSS=""
    AC_MSG_RESULT([none])
])

AC_SUBST(HTMLCSS)

dnl }}}

dnl {{{ enable Windows HTML Help only pages in build

AC_MSG_CHECKING(for chmonly inclusion)

AC_ARG_WITH(chm,
[  --with-chm=yes          enable Windows HTML Help Edition pages],
[
  if test "$withval" = "yes"; then
    CHMENABLED=yes
    CHMONLY_INCL_BEGIN=""
    CHMONLY_INCL_END=""
    AC_MSG_RESULT([enabled])
  else
    CHMENABLED=no
    CHMONLY_INCL_BEGIN="<!--"
    CHMONLY_INCL_END="-->"
    AC_MSG_RESULT([disabled])
  fi
],[
  CHMENABLED=no
  CHMONLY_INCL_BEGIN="<!--"
  CHMONLY_INCL_END="-->"
  AC_MSG_RESULT([disabled (default)])
])

AC_SUBST(CHMONLY_INCL_BEGIN)
AC_SUBST(CHMONLY_INCL_END)

dnl }}}


dnl {{{ disable Internals documentation

AC_MSG_CHECKING(for internals docs exclusion)

AC_ARG_WITH(internals,
[  --without-internals     exclude internals documentation],
[
  INTERNALS_EXCL_BEGIN="<!--"
  INTERNALS_EXCL_END="-->"
  AC_MSG_RESULT([yes])
],[
  INTERNALS_EXCL_BEGIN=""
  INTERNALS_EXCL_END=""
  AC_MSG_RESULT([no (default)])
])

AC_SUBST(INTERNALS_EXCL_BEGIN)
AC_SUBST(INTERNALS_EXCL_END)

dnl }}}

dnl }}}

dnl {{{ language specific stuff

AC_MSG_CHECKING(for language)

PHP_BUILD_DATE=`date '+%Y-%m-%d'`
AC_ARG_WITH(lang,
[  --with-lang=LANG        choose a language to work with],[
  if test "$withval" = "yes"; then
    LANG="en"
    LANGWEB="en"
    MANUAL="php_manual_$LANG"
    AC_MSG_RESULT([en (default)])
  else
    if test ! -d "$srcdir/$withval"; then
      AC_MSG_RESULT()
      AC_MSG_ERROR(Language \"$withval\" not supported!)
    fi
       
    LANG_HACK_FOR_HE="no"
    HACK_RTL_LANGS_PAGES=""
    HACK_RTL_LANGS_PHPWEB=""
    case $withval in
      kr)
        LANG="ko"
        LANGWEB="ko"
        LANGDIR="kr"
      ;;
      ja)
        LANG="ja"
        LANGWEB="ja"
        LANGDIR="ja"
        PHP_BUILD_DATE=`date '+%Y/%m/%d'`
      ;;
      he)
        LANG="en"
        LANGWEB="he"
        LANG_HACK_FOR_HE="yes"
        HACK_RTL_LANGS_PAGES="$PHP $srcdir/scripts/rtlpatch/rtlpatch.php ./html"
        HACK_RTL_LANGS_PHPWEB="$PHP $srcdir/scripts/rtlpatch/rtlpatch.php ./php"
        LANGDIR="he"
      ;;
      hk)
        LANG="zh_hk"
        LANGWEB="zh_hk"
        LANGDIR="hk"
      ;;
      tw)
        LANG="zh_tw"
        LANGWEB="zh_tw"
        LANGDIR="tw"
      ;;
      zh)
        LANG="zh_cn"
        LANGWEB="zh_cn"
        LANGDIR="zh"
      ;;
      *)
        LANG=$withval
        LANGWEB=$withval
        LANGDIR=$withval
    esac
    AC_SUBST(HACK_RTL_LANGS_PAGES)
    AC_SUBST(HACK_RTL_LANGS_PHPWEB)
    MANUAL="php_manual_$withval"
    AC_MSG_RESULT( $withval )
  fi
],[
  LANG="en"
  LANGWEB="en"
  LANGDIR="en"
  MANUAL="php_manual_$LANG"
  AC_MSG_RESULT([en (default)])
])
AC_SUBST(LANG)
AC_SUBST(LANGWEB)
AC_SUBST(LANGDIR)
AC_SUBST(PHP_BUILD_DATE)
AC_SUBST(MANUAL)

dnl localize paper size by language
dnl (instead of using system-dependant default)
case "$LANG" in
  ar|cs|de|hu|it|ja|ko|pl|ro|sk|tr|zh_hk|zh_tw|zh_cn)
    PAPER_TYPE="A4"
    PDF_PAPER_TYPE="a4"
    ;;
  *)
    PAPER_TYPE="USletter"
    PDF_PAPER_TYPE="letter"
    ;;
esac
AC_SUBST(PAPER_TYPE)
AC_SUBST(PDF_PAPER_TYPE)


dnl localize order of number and element name
dnl in some headers autogenerated by jade
case "$LANG" in
  hu|ko) NUMBER_FIRST="#t" ;;
  *) NUMBER_FIRST="#f" ;;
esac
AC_SUBST(NUMBER_FIRST)


dnl optionaly reduce margins to save some trees life
dnl this works is dsssl only for now
AC_MSG_CHECKING(for treesaving)
AC_ARG_WITH(treesaving,
[  --with-treesaving       save trees by setting pagesize and margins],
[
  TREESAVING="#t";
  LEFT_MARGIN="(define %left-margin% 4pi)";   
  RIGHT_MARGIN="(define %right-margin% 3pi)";
  TOP_MARGIN="(define %top-margin% 3pi)";
  HEADER_MARGIN="(define %header-margin% 2pi)";
  FOOTER_MARGIN="(define %footer-margin% 2pi)";
  BOTTOM_MARGIN="(define %bottom-margin% 3pi)";
  LINE_SPACING="(define %line-spacing-factor% 1.2)";
  HEAD_BEFORE="(define %head-before-factor% 0.6)";
  HEAD_AFTER="(define %head-after-factor% 0.3)";
  BODY_START="(define %body-start-indent% 3pi)";
  BLOCK_SEP="(define %block-sep% (* %para-sep% 1.2))";
],[ 
  TREESAVING="#f";
  LEFT_MARGIN="";   
  RIGHT_MARGIN="";
  TOP_MARGIN="";
  HEADER_MARGIN="";
  FOOTER_MARGIN=""; 
  BOTTOM_MARGIN=""; 
  LINE_SPACING="";
  HEAD_BEFORE="";
  HEAD_AFTER="";
  BODY_START="";
  BLOCK_SEP="";
])
AC_SUBST(LEFT_MARGIN)
AC_SUBST(RIGHT_MARGIN)
AC_SUBST(TOP_MARGIN)
AC_SUBST(HEADER_MARGIN)
AC_SUBST(FOOTER_MARGIN)
AC_SUBST(BOTTOM_MARGIN)
AC_SUBST(LINE_SPACING)
AC_SUBST(HEAD_BEFORE)
AC_SUBST(HEAD_AFTER)
AC_SUBST(BODY_START)
AC_SUBST(BLOCK_SEP)
AC_SUBST(TREESAVING)
echo "saving trees: $TREESAVING";

case "$LANG" in
  zh_tw|zh_hk) ENCODING="big5";;
  zh_cn) ENCODING="gb2312";;
  cs|hu|ro|sk) ENCODING="ISO-8859-2";;
  ar) ENCODING="ISO-8859-6";;
  tr) ENCODING="ISO-8859-9";;
  he) ENCODING="ISO-8859-8";;
  el) ENCODING="ISO-8859-7";;
  *) ENCODING="UTF-8";;
esac
if test "$LANG_HACK_FOR_HE" = "yes"; then
  ENCODING="ISO-8859-8"
fi

dnl localize the PalmPilot DOC title
case "$LANG" in
  de) PALMDOCTITLE="'PHP Handbuch'";;
  es) PALMDOCTITLE="'Manual de PHP'";;
  fr) PALMDOCTITLE="'Manuel PHP'";;
  hu) PALMDOCTITLE="'PHP K�zik�nyv'";;
  it) PALMDOCTITLE="'Manuale PHP'";;
  nl) PALMDOCTITLE="'PHP Handleiding'";;
  pl) PALMDOCTITLE="'Podr�cznik PHP'";;
  pt_BR) PALMDOCTITLE="'Manual do PHP'";;
  ro) PALMDOCTITLE="'Manual PHP'";;
# tr) PALMDOCTITLE="";;
  zh_hk) PALMDOCTITLE="PHP ��U";;
  *) PALMDOCTITLE="'PHP Manual'";;
esac
AC_SUBST(PALMDOCTITLE)

HTMLHELP_ENCODING=$ENCODING
SP_OPTIONS="SP_ENCODING=XML SP_CHARSET_FIXED=YES"

case "$ENCODING" in
  ISO-8859-2)
    HTMLHELP_ENCODING="windows-1250"
    ;;
  ISO-8859-6)
    HTMLHELP_ENCODING="windows-1256"
    ;;
  ISO-8859-8)
    HTMLHELP_ENCODING="windows-1255"
    ;;
  ISO-8859-9)
    HTMLHELP_ENCODING="windows-1254"
    ;;
esac

ENCODING="UTF-8"
AC_SUBST(ENCODING)
AC_SUBST(SP_OPTIONS)

AC_SUBST(HTMLHELP_ENCODING)

dnl }}}

dnl {{{ makefile targets for configure-generated files

rm -f autogenerated_rules


echo -n "checking for *.in files... "
if test -e infiles.cache ; then
    echo -n "(cached) "
    infiles=`cat infiles.cache | sed -e 's/\r\n/\n/g'`
else
    infiles=`find . -name "*.in"`
    `echo -n "$infiles" > infiles.cache`
fi

echo "done!"

(
for file in $infiles; do
  case "$file" in
    ./configure.in)
      echo  configure: configure.in
      printf '\t autoconf'
      echo
      ;;
    ./manual.xml.in)
      ;;
    *)
      echo `dirname $file`/`basename $file .in`: '$(srcdir)'/$file ./config.status
      printf '\t CONFIG_FILES=$@ CONFIG_HEADERS= ./config.status'
      echo
  esac
done
) > autogenerated_rules
AUTOGENERATED_RULES=autogenerated_rules
AC_SUBST_FILE(AUTOGENERATED_RULES)
rm -f autogenerated_rules

dnl }}}

dnl {{{ generate output files 

dnl {{{ find all *.in files and process them with AC_OUTPUT
for infile in $infiles
do 
    if test `basename $infile` != "configure.in"
    then
        outfile=`basename $infile .in`
        outdir=`dirname $infile`
        outdir=`echo $outdir/ | sed -e"s|$srcdir/||"`
        OUTFILES="$OUTFILES ./$outdir$outfile"
    fi
done
AC_OUTPUT($OUTFILES)
find ./scripts -name "*.sh" | tee find.log | xargs chmod u+x 
dnl }}}

dnl {{{ create default empty phpweb.ent file

rm -f ./entities/phpweb.ent
touch ./entities/phpweb.ent

dnl }}}

dnl {{{ generate entity mapping file, missing entities and IDs

dnl if we have PHP use it for all of these things
if test $PHP != "no"
then

 dnl create entity mapping file supporting Zend, CHM and other specialities
 $PHP -c $INIPATH -q ./scripts/file-entities.php
 
 dnl create missing-entities.ent and missing-ids.xml
 rm -f entities/missing*
 rm -f entities/missing-ids.xml
 $PHP -c $INIPATH -q ./scripts/missing-entities.php
 
else

  echo ERROR: configure process cannot continue, PHP is not found

fi

dnl }}}

dnl }}}

