#!/bin/sh
#
# Configure script for mythplugins
#

# 
#    default parameters for all plugins
#

prefix="/usr/local"
libdir_name="lib"

music="yes"
video="yes"
weather="yes"
gallery="yes"
game="yes"
news="yes"
phone="yes"
browser="yes"
controls="yes"
flix="yes"
archive="yes"
zoneminder="yes"
movies="yes"

cc="gcc"

opengl="yes"
visual="yes"
fftw_lib="yes"
fftw_lib3="yes"
sdl="yes"
aac="no"          # compile fails w/libfaad v2.0
exif="yes"
newexif="yes"
festival="no"     # no config detection/setup routine
createdvd="yes"
createarchive="yes"
encodevideo="no"
zmversion="1.22.2"

targetos=`uname -s`
case $targetos in
OpenBSD)
    phone="no"
;;
*) ;;
esac


if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
cat << EOF

Usage:   configure [options]
Options: [defaults in brackets after descriptions]
NB:      all --enable-* options can be reversed with --disable-*

Generic options:
  --prefix=PREFIX          MythTV install location PREFIX [$prefix]"
  --libdir-name=LIBNAME    install/look for libs in PREFIX/LIBNAME [$libdir_name]"
  --help                   print this message
  --enable-all             Enable all options
  --enable-opengl          enable OpenGL (Music and Gallery) [$opengl]
  --previous               use previous configure parameters if possible

MythArchive related options:
  --enable-mytharchive     build the mytharchive plugin [$archive]
  --enable-create-dvd      enable dvd creation [$createdvd]
  --enable-create-archive  enable native archive creation [$createarchive]

MythBrowser related options:
  --enable-mythbrowser     build the mythbrowser plugin [$browser]

MythControls related options:
  --enable-mythcontrols    build the mythcontrols plugin [$controls]

MythFlix related options:
  --enable-mythflix        build the mythflix plugin [$flix]

MythGallery related options:
  --enable-mythgallery     build the mythgallery plugin [$gallery]
  --enable-exif            enable reading of EXIF headers [$exif]
  --enable-new-exif        use libexif > version 0.6.9 [$newexif]

MythGame related options:
  --enable-mythgame        build the mythgame plugin [$game]

MythMusic related options:
  --enable-mythmusic       build the mythmusic plugin [$music]
  --enable-libvisual       enable libvisual visualizers [$visual]
  --enable-fftw            enable fftw visualizers [$fftw_lib]
  --enable-sdl             use SDL for the synaesthesia output [$sdl]
  --enable-aac             enable AAC/MP4 audio file decompression [$aac]

MythNews related options:
  --enable-mythnews        build the mythnews plugin [$news]

MythPhone related options:
  --enable-mythphone       build the mythphone plugin [$phone]
  --enable-festival        enable festival TTS Engine [$festival]

MythVideo related options:
  --enable-mythvideo       build the mythvideo plugin [$video]

MythWeather related options:
  --enable-mythweather     build the mythweather plugin [$weather]

MythZoneMinder related options:
  --enable-mythzoneminder  build the mythzoneminder plugin [$zoneminder]
  --zm-version=VERSION     what version of ZoneMinder is in use [$zmversion]

MythMovies related options:
  --enable-mythmovies      build the mythmovies plugin [$movies]

EOF
exit 1
fi

if [ -e config.log ] ; then
    PCONF=`cat config.log | tail -n 1 | grep configure`
    if test x"$PCONF" != x"" ; then
        PCONF=`echo $PCONF | sed 's/.\/configure//g'`
    fi
    for opt do
        if test x"$opt" != x"--prev" -a x"$opt" != x"--previous" ; then
            OTHOPT="$OTHOPT$opt"
        fi
        if test x"$opt" = x"--prev" -o x"$opt" = x"--previous" ; then
            if test x"$PCONF" != "--prev" ; then
                PREV="yes";
            fi
        fi
    done
    if test x"$PREV" = x"yes"; then
        echo "Options: $PCONF $OTHOPT"
        ./configure $PCONF $OTHOPT
        exit
    fi
fi

CONFIGURATION_OPTS=""
for opt do
  CONFIGURATION_OPTS="$CONFIGURATION_OPTS ""$opt"
done

date >> config.log
echo "   $0$CONFIGURATION_OPTS" >> config.log

for opt do
  case "$opt" in
  --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
  ;;
  --libdir-name=*) libdir_name=`echo $opt | cut -d '=' -f 2`;
  ;;
  --enable-mytharchive) archive="yes"
  ;;
  --disable-mytharchive) archive="no"
  ;;
  --enable-create-dvd) createdvd="yes"
  ;;
  --disable-create-dvd) createdvd="no"
  ;;
  --enable-create-archive) createarchive="yes"
  ;;
  --disable-create-archive) createarchive="no"
  ;;
  --enable-encode-video) encodevideo="yes"
  ;;
  --disable-encode-video) encodevideo="no"
  ;;
  --enable-mythmusic) music="yes"
  ;;
  --disable-mythmusic) music="no"
  ;;
  --enable-mythvideo) video="yes"
  ;;
  --disable-mythvideo) video="no"
  ;;
  --enable-mythweather) weather="yes"
  ;;
  --disable-mythweather) weather="no"
  ;;
  --enable-mythgallery) gallery="yes"
  ;;
  --disable-mythgallery) gallery="no"
  ;;
  --enable-mythgame) game="yes"
  ;;
  --disable-mythgame) game="no"
  ;;
  --enable-mythnews) news="yes"
  ;;
  --disable-mythnews) news="no"
  ;;
  --enable-mythphone) phone="yes"
  ;;
  --disable-mythphone) phone="no"
  ;;
  --enable-mythbrowser) browser="yes"
  ;;
  --disable-mythbrowser) browser="no"
  ;;
  --enable-mythzoneminder) zoneminder="yes"
  ;;
  --disable-mythzoneminder) zoneminder="no"
  ;;
  --zm-version=*) zmversion=`echo $opt | cut -d '=' -f 2`
  ;;
  --enable-mythcontrols) controls="yes"
  ;;
  --disable-mythcontrols) controls="no"
  ;;
  --enable-mythflix) flix="yes"
  ;;
  --disable-mythflix) flix="no"
  ;;
  --enable-mythmovies) movies="yes"
  ;;
  --disable-mythmovies) movies="no"
  ;;
  --enable-opengl) opengl="yes"
  ;;
  --disable-opengl) opengl="no"
  ;;
  --enable-libvisual) visual="yes"
  ;;
  --disable-libvisual) visual="no"
  ;;
  --enable-fftw) fftw_lib="yes"
  ;;
  --disable-fftw) fftw_lib="no"
  ;;
  --enable-sdl) sdl="yes"
  ;;
  --disable-sdl) sdl="no"
  ;;
  --enable-aac) aac="yes"
  ;;
  --disable-aac) aac="no"
  ;;
  --enable-exif) exif="yes"
  ;;
  --enable-new-exif)  newexif="yes"
                      exif="yes"
  ;;
  --disable-new-exif) newexif="no"
  ;;
  --disable-exif) exif="no"
  ;;
  --enable-festival) festival="yes"
  ;;
  --disable-festival) festival="no"
  ;;
  --enable-all)  music="yes"; 
                 video="yes";
                 weather="yes";
                 gallery="yes";
                 game="yes";
                 news="yes";
                 phone="yes";
                 browser="yes";
                 zoneminder="yes";
                 controls="yes";
                 flix="yes";
                 movies="yes";
                 sdl="yes";
                 opengl="yes";
                 visual="yes";
                 fftw_lib="yes";
                 aac="yes";
                 exif="yes";
                 festival="yes";
                 archive="yes";
                 createdvd="yes";
                 createarchive="yes";
                 encodevideo="yes";
  ;;
  --disable-all) music="no";  
                 video="no";  
                 weather="no";  
                 gallery="no";  
                 game="no";  
                 news="no";
                 phone="no";
                 browser="no";
                 zoneminder="no";
                 controls="no";
                 flix="no";
                 movies="no";
                 sdl="no";  
                 opengl="no"; 
                 visual="no"; 
                 fftw_lib="no"; 
                 aac="no"; 
                 exif="no";
                 festival="no";
                 archive="no";
                 createdvd="no";
                 createarchive="no";
                 encodevideo="no";
  esac
done

# set temporary file name
if test ! -z "$TMPDIR" ; then
    TMPDIR1="${TMPDIR}"
