#!/bin/bash

if [ "$1" = "clean" ]; then
  for f in `ls`; do make -C $f clean; done
  exit
fi

if [ "$1" = "all" -o "$1" = "pkg-config" ]; then
  cd pkg-config-0.23
  make clean
  ./configure --with-installed-glib --prefix=/usr
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "rdesktop" ]; then
  cd rdesktop-1.6.0
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "sqlite" ]; then
  cd sqlite
  make clean
  ./configure --prefix=/opt/local --enable-threadsafe --disable-tcl --disable-static CFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA=1"
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "git" ]; then
  cd git-1.6.0
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "libmpeg2" ]; then
  cd libmpeg2-0.5.1
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "mc" ]; then
  cd mc-4.6.1
  make clean
  ./configure --prefix=/opt/local --with-screen=ncurses --without-x --with-mcfs --enable-extcharset --enable-charset
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "liboil" ]; then
  cd liboil-0.3.15
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "pixman" ]; then
  cd pixman-0.12.0
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "fontconfig" ]; then
  cd fontconfig-2.6.0
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "freetype" ]; then
  cd freetype-2.3.7
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "cairo" ]; then
  cd cairo-1.6.4
  make clean
  ./configure --prefix=/opt/local --enable-freetype=yes --enable-quartz-font=yes --enable-xlib=no --enable-atsui
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "pango" ]; then
  cd pango-1.20.5
  make clean
  ./configure --prefix=/opt/local --without-x
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "gettext" ]; then
  cd gettext-0.17
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "glib" ]; then
  cd glib-2.18.1
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "jpeg" ]; then
  cd jpeg-6b
  make clean
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "atk" ]; then
  cd atk-1.24.0
  make clean
  ./configure --prefix=/opt/local --disable-gtk-doc
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "gtk" ]; then
  cd gtk+-2.14.3
  make clean
  ./configure --prefix=/opt/local --enable-xlib=no --disable-gtk-doc --without-x --without-libtiff --without-libjasper --with-gdktarget=quartz
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "intltool" ]; then
  cd intltool-0.40.4
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "libgcrypt" ]; then
  cd libgpg-error-1.6
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
  cd libgcrypt-1.4.3
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "gnutls" ]; then
  cd gnutls-2.4.2
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi


if [ "$1" = "all" -o "$1" = "pidgin" ]; then
  cd pidgin-2.5.1
  make clean
  ./configure --prefix=/opt/local --without-x --disable-startup-notification --disable-gtkspell --disable-gstreamer --disable-meanwhile --disable-avahi --disable-dbus --disable-perl --enable-cyrus-sasl --enable-gtkstatusicon --disable-gestures
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "clutter" ]; then
  cd clutter/clutter
  make clean
  ./autogen.sh
  export LDFLAGS="-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib"
  ./configure --prefix=/opt/local --with-flavour=osx --without-x --with-imagebackend=gdk-pixbuf --disable-gtk-doc
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "tidy" ]; then
  cd clutter/tidy
  make clean
  touch README INSTALL
  aclocal $ACLOCAL_FLAGS || exit $?
  libtoolize --force || exit $?
  autoheader || exit $?
  echo "EXTRA_DIST=" > gtk-doc.make
  automake --add-missing || exit $?
  autoconf || exit $?
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "sdl" ]; then
  cd SDL-1.2.13
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "nasm" ]; then
  cd nasm-2.05rc1
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "x264" ]; then
  cd x264-snapshot-20081006-2245
  make clean
  ./configure --prefix=/opt/local --enable-pic --enable-shared --disable-asm
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "faad2" ]; then
  cd faad2
  ./bootstrap
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "faac" ]; then
  cd faac
  ./bootstrap
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "a52dec" ]; then
  cd a52dec-0.7.4
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "libogg" ]; then
  cd libogg-1.1.3
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "libvorbis" ]; then
  cd libvorbis-1.2.0
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "libungif" ]; then
  cd libungif-4.1.4
  make clean
  ./configure --prefix=/opt/local --without-x
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "libid3tag" ]; then
  cd libid3tag-0.15.1b
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "imlib2" ]; then
  cd imlib2-1.4.1
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "lame" ]; then
  cd lame-398
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "xvidcore" ]; then
  cd xvidcore-1.1.3/build/generic
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ../../../
fi

