# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
setvar pkgname = 'cmake'
setvar pkgver = '3.9.3'
setvar pkgrel = '0'
setvar pkgdesc = ""CMake is a cross-platform open-source make system""
setvar url = ""http://www.cmake.org""
setvar arch = ""all""
setvar license = ""CMake""
setvar makedepends = ""ncurses-dev curl-dev expat-dev zlib-dev bzip2-dev libarchive-dev
    libuv-dev xz-dev rhash-dev""
setvar options = ""!checkroot !check""
setvar checkdepends = ""musl-utils file""
setvar subpackages = ""$pkgname-doc""

case (pkgver) {
*.*.*.* { setvar _v = "v${pkgver%.*.*}"}
*.*.* { setvar _v = "v${pkgver%.*}"}
}

setvar source = ""http://www.cmake.org/files/$_v/cmake-${pkgver}.tar.gz""
setvar builddir = ""$srcdir/$pkgname-$pkgver""

proc parallel_opt {
	local i n
	for i in $MAKEOPTS {
		case (i) {
			-j* { setvar n = ${i#-j}}
		};
	}
	test -n $n && echo "--parallel $n"
}

proc build {
	cd $builddir
	# jsoncpp needs cmake to build so to avoid recursive build
	# dependency, we use the bundled version of jsoncpp
	./bootstrap --prefix=/usr \
		--mandir=/share/man \
		--datadir=/share/$pkgname \
		--docdir=/share/doc/$pkgname \
		--system-libs \
		--no-system-jsoncpp \
		$(parallel_opt)

	make
}

proc check {
	cd $builddir'
	CTEST_OUTPUT_ON_FAILURE=TRUE' bin/ctest
}

proc package {
	cd $startdir/src/$pkgname-$pkgver
	make DESTDIR="$pkgdir" install
}

setvar sha512sums = ""30058cf4c154221846d1cd22eaf44a297d2a2d020a443f3e6f40384dfb86ee9a639a1299aa9f187f230505b2a6ee0fe69fbf5e80410711a6ac3d7a07b37f8dfc  cmake-3.9.3.tar.gz""