elif test ! -z "$TEMPDIR" ; then
    TMPDIR1="${TEMPDIR}"
else
    TMPDIR1="/tmp"
fi

TMPC="${TMPDIR1}/myth-comp-${RANDOM}-$$-${RANDOM}.c"
TMPE="${TMPDIR1}/myth-conf-${RANDOM}-$$-${RANDOM}"


has_library()
{
    if test -f /etc/ld.so.conf ; then
        LIBPATHS=`cat /etc/ld.so.conf | grep -v "#" | grep -v "include"`
    else
        LIBPATHS=''
    fi

    LIBPATHS="$LIBPATHS `echo $LD_LIBRARY_PATH | sed s/':'/' '/g` "
    # Mac OS X has a different variable for this:
    LIBPATHS="$LIBPATHS `echo $DYLD_LIBRARY_PATH | sed s/':'/' '/g` "

    # recurse down just one level, should be enough in most cases
    if test -f /etc/ld.so.conf ; then
        INCL=`cat /etc/ld.so.conf | grep -v "#" | grep  "^include"`
        SRCH=`echo "$INCL" | sed '{ s/^include \//\//; s/^include /\/etc\//}'`
        for x in $SRCH ; do
            LP_APPEND=`cat $x | grep -v "#" | grep -v "^include"`
            LIBPATHS="$LIBPATHS $LP_APPEND"
        done
    fi

    LIBPATHS="`echo $LIBPATHS $prefix/$libdir_name /$libdir_name /usr/$libdir_name /usr/local/$libdir_name /usr/X11R6/$libdir_name | sed s/'\/ '/' '/g` "

    HAS_IT="no"
    for LIBPATH in $LIBPATHS ; do
        if test x`ls $LIBPATH/$1* 2> /dev/null | head -n 1` != x"" ; then
            HAS_IT="yes"
        fi
    done
    expr $HAS_IT : "yes" > /dev/null
}

has_header()
{
    HPATHS="$prefix/include /usr/local/include /usr/include /usr/include/g++-v3 /usr/X11R6/include /"
    INCL=`echo $DYLD_LIBRARY_PATH $LD_LIBRARY_PATH | sed s/':'/' '/g`
    HPATHS="$HPATHS `echo $INCL | sed s/$libdir_name/include/g` "

    HAS_IT="no"
    for HPATH in $HPATHS ; do
        if test x`ls $HPATH/$1* 2> /dev/null | head -n 1` != x"" ; then
            HAS_IT="yes"
        fi
    done
    expr $HAS_IT : "yes" > /dev/null
}

if test "$opengl" != "no" ; then
    opengl="no"
    if has_library libGL ; then
        opengl="yes"
    fi
    if test -f /System/Library/Frameworks/AGL.framework/Versions/A/AGL ; then
        opengl="yes"
    fi
fi

if test "$visual" != "no" ; then
    visual="no"
    if has_library libvisual-0.4 ; then
        if has_header libvisual-0.4/libvisual/libvisual.h ; then
            visual="yes"
        fi
    fi
fi

if test "$fftw_lib3" != "no" ; then
    fftw_lib3="no"
    if has_library libfftw3f_threads ; then
        if has_library libfftw3_threads ; then
            if has_header fftw3.h ; then
                fftw_lib3="yes"
            fi
        fi
    fi
fi

if test "$fftw_lib" != "no" ; then
    fftw_lib="no"
    if has_library libfftw ; then
        if has_library librfftw ; then
            if has_header fftw.h ; then
                fftw_lib="yes"
            fi
        fi
    fi
fi

if test "$sdl" != "no" ; then
    sdl="no"
    if test x`which sdl-config` != x ; then
        sdl="yes"
    fi
fi

if test "$aac" != "no" ; then
    aac="no"
    if has_library libfaad ; then
        if has_library libmp4ff ; then
            if has_header faad.h ; then
                aac="yes"
            fi
        fi
    fi
fi

if test "$exif" != "no" ; then
    exif="no"
    if has_library libexif ; then
        if has_header libexif/exif-data.h ; then
            exif="yes"
        fi
    fi
fi

