# Template file for 'cmake-bootstrap'
pkgname=cmake-bootstrap
version=3.19.4
revision=1
wrksrc=cmake-$version
bootstrap=yes
build_style=configure
configure_args="--prefix=/usr --datadir=share/$pkgname --bindir=bin
 --system-libs --no-system-curl --no-system-jsoncpp --no-system-nghttp2
 --no-system-librhash --no-system-libuv --no-system-expat --no-qt-gui
 ${XBPS_MAKEJOBS:+--parallel=$XBPS_MAKEJOBS}"
make_build_args="-C Bootstrap.cmk DOCDIR=/usr/share/doc"
makedepends="libarchive-devel"
short_desc="CMake (for bootstrapping only, not for normal usage)"
maintainer="Đoàn Trần Công Danh <congdanhqx@gmail.com>"
license="LGPL-2.1-or-later, BSD-3-Clause"
homepage="https://www.cmake.org"
distfiles="https://www.cmake.org/files/v${version%.*}/cmake-${version}.tar.gz"
checksum=7d0232b9f1c57e8de81f38071ef8203e6820fe7eec8ae46a1df125d88dbcc2e1
conflicts="cmake>=0"

CFLAGS="-DCMAKE_USE_SYSTEM_ZLIB -DCMAKE_USE_SYSTEM_LIBARCHIVE"
CXXFLAGS="$CFLAGS"

post_patch() {
	vsed -i -e '/exe_dir = CMAKE_BOOTSTRAP_BINARY_DIR/d' \
		-e '/ifndef CMAKE_BOOTSTRAP/{N;/Install tree/s/BOOTSTRAP/&_NO/}' \
		Source/cmSystemTools.cxx
	vsed -i -e 's/[ 	]RES=/ return /' \
		-e '/define CMAKE_BIN_DIR/s,/[a-z-]*,bin,' \
		-e "/define CMAKE_DATA_DIR/s,/[a-z-]*,share/$pkgname," \
		-e '/Run make to build bootstrap cmake/,$d' \
		bootstrap
	rm -rf Utilities/cmbzip2
	rm -rf Utilities/cmcurl
	rm -rf Utilities/cmexpat
	rm -rf Utilities/cmlibarchive
	rm -rf Utilities/cmliblzma
	rm -rf Utilities/cmlibrhash
	rm -rf Utilities/cmnghttp2
	rm -rf Utilities/cmzlib
	rm -rf Utilities/cmzstd
}

do_check() {
	: "this is half baked cmake"
}

do_install() {
	vbin Bootstrap.cmk/cmake
	vmkdir usr/share/$pkgname
	vcopy Modules usr/share/$pkgname
	vcopy Templates usr/share/$pkgname

	vlicense Copyright.txt
	vlicense Utilities/KWIML/Copyright.txt  KWIML-Copyright.txt
	vlicense Utilities/cmlibuv/LICENSE      libuv-LICENSE
	vlicense Utilities/cmjsoncpp/LICENSE    jsoncpp-LICENSE
}
