#!/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/osx") -%]
  # Setting this after `configure` but before `make` might be enough, but let's
  # not bet on that and just set it here.
  export MACOSX_DEPLOYMENT_TARGET=[% c("var/macosx_deployment_target") %]
[% END -%]
./autogen.sh
./configure [% c("var/configure_opt") %] --disable-libevent-regress --disable-samples --prefix=$distdir
[% IF c("var/osx") -%]
  export LD_PRELOAD=[% c("var/faketime_path") %]
  export FAKETIME="[% USE date; GET date.format(c('timestamp'), format = '%Y-%m-%d %H:%M:%S') %]"
[% END -%]
make -j[% c("buildconf/num_procs") %]
make install
cd /var/tmp/dist
[% c('tar', {
        tar_src => [ project ],
        tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
    }) %]