if test "$music" != "no" ; then
    mad="no"
    if has_library libmad && has_header mad.h ; then
        mad="yes"
    else
        echo "MythMusic requires libmad."
    fi 

    vorbis="no"
    if has_header ogg/ogg.h && has_header vorbis/vorbisenc.h && has_header vorbis/vorbisfile.h && has_header vorbis/codec.h && has_library libogg && has_library libvorbisfile && has_library libvorbisenc && has_library libvorbis ; then
        vorbis="yes"
    else
        echo "MythMusic requires vorbis."
    fi

    flac="no"
    if has_header FLAC/all.h && has_library libFLAC ; then
        flac="yes"
    else
        echo "MythMusic requires FLAC."
    fi

    cdaudio="no"
    if has_header cdaudio.h && has_library libcdaudio ; then
        cdaudio="yes"
    fi

    if test "$cdaudio" = "no" -a "$targetos" != "Darwin"; then
        echo "MythMusic requires libcdaudio."
    fi

    paranoia="no"
    if has_library libcdda_paranoia && has_library libcdda_interface ; then
        if has_header cdda_paranoia.h ; then
            paranoia="yes"
        fi
        if has_header cdda/cdda_paranoia.h ; then
            paranoia="yes"
        fi
    fi

    if test "$paranoia" = "no" -a "$targetos" != "Darwin" -a \
                                  "`echo ${targetos} | cut -c1-5`" != "MINGW"; then
        echo "MythMusic requires CDDA Paranoia."
    fi

    mp3lame="no"
    if has_header lame/lame.h && has_library libmp3lame ; then
        mp3lame="yes"
    else
        echo "MythMusic requires the LAME mp3 encoder."
    fi

    taglib="no"
    taglib_minor=`taglib-config --version | cut -d. -f2`
    if has_library libtag && has_header taglib/fileref.h && test $taglib_minor -ge 4 ; then
        taglib="yes"
    else
        echo "MythMusic requires taglib 1.4 or later."
    fi 

    if test "$targetos" != "Darwin" -a "`echo ${targetos} | cut -c1-5`" != "MINGW" ; then
        if test "$cdaudio" = "no" -o "$paranoia" = "no" ; then
            cdlibs="no"
        fi
    fi

    if test "$mad" = "no" -o "$vorbis" = "no" -o "$flac" = "no" -o "$mp3lame" = "no" -o "$taglib" = "no" -o "$cdlibs" = "no" ; then
        echo "Disabling MythMusic due to missing dependencies."
        music="no"
    fi 
fi

if test "$gallery" != "no" ; then
    if has_library libtiff && has_header tiffio.h ; then
        echo -n ""
    else
        echo "Disabling MythGallery due to missing libtiff."
        gallery="no"
    fi
fi

if test "$archive" != "no" ; then
    if test "$createdvd" = "no" -a "$createarchive" = "no" -a "$encodevideo" = "no" ; then
        echo "Disabling MythArchive. You need to enable at least one archive format."
        archive="no"
    fi 

fi

if test "$zoneminder" != "no" ; then
    if has_header mysql/mysql.h ; then
        if test "$zmversion" != "1.22.2" -a "$zmversion" != "1.22.3" ; then
            echo "Disabling MythZoneMinder. Unknown ZoneMinder version '$zmversion' given."
            zoneminder="no"
        fi
    else
        echo "Disabling MythZoneMinder. Requires mysql/mysql.h header"
        zoneminder="no"
    fi
fi

if test "$browser" != "no" ; then
    hasit="no"
    if has_library libkhtml ; then
        if has_header kde/khtml_part.h                  || \
           has_header /opt/kde3/include/khtml_part.h    || \
           has_header /usr/kde/3.3/include/khtml_part.h || \
           has_header /usr/kde/3.4/include/khtml_part.h || \
           has_header /usr/kde/3.5/include/khtml_part.h || \
           has_header khtml_part.h ; then
            hasit="yes"
        fi
    fi
    if test "$hasit" = "no" ; then
        echo "Disabling MythBrowser due to missing KDE development packages."
        browser="no"
    fi
fi

if test "$festival" != "no" ; then
    festival="no"
    if has_library libFestival && has_library libestools && has_library libestbase && has_library libeststring && has_library libtermcap && has_header festival/festival.h ; then
       festival="yes"
    fi
fi

