#
#
# Compile various libraries needed for VLC or mplayer or xine
# ----------------------------------------------------------
#
# Original Files
# --------------
#	http://Linux-Video.net/VideoPlayers/LIBS-Src.FC5.install.sh
#	http://Linux-Video.net/VideoPlayers/LIBS-Src.2005.0327.tgz
#
#
#	find LIBS-Src -type f | egrep -iv "\.compile$|\.log$|\.ok$|\.2$|\.FAILED$|*.needs.*|*.requires.*"
#		zcvf LIBS-Src.2006.0327.tgz -T -
#
#
# ------------------------
# Compiling Mplayer or VLC 
# ------------------------
#	http://Linux-Video.net/VideoPlayers/MPlayer
#	http://Linux-Video.net/VideoPlayers/VLC
#
#
# 07-Dec-02 amo vlc plays dvd
# 20-Mar-06 amo Modified to compile required libs for vlc
# 27-Mar-06 amo Clean up Libs-Src, vlc needs -fPIC for libmad, zlib, liba52dec, x264
# 28-Mar-06 amo vlc-0.8.5-svn compiled and linked
# 29-Mar-06 amo Added gtk-devel ( gtk-config for skins (wxwidgets)  ), use gloable ConfOpt without if ; then; else 
# 13-Apr-06 amo Install libs on a clean FC5 system
#
#
#	tar zcvf LIBS-Src.2006.0327.tgz LIBS-Src  LIBS-Src.FC5.install.sh
#
# 
# Make sure you have gcc, g++, gtk
# ---------------------------
#	yum install gcc-g++
#
#	yum install gtk	
#	yum install gtk-devel	gtk-devel.x86_64 	( has gtk-config )
#	yum install gtk2
#	yum install gtk2-devel	gtk2-devel.x86_64
#
#
# GLUT errors
# -----------
#	# cannot find -lGLU	
#	yum install fltk-devel.x86_64
#
# x264 needs yasm
# ---------------
#
# Bad Value errors
# ----------------
#	#
#	# fix these with various compile options: -fPIC and other flgas
#	#
#	/usr/local/lib/libz.a: could not read symbols: Bad value
# 	/usr/local/lib/libmad.a: could not read symbols: Bad value
#	/usr/local/lib/libx264.a: could not read symbols: Bad value
#
#
# ----------------------------
# watch out for duplicate libs and similarly for other libs
# ----------------------------
#	/usr/lib/libz.a
#	/usr/local/lib/libz.a
#
#
SRC="/usr/local.FC5/src"
#
# 	cd $SRC ; ln -s /Data/Local.Src/LIBS-Src .
#
LibSrc=$SRC/LIBS-Src
LibBin=$SRC/LIBS-Bin
#
#
if [ ! -z "$LibBin" ];
then
  echo "#"
  echo "# rm -rf $LibBin"
  echo "# rm -f  $LibBin/*/*.Compiled.OK"
  echo "#"
  #
  sleep 5