if [ "$1" = "all" -o "$1" = "libmad" ]; then
  cd libmad-0.15.1b
  make clean
  ./configure --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "ffmpeg" ]; then
  cd ffmpeg
  make clean
  ./configure --prefix=/opt/local --enable-gpl --disable-vhook --enable-libmp3lame --enable-libvorbis --enable-libfaac --enable-libfaad --enable-libxvid --enable-libx264 --disable-libamr-nb --enable-swscale --disable-mmx --disable-alvitec
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "mplayer" ]; then
  cd mplayer
  make distclean
  ./configure --prefix=/opt/local --enable-menu
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "gstreamer" ]; then
  cd gstreamer/gstreamer
  make clean distclean
  ./autogen.sh --prefix=/opt/local
  sed -i -e 's/@lang/\-lang/g' po/Makefile
  make install
  cd ../..
fi

if [ "$1" = "all" -o "$1" = "gstreamer-base" ]; then
  cd gstreamer/gst-plugins-base
  make distclean
  ./autogen.sh --prefix=/opt/local --disable-x
  sed -i -e 's/@lang/\-lang/g' po/Makefile
  make install
  cd ../..
fi

if [ "$1" = "all" -o "$1" = "gstreamer-good" ]; then
  cd gstreamer/gst-plugins-good
  make distclean
  ./autogen.sh --prefix=/opt/local --disable-x
  sed -i -e 's/\-Werror//g' ext/jpeg/Makefile
  sed -i -e 's/@lang/\-lang/g' po/Makefile
  make install
  cd ../..
fi

if [ "$1" = "all" -o "$1" = "gstreamer-bad" ]; then
  cd gstreamer/gst-plugins-bad
  make distclean
  ./autogen.sh --prefix=/opt/local --disable-x
  cp ../gstreamer/libtool ../gstreamer/compile ../gstreamer/depcomp ../gstreamer/ltmain.sh .
  sed -i -e 's/@lang/\-lang/g' po/Makefile
  sed -i -e 's/\-Werror//g' gst/speexresample/Makefile
  sed -i -e 's/\-Werror//g' ext/faac/Makefile
  sed -i -e 's/\-Werror//g' ext/x264/Makefile
  sed -i -e 's/\-Werror//g' sys/qtwrapper/Makefile
  make install
  cd ../..
fi

if [ "$1" = "all" -o "$1" = "gstreamer-ugly" ]; then
  cd gstreamer/gst-plugins-ugly
  make distclean
  ./autogen.sh --prefix=/opt/local --disable-x
  sed -i -e 's/@lang/\-lang/g' po/Makefile
  make install
  cd ../..
fi

if [ "$1" = "all" -o "$1" = "gstreamer-ffmpeg" ]; then
  cd gst-ffmpeg-0.10.5
  make distclean
  ./autogen.sh --prefix=/opt/local
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "neon" ]; then
  cd neon-0.28.3
  make clean
  ./configure --prefix=/opt/local --with-ssl=gnutls
  make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "subversion" ]; then
  cd subversion-1.5.2
  make clean
  ./configure --prefix=/opt/local --with-ssl
  sudo make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "readline" ]; then
  cd readline-5.2
  make clean
  ./configure --prefix=/opt/local 
  sudo make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "wget" ]; then
  cd wget-1.11.4
  make clean
  ./configure --prefix=/opt/local 
  sudo make install
  cd ..
fi

if [ "$1" = "all" -o "$1" = "magick" ]; then
  cd ImageMagick-6.4.6
  make clean
  ./configure --prefix=/opt/local --disable-dependency-tracking --disable-installed --enable-delegate-build --enable-shared --disable-static --enable-libtool-verbose --without-rsvg --without-gslib --without-gvc --disable-openmp --enable-osx-universal-binary --without-wmf 
  make install
  cd ..
fi