if test "$phone" != "no" ; then
    if test "$targetos" = "OpenBSD" ; then
        echo "Disabling MythPhone on this platform"
        phone="no"
    fi

    if has_library libtiff && has_header tiffio.h ; then
        echo -n ""
    fi
fi

cat > $TMPC << EOF
#include <stdint.h>
int main( void ) { return 0; }
EOF

_stdint_h=no
if $cc -o $TMPE $TMPC 2> /dev/null ; then
  _stdint_h=yes
fi

rm -f $TMPC $TMPE

###########################################################
#                                                         #
#  Top level mythplugin.pro file creation                 #
#  (ie. which plugins to build)                           #
#                                                         #
###########################################################

# bring in mythtv config
if [ -e $prefix/include/mythtv/mythconfig.mak ] ; then
  rm mythconfig.mak 2> /dev/null
  ln -s $prefix/include/mythtv/mythconfig.mak mythconfig.mak
else
  echo "ERROR: mythconfig.mak not found at $prefix/include/mythtv/mythconfig.mak"
  echo "Did you make AND install MythTV first?"
  echo "Are you using the correct prefix ($prefix)?"
  echo "Bailing out!!"
  exit
fi

echo ""
echo "Configuration settings: "
echo " "

echo "#" > ./config.pro
echo "#    Automatically generated by mythplugin configure" >> ./config.pro
echo "#    (manual modifications will be overwritten)" >> ./config.pro
echo "#" >> ./config.pro

if test "$archive" = "yes" ; then
  echo "        MythArchive    plugin will be built"
  echo "SUBDIRS += mytharchive" >> ./config.pro
else
  echo "        MythArchive    plugin will not be built"
fi

if test "$browser" = "yes" ; then
  echo "        MythBrowser    plugin will be built"
  echo "SUBDIRS += mythbrowser" >> ./config.pro
else
  echo "        MythBrowser    plugin will not be built"
fi

if test "$controls" = "yes" ; then
  echo "        MythControls   plugin will be built"
  echo "SUBDIRS += mythcontrols" >> ./config.pro
else
  echo "        MythControls   plugin will not be built"
fi

if test "$flix" = "yes" ; then
  echo "        MythFlix       plugin will be built"
  echo "SUBDIRS += mythflix" >> ./config.pro
else
  echo "        MythFlix       plugin will not be built"
fi

if test "$gallery" = "yes" ; then
  echo "        MythGallery    plugin will be built"
  echo "SUBDIRS += mythgallery" >> ./config.pro
else
  echo "        MythGallery    plugin will not be built"
fi

if test "$game" = "yes" ; then
  echo "        MythGame       plugin will be built"
  echo "SUBDIRS += mythgame" >> ./config.pro
else
  echo "        MythGame       plugin will not be built"
fi

if test "$music" = "yes" ; then
  echo "        MythMusic      plugin will be built"
  echo "SUBDIRS += mythmusic" >> ./config.pro
else
  echo "        MythMusic      plugin will not be built"
fi

if test "$news" = "yes" ; then
  echo "        MythNews       plugin will be built"
  echo "SUBDIRS += mythnews" >> ./config.pro
else
  echo "        MythNews       plugin will not be built"
fi

if test "$phone" = "yes" ; then
  echo "        MythPhone      plugin will be built"
  echo "SUBDIRS += mythphone" >> ./config.pro
else
  echo "        MythPhone      plugin will not be built"
fi

if test "$video" = "yes" ; then
  echo "        MythVideo      plugin will be built"
  echo "SUBDIRS += mythvideo" >> ./config.pro
else
  echo "        MythVideo      plugin will not be built"
fi

if test "$weather" = "yes" ; then
  echo "        MythWeather    plugin will be built"
  echo "SUBDIRS += mythweather" >> ./config.pro
else
  echo "        MythWeather    plugin will not be built"
fi

if test "$zoneminder" = "yes" ; then
  echo "        MythZoneMinder plugin will be built"
  echo "SUBDIRS += mythzoneminder" >> ./config.pro
else
  echo "        MythZoneMinder plugin will not be built"
fi

if test "$movies" = "yes" ; then
  echo "        MythMovies     plugin will be built"
  echo "SUBDIRS += mythmovies" >> ./config.pro
else
  echo "        MythMovies     plugin will not be built"
fi

###########################################################
#                                                         #
#   MythArchive related configuration options             #
#                                                         #
###########################################################

