dnl $Id: configure.in,v 1.143 2002/02/24 11:04:22 goba Exp $

dnl autoconf initialisation
AC_INIT()
SRCDIR=$srcdir
AC_SUBST(SRCDIR)

dnl debug output
echo "file versions"
for file in $srcdir/*.in; do
  fgrep '$Id' $file | head -1 | sed -e"s/^.*: //g" | sed -e"s/200.\/.*$//g"
done
echo "configure options: $@" 
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
    AC_PATH_PROGS(PHP,"php php4",no)
  fi
],[
  AC_PATH_PROGS(PHP,"php php4",no)
]
)
if test $PHP = "no"; then
  AC_MSG_WARN([no PHP binary found])
else
  AC_MSG_CHECKING([php version])
  PHPVERSION=`$PHP -qv`
  if test "yes" = `echo '<?php echo phpversion()>3?"yes":"no"; ?>' | $PHP -q`; then
    AC_MSG_RESULT($PHPVERSION ok)
  else
    AC_MSG_RESULT($PHPVERSION)
    AC_MSG_WARN([PHP version 4.0.0 or newer needed])
    PHP=no
  fi
fi
AC_SUBST(PHP)

dnl }}}

dnl {{{   check for the 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
      AC_PATH_PROG(OPENJADE,"openjade",no)
      if test $OPENJADE = "no"; then
        AC_PATH_PROG(JADE,"jade",no)
      else
        JADE=$OPENJADE
      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
    AC_PATH_PROG(OPENJADE,"openjade",no)
    if test $OPENJADE = "no"; then
      AC_PATH_PROG(JADE,"jade",no)
    else
      JADE=$OPENJADE
    fi
   fi
]
)
AC_SUBST(JADE)

dnl }}}

dnl {{{   check for nsgmls

AC_ARG_WITH(nsgmls,
[  --with-nsgmls=PATH      Look for nsgmls 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
      AC_PATH_PROG(NSGMLS,"nsgmls",no)
    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
    AC_PATH_PROG(NSGMLS,"nsgmls",no)
  fi
]
)
AC_SUBST(NSGMLS)

dnl }}}

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

AC_ARG_WITH(java,
[  --with-java=PATH        Look for JAVA executable],
[
  if test $withval != "yes"; then
    AC_MSG_CHECKING([for java])
    if test -x $withval -a -f $withval
    then
      JAVA=$withval
      AC_MSG_RESULT($JAVA)
    elif test -x $withval/bin/java
    then
      JAVA=$withval/bin/java
      AC_MSG_RESULT($JAVA)
    elif test -x $withval/bin/jre
    then
      JAVA=$withval/bin/java
      AC_MSG_RESULT($JAVA)
    else
      JAVA=no
      AC_MSG_RESULT(no)
      AC_MSG_ERROR([$withval: no java binary found])
    fi
  else
    AC_PATH_PROGS(JAVA,"java jre",no)
  fi
],[
  AC_PATH_PROGS(JAVA,"java jre",no)
]
)
if test $JAVA = "no"; then
  AC_MSG_WARN([no JAVA binary found])
fi
AC_SUBST(JAVA)

dnl }}}

dnl }}}

dnl {{{ check for DocBook stuff

dnl {{{   check for docbook DTD

dnl AC_MSG_CHECKING(for DocBook doctype)
dnl check_catalog_files() {
dnl    for catalog in $@; do
dnl     DBDT=`grep -E '^PUBLIC.*"docbook.dtd".*$' $catalog 2>/dev/null | cut -d'"' -f 2 `
dnl     if test -n "$DBDT" ; then
dnl         DOCBOOK_DOCTYPE=$DBDT
dnl         return 1
dnl     fi  
dnl     MORECATS=`grep -i '^catalog' $catalog 2>/dev/null | cut -d'"' -f 2`
dnl     if test -n "$MORECATS" ; then
dnl        if check_catalog_files $MORECATS ; then
dnl          return 1
dnl        else 
dnl          return 0
dnl        fi
dnl     fi
dnl     return 0
dnl    done
dnl    return 0
dnl }
dnl if test -n "$SGML_CATALOG_FILES" ; then
dnl    CATFILES=`echo $SGML_CATALOG_FILES | sed -e 's/:/ /'g`
dnl    check_catalog_files $CATFILES
dnl fi
dnl if test -n "$DOCBOOK_DOCTYPE"; then
dnl    AC_MSG_RESULT(got $DOCBOOK_DOCTYPE)
dnl else 
dnl    DOCBOOK_DOCTYPE="-//Davenport//DTD DocBook V3.0//EN"
dnl    AC_MSG_RESULT(defaulting to $DOCBOOK_DOCTYPE)
dnl fi 


if grep -q methodsynopsis $srcdir/en/functions/array.xml; then
	DOCBOOK_DOCTYPE="-//OASIS//DTD DocBook XML V4.1.2//EN"
	DOCBOOK_VERSION="4.1.2"
else
	DOCBOOK_DOCTYPE="-//Norman Walsh//DTD DocBk XML V3.1.7//EN"
	DOCBOOK_VERSION="3.1.7"
fi
AC_SUBST(DOCBOOK_DOCTYPE)
AC_SUBST(DOCBOOK_VERSION)

dnl }}}

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
],[
  for dir1 in $srcdir/phpdoc-tools/dsssl \
              $srcdir/../phpdoc-tools/dsssl \
              /usr/share/sgml \
              /usr/local/share/sgml \
              /usr/lib/sgml \
              /usr/lib/dsssl \
              /usr/local/lib/sgml \
              /usr/local/lib/dsssl \
              /opt/sgml/lib 
  do
    for dir2 in docbook \
                docbook/dsssl-stylesheets \
                docbook/dsssl/modular \
                docbook/stylesheet/dsssl/modular \
                docbk30/dsl \
                docbkdsl \
                stylesheets/docbook \
                stylesheets/nwalsh-modular 
    do
      if test -f "$dir1/$dir2/html/docbook.dsl"; then
        DOCBOOK_HTML="$dir1/$dir2/html/docbook.dsl"
        DOCBOOK_PRINT="$dir1/$dir2/print/docbook.dsl"
        AC_MSG_RESULT(autodetected: $dir1/$dir2)
        break
      fi
    done
    if test ! -z "$DOCBOOK_HTML"; then break; fi
  done
])
if test -z "$DOCBOOK_HTML"; then
    AC_MSG_RESULT(not found)
fi

AC_SUBST(DOCBOOK_HTML)
AC_SUBST(DOCBOOK_PRINT)

dnl }}}

dnl {{{   check for XSLT stylesheets

AC_MSG_CHECKING(for docbook.xsl)

AC_ARG_WITH(xsl,
[  --with-xsl=[DIR]        Look for XSL stylesheets in the specified DIR],
[
  if test -f "$withval/html/docbook.xsl"; then
    DOCBOOKXSL_BIGHTML=$withval/html/docbook.xsl
    DOCBOOKXSL_HTML=$withval/html/chunk.xsl
    DOCBOOKXSL_PRINT=$withval/fo/docbook.xsl
    AC_MSG_RESULT(in $withval)
  fi
],[
   for dir in \
        $srcdir/phpdoc-tools/xsl \
        $srcdir/phpdoc-tools/xsl/docbook \
        $srcdir/../phpdoc-tools/xsl \
        $srcdir/../phpdoc-tools/xsl/docbook \
        /usr/share/sgml/docbkxsl 
    do
        if test -f "$dir/html/docbook.xsl"; then
            DOCBOOKXSL_BIGHTML=$dir/html/docbook.xsl
            DOCBOOKXSL_HTML=$dir/html/chunk.xsl
            DOCBOOKXSL_PRINT=$dir/fo/docbook.xsl
            AC_MSG_RESULT(autodetected: $dir)            
            break
        fi
		done
])
if test -z "$DOCBOOKXSL_BIGHTML"; then
    AC_MSG_RESULT(not found)
fi
AC_SUBST(DOCBOOKXSL_BIGHTML)
AC_SUBST(DOCBOOKXSL_HTML)
AC_SUBST(DOCBOOKXSL_PRINT)

dnl }}}

dnl {{{   manual XSLT stylesheets option [temp] 

AC_MSG_CHECKING(for manually specified docbook.xsl)

AC_ARG_WITH(mxsl,
[  --with-mxsl=[DIR]        Look for XSL stylesheets in the manually specified DIR],
[
  DOCBOOKXSL_BIGHTML=$withval/html/docbook.xsl
  DOCBOOKXSL_HTML=$withval/html/chunk.xsl
  DOCBOOKXSL_PRINT=$withval/fo/docbook.xsl
  AC_MSG_RESULT(in $withval)
])
if test -z "$DOCBOOKXSL_BIGHTML"; then
    AC_MSG_RESULT(not found)
fi
AC_SUBST(DOCBOOKXSL_BIGHTML)
AC_SUBST(DOCBOOKXSL_HTML)
AC_SUBST(DOCBOOKXSL_PRINT)

dnl }}}

if test -z "$DOCBOOK_HTML" -a -z "$DOCBOOKXSL_HTML"; then
  AC_MSG_ERROR(WARNING!!! NO STYLESHEETS FOUND - WON'T WORK THIS WAY)
fi

dnl {{{   check for catalog files

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

dnl SuSE 6.2/6.3 need this
if test -e /usr/share/sgml/CATALOG.docbk30
then
  CATALOG="$CATALOG -c /usr/share/sgml/CATALOG.docbk30"
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
if test -e ../phpdoc-tools/jade/catalog
then
  CATALOG="$CATALOG -c ../phpdoc-tools/jade/catalog"
fi

dnl iso-ents catalog file
if test -e ../phpdoc-tools/iso-entities/catalog
then
  CATALOG="$CATALOG -c ../phpdoc-tools/iso-entities/catalog"
fi

dnl dsssl catalog file
if test -e ../phpdoc-tools/dsssl/docbook/catalog
then
  CATALOG="$CATALOG -c ../phpdoc-tools/dsssl/docbook/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
    PHP_SOURCE=$srcdir/../php4
  fi
],[
  PHP_SOURCE=$srcdir/../php4
])
if test ! -d $PHP_SOURCE; then
	PHP_SOURCE=no
fi
AC_MSG_RESULT($PHP_SOURCE)
AC_SUBST(PHP_SOURCE)

dnl }}}

dnl {{{ check for ZendEngine API documentation to include

AC_MSG_CHECKING(for ZendAPI)

AC_ARG_WITH(zendapi,
[  --with-zendapi=[DIR]    Look for ZendAPI documentation in the specified directory],
[
  if test -f "$withval/Extending_Zend.xml" ; then
    ZENDAPI=$withval
  fi
],[
  ZENDAPI="not found"
  for dir in \
    $srcdir/en/ZendAPI \
    $srcdir/ZendAPI \
    $srcdir/../ZendAPI
  do
    if test -f "$dir/Extending_Zend.xml"; then
      ZENDAPI="$dir"
      break
    fi
  done
  if test -d "$ZENDAPI"; then
    ZEND_FIGURES="cp -r $ZENDAPI/figures ."
  else
    ZEND_FIGURES=""
  fi
])

AC_MSG_RESULT($ZENDAPI)
AC_SUBST(ZEND_FIGURES)

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
    AC_MSG_RESULT([enabled])
  else
    CHMENABLED=no
    AC_MSG_RESULT([disabled])
  fi
],[
  CHMENABLED=no
  AC_MSG_RESULT([disabled (default)])
])

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
    AC_MSG_RESULT([en (default)])
  else
    if test ! -d "$srcdir/$withval"; then
      AC_MSG_RESULT()
      AC_MSG_ERROR(Language \"$withval\" not supported!)
    fi
       
    PHP_BUILD_DATE=`date '+%d-%m-%Y'`

    case $withval in
      kr)
        LANG="ko"
        LANGDIR="kr"
      ;;
      hk)
        LANG="zh_hk"
        LANGDIR="hk"
      ;;
      tw)
        LANG="zh_tw"
        LANGDIR="tw"
      ;;
      *)
        LANG=$withval
        LANGDIR=$withval
    esac
    AC_MSG_RESULT( $withval )
  fi
],[
  LANG=en
  LANGDIR=en
  AC_MSG_RESULT([en (default)])
])
AC_SUBST(LANG)
AC_SUBST(LANGDIR)
AC_SUBST(PHP_BUILD_DATE)

MANUAL="php_manual_$LANG"
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|tr|zh_hk)
    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
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
  ja|tw|ko) ENCODING="UTF-8";;
  zh_hk) ENCODING="big5";;
  cs|hu|pl|ro) ENCODING="ISO-8859-2";;
  ar) ENCODING="ISO-8859-6";;
  tr) ENCODING="ISO-8859-9";;
  he) ENCODING="iso-8859-8";;
  *) ENCODING="ISO-8859-1";;
esac
AC_SUBST(ENCODING)

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

case "$ENCODING" in
  UTF-8)
    SP_OPTIONS="SP_ENCODING=XML SP_CHARSET_FIXED=YES"
    ;;
  big5)
    SP_OPTIONS="SP_ENCODING=big5 SP_CHARSET_FIXED=YES"
    ;;
  ISO-8859-2)
    SP_OPTIONS="SP_ENCODING=ISO-8859-2"
    HTMLHELP_ENCODING="windows-1250"
    ;;
  ISO-8859-6)
    SP_OPTIONS="SP_ENCODING=ISO-8859-6"
    HTMLHELP_ENCODING="windows-1256"
    ;;
  ISO-8859-8)
    SP_OPTIONS="SP_ENCODING=ISO-8859-8"
    HTMLHELP_ENCODING="windows-1255"
    ;;
  ISO-8859-9)
    SP_OPTIONS="SP_ENCODING=ISO-8859-9"
    HTMLHELP_ENCODING="windows-1254"
    ;;
  *)
    SP_OPTIONS=""
    ;;
esac

AC_SUBST(SP_OPTIONS)

AC_SUBST(HTMLHELP_ENCODING)

dnl }}}

dnl {{{ check for some common sources of trouble

dnl sanity checks for SuSE 6.x
if test -e /usr/share/sgml/docbk30/docbook.dcl 
then
  if grep -n "NAMELEN.\+44" /usr/share/sgml/docbk30/docbook.dcl /dev/null
  then
    AC_MSG_WARN(please change this to e.g. 'NAMELEN 54' in /usr/share/sgml/docbk30/docbook.dcl )
  fi
  if grep -n "OMITTAG.\+NO" /usr/share/sgml/docbk30/docbook.dcl /dev/null
  then
    AC_MSG_WARN(please change this to 'OMITTAG YES' in /usr/share/sgml/docbk30/docbook.dcl )
  fi

dnl look for tex bug in print stylesheet
  if test -e /usr/share/sgml/docbkdsl/print/dbprint.dsl
  then 
    if test 2 -eq  `grep -c tex  /usr/share/sgml/docbkdsl/print/dbprint.dsl`
    then
      if fgrep -q 'country: (dsssl-country-code)' /usr/share/sgml/docbkdsl/print/dbprint.dsl
      then  
        if ! grep -q ';;.*country:' /usr/share/sgml/docbkdsl/print/dbprint.dsl
        then
          AC_MSG_WARN(to prevent a tex bug you should comment out )
          AC_MSG_WARN('country: (dsssl-country-code)' )
          AC_MSG_WARN(in /usr/share/sgml/docbkdsl/print/dbprint.dsl )
          AC_MSG_WARN(or update your DSSSL-Stylesheets)
          AC_MSG_WARN(to at least version 1.54)
        fi
      fi
    fi
  fi
fi

dnl }}}

dnl {{{ makefile targets for configure-generated files

rm -f autogenerated_rules
(
for file in `find . -name "*.in"`; 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 `find $srcdir -name "*.in"` 
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 . -name "*.sh" | xargs chmod u+x 
dnl }}}

dnl {{{ generate entity mapping file for translation support

dnl check for files and translations, create chapter entities
echo creating entities/chapters.ent
rm -f entities/chapters.ent
DEPEND_FILES=""
echo "<!-- DON'T TOUCH - AUTOGENERATED BY ./configure -->" > entities/chapters.ent
if test -d "$ZENDAPI"; then
  echo  >> entities/chapters.ent
  echo "<!-- begin ZendAPI integration -->" >> entities/chapters.ent
  echo "<!ENTITY % zend.defs SYSTEM \"$ZENDAPI/Extending_Zend.ent\">" >> entities/chapters.ent
  echo "<!ENTITY zendapi.toc SYSTEM \"$ZENDAPI/Extending_Zend.xml\">" >> entities/chapters.ent
  echo  >> entities/chapters.ent
  echo "%zend.defs;"  >> entities/chapters.ent
  echo "<!-- end ZendAPI integration -->" >> entities/chapters.ent
  echo  >> entities/chapters.ent
  echo " Zend part included"
else
  echo "<!-- ZendAPI not found -->" >> entities/chapters.ent
  echo "<!ENTITY zendapi.toc \"\">" >> entities/chapters.ent
  echo  >> entities/chapters.ent
  echo " Zend part not found"
fi
if test "$CHMENABLED" = "yes"; then
  echo "<!-- chmonly pages inclusion enabled -->" >> entities/chapters.ent
  echo "<!ENTITY chmonly SYSTEM 'chmonly.xml'>" >> entities/chapters.ent
  echo  >> entities/chapters.ent
  echo " CHM inclusion enabled"
else
  echo "<!-- chmonly pages inclusion disabled -->" >> entities/chapters.ent
  echo "<!ENTITY chmonly ''>" >> entities/chapters.ent
  echo  >> entities/chapters.ent
  echo " CHM inclusion disabled"
fi
if test -f "$srcdir/$LANGDIR/chapters/install.xml"; then
  echo "<!-- old install.xml found in language dir -->" >> entities/chapters.ent
  echo "<!ENTITY chapters.install SYSTEM '$srcdir/$LANGDIR/chapters/install.xml'>" >> entities/chapters.ent
  echo  >> entities/chapters.ent
  echo " Using install.xml in language dir"
else
  echo "<!-- old install.xml not found in language dir -->" >> entities/chapters.ent
  echo "<!ENTITY chapters.install SYSTEM 'installpart.xml'>" >> entities/chapters.ent
  echo  >> entities/chapters.ent
  echo " Using the install part from installpart.xml"
fi
for file in `find $srcdir/en -name "*.xml" | sed -e"s%^$srcdir\/en\/%%g" | sort`
do 
  name=`echo $file | sed -e"s/\//./g" -e"s/.xml$//g" -e "s/_/-/g"`
  if test -f $srcdir/$LANGDIR/$file  
  then
    file=$srcdir/$LANGDIR/$file 
  else
    file=$srcdir/en/$file
    echo " Untranslated $file (`wc -l <$file | tr -d ' '` lines)"
  fi
  DEPEND_FILES="$DEPEND_FILES $file"
  echo "<!ENTITY $name     SYSTEM \"$file\">" >> entities/chapters.ent
done
echo "<!ENTITY global.function-index  SYSTEM \"./funcindex.xml\">" >> entities/chapters.ent

chmod a-w entities/chapters.ent

dnl }}}

dnl {{{ check for missing IDs and ENTITYs in translation

echo creating entities/missing-entities.ent and entities/missing-ids.xml
rm -f entities/missing*
chmod u+x scripts/missing-entities.sh
scripts/missing-entities.sh

dnl }}}

dnl }}}

