# Template file for 'android-tools'
pkgname=android-tools
# NOTE: not all upstream updates has code changes for the parts
#       of android used by android-tools. Check for diff with:
#         curl -L http://git.io/vvC0Z | sh -s 5.0.2_r1 5.1.0_r1
version=9.0.0r3
revision=1
_distver=${version/r/_r}
create_wrksrc=yes
hostmakedepends="ruby cmake ninja perl go"
makedepends="gtest-devel zlib-devel libressl-devel libusb-devel pcre2-devel"
short_desc="Android platform tools (adb and fastboot)"
maintainer="John <johnz@posteo.net>"
license="Apache-2.0, ISC, GPL-2.0-only, MIT"
homepage="http://developer.android.com/tools/help/adb.html"
_baseurl=https://android.googlesource.com/platform
distfiles="
 ${_baseurl}/system/core/+archive/android-${_distver}.tar.gz>core.tar.gz
 ${_baseurl}/system/extras/+archive/android-${_distver}.tar.gz>extras.tar.gz
 ${_baseurl}/external/selinux/+archive/android-${_distver}.tar.gz>selinux.tar.gz
 ${_baseurl}/external/f2fs-tools/+archive/android-${_distver}.tar.gz>f2fs-tools.tar.gz
 ${_baseurl}/external/e2fsprogs/+archive/android-${_distver}.tar.gz>e2fsprogs.tar.gz
 https://boringssl.googlesource.com/boringssl/+archive/3359.tar.gz>boringssl.tar.gz"
# Contents checksums because the tarballs change with every download
checksum="@6c4e5d93ef8d543a0d7f3a208cccc7b708176eb193352b0bbff6f53c6a7188df
 @9257b1a098c8012f154ed47795093e12040b562345a2ae889fc06db931fc5b0c
 @9f2b5e379eca4c56e2d422598831bfd7bdf2b7b3c3d011ce513c7603aa46b574
 @47b98c4ec5f037379b0b4e237d7cac87452ecf3aa7882114f7715a9995e959ad
 @e98509632e865e792dc4b344b0a1ada0662dda7571534fa7c5d1a8902dcfb0f4
 @9ec3dd8c7f6ec5f4d8b60e22d8dcba3dc4432763ec8a637c05ba24d3b58b2826"

nocross="error: requested alignment 64 is larger than 8 [-Werror=attributes]"

do_extract() {
	local tarball p
	for p in ${distfiles}; do
		tarball=${p##*>}
		mkdir -p ${wrksrc}/${tarball/.*}
		tar -x --no-same-permissions --no-same-owner -f \
			${XBPS_SRCDISTDIR}/${pkgname}-${version}/${tarball} \
			-C ${wrksrc}/${tarball/.*}
	done
}

pre_configure() {
	PKGVER=${_distver} ${FILESDIR}/generate_build.rb > build.ninja

	mkdir -p boringssl/build
	cd boringssl/build

	cmake -GNinja \
		-DBUILD_SHARED_LIBS=FALSE \
		-DCMAKE_BUILD_TYPE=RELEASE \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		..
	ninja
}

do_build() {
	ninja
}

do_install() {
	for i in adb fastboot mke2fs.android e2fsdroid ext2simg \
		core/mkbootimg/mkbootimg ;do
		vbin $i
	done
	vlicense boringssl/LICENSE boringssl.LICENSE
	vlicense boringssl/third_party/fiat/LICENSE fiat.LICENSE
	vlicense boringssl/third_party/googletest/LICENSE gtest.LICENSE
	vlicense boringssl/third_party/android-cmake/LICENSE android-cmake.LICENSE
	vsv adb
}

# REMARKS:
# If there is any reason at all that fastboot may not be a position independent
# executable, please document it here.
