---
name: "tor-linux"
suites:
- "lucid"
architectures:
- "i386"
- "amd64"
packages:
- "git-core"
- "unzip"
- "zip"
- "autoconf"
- "autoconf2.13"
- "automake"
- "faketime"
- "libtool"
- "hardening-wrapper"
- "zlib1g-dev"
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"
- "dzip.sh"
- "openssl-linux32-utils.zip"
- "openssl-linux64-utils.zip"
- "libevent-linux32-utils.zip"
- "libevent-linux64-utils.zip"
script: |
  INSTDIR="$HOME/install"
  source versions
  export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
  export FAKETIME=$REFERENCE_DATETIME
  export TZ=UTC
  export LC_ALL=C
  umask 0022

  # Config options for hardening-wrapper
  export DEB_BUILD_HARDENING=1
  export DEB_BUILD_HARDENING_STACKPROTECTOR=1
  export DEB_BUILD_HARDENING_FORTIFY=1
  export DEB_BUILD_HARDENING_FORMAT=1
  export DEB_BUILD_HARDENING_PIE=1

  mkdir -p $INSTDIR/Data/Tor/
  mkdir -p $INSTDIR/Tor/
  mkdir -p $INSTDIR/Debug/Tor/
  unzip -d $INSTDIR openssl-linux$GBUILD_BITS-utils.zip
  unzip -d $INSTDIR libevent-linux$GBUILD_BITS-utils.zip
  cp $INSTDIR/openssl/lib/libssl.so.1.0.0 $INSTDIR/Tor/
  cp $INSTDIR/openssl/lib/libcrypto.so.1.0.0 $INSTDIR/Tor/
  cp $INSTDIR/libevent/lib/libevent-2.0.so.5 $INSTDIR/Tor/
  chmod 700 $INSTDIR/Tor/*so*

  # Building tor
  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 --disable-asciidoc --with-libevent-dir=$INSTDIR/libevent --with-openssl-dir=$INSTDIR/openssl --prefix=$INSTDIR
  make $MAKEOPTS
  make install
  cp $INSTDIR/share/tor/geoip $INSTDIR/Data/Tor/
  cp $INSTDIR/share/tor/geoip6 $INSTDIR/Data/Tor/
  # Strip and generate debuginfo for libs
  cd $INSTDIR
  objcopy --only-keep-debug $INSTDIR/bin/tor $INSTDIR/Debug/Tor/tor
  install -s $INSTDIR/bin/tor $INSTDIR/Tor/
  objcopy --add-gnu-debuglink=./Debug/Tor/tor $INSTDIR/Tor/tor
  for i in $INSTDIR/Tor/*so*
  do
    LIB=`basename $i`
    objcopy --only-keep-debug $INSTDIR/Tor/$LIB $INSTDIR/Debug/Tor/$LIB
    strip $INSTDIR/Tor/$LIB
    objcopy --add-gnu-debuglink=./Debug/Tor/$LIB $INSTDIR/Tor/$LIB
  done

  # Grabbing the results
  ~/build/dzip.sh tor-linux$GBUILD_BITS-gbuilt.zip Data/ Tor/
  ~/build/dzip.sh tor-linux$GBUILD_BITS-debug.zip Debug/
  cp tor-linux$GBUILD_BITS-gbuilt.zip $OUTDIR/
  cp tor-linux$GBUILD_BITS-debug.zip $OUTDIR/
