#!/bin/sh

FEATURES="
SKINS skins2
FAMILIAR familiar
WXWINDOWS wxwindows
OPIE opie
MACOSX macosx
QNX qnx
NCURSES ncurses
XOSD xosd
VISUAL visual
GOOM goom
SLP slp
LIRC lirc
JOYSTICK joystick
CORBA corba
LIVEDOTCOM livedotcom
DVDREAD dvdread
DVDNAV dvdnav
DSHOW dshow
DVBPSI dvbpsi
V4L v4l
PVR pvr
VCD vcd
SATELLITE satellite
DVB dvb
OGG ogg
MKV mkv
MOD mod
X11 x11
XVIDEO xvideo
GLX glx
FB fb
MGA mga
SDL sdl
FREETYPE freetype
FRIBIDI fribidi
SVG svg
QTE qte
HD1000V hd1000v
DIRECTX directx
WINGDI wingdi
SVGALIB svgalib
GGI ggi
GLIDE glide
AA aa
CACA caca
OSS oss
ESD esd
ARTS arts
ALSA alsa
WAVEOUT waveout
COREAUDIO coreaudio
HD1000A hd1000a
MAD mad
FFMPEG ffmpeg
FAAD faad
QUICKTIME quicktime
A52 a52
DTS dts
FLAC flac
LIBMPEG2 libmpeg2
VORBIS vorbis
TREMOR tremor
SPEEX speex
TARKIN tarkin
THEORA theora
CMML cmml
UTF8 utf8
PTH pth
ST st
GPROF gprof
CPROF cprof
MOZILLA mozilla
TESTSUITE testsuite
OPTIMIZATIONS optimizations
ALTIVEC altivec
DEBUG debug
RELEASE release
SOUT sout
WITHFFMPEGMP3LAME ffmpeg-mp3lame
WITHFFMPEGFAAC ffmpeg-faac
GALAKTOS galaktos
"
PATHS="
WITHXML2CONFIGPATH xml2-config-path
WITHWXCONFIGPATH wx-config-path
WITHQTE qte
WITHGOOMTREE goom-tree
WITHSLP slp
WITHLIVEDOTCOMTREE livedotcom-tree
WITHDVDREAD dvdread
WITHDVDREADTREEE dvdread-tree
WITHDVDNAVCONFIGPATH dvdnav-config-path
WITHDVBPSI dvbpsi
WITHDVBPSITREE dvbpsi-tree
WITHV4L v4l
WITHDVB dvb
WITHSDLCONFIGPATH sdl-config-path
WITHSDLPREFIX sdl-prefix
WITHFREETYPECONFIGPATH freetype-config-path
WITHFRIBIDICONFIGPATH fribidi-config-path
WITHQTE qte
WITHDIRECTX directx
WITHGGI ggi
WITHGLIDE glide
WITHCACACONFIGPATH caca-config-path
WITHMAD mad
WITHMADTREE mad-tree
WITHFFMPEGTREE ffmpeg-tree
WITHFAADTREE faad-tree
WITHA52 a52
WITHA52TREE a52-tree
WITHDTSTREE dts-tree
WITHLIBMPEG2TREE libmpeg2-tree
WITHTARKINTREE tarkin-tree
WITHMOZILLASDKPATH mozilla-sdk-path
ENDIANNESS words
"
if [ ! -e .config ]
then
   ./menuconfig
fi

if [ -e .cmd ]
then
   echo ".cmd still exist. Removing it."
   rm -f .cmd
fi

echo -n "./configure " > .cmd
source .config

check_features () {
while [ -n "$1" ]
do
   eval x="\$CONFIG_$1"
   if [ "$x" == "y" ]
   then
      if [ "$1" == "WITHFFMPEGMP3LAME" ] || [ "$1" == "WITHFFMPEGFAAC" ]
      then
         echo -n "--with-$2 " >> .cmd
      else
         echo -n "--enable-$2 " >> .cmd
      fi
   else
      if [ "$1" != "WITHFFMPEGMP3LAME" ] && [ "$1" != "WITHFFMPEGFAAC" ]
      then
         echo -n "--disable-$2 " >> .cmd
      fi
   fi
   shift; shift
done
}

check_paths () {
while [ -n "$1" ]
do
   if [ -n $1 ]
   then
      eval x="\$CONFIG_$1"
      if [ "$x" != "" ]
      then
         echo -n "--with-$2=$x " >> .cmd
      fi
   fi
   shift; shift
done
}

check_features $FEATURES
check_paths $PATHS

if [ ! -e configure ]
then
   ./bootstrap
fi

source .cmd
make
rm -f .cmd
