---
name: "tor-mac"
suites:
- "precise"
architectures:
- "i386"
packages:
- "git-core"
- "unzip"
- "zip"
- "autoconf"
- "autoconf2.13"
- "automake"
- "faketime"
- "libtool"
reference_datetime: "2000-01-01 00:00:00"
remotes:
- "url": "https://git.torproject.org/tor.git"
  "dir": "tor"
files:
- "versions"
- "bug10297.patch"
- "bug5018.patch"
- "bug11156.patch"
- "bug11200.patch"
- "bug11069.patch"
- "bug9665.patch"
- "bug8402.patch"
- "bug8402-master.patch"
- "apple-uni-sdk-10.6_20110407-0.flosoft1_i386.deb"
- "multiarch-darwin11-cctools127.2-gcc42-5666.3-llvmgcc42-2336.1-Linux-120724.tar.xz"
- "dzip.sh"
- "openssl-mac32-utils.zip"
- "libevent-mac32-utils.zip"
script: |
  INSTDIR="$HOME/install"
  TBDIR="$INSTDIR/TorBrowserBundle.app/TorBrowser"
  source versions
  export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
  export FAKETIME=$REFERENCE_DATETIME
  export TZ=UTC
  export LC_ALL=C
  umask 0022
  #
  mkdir -p $INSTDIR/bin/
  mkdir -p $TBDIR/Tor/
  mkdir -p $TBDIR/Data/Tor/
  mkdir -p $OUTDIR/
  #
  sudo dpkg -i *.deb
  tar xaf multiarch-darwin*tar.xz
  export PATH="$PATH:$HOME/build/apple-osx/bin/"
  unzip -d $INSTDIR openssl-mac32-utils.zip
  unzip -d $INSTDIR libevent-mac32-utils.zip
  cp $INSTDIR/libevent/lib/libevent-*.dylib $TBDIR/Tor/
  LIBEVENT_FILE=`basename $INSTDIR/libevent/lib/libevent-*.dylib`

  # Building tor
  # XXX Clean up these flags?
  export CFLAGS="-I/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/include/ -I/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/ -I.  -L/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib/ -L/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib/system/ -mmacosx-version-min=10.5"
  export LDFLAGS="-L/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib/ -L/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib/system/ -mmacosx-version-min=10.5"
  cd tor
  git update-index --refresh -q
  export GIT_COMMITTER_NAME="nobody"
  export GIT_COMMITTER_EMAIL="nobody@localhost"
  export GIT_COMMITTER_DATE="$REFERENCE_DATETIME"
  if [ ${TOR_TAG::9} == "tor-0.2.4" ];
  then
    git am ~/build/bug10297.patch
  fi
  if [ $BUILD_PT_BUNDLES ]; then
    if [ ${TOR_TAG::9} == "tor-0.2.4" ];
    then
      git am ~/build/bug5018.patch
      git am ~/build/bug11069.patch
      git am ~/build/bug11156.patch
      git am ~/build/bug9665.patch
      git am ~/build/bug11200.patch
      git am ~/build/bug8402.patch
    else
      git am ~/build/bug8402-master.patch
    fi
  fi
  mkdir -p $OUTDIR/src
  #git archive HEAD | tar -x -C $OUTDIR/src
  ./autogen.sh
  find -type f | xargs touch --date="$REFERENCE_DATETIME"
  ./configure --enable-static-openssl --disable-asciidoc --host=i686-apple-darwin11 --with-libevent-dir=$INSTDIR/libevent --with-openssl-dir=$INSTDIR/openssl --prefix=$INSTDIR
  make $MAKEOPTS
  make install
  cd $INSTDIR
  cp bin/tor $TBDIR/Tor/
  cp share/tor/geoip $TBDIR/Data/Tor/
  cp share/tor/geoip6 $TBDIR/Data/Tor/
  cd $TBDIR/Tor/
  i686-apple-darwin11-install_name_tool -change $INSTDIR/libevent/lib/$LIBEVENT_FILE @executable_path/$LIBEVENT_FILE tor

  # Grabbing the result
  cd $INSTDIR
  ~/build/dzip.sh tor-mac32-gbuilt.zip TorBrowserBundle.app
  cp tor-mac32-gbuilt.zip $OUTDIR/
