#!/bin/bash
[% c("var/set_default_env") -%]

distdir=$rootdir/[% project %]
mkdir -p $distdir

mkdir $distdir/android-sdk-linux
cd $distdir/android-sdk-linux

# Command line tools
mkdir -p cmdline-tools
unzip -qq $rootdir/[% c("input_files_by_name/android_commandlinetools") %] -d cmdline-tools
mv cmdline-tools/cmdline-tools cmdline-tools/[% c("var/commandlinetools_version_string") %]

# NDK
mkdir ndk
unzip -qq $rootdir/[% c("input_files_by_name/android_ndk_compiler")%] -d ndk
ln -s android-ndk-r[% c("var/android_ndk_version") %][% c("var/android_ndk_revision") %] ndk/[% c("var/android_ndk_version_build") %]

# Build tools
mkdir build-tools
unzip -qq $rootdir/[% c("input_files_by_name/build_tools") %] -d build-tools
mv build-tools/[% c("var/android_release_dir") %] build-tools/[% c("version") %]

# Platform
mkdir platforms
unzip -qq $rootdir/[% c("input_files_by_name/platform") %] -d platforms

# Platform tools
unzip -qq $rootdir/[% c("input_files_by_name/platform_tools") %]

# That's a quirk required by GeckoView but let's have it here instead of in the
# project's build script
mkdir emulator
touch emulator/emulator
chmod +x emulator/emulator

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