if test "$archive" = "yes" ; then

    echo "/*" >  ./mytharchive/mytharchive/config.h
    echo "    Automatically generated by configure - do not modify" >> ./mytharchive/mytharchive/config.h
    echo "*/" >> ./mytharchive/mytharchive/config.h

    echo "#" > ./mytharchive/mytharchive/config.pro
    echo "#    Automatically generated by configure - modify only under penalty of death" >> ./mytharchive/mytharchive/config.pro
    echo "#" >> ./mytharchive/mytharchive/config.pro

    if test "$createdvd" = "yes" ; then
        echo "        DVD creation   support will be included in MythArchive"
        echo "#define CREATE_DVD 1" >> ./mytharchive/mytharchive/config.h
        echo "CONFIG += createdvd" >> ./mytharchive/mytharchive/config.pro
    fi

    if test "$createdvd" = "no" ; then
        echo "        DVD creation   support will not be included in MythArchive"
    fi

    if test "$createarchive" = "yes" ; then
        echo "        Native Archive support will be included in MythArchive"
        echo "#define CREATE_NATIVE 1" >> ./mytharchive/mytharchive/config.h
        echo "CONFIG += createnative" >> ./mytharchive/mytharchive/config.pro
    fi

    if test "$createarchive" = "no" ; then
        echo "        Native Archive support will not be included in MythArchive"
    fi

#    if test "$encodevideo" = "yes" ; then
#        echo "        Video re-encoding support will be included in MythArchive"
#        echo "#define ENCODE_VIDEO 1" >> ./mytharchive/mytharchive/config.h
#        echo "CONFIG += encodevideo" >> ./mytharchive/mytharchive/config.pro
#    fi

#    if test "$encodevideo" = "no" ; then
#        echo "        Video re-encoding support will not be included in MythArchive"
#    fi
fi

###########################################################
#                                                         #
#   MythGallery related configuration options             #
#                                                         #
###########################################################

if test "$gallery" = "yes" ; then

    echo "/*" >  ./mythgallery/mythgallery/config.h
    echo "    Automatically generated by configure - do not modify" >> ./mythgallery/mythgallery/config.h
    echo "*/" >> ./mythgallery/mythgallery/config.h

    echo "#" > ./mythgallery/mythgallery/config.pro
    echo "#    Automatically generated by configure - modify only under penalty of death" >> ./mythgallery/mythgallery/config.pro
    echo "#" >> ./mythgallery/mythgallery/config.pro

    if test "$opengl" = "yes" ; then
        echo "        OpenGL         support will be included in MythGallery"
        echo "#define OPENGL_SUPPORT 1" >> ./mythgallery/mythgallery/config.h
        echo "CONFIG += opengl" >> ./mythgallery/mythgallery/config.pro
        echo "HEADERS += glsingleview.h" >> ./mythgallery/mythgallery/config.pro
        echo "SOURCES += glsingleview.cpp" >> ./mythgallery/mythgallery/config.pro
    fi

    if test "$opengl" = "no" ; then
        echo "        OpenGL         support will not be included in MythGallery"
    fi

    if test "$exif" = "yes" ; then
        echo "        EXIF           support will be included in MythGallery"
        echo "#define EXIF_SUPPORT 1" >> ./mythgallery/mythgallery/config.h
        echo "LIBS += -lexif" >> ./mythgallery/mythgallery/config.pro

        if test x`which pkg-config 2>/dev/null` != x"" ; then
            if `pkg-config --atleast-version 0.6.9 libexif` ; then
                echo "#define NEW_LIB_EXIF 1" >> \
                    ./mythgallery/mythgallery/config.h
            fi
        else
            if test x"$newexif" = x"yes" ; then
		echo "#define NEW_LIB_EXIF 1" >> \
                    ./mythgallery/mythgallery/config.h
            else
                echo
                echo "Could not determine libexif version, if it is greater"
                echo "than or equal to 0.6.9 you need to add"
                echo "--enable-new-exif to the configure flags"
                echo
            fi
        fi
    fi

    if test "$exif" = "no" ; then
        echo "        EXIF           support will not be included in MythGallery"
    fi
fi

###########################################################
#                                                         #
#  MythMusic related configuration options                #
#                                                         #
###########################################################

