#!/bin/bash
[% c("var/set_default_env") -%]
[% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
distdir=/var/tmp/dist/[% project %]
mkdir -p /var/tmp/build
tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
cd /var/tmp/build/[% project %]-[% c('version') %]
[% IF c("var/osname") == "linux-i686" -%]
export CC='gcc -m32'
[% END %]
[% IF c("var/osx") -%]
  # Tricking OpenSSL into using our clang as cross-compiler
  ln -s $clangdir/bin/clang $clangdir/bin/x86_64-apple-darwin11-cc
  export CC="cc [% c("var/FLAGS") %]"
[% END -%]
[% IF c("var/windows") -%]
  patch -p1 < $rootdir/escape-openssldir.patch
  patch -p1 < $rootdir/use-SOURCE_DATE_EPOCH.patch
[% END -%]
# OpenSSL expects the NDK home to include the pre-assembled architecture directory
[% IF c("var/android") -%]
  export ANDROID_NDK_HOME=$ANDROID_NDK_HOME/[% c("var/toolchain_arch") %]
[% END -%]
export SOURCE_DATE_EPOCH='[% c("timestamp") %]'
./Configure [% c('var/configure_opts') %]
make
make DESTDIR="$distdir" install
cd /var/tmp/dist
ln -s '[% c("var/openssldir") %]' openssl/openssl
[% c('tar', {
        tar_src => [ project ],
        tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
    }) %]
