# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=f2fs-tools
pkgver=1.6.1
pkgrel=0
pkgdesc="Tools for Flash-Friendly File System (F2FS)"
url="http://git.kernel.org/cgit/linux/kernel/git/jaegeuk/f2fs-tools.git"
arch="all"
license="GPL-2.0-or-later"
depends=""
depends_dev=""
makedepends="$depends_dev automake autoconf libtool util-linux-dev
	linux-headers bsd-compat-headers"
install=""
subpackages="$pkgname-doc $pkgname-dev $pkgname-libs"
#source="http://git.kernel.org/cgit/linux/kernel/git/jaegeuk/f2fs-tools.git/snapshot/f2fs-tools-$pkgver.tar.gz"
source="http://dev.alpinelinux.org/archive/f2fs-tools/f2fs-tools-$pkgver.tar.gz
	"
disturl="dev.alpinelinux.org:/archive/$pkgname/"
giturl=git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git

_builddir="$srcdir"/f2fs-tools-$pkgver
snapshot() {
	local _format="tar.gz"
	mkdir -p "$srcdir" && cd "$srcdir"
	# clone git repo and archive
	local _tag=v$pkgver
	msg "Creating git snapshot: $pkgname-$pkgver"
	git clone --branch $_tag --depth=1 \
		--bare $giturl ${pkgname}.git || return 1
	git --git-dir ${pkgname}.git archive \
		--format=$_format \
		-o $pkgname-$pkgver.$_format \
		--prefix=$pkgname-$pkgver/ $_tag \
		|| return 1
	# upload to defined distfiles url
	scp $pkgname-$pkgver.$_format $disturl || return 1
}

prepare() {
	local i
	cd "$_builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
	libtoolize --force && aclocal && autoheader && autoconf \
		&& automake --add-missing
}

build() {
	cd "$_builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		|| return 1
	make || return 1
}

package() {
	cd "$_builddir"
	make install DESTDIR="$pkgdir" || return 1
	mkdir -p "$pkgdir"/usr/include
	install -m 644 include/f2fs_fs.h mkfs/f2fs_format_utils.h \
		"$pkgdir"/usr/include/ || return 1
}

md5sums="722f620fb04fa1abfef050a5468d23f6  f2fs-tools-1.6.1.tar.gz"
sha256sums="6e2f46df79d2f8da12ba943d9fd0e82f159fffff9e1566c09db8668956378638  f2fs-tools-1.6.1.tar.gz"
sha512sums="95ba7ed50e7ca9f0218b08c7f26ecdb60e8bde37502239804ae207e65b2241636ed33956a33e5c3dfdcc151457323b7d3bdcfd6650a321a54fef46b97334fae0  f2fs-tools-1.6.1.tar.gz"
