#------------------------------------------------------------------------------
# Modified Calculate Utilities 3.7.6.8
# Processed template files:
# /var/db/repos/calculate/profiles/templates/2_ac_install_merge/sys-apps/calculate-utils/profile.bashrc.d/50-patch-package
#------------------------------------------------------------------------------
# vim: set syntax=sh
#
# Copyright 2014-2015 Calculate Ltd. http://www.calculate-linux.org
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0

CL_CORE_PATCH=/usr/bin/cl-core-patch
[[ -f $CL_CORE_PATCH ]] || CL_CORE_PATCH=/usr/sbin/cl-core-patch

if [[ ${EBUILD_PHASE} == "compile" ]] && [[ -d ${S} ]] && check_skip; then
	if ! [[ -f /var/lib/calculate/calculate-core/cache/merge-patch.list ]] ||
		grep ${CATEGORY}/${PN} /var/lib/calculate/calculate-core/cache/merge-patch.list &>/dev/null
	then
		[ -f ${CL_CORE_PATCH} ] && ${CL_CORE_PATCH} --no-progress --pkg-version ${PVR} \
			--pkg-slot ${SLOT/\/*} --pkg-category ${CATEGORY} \
			--pkg-path ${S} --pkg-name ${PN} --verbose
		if [[ $? -eq 2 ]]
		then
			if /usr/libexec/calculate/cl-variable --value main.cl_template_wrong_patch | grep break &>/dev/null
			then
				die "Failed to apply Calculate utilities patch"
			fi
		fi
	fi
fi
