#!/bin/sh -e

VERSION=$1
PREV_VERSION=$2

git checkout refs/tags/release-$VERSION
git log --pretty=fuller --date=short refs/tags/release-$PREV_VERSION..HEAD > ChangeLog

autoreconf -i

./configure && \
    make dist-bzip2 && make dist-gzip && make dist-xz
make distclean

release_mingw()
{
    export HOST=$1
    export LABEL=$2

    mkdir -p mingw-out

    docker build \
	   --build-arg HOST=$HOST \
	   --build-arg ARIA2_VERSION=release-$VERSION \
	   --build-arg ARIA2_REF=refs/tags/release-$VERSION \
	   -t aria2-mingw-$HOST - < Dockerfile.mingw

    docker run --rm -it -v $PWD/mingw-out:/out aria2-mingw-$HOST \
	   cp /aria2/src/aria2c.exe /out

    ./mingw-release

    rm -rf mingw-out
}

# mingw 32bit
release_mingw i686-w64-mingw32 win-32bit

# mingw 64bit
release_mingw x86_64-w64-mingw32 win-64bit

# android
mkdir -p android-out

docker build \
       --build-arg ARIA2_VERSION=release-$VERSION \
       -t aria2-android - < Dockerfile.android

docker run --rm -it -v $PWD/android-out:/out aria2-android \
       cp /root/build/aria2/src/aria2c /out

./android-release

rm -rf android-out

# OSX builds are created separately using makerelease-osx.mk
