From dceaf642d0d0a32a0ac3d84b5f740aaad6f8a303 Mon Sep 17 00:00:00 2001
From: Alexander Golubev <fatzer2@gmail.com>
Date: Mon, 11 May 2026 02:42:52 +0300
Subject: trinity-base-2.eclass: rework dependency upon tdelibs

- Add a tristate (yes|no|optional) variable TRINITY_NEEDED
- Handle the dependency more uniformly for live/stable packages
- Call set-trinityver when needed (this fixes FTBFS in pytde introduced
  by 0230c7a8)

Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
---
 eclass/trinity-base-2.eclass | 63 +++++++++++++++++++++++---------------------
 1 file changed, 33 insertions(+), 30 deletions(-)

diff --git a/eclass/trinity-base-2.eclass b/eclass/trinity-base-2.eclass
index 1a0b9119..e37fcb5a 100644
--- a/eclass/trinity-base-2.eclass
+++ b/eclass/trinity-base-2.eclass
@@ -190,46 +190,45 @@ else
 	die "Unknown BUILD_TYPE=${BUILD_TYPE}"
 fi
 
-if [[ ${BUILD_TYPE} == live ]]; then
-	TRINITY_VER=14
-	if [[ ${CATEGORY} = trinity-base ]]; then
-		[[ -z ${SLOT} ]] && SLOT=${TRINITY_VER}
-	fi
-
-	export TDEDIR="/usr/trinity/${TRINITY_VER}"
-	export TDEDIRS="/usr/trinity/${TRINITY_VER}"
-
-	# TODO: get rid of these hacks re prefixing
-	adjust-trinity-paths
-
-	case ${CATEGORY} in
-		trinity-base|trinity-apps)
-			[[ ${PN} != tdelibs ]] && [[ ${TRINITY_MODULE_TYPE} != "dependencies" ]] && [[ ${PN} != "arts" ]] &&
-			[[ ${PN} != "trinity-cmake" ]] &&
-			COMMON_DEPEND+=" ~trinity-base/tdelibs-${PV}"
-			;;
-		*) ;;
-	esac
-elif [[ ${CATEGORY} = trinity-base ]]; then
-	# Set SLOT, TDEDIR, TRINITY_VER and PREFIX
-	set-trinityver
-	[[ -z ${SLOT} ]] && SLOT=${TRINITY_VER}
-	# Common dependencies
-	[[ ${PN} != tdelibs ]] && [[ ${PN} != "arts" ]] && [[ ${PN} != "trinity-cmake" ]] && need-trinity
-elif [[ ${CATEGORY} = "trinity-apps" ]]; then
-	need-trinity
+# @ECLASS_VARIABLE: TRINITY_NEEDED
+# @DESCRIPTION:
+# If set to "yes", add an unconditional dependency on trinity-base/tdelibs. If set to "optional",
+# add the dependency with IUSE="tde". Valid values are: "yes", "optional" and "no".  Default value
+# is "no" if TRINITY_MODULE_TYPE == dependencies and "yes" otherwise.
+if [[ "${TRINITY_MODULE_TYPE}" == "dependencies" ]]; then
+	: ${TRINITY_NEEDED:=no}
+else
+	: ${TRINITY_NEEDED:=yes}
 fi
 
 # @ECLASS_VARIABLE: TRINITY_NEED_PREFIX
 # @DESCRIPTION:
-# If set to "yes", add an unconditional dependency on trinity-base/trinity-prefix. Valid values are
-# "yes" and "no".  Default value is "no" if TRINITY_MODULE_TYPE == dependencies and "yes" otherwise.
+# If set to "yes", add an unconditional dependency on trinity-base/trinity-prefix and set
+# TDEDIR/TRINITY_VER. Valid values are "yes" and "no".  Default value is "no" if
+# TRINITY_MODULE_TYPE == dependencies and "yes" otherwise.
 if [[ "${TRINITY_MODULE_TYPE}" == "dependencies" ]]; then
 	: ${TRINITY_NEED_PREFIX:=no}
 else
 	: ${TRINITY_NEED_PREFIX:=yes}
 fi
 
+if [[ "${CATEGORY}" =~ ^trinity-.*$ || "${TRINITY_NEEDED}" != "no" || "${TRINITY_NEED_PREFIX}" != "no" ]]; then
+	set-trinityver
+fi
+
+case ${TRINITY_NEEDED} in
+	no) ;;
+	optional)
+		COMMON_DEPEND+=" tde? ( ~trinity-base/tdelibs-${TRINITY_VER} ) "
+		;;
+	yes)
+		need-trinity
+		;;
+	*)
+		die "Value TRINITY_NEEDED=\"${TRINITY_NEEDED}\" is not supported"
+		;;
+esac
+
 case ${TRINITY_NEED_PREFIX} in
 	no) ;;
 	yes)
@@ -241,6 +240,10 @@ case ${TRINITY_NEED_PREFIX} in
 		;;
 esac
 
+# set slot unless alredy set
+if [[ "${CATEGORY}" =~ ^trinity-.*$ ]]; then
+	[[ -z ${SLOT} ]] && SLOT=${TRINITY_VER}
+fi
 
 # Common dependencies
 [[ ${PN} != "trinity-cmake" ]] &&
-- 
cgit v1.2.3

