#!/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.[% c('compress_tar') %]
cd /var/tmp/build/[% project %]-[% c('version') %]

[% IF c("var/windows") -%]
  make BINARY_PATH=$distdir/lib INCLUDE_PATH=$distdir/include LIBRARY_PATH=$distdir/lib -f win32/Makefile.gcc PREFIX=[% c("arch") %]-w64-mingw32- CC=[% c("arch") %]-w64-mingw32-cc -j[% c("num_procs") %] SHARED_MODE=1 LOC="[% c("var/CFLAGS") %] [% c("var/LDFLAGS") %]"
  make BINARY_PATH=$distdir/lib INCLUDE_PATH=$distdir/include LIBRARY_PATH=$distdir/lib -f win32/Makefile.gcc PREFIX=[% c("arch") %]-w64-mingw32- CC=[% c("arch") %]-w64-mingw32-cc -j[% c("num_procs") %] SHARED_MODE=1 LOC="[% c("var/CFLAGS") %] [% c("var/LDFLAGS") %]" install
[% END -%]

[% IF c("var/android") -%]
  export CHOST=[% c("var/cross_prefix") %]
  export CC=[% c("var/CC") %]
  ./configure --prefix=$distdir
  make -j[% c("num_procs") %]
  make -j[% c("num_procs") %] install
[% END -%]

cp LICENSE $distdir/

cd /var/tmp/dist
[% c('tar', {
        tar_src => [ project ],
        tar_args => '-caf ' _ dest_dir _ '/' _ c('filename'),
    }) %]
