#!/bin/sh
#
# $Id$
#
# Copyright (C) 1997-2014 by Dimitri van Heesch.
# 
# Permission to use, copy, modify, and distribute this software and its
# documentation under the terms of the GNU General Public License is hereby 
# granted. No representations are made about the suitability of this software 
# for any purpose. It is provided "as is" without express or implied warranty.
# See the GNU General Public License for more details.
# 
# Documents produced by Doxygen are derivative works derived from the
# input used in their production; they are not affected by this license.
# 
# shell script to configure doxygen

doxygen_version_major=1
doxygen_version_minor=8
doxygen_version_revision=7

#NOTE: Setting version_mmn to "NO" will omit mmn info from the package.
doxygen_version_mmn=NO

bin_dirs=`echo $PATH | sed -e "s/:/ /g"`

f_debug=NO
f_shared=YES
f_make=NO
f_dot=NO
f_perl=NO
f_python=NO
f_plf_auto=NO
f_prefix=/usr/local
f_insttool=NO
f_english=NO
f_wizard=NO
f_app=NO
f_doxmlparser=NO
f_thread=NO
f_flex=NO
f_bison=NO
f_search=NO
f_sqlite3=NO
f_sqlite3static=NO
f_sqlite3_path=NO
f_libclang=NO
f_libclangstatic=NO

#
# first setup the list with availabe languages, so we cannot forget any
# list will be in case as specified (f_langs) and in uppercase (f_ulangs) as used in the internal perl script
#
f_langs=`ls -1 src/translator_??.h | sed -e 's%src/translator_%%g' | sed -e 's/\.h//' | tr '\012' ','`

while test -n "$1";  do
  case $1 in
    --prefix=*)
       f_prefix=`echo $1 | sed 's/^--prefix=//'`
       ;;
    --prefix | -prefix)
       shift; f_prefix=$1
       ;;
    --docdir=*)
       f_docdir=`echo $1 | sed 's/^--docdir=//'`
       ;;
    --docdir | -docdir)
       shift; f_docdir=$1
       ;;
    --shared | -shared)
       f_shared=YES
       ;;
    --static | -static)
       f_shared=NO
       ;;
    --release | -release)
       f_debug=NO
       ;;
    --debug | -debug)
       f_debug=YES
       ;;
    --english-only | -english-only)
       f_english=YES
       ;;
    --enable-langs=*)
       f_langs=`echo $1 | sed 's/^--enable-langs=//'`
       ;;
    --enable-langs | -enable-langs)
       shift; f_langs=$1
       ;;
    --platform=*)
       f_platform=`echo $1 | sed 's/^--platform=//'`
       ;;
    --platform | -platform)
       shift; f_platform=$1
       ;;
    --make=*)
       f_make=`echo $1 | sed 's/^--make=//'`
       ;;
    --make | -make)
       shift; f_make=$1
       ;;
    --dot=*)
       f_dot=`echo $1 | sed 's/^--dot=//'`
       ;;
    --dot | -dot)
       shift; f_dot=$1
       ;;
    --python=*)
       f_python=`echo $1 | sed 's/^--python=//'`
       ;;
    --python | -python)
       shift; f_python=$1
       ;;
    --perl=*)
       f_perl=`echo $1 | sed 's/^--perl=//'`
       ;;
    --perl | -perl)
       shift; f_perl=$1
       ;;
    --flex=*)
       f_flex=`echo $1 | sed 's/^--flex=//'`
       ;;
    --flex | -flex)
       shift; f_flex=$1
       ;;
    --bison=*)
       f_bison=`echo $1 | sed 's/^--bison=//'`
       ;;
    --bison | -bison)
       shift; f_bison=$1
       ;;
    --install=*)
       f_insttool=`echo $1 | sed 's/^--install=//'`
       ;;
    --install | -install)
       shift; f_insttool=$1
       ;;
    --with-doxywizard | -with-doxywizard)
       f_wizard=YES
       ;;
    --with-doxyapp | -with-doxyapp)
       f_app=YES
       ;;
    --with-doxmlparser | -with-doxmlparser)
       f_doxmlparser=YES
       ;;
    --with-doxysearch | -with-doxysearch)
       f_search=YES
       ;;
    --with-sqlite3 | -with-sqlite3)
       f_sqlite3=YES
       ;;
    --with-sqlite3-static | -with-sqlite3-static)
       f_sqlite3=YES
       f_sqlite3static=YES
       ;;
    --sqlite3-path=*)
       f_sqlite3_path=`echo $1 | sed 's/^--sqlite3-path=//'`
       ;;
    --sqlite3-path | -sqlite3-path)
       shift; f_sqlite3_path=$1
       ;;
    --with-libclang | -with-libclang)
       f_libclang=YES
       ;;
    --with-libclang-static | -with-libclang-static)
       f_libclang=YES
       f_libclangstatic=YES
       ;;
    -h | -help | --help)
       f_help=y
       ;;
    *)
       echo $1: unknown argument
       f_help=y
       f_error=y
       ;;
  esac
  shift
