#!/usr/bin/env modbuild

if (( V_MAJOR == 1 )) && (( V_MINOR <= 12 )); then
	pbuild::set_download_url "https://github.com/google/googletest/archive/refs/tags/release-${V_PKG}.tar.gz"
else
	pbuild::set_download_url "https://github.com/google/googletest/archive/refs/tags/v${V_PKG}.tar.gz"
fi
pbuild::add_to_group 'Compiler'

if (( V_MAJOR == 1 )) && (( V_MINOR <= 7 )); then
	pbuild::install_docfiles \
		CHANGES \
		CONTRIBUTORS \
		LICENSE \
		README

	pbuild::install() {
		local -r _include_srcdir="${SRC_DIR}/include/gtest"
		local -r _include_dstdir="${PREFIX}/include/gtest"
		if [[ -e "${_include_dstdir}" ]]; then
			chmod -R u+w "${_include_dstdir}"
		fi
		mkdir -p "${_include_dstdir}"
		cp -rv "${_include_srcdir}"/* "${_include_dstdir}"

		local -r _lib_dstdir="${PREFIX}/lib"
		mkdir -p "${_lib_dstdir}"
		cp -v *.a "${_lib_dstdir}"
	}
else
	pbuild::install_docfiles \
		CONTRIBUTING.md \
		LICENSE \
		README.md
fi

