#!/bin/bash
#
# This file is part of Builder.
#
# Builder is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Builder is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Builder.  If not, see <https://www.gnu.org/licenses/>.
#

# Here are some common definitions for all nest versions.
# Source this file from version specific build plans.

build_package () {
	log_status ">>> build"
	cd "${BUILD}"
	set -x
	cmake ${CMAKEFLAGS} -DCMAKE_INSTALL_PREFIX:PATH="$TARGET" "$SOURCE" 2>&1 | tee "${LOG}/cmake.log"
	make -j ${MAKE_THREADS:-$(nproc)} 2>&1 | tee "${LOG}/make.log"
	set +x
}

build_install () {
	log_status ">>> install"
	make install 2>&1 | tee "${LOG}/make-install.log"
	awk 'BEGIN {f=3;x=0}; /^-------/{x=1;if (f>0) f--} f*x' "${LOG}/cmake.log" >"${TARGET}/ConfigurationSummary.txt"
}

build_install_test () {
	log_status ">>> test"
	make installcheck 2>&1 | tee "${LOG}/make-installcheck.log"
	log_success "installcheck passed." >>"${TARGET}/ConfigurationSummary.txt"
	awk '/Testsuite Summary/{f=1} /Built target/{f=0} f;' "${LOG}/make-installcheck.log" >>"${TARGET}/ConfigurationSummary.txt"
}