done

if test "$f_help" = y; then
  cat <<EOF
Usage: $0 [--help] [--shared] [--static] [--release] [--debug] [--python name]
          [--perl name] [--flex name] [--bison name] [--make name] 
          [--dot name] [--platform target] [--prefix dir] [--docdir dir] 
          [--install name] [--english-only] [--enable-langs list] 
          [--with-sqlite3] [--with-sqlite3-static] [--sqlite3-path]
          [--with-libclang] [--with-libclang-static]
          [--with-doxywizard] [--with-doxysearch] [--with-doxyapp]
          [--with-doxxmlparser]

Options: 

  --help                Print this help
  --shared | --static   Build using shared or static linking
		        [default: shared]
  --release | --debug   Build for release or debug 
		        [default: release]
  --python name         Use \`name' as the name of the python interpreter 
		        [default: autodetect]
  --perl name           Use \`name' as the name of the perl interpreter 
		        [default: autodetect]
  --flex name           Use \`name' as the name of the GNU lexical scanner 
		        [default: autodetect]
  --bison name          Use \`name' as the name of the GNU compiler generator 
		        [default: autodetect]
  --make name           Use \`name' as the name of the GNU make tool
		        [default: autodetect]
  --dot name            Use \`name' as the name of the dot tool that
                        is part of the Graphviz package.
                        [default: autodetect]
  --platform target     Do not detect platform but use \`target' instead.
                        See PLATFORMS for a list of possibilities
  --prefix dir          Installation prefix directory (doxygen will be
                        put in PREFIX/bin/doxygen)
                        [default: $f_prefix]
  --docdir dir          Documentation is installed in DOCDIR/
                        [default: PREFIX/share/doc/packages/doxygen]
  --install name        Use \`name' as the name of the GNU install tool
                        [default: autodetect]
  --english-only        Include support for English only.
  --enable-langs list 	Include support for output languages listed in list.
  			[default: $f_langs]
  --with-sqlite3        Add support for sqlite3 output [experimental]
  --with-libclang       Add support for libclang parsing
  --with-doxywizard     Build the GUI frontend for doxygen. This
                        requires Qt version 4.
  --with-doxysearch     Build external search tools (doxysearch and doxyindexer)
                        requires Xapian library version 1.2
  --with-doxyapp        Example showing how to embed doxygen in an application.
  --with-doxmlparser    Example showing how to parse doxygen's XML output.

EOF
  test "$f_error" = y && exit 1
  exit 0;
fi

u_release=`(uname -r) 2>/dev/null` || u_release=unknown
u_system=`(uname -s) 2>/dev/null` || u_system=unknown

if test -z "$f_platform"; then
  f_platforms="`cat PLATFORMS`"
  
  case "$u_system:$u_release" in
    AIX*)
      f_platform=aix-xlc
      ;;
    BeOS*)
      f_platform=beos-g++
      ;;
    dgux:*)
      f_platform=dgux-g++
      ;;
    Darwin:*)
      f_platform=macosx-c++
      if test "$f_insttool" = NO; then
        f_insttool=/usr/bin/install
      fi
      ;;
    FreeBSD:*)
      f_platform=freebsd-g++
      if test "$f_insttool" = NO; then
        f_insttool=/usr/bin/install
      fi
      ;;
    NetBSD:*)
      f_platform=netbsd-g++
      if test "$f_insttool" = NO; then
        f_insttool=/usr/bin/install
      fi
      ;;
    HP-UX:*)
      f_platform=hpux-g++
      if test "$f_insttool" = NO; then
        f_insttool=/usr/bin/install
      fi
      ;;
    IRIX64:*)
      f_platform=irix-64
      ;;
    IRIX:*)
      f_platform=irix-n32
      ;;
    Linux:*|GNU:*|GNU/*:*)
      f_platform=linux-g++
      ;;
    NetBSD:*)
      f_platform=netbsd-g++
      ;;
    OpenBSD:*)
      f_platform=openbsd-g++
      ;;
    OSF1:*)
      f_platform=osf1-g++
      ;;
    QNX:*)
      f_platform=qnx-g++
      ;;
    *:3.2)
      f_platform=sco-g++
      ;;
    SunOS:4*)
      f_platform=sunos-g++
      ;;
    SunOS:5*)
      f_platform=solaris-g++
      if test "$f_insttool" = NO; then
        f_insttool=/usr/bin/install
      fi
      ;;
    ULTRIX:*)
      f_platform=ultrix-g++
      ;;
    UNIX_SV:4.2*)
      f_platform=unixware-g++
      ;;
    Cygwin:*|CYGWIN*)
      f_platform=win32-g++
      ;;
    MINGW32_NT*)
      f_platform=win32-mingw
      ;;
    *MiNT:*)
      f_platform=m68k-atari-mint-g++
      ;;
    *)
    echo
    echo "Your platform was not recognised by this configure script"
    echo "Please use the -platform option to specify one of platforms"
    echo "in this list:"
    echo
    for p in $f_platforms
    do
      echo "    $0 $* -platform $p"
    done
    echo
    exit 2
  esac 
  echo "  Autodetected platform $f_platform... "
  f_plf_auto=YES
fi

if test -z "$f_docdir"; then
  f_docdir='$(INSTALL)/share/doc/packages/doxygen'
fi

if test "$f_plf_auto" = NO; then
  printf "  Checking for platform $f_platform... "
  if test '!' -d tmake/lib/$f_platform; then
    echo "not supported!" 
    echo
    exit 2
  fi
  echo "supported"
fi

#- check for qt --------------------------------------------------------------
 
if test "$f_wizard" = YES; then
  if test -z "$QTDIR"; then
    echo "  QTDIR environment variable not set!"
    printf "  Checking for Qt..."
    for d in /usr/{lib,share,qt}/{qt-4,qt4,qt,qt*,4} /usr; do
      if test -x "$d/bin/qmake"; then
        QTDIR=$d
        break 2
      fi
    done
  else
    if test -e "$QTDIR/bin/qmake"; then
      printf "  Detected Qt via the QTDIR environment variable..."
    else
      printf "ERROR Detected Qt via the QTDIR environment variable..."
      echo ", but $QTDIR/bin/qmake does not exist."
      echo "      Set the QTDIR environment variable such that \$QTDIR/bin/qmake exists."
      exit 2
    fi
  fi
  if test -z "$QTDIR"; then
    echo "QTDIR not set and Qt not found at standard locations!"
    echo
    echo "Set the QTDIR environment variable such that \$QTDIR/bin/qmake exists."
    echo "check the Qt installation instructions!"
    exit 2
  fi
  echo using $QTDIR
fi

#- check for xapian -----------------------------------------------------------

if test "$f_search" = YES; then
  if test -z "$XAPIAN"; then
    printf "  Checking for Xapian..."
    for d in /usr /usr/local /opt/local; do
      if test -e "$d/include/xapian.h"; then
        XAPIAN=$d
        break 2
      fi
    done
  else
    if test -e "$XAPIAN/include/xapian.h"; then
      printf "  Detected Xapian via the XAPIAN environment variable..."
    else
      printf "ERROR Detected Xapian via the XAPIAN environment variable..."
      echo ", but $XAPIAN/include/xapian.h does not exist."
      echo "      Set the XAPIAN environment variable such that \$XAPIAN/include/xapian.h exists."
      exit 2
    fi
  fi
  if test -z "$XAPIAN"; then
    echo "XAPIAN not set and xapian.h not found at standard locations!"
    exit 2;
  fi
  echo using $XAPIAN
fi
   
# - check for make ------------------------------------------------------------

printf "  Checking for GNU make tool... "
if test "$f_make" = NO; then
  make_names="gmake make"
  make_dirs="$bin_dirs /usr/bin /usr/local/bin /bin /sbin"
  make_prog=NO
  for i in $make_names; do
    for j in $make_dirs; do
      if test -x "$j/$i"; then
        if test -n "`$j/$i --version 2>/dev/null | grep GNU`"; then
          make_prog="$j/$i"
          break 2
        fi
      fi
    done
  done
  f_make="$make_prog" 
fi

if test "$f_make" = NO; then
  echo "not found!";
  echo
  exit 2
fi
echo "using $f_make"

# - check for install ------------------------------------------------------------

printf "  Checking for GNU install tool... "
if test "$f_insttool" = NO; then
  install_names="ginstall install"
  install_dirs="$bin_dirs /usr/bin /usr/local/bin /bin /sbin /usr/ucb"
  install_prog=NO
  install_found=NO
  for i in $install_names; do
    for j in $install_dirs; do
      if test -x "$j/$i"; then
        if test -n "`$j/$i --version 2>/dev/null | grep utils`"; then
          install_found=YES
          install_prog="$j/$i"
          break 2
        fi
      fi
    done
  done
  f_insttool="$install_prog" 
fi

if test "$f_insttool" = NO; then
  if test "$install_found" = YES; then
    echo;
  else
    echo "not found!";
    echo
  fi
  echo "GNU version of install is required: this is part of the fileutils/coreutils package: "
  echo "see http://www.gnu.org/software/fileutils/fileutils.html"
  echo
  exit 2
fi
echo "using $f_insttool";


# - check for dot ------------------------------------------------------------

printf "  Checking for dot (part of GraphViz)... "
if test "$f_dot" = NO; then
  dot_dirs="$bin_dirs /usr/bin /usr/local/bin /bin /sbin"
  dot_prog=NO
  for j in $dot_dirs; do
    if test -x "$j/dot"; then
      dot_prog="$j/dot"
      break 2
    fi
  done
  f_dot="$dot_prog" 
fi

if test "$f_dot" = NO; then
  echo "not found!";
else
  echo "using $f_dot"
fi

# - check for sqlite3 ---------------------------------------------------------

if test "$f_sqlite3" = YES; then
  printf "  Checking for sqlite3 ... "
  if test "$f_sqlite3_path" = NO; then
    sqlite3_hdr_dir="/usr/include /usr/local/include /opt/local/include"
    sqlite3_lib_dir="/usr/lib /usr/local/lib /opt/local/lib /usr/lib/x86_64-linux-gnu /usr/lib64"
  else
    sqlite3_hdr_dir="$f_sqlite3_path/include"
    sqlite3_lib_dir="$f_sqlite3_path/lib"
  fi
  if test "$f_sqlite3static" = NO; then
    sqlite3_lib_name="libsqlite3.so libsqlite3.dylib libsqlite3.a libsqlite3.dll.a"
  else
    sqlite3_lib_name="libsqlite3.a"
  fi
  sqlite3_hdr=NO
  sqlite3_lib=NO
  sqlite3_link=
  for j in $sqlite3_hdr_dir; do
    if test -f "$j/sqlite3.h"; then
      sqlite3_hdr="$j/sqlite3.h"
      break
    fi
  done
  for i in $sqlite3_lib_dir; do
    if test "$sqlite3_lib" = NO; then
      for j in $sqlite3_lib_name; do
        if test -e "$i/$j"; then
          if test "$f_sqlite3static" = NO; then
            sqlite3_lib="$i/$j"
            sqlite3_link="-L$i -lsqlite3"
          else
            sqlite3_lib="$i/$j"
            sqlite3_link="$i/$j -ldl"
          fi
          break
        fi
      done
    fi
  done
  if test "$sqlite3_hdr" = NO -o "$sqlite3_lib" = NO; then
    echo "not found!";
    exit 1
  else
    echo "using header $sqlite3_hdr and library $sqlite3_lib...";
  fi
fi

# - check for libclang ---------------------------------------------------------

if test "$f_libclang" = YES; then
  printf "  Checking for libclang ... "
  libclang_hdr_dir="/usr/include /usr/local/include /opt/local/include"
  libclang_lib_dir="/usr/lib /usr/local/lib /opt/local/lib /usr/lib64/llvm /usr/lib/llvm"
  if test "$f_libclangstatic" = NO; then
    libclang_lib_name="libclang.so libclang.dylib libclang.a libclang.dll.a"
  else
    libclang_lib_name="libclang.a"
  fi
  libclang_hdr=NO
  libclang_lib=NO
  libclang_link=
  for j in $libclang_hdr_dir; do
    if test -f "$j/clang-c/Index.h"; then
      libclang_hdr="$j/clang-c/Index.h"
      break
    fi
  done
  for i in $libclang_lib_dir; do
    if test "$libclang_lib" = NO; then
      for j in $libclang_lib_name; do
        if test -f "$i/$j"; then
          libclang_lib="$i/$j"
          if test "$f_libclangstatic" = NO; then
            libclang_link="-L $i -lclang"
          else
            libclang_link="$i/libclang.a $i/libclangFrontend.a $i/libclangSerialization.a $i/libclangParse.a $i/libclangSema.a $i/libclangAnalysis.a $i/libclangStaticAnalyzerCore.a $i/libclangAST.a $i/libclangBasic.a $i/libclangDriver.a $i/libclangEdit.a $i/libclangLex.a $i/libclangRewriteCore.a $i/libLLVMBitReader.a $i/libLLVMMC.a $i/libLLVMMCParser.a $i/libLLVMSupport.a -ldl -lpthread"
          fi
          break
        fi
      done
    fi
  done
  if test "$libclang_hdr" = NO -o "$libclang_lib" = NO; then
    echo "not found!";
  else
    echo "using header $libclang_hdr and library $libclang_lib...";
  fi
fi

# - check for python ----------------------------------------------------------

printf "  Checking for python... "
if test "$f_python" = NO; then
  python_names="python2 python"
  python_dirs="$bin_dirs /usr/bin /usr/local/bin /bin /sbin"
  python_prog=NO
  python_found=NO
  for i in $python_names; do
    for j in $python_dirs; do
      if test -x "$j/$i"; then
        python_found=YES
        if test `$j/$i -c "import sys; print sys.version_info[0]"` = 2; then
          python_prog="$j/$i"
          break 2
        fi
      fi
    done
  done
  f_python="$python_prog" 
fi

if test "$f_python" = NO; then
  if test "$python_found" = YES; then
    echo "version should be python 2."
  else
    echo "not found!";
  fi
  echo
  exit 2
fi
echo "using $f_python";

# - check for perl ------------------------------------------------------------

printf "  Checking for perl... "
if test "$f_perl" = NO; then
  perl_names="perl perl5"
  perl_dirs="$bin_dirs /usr/bin /usr/local/bin /bin /sbin"
  perl_prog=NO
  perl_found=NO
  for i in $perl_names; do
    for j in $perl_dirs; do
      if test -x "$j/$i"; then
        perl_found=YES
        if $j/$i -e 'require 5.000;' 2>/dev/null ; then
          perl_prog="$j/$i"
          break 2
        fi
      fi
    done
  done
  f_perl="$perl_prog" 
fi

if test "$f_perl" = NO; then
  if test "$perl_found" = YES; then
    echo "version is too old (5.000 or higher is required)."
  else
    echo "not found!";
  fi
  echo
  exit 2
fi
echo "using $f_perl";

# - check for flex ------------------------------------------------------------

printf "  Checking for flex... "
if test "$f_flex" = NO; then
  flex_dirs="$bin_dirs /usr/bin /usr/local/bin /bin"
  flex_prog=NO
  flex_found=NO
  for j in $flex_dirs; do
    if test -x "$j/flex"; then
      flex_found=YES
      flex_prog="$j/flex"
      break
    fi
  done
  f_flex="$flex_prog" 
fi

if test "$f_flex" = NO; then
  echo "not found!";
  exit 2
else
  echo "using $f_flex"
fi

# - check for bison ------------------------------------------------------------

printf "  Checking for bison... "
if test "$f_bison" = NO; then
  bison_dirs="$bin_dirs /usr/bin /usr/local/bin /bin"
  bison_prog=NO
  bison_found=NO
  for j in $bison_dirs; do
    if test -x "$j/bison"; then
      bison_found=YES
      bison_prog="$j/bison"
      break
    fi
  done
  f_bison="$bison_prog" 
fi

if test "$f_bison" = NO; then
  echo "not found!";
  exit 2
else
  echo "using $f_bison"
fi

# -----------------------------------------------------------------------------

mkdir -p generated_src/doxygen
if test "$f_wizard" = YES; then
  mkdir -p generated_src/doxywizard
fi

#
# Make VERSION file
#
test -f "VERSION" && chmod u+w VERSION
test -f "generated_src/doxygen/version.cpp" && chmod u+w generated_src/doxygen/version.cpp
echo "  Generating generated_src/doxygen/version.cpp and VERSION..."
cd src
$f_python version.py ../generated_src/doxygen
cd ..
if test "$f_wizard" = YES; then
  test -f "VERSION" && chmod u+w VERSION
  test -f "generated_src/doxywizard/version.cpp" && chmod u+w generated_src/doxywizard/version.cpp
  echo "  Generating generated_src/doxywizard/version.cpp and VERSION..."
  cd src
  $f_python version.py ../generated_src/doxywizard
  cd ..

fi

test -f .makeconfig && rm .makeconfig
test -f .tmakeconfig && rm .tmakeconfig

configPWD=`pwd`

cat > .makeconfig <<EOF
DOXYGEN   = $configPWD
TMAKEPATH = $configPWD/tmake/lib/$f_platform
ENV       = env TMAKEPATH="\$(TMAKEPATH)"
TMAKE     = $configPWD/tmake/bin/tmake
MAKE      = $f_make
PYTHON    = $f_python
LEX       = $f_flex
RM        = rm -f
CP        = cp
VERSION   = `cat VERSION`
INSTALL   = $f_prefix
INSTTOOL  = $f_insttool
DOXYDOCS  = ..
DOCDIR    = $f_docdir
QTDIR     = $QTDIR
EOF

if test "$f_dot" != NO; then
  cat >> .makeconfig <<EOF
HAVE_DOT  = $f_dot
EOF
fi


if test "$f_platform" = "m68k-atari-mint-g++"; then
  cat >> .makeconfig <<EOF
TMAKE += -unix
EOF
fi

if test "$f_platform" = "macosx-c++"; then
  cat >> .makeconfig <<EOF
MKSPECS   = -spec macx-g++
EOF
fi
if test "$f_platform" = "macosx-uni-c++"; then
  cat >> .makeconfig <<EOF
MKSPECS   = -spec macx-g++
EOF
fi

# Make doxygen.spec...
#
echo "  Created doxygen.spec file, for rpm generation."

echo "%define version $doxygen_version_major.$doxygen_version_minor.$doxygen_version_revision" > spec.tmp
if test "$doxygen_version_mmn" = NO; then
  echo "%define revision 1" >> spec.tmp
  echo "%define mmn 1"      >> spec.tmp
else
  echo "%define revision $doxygen_version_mmn" >> spec.tmp
  echo "%define mmn $doxygen_version_mmn"      >> spec.tmp
fi

mkdir -p packages
mkdir -p packages/rpm

cat spec.tmp ./packages/rpm/doxygen.spec.in > ./packages/rpm/doxygen.spec

rm -f spec.tmp


# make .tmakeconfig
#
touch .tmakeconfig
if test "$f_shared" = NO; then
  if test "$f_platform" = "osf1-cxx" -o "$f_platform" = "irix-n32"; then
  cat >> .tmakeconfig <<EOF
    TMAKE_LFLAGS += -non_shared
EOF
  elif test "$f_platform" = "solaris-cc"; then
  cat >> .tmakeconfig <<EOF
    TMAKE_LFLAGS += -Bstatic
EOF
  elif test "$f_platform" = "hpux-cc"; then
  cat >> .tmakeconfig <<EOF
    TMAKE_LFLAGS += -noshared
EOF
  else
  cat >> .tmakeconfig <<EOF
    TMAKE_LFLAGS += -static
EOF
  fi
fi
if test "$f_platform" = "hpux-g++" -o "$f_platform" = "linux-g++"; then
  cat >> .tmakeconfig <<EOF
    TMAKE_CXXFLAGS += -D_LARGEFILE_SOURCE
EOF
fi
if test "$f_platform" = "macosx-uni-c++"; then
  if test -n "`ls /Developer/SDKs/MacOSX10.*.sdk 2>/dev/null`"; then
    mac_sdk=MacOSX10.4u.sdk
  fi
  if test -n "`ls /Developer/SDKs/MacOSX10.5*.sdk 2>/dev/null`"; then
    mac_sdk=MacOSX10.5.sdk
  fi
  if test -n $mac_sdk; then
  cat >> .tmakeconfig <<EOF
    TMAKE_CFLAGS   += -isysroot /Developer/SDKs/$mac_sdk
    TMAKE_CXXFLAGS += -isysroot /Developer/SDKs/$mac_sdk
    TMAKE_LFLAGS   += -Wl,-syslibroot,/Developer/SDKs/$mac_sdk
EOF
  fi
fi
if test "$f_wizard" = YES; then
  cat >> .tmakeconfig <<EOF
TMAKE_MOC = $QTDIR/bin/moc
EOF
fi

if test "$f_search" = YES; then
  cat >> .tmakeconfig <<EOF
LIBS += -L$XAPIAN/lib
INCLUDEPATH += $XAPIAN/include
EOF
fi

f_inmakefiles="Makefile.in qtools/Makefile.in src/Makefile.in examples/Makefile.in doc/Makefile.in addon/doxywizard/Makefile.in addon/doxmlparser/src/Makefile.in addon/doxmlparser/test/Makefile.in addon/doxmlparser/examples/metrics/Makefile.in libmd5/Makefile.in addon/doxyapp/Makefile.in addon/doxysearch/Makefile.in"

for i in $f_inmakefiles ; do
     SRC=$i
     DST=`echo $i|sed 's%\(.*\).in$%\1%'`
     TIME=`date`
     cat > $DST <<EOF
#
# This file was generated from `basename $i` on $TIME
#

EOF
     cat .makeconfig >> $DST
     if test $i = Makefile.in; then
       echo "" >> $DST
       EXTRADEPS=
       if test $f_wizard = YES; then
         EXTRADEPS=doxywizard
       fi
#       if test $f_search = YES; then
#         EXTRADEPS="$EXTRADEPS doxysearch"
#       fi
       echo "all: generated_src/doxygen/version.cpp $EXTRADEPS" >> $DST
       echo "	\$(MAKE) -C qtools" >> $DST
       echo "	\$(MAKE) -C libmd5" >> $DST
       echo "	\$(MAKE) -C src" >> $DST
       if test $f_wizard = YES; then
         echo "	\$(MAKE) MAN1DIR=\$(MAN1DIR) -C addon/doxywizard" >> $DST
       fi
       if test $f_search = YES; then
         echo "	\$(MAKE) -C addon/doxysearch" >> $DST
       fi
       if test $f_app = YES; then
         echo "	\$(MAKE) -C addon/doxyapp" >> $DST
       fi
       if test $f_doxmlparser = YES; then
         echo "	\$(MAKE) -C addon/doxmlparser/src" >> $DST
         echo "	\$(MAKE) -C addon/doxmlparser/test" >> $DST
         echo "	\$(MAKE) -C addon/doxmlparser/examples/metrics" >> $DST
       fi
       echo "" >> $DST
       echo "doxywizard_install:" >> $DST
       if test $f_wizard = YES; then
         echo "	\$(MAKE) INSTALL=\$(DESTDIR)\$(INSTALL) MAN1DIR=\$(MAN1DIR) -C addon/doxywizard install" >> $DST
       fi
       echo "doxysearch_install:" >> $DST
       if test $f_search = YES; then
         echo "	\$(MAKE) INSTALL=\$(DESTDIR)\$(INSTALL) MAN1DIR=\$(MAN1DIR) -C addon/doxysearch install" >> $DST
       fi
       echo "" >> $DST
     fi
     if test $f_wizard = YES; then
       sed -e "s/%%WITHDOXYWIZARD%% /--with doxywizard /g" $SRC >> $DST
     else
       sed -e "s/%%WITHDOXYWIZARD%% //g" $SRC >> $DST
     fi
     echo "  Created $DST from $SRC..."
done

cat src/libdoxycfg.t.in | sed -e "s|%%FLEX%%|$f_flex|g" -e "s|%%BISON%%|$f_bison|g" -e "s|%%PYTHON%%|$f_python|g" > src/libdoxycfg.t
cat src/libdoxygen.t.in | sed -e "s|%%FLEX%%|$f_flex|g" -e "s|%%BISON%%|$f_bison|g" -e "s|%%PYTHON%%|$f_python|g" > src/libdoxygen.t

f_inprofiles="qtools/qtools.pro.in src/libdoxygen.pro.in src/libdoxycfg.pro.in src/doxygen.pro.in addon/doxywizard/doxywizard.pro.in addon/doxmlparser/src/doxmlparser.pro.in addon/doxmlparser/test/xmlparse.pro.in addon/doxmlparser/examples/metrics/metrics.pro.in libmd5/libmd5.pro.in addon/doxyapp/doxyapp.pro.in addon/doxysearch/doxysearch.pro.in addon/doxysearch/doxyindexer.pro.in" 

for i in $f_inprofiles ; do
     SRC=$i
     DST=`echo $i|sed 's%\(.*\).in$%\1%'`
     TIME=`date`
     cat > $DST <<EOF
#
# This file was generated from `basename $i` on $TIME
#

EOF
     if test "$f_debug" = NO; then
       realopts="release"
     else
       realopts="debug"
     fi
     #if test "$f_thread" = YES; then
     #  realopts="$realopts thread"
     #fi
     cat $SRC .tmakeconfig | sed -e "s/\$extraopts/$realopts/g" -e "s;%%SQLITE3_INC%%;$sqlite3_hdr_dir;g" -e "s;%%SQLITE3_LIBS%%;$sqlite3_link;g" -e "s;%%LIBCLANG_LIBS%%;$libclang_link;g" >> $DST
     echo "  Created $DST from $SRC..."
done

# - generating generated_src/doxygen/doxygen/lang_cfg.h 
# use consistent method on Linux and Windows

if test -f "generated_src/doxygen/lang_cfg.h"; then
    chmod u+w generated_src/doxygen/lang_cfg.h   # make sure file can be overwritten
fi
echo "  Generating generated_src/doxygen/lang_cfg.h..."
if test "$f_english" = YES; then
   $f_python src/lang_cfg.py ENONLY > generated_src/doxygen/lang_cfg.h
else
   f_ulangs=`echo $f_langs | tr '[a-z,]' '[A-Z ]'`
   $f_python src/lang_cfg.py $f_ulangs > generated_src/doxygen/lang_cfg.h
fi

if test -f "generated_src/doxygen/settings.h"; then
    chmod u+w generated_src/doxygen/settings.h
fi
echo "  Generating generated_src/doxygen/settings.h..."
$f_python src/settings.py $f_sqlite3 $f_libclang generated_src/doxygen

if test "$f_wizard" = YES; then
  if test -f "generated_src/doxywizard/settings.h"; then
      chmod u+w generated_src/doxywizard/settings.h
  fi
  echo "  Generating generated_src/doxywizard/settings.h..."
  $f_python src/settings.py $f_sqlite3 $f_libclang generated_src/doxywizard
fi

cd ..
echo "  Finished"