if test "$music" = "yes" ; then

    echo "/*" >  ./mythmusic/mythmusic/config.h
    echo "    Automatically generated by configure - do not modify" >> ./mythmusic/mythmusic/config.h
    echo "*/" >> ./mythmusic/mythmusic/config.h

    echo "#" > ./mythmusic/mythmusic/config.pro
    echo "#    Automatically generated by configure - modify only under penalty of death" >> ./mythmusic/mythmusic/config.pro
    echo "#" >> ./mythmusic/mythmusic/config.pro

    if test "$_stdint_h" = "yes" ; then
      echo "#define HAVE_STDINT_H 1" >> ./mythmusic/mythmusic/config.h
    else
      echo "#undef  HAVE_STDINT_H" >> ./mythmusic/mythmusic/config.h
    fi

    if test "$cdaudio" = "yes" ; then
      echo "#define HAVE_CDAUDIO 1" >> ./mythmusic/mythmusic/config.h
      echo "CONFIG += cdaudio" >> ./mythmusic/mythmusic/config.pro
    else
      echo "#undef  HAVE_CDAUDIO" >> ./mythmusic/mythmusic/config.h
    fi

    if test "$paranoia" = "yes" ; then
      echo "#define HAVE_PARANOIA 1" >> ./mythmusic/mythmusic/config.h
      echo "CONFIG += paranoia" >> ./mythmusic/mythmusic/config.pro
    else
      echo "#undef  HAVE_PARANOIA" >> ./mythmusic/mythmusic/config.h
    fi

    if test "$opengl" = "yes" ; then
        echo "        OpenGL         support will be included in MythMusic"
        echo "#define OPENGL_SUPPORT 1" >> ./mythmusic/mythmusic/config.h
        echo "CONFIG += opengl" >> ./mythmusic/mythmusic/config.pro
    fi

    if test "$opengl" = "no" ; then
        echo "        OpenGL         support will not be included in MythMusic"
    fi

    if test "$visual" = "yes" ; then
        if test "$sdl" = "yes" ; then
            echo "        libvisual      support will be included in MythMusic"
            echo "#define LIBVISUAL_SUPPORT 1" >> ./mythmusic/mythmusic/config.h
            echo "INCLUDEPATH += /usr/include/libvisual-0.4" >> ./mythmusic/mythmusic/config.pro
            echo "LIBS += -lvisual-0.4" >> ./mythmusic/mythmusic/config.pro
        else
            echo "        libvisual      support will not be included in MythMusic (requires SDL support)"
        fi
    fi

    if test "$visual" = "no" ; then
        echo "        libvisual      support will not be included in MythMusic"
    fi

    if test "$fftw_lib3" = "yes" ; then
        echo "        FFTW v.3       support will be included in MythMusic"
        echo "#define FFTW3_SUPPORT 1" >> ./mythmusic/mythmusic/config.h
        echo "LIBS += -lfftw3 -lm" >> \
             ./mythmusic/mythmusic/config.pro
    elif test "$fftw_lib" = "yes" ; then
        echo "        FFTW v.2       support will be included in MythMusic"
        echo "#define FFTW2_SUPPORT 1" >> ./mythmusic/mythmusic/config.h
        echo "LIBS += -lrfftw -lfftw" >> ./mythmusic/mythmusic/config.pro
    fi

    if test "$fftw_lib" = "no" -a "$fftw_lib3" = "no" ; then
        echo "        FFTW           support will not be included in MythMusic"
    fi

    if test "$sdl" = "yes" ; then
        echo "        SDL            support will be included in MythMusic"
        echo "#define SDL_SUPPORT 1" >> ./mythmusic/mythmusic/config.h
        echo "LIBS += `sdl-config --libs`" >> ./mythmusic/mythmusic/config.pro
        echo "QMAKE_CXXFLAGS_RELEASE += `sdl-config --cflags`" >> ./mythmusic/mythmusic/config.pro
        echo "QMAKE_CXXFLAGS_DEBUG += `sdl-config --cflags`" >> ./mythmusic/mythmusic/config.pro
    fi
    if test "$sdl" = "no" ; then
        echo "        SDL            support will not be included in MythMusic"
    fi

    if test "$aac" = "yes" ; then
        echo "        AAC            support will be included in MythMusic"
        echo "#define AAC_SUPPORT 1" >> ./mythmusic/mythmusic/config.h
        echo "LIBS += -lfaad -lmp4ff" >> ./mythmusic/mythmusic/config.pro
        echo "HEADERS += metaiomp4.h aacdecoder.h" >> ./mythmusic/mythmusic/config.pro
        echo "SOURCES += metaiomp4.cpp aacdecoder.cpp" >> ./mythmusic/mythmusic/config.pro
    fi

    if test "$aac" = "no" ; then
        echo "        AAC            support will not be included in MythMusic"
    fi

    if test "$taglib" = "yes" ; then
        echo "INCLUDEPATH += `taglib-config --prefix`/include/taglib" >> ./mythmusic/mythmusic/config.pro
    fi