fi
#
#
# Abort if the command fails
# ---------------------------
docmd()
{
  log=$1
  cmd="$2"
  #
  #
  # make 2>&1 > logfile.txt 2>&1
  #
  #
  echo "# $2 " | tee -a $log
  eval "  $2 " &> $log
  #
  if [ $? != 0 ];
  then
    echo "#"
    echo "# ERROR: Aborting: '$2' Failed.. "
    echo "#"
    #
    #  binaries can be erased --> tag the source instead
    touch "$LibSrc/$Dir/$base.FAILED"	# for feedback when LibBin is erased
    touch "$LibBin/$Dir/$base.FAILED"	# for compiling status
    #
    exit 1
  fi
  #
} # docmd
#
#
# Install the Sources
# ----------------------
InstallSrc ()
{
  #
  Dir=$1
  Lib=$2
  #
  Base="$3"
  #
  mkdir -p "$LibBin/$Dir"
  #
  b1=`basename $Lib .tar.gz `
  b2=`basename $Lib .tar.bz2 `
  #
  #
  #
  # it will NOT be same if it is true
  # ---------------------------------
  #
  if [ "$b1" != "$Lib" ];
  then
    #
    Tar="tar zxfp"
    base=$b1
    #
  elif [ "$b2" != "$Lib" ];
  then
    #
    Tar="tar jxfp"
    base=$b2
    #
  else
    #
    echo "#"
    echo "# ERROR: ABORTING: not *.tar.gz nor *.tar.bz2 "
    echo "#"
    #
    exit 1
    #
  fi
  #
  if [ ! -z "$Base" ];
  then
    #
    base=$Base
    #
  fi
  #
  # echo "b1=$b1.."
  # echo "b2=$b2.."
  # echo "tar=$Tar.."
  #
  #
  LOG="$LibBin/$Dir/$base.log"
  #
  #
  # ---------------------------------------------
  # Split it apart so we can tell where it died
  # ---------------------------------------------
  #
  if [ -f "$LibBin/$Dir/$base.Compiled.OK" ];
  then
    #
    echo ".. $Dir/$Lib .. ok .. "
    #
  elif [ -f "$LibBin/$Dir/$base.FAILED" ];
  then
    #
    echo ".. $Dir/$Lib .............................. FAILED.. $FailMsg "
    FailMsg=""	# reset
    #
  else
    #
    docmd $LOG "cd $LibSrc ; ls -la $Dir/$Lib "
    #
    Configure=1
    Configure=0
    if [ ! -d "$LibBin/$Dir/$base" ];
    then
      docmd $LOG "cd $LibBin/$Dir ; $Tar $LibSrc/$Dir/$Lib "
      Configure=1
    fi
    #
    if [ "$base" = "Device-Cdio-v0.2.0" ];
    then
     docmd $LOG "cd $LibBin/$Dir/$base ; perl Makefile.PL "
    fi
    #
    if [ "$DIR" = "LibFAAC" ];
    then
      docmd $LOG "cd $LibBin/$Dir/$base ; sh ./bootstrap "
    fi
    #
    #
    DirBase="$LibBin/$Dir/$base"
    #
    if [ "$Dir" = "LibMatroska" ];
    then
      # libebml does not use ./configure
      DirBase="$LibBin/$Dir/$base/make/linux"
      Configure=0	
      #
      if [ "$base" = "libebml-0.7.6" ];
      then
        if [ -s /usr/local/lib/libebml.so ];
        then
	  rm /usr/local/lib/libebml.so
        fi
      fi
    fi
    #
    #
    if [ "$Configure" = 1 ];
    then
      #ocmd $LOG "cd $DirBase && make clean "
      docmd $LOG "cd $DirBase && ./configure $ConfOpts "
      ConfOpts=""	# reset
    fi
    #
    docmd $LOG "cd $DirBase && make "
    docmd $LOG "cd $DirBase && make install "
    #
    #ocmd $LOG "ldoonfig "
    #
    #
    touch "$LibSrc/$Dir/$base.Compiled.OK"	# for feedback when LibBin is erased
    touch "$LibBin/$Dir/$base.Compiled.OK"	# for compiling status
    #
    echo "#"
    echo "# logile=$LOG.."
    echo "#"
    echo ""
    #
  fi
  #
} # InstallSrc
#
#
# =======================
# Install these Libraries
# =======================
#
echo "# "
echo "# vi zlib-1.2.3/Makefile"
echo "#     CFLAGS=-O -fPIC "
echo "# "
InstallSrc LibZlib zlib-1.2.3.tar.bz2
#
ConfOpts=" CFLAGS=-fPIC "
InstallSrc Liba52dec a52dec-0.7.4.tar.gz
#
ConfOpts=" CFLAGS=-fPIC "
InstallSrc LibCDIO libcdio-0.76.tar.gz
#
# Skip -- needs perl
InstallSrc LibCDIO Device-Cdio-v0.2.0.tar.gz
InstallSrc LibCDIO pycdio-0.10.tar.gz
InstallSrc LibCDIO vcdimager-0.7.23.tar.gz
#
ConfOpts=" CFLAGS=-fPIC "
InstallSrc LibMAD libid3tag-0.15.1b.tar.gz
InstallSrc LibMAD libmad-0.15.1b.tar.gz
InstallSrc LibMAD mad-0.14.2b.tar.gz
#
InstallSrc LibMAD madplay-0.15.2b.tar.gz
#
# # missing ebml/*.h files
InstallSrc LibMatroska libebml-0.7.6.tar.bz2
#
FailMsg="whacky install but worked"
InstallSrc LibMatroska libmatroska-0.8.0.tar.bz2
#
#
# Skip -- missing install-sh
# stallSrc LibFAAC faac-1.24.tar.bz2
#
#	sh ./bootstrap
InstallSrc LibFAAC faac-18102004.tar.gz faac
#
# fails to compile mp4ff_int_types.h:23:7: warning: no newline at end of file
#nstallSrc LibFAAC faad2-15092004.tar.gz
#
FailMsg="corrupt file problem ?? "
InstallSrc LibFAAC faad2-20040923.tar.bz2
#
#
# unzip ../faad2-2.0.zip -d x
# cd x ; autoreconf -vif ; ./configure ; make
#
#
# fails to compile 
InstallSrc Libdbus libcairo_1.0.2.orig.tar.gz cairo-1.0.2
#
FailMsg="dbus needs libcairo"
InstallSrc Libdbus dbus-0.61.tar.gz
#
InstallSrc LibDVD libdvdread-0.9.5.tar.gz
#
InstallSrc LibDVD libdvbpsi4-0.1.5.tar.bz2
#
InstallSrc LibDVD libdvdcss-1.2.9.tar.bz2
#
InstallSrc LibDVD libdvdnav-20050211.tar.bz2
#
InstallSrc LibDVD libdvdplay-1.0.1.tar.bz2
#
InstallSrc LibDVD libdvdread-20041028.tar.bz2
#
#
# LibFFMpeg ffmpeg-0.4.9-pre1.tar.gz
#	/usr/local/lib/libz.a: could not read symbols: Bad value
#
#	http://libmpeg2.sf.net
#
#
ConfOpts=" --enable-gpl --enable-pp "
#
# stallSrc LibFFMpeg ffmpeg-20051126.tar.bz2
InstallSrc LibFFMpeg ffmpeg-2006.0327.tar.gz ffmpeg-20060327
#nstallSrc LibFFMpeg ffmpeg-2006.0413.tar.gz
#
#
# Skip -- fails to compile
#nstallSrc LibFFMpeg mpeg2dec-snapshot-2006.0303.tar.gz mpeg2dec-0.4.1-cvs
InstallSrc LibFFMpeg mpeg2dec-snapshot-2006.0327.tar.gz mpeg2dec-0.4.1-cvs
#
#
# Skip -- needs curses.h term.h
InstallSrc LibLAME lame-3.96.1.tar.gz
#
InstallSrc LibLAME twolame-0.3.6.tar.gz
#
InstallSrc LibModPlug libmodplug-0.7.tar.gz
#
# Skip -- needs GTK_CONFIG
FailMsg="modplugxmms needs xmms-config"
InstallSrc LibModPlug modplugxmms-2.05.tar.gz
#
InstallSrc LibOGG libtheora-1.0alpha5.tar.bz2
#
InstallSrc LibOGG flac-1.1.2.tar.gz
InstallSrc LibOGG libao-0.8.6.tar.gz
InstallSrc LibOGG libogg-1.1.3.tar.gz
#
# tar.gz has a different name
InstallSrc LibOGG libspeex-1.1.10.tar.gz speex-1.1.10
#
InstallSrc LibOGG libtheora-1.0alpha5.tar.gz
InstallSrc LibOGG libvorbis-1.1.2.tar.gz
# InstallSrc LibOGG speex-1.0.5.tar.gz	-- use libspeex-1.1.10
InstallSrc LibOGG vorbis-tools-1.1.1.tar.gz
#
#
# x264 requres yasm
# -----------------
docmd /tmp/junk.log "which yasm"
#
#
# stallSrc Libx264 x264-20051126.tar.bz2
#
#	 ./configure --extra-cflags=-fPIC
# stallSrc Libx264 x264-snapshot-20060320-2245.tar.bz2
#
#onfopts=" --extra-cflags='-fPIC' "
#onfopts=" --extra-cflags='-fPIC' --extra-ldflags=-fPIC "
ConfOpts=" --enable-pic "
#nstallSrc Libx264 x264-svn-2006.0327.tar.gz
InstallSrc Libx264 x264-svn-2006.0413.tar.gz
#
#
#
# Minimum config tests
# --------------------
docmd /tmp/junk.log "which pkg-config "
echo "#" >> /tmp/junk.log
echo "pkg-config --version" >>  /tmp/junk.log
eval "pkg-config --version  >>  /tmp/junk.log"
#
docmd /tmp/junk.log "which gtk-config "
echo "#" >> /tmp/junk.log
echo "gtk-config --version" >>  /tmp/junk.log
eval "gtk-config --version  >>  /tmp/junk.log"
#
#
echo "#" >> /tmp/junk.log
docmd /tmp/junk.log "find /usr/local/lib -name gtk+-2.0.pc -ls"
docmd /tmp/junk.log "ls -la /usr/local/lib/pkgconfig > /dev/null "
#
docmd /tmp/junk.log "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig"
#
#	env | grep -i pkg_config_path
#	set | grep -i pkg_config_path
#
# wxX11 and wxWidgets needs GTK
#	pkg-config  --version
#	pkg-config gtk+-2.0 --libs
#	gtk-config --libs
#
ConfOpts=" --with-x11 "
# stallSrc LibWidgets wxX11-2.6.2.tar.bz2
InstallSrc LibWidgets wxX11-2.6.3.tar.bz2
#
ConfOpts=" --with-x11 "
# stallSrc LibWidgets wxWidgets-2.6.2.tar.gz
InstallSrc LibWidgets wxWidgets-2.6.3.tar.bz2
#
#
# we should now have wx-config after installing wxWidgets
#
docmd /tmp/junk.log "which wx-config "
echo "#" >> /tmp/junk.log
echo "wx-config --version" >>  /tmp/junk.log
eval "wx-config --version  >>  /tmp/junk.log"
#
#
echo "#"
echo "# Now you should be able to compile VLC or mplayer or xine or ?? .. "
echo "#"
#
#
# End of file