fi

###########################################################
#                                                         #
#   MythPhone related configuration options               #
#                                                         #
###########################################################

if test "$phone" = "yes" ; then

    echo "/*" >  ./mythphone/mythphone/config.h
    echo "    Automatically generated by configure - do not modify" >> ./mythphone/mythphone/config.h
    echo "*/" >> ./mythphone/mythphone/config.h

    echo "#" > ./mythphone/mythphone/config.pro
    echo "#    Automatically generated by configure - modify only under penalty of death" >> ./mythphone/mythphone/config.pro
    echo "#" >> ./mythphone/mythphone/config.pro

    if test "$festival" = "yes" ; then
        echo "        FESTIVAL       support will be included in MythPhone"
        echo "#define FESTIVAL_SUPPORT 1" >> ./mythphone/mythphone/config.h
        echo "FESTIVALDIR = /home/paul/Build/festival/festival/" >> ./mythphone/mythphone/config.pro
        echo "DEFINES += FESTIVAL_HOME=\\\"\$\${FESTIVALDIR}\\\"" >> ./mythphone/mythphone/config.pro
        echo "INCLUDEPATH += /usr/include/festival /usr/include/speech_tools" >> ./mythphone/mythphone/config.pro
        echo "INCLUDEPATH += /usr/local/include/festival /usr/local/include/speech_tools" >> ./mythphone/mythphone/config.pro
        echo "LIBS += -lFestival -lestools -lestbase -leststring -ltermcap" >> ./mythphone/mythphone/config.pro
    fi

    if test "$festival" = "no" ; then
        echo "        FESTIVAL       support will not be included in MythPhone"
    fi
fi

###########################################################
#                                                         #
#   MythZoneMinder related configuration options          #
#                                                         #
###########################################################

if test "$zoneminder" = "yes" ; then

    echo "/*" >  ./mythzoneminder/mythzmserver/config.h
    echo "    Automatically generated by configure - do not modify" >> ./mythzoneminder/mythzmserver/config.h
    echo "*/" >> ./mythzoneminder/mythzmserver/config.h

    if test "$zmversion" = "1.22.2" ; then
        echo "        MythZoneMinder is configured for ZoneMinder version 1.22.2"
        echo "#define ZMVERSION_1_22_2 1" >> ./mythzoneminder/mythzmserver/config.h
    else
        echo "        MythZoneMinder is configured for ZoneMinder version 1.22.3"
        echo "#define ZMVERSION_1_22_3 1" >> ./mythzoneminder/mythzmserver/config.h
    fi
fi

###########################################################
#                                                         #
#   An extra directory and Makefile for cleanup rules     #
#                                                         #
###########################################################

mkdir -p cleanup
cat << END_CLEANUP > cleanup/Makefile
all:
clean:
distclean:
install:
qmake_all:
	\$(NONE)

# Hack to remove some empty directories that qmake doesn't create rules for
uninstall:
	-rmdir \$(INSTALL_ROOT)/$prefix/share/mythtv/*
	-rmdir \$(INSTALL_ROOT)/$prefix/share/mythtv

END_CLEANUP

echo >> ./config.pro
echo "# clean up for 'make uninstall'. This must be last" >> ./config.pro
echo "SUBDIRS += cleanup " >> ./config.pro

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

echo ""

if test -x $QTDIR/bin/qmake; then
  $QTDIR/bin/qmake QMAKE=${QTDIR}/bin/qmake mythplugins.pro
else
  qmake mythplugins.pro
fi
