From 9e1840a4808a600474f10c91d77751b850fb3b46 Mon Sep 17 00:00:00 2001
From: Michele Calgaro <michele.calgaro@yahoo.it>
Date: Thu, 13 Nov 2025 21:39:19 +0900
Subject: DEB buildscripts: add functionality to allow to build single modules
 without requiring the build of all others.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
---
 debian/_buildscripts/local/README.txt              | 13 ++++--
 .../local/internals/_config_template.sh            | 11 +++--
 debian/_buildscripts/local/internals/_pbuilder.sh  | 53 ++++++++++++++++++----
 .../_buildscripts/local/internals/extra_deps.txt   |  9 ----
 .../local/internals/prebuilt_pkg_paths.txt         | 17 +++++++
 5 files changed, 80 insertions(+), 23 deletions(-)
 delete mode 100644 debian/_buildscripts/local/internals/extra_deps.txt
 create mode 100644 debian/_buildscripts/local/internals/prebuilt_pkg_paths.txt

diff --git a/debian/_buildscripts/local/README.txt b/debian/_buildscripts/local/README.txt
index a732e06af..83300c7af 100644
--- a/debian/_buildscripts/local/README.txt
+++ b/debian/_buildscripts/local/README.txt
@@ -16,6 +16,8 @@ A) Environment preparation
    - you can change folder names below, as long as you update the "_config.sh" file accordingly.
    - you need to choose whether to use standard git repository clones or use git worktrees.
      Different instructions will be provided where necessary, based on the choice made.
+   - if you want to build a single module, you can choose to use prebuilt TDE packages to satisfy the missing
+     dependencies. More on this at point 8).
    - you need to choose whether to use pre built extra dependency packages or build them yourself.
      Different instructions will be provided where necessary, based on the choice made.
      More on this at point 9).
@@ -96,9 +98,14 @@ A) Environment preparation
        from your current setup. Otherwise the variables can be left empty and auto detection will be performed.
      * UPDATE_BRANCHES to the branches you want to keep updated from the main repositories.
      * DEFAULT_REPO_BRANCH to the branch to check out at the end of the repositories update process.
-
-9) Some additional packages (referred to as extra dependencies) are required to build and install TDE in debian/devuan/ubuntu.
-   These modules can be built locally or alternatively pre-built binaries from the TDE archive can be used.
+     * USE_PREBUILD_PACKAGES to decide whether to use prebuilt TDE packages to safisty missing dependencies.
+       Setting this to "y" is useful if you intend to work on a specific module, because it allows you to
+       build it without having to previously build all the other TDE modules that it depends upon.
+       The prebuilt modules will be taken from the TDE prelimirary builds archive.
+
+9) Some additional packages (referred to as extra dependencies) are required to build and install TDE in
+   debian/devuan/ubuntu. These modules can be built locally or alternatively pre-built binaries from the
+   TDE prelimirary builds archive can be used.
 
    9.1) Using pre-built extra dependencies
      - open "_config.sh" and set the variable USE_PREBUILD_EXTRA_DEPS to "y" (this is the default initial setting)
diff --git a/debian/_buildscripts/local/internals/_config_template.sh b/debian/_buildscripts/local/internals/_config_template.sh
index 7c1e929c6..ff506273c 100644
--- a/debian/_buildscripts/local/internals/_config_template.sh
+++ b/debian/_buildscripts/local/internals/_config_template.sh
@@ -5,19 +5,24 @@ set -a
 #----------------------------
 # Repo information
 #----------------------------
-TDE_DIR=""                        # TDE root folder
-UPDATE_BRANCHES="master"          # Space separated list. Available choices: master, r14.1.x
+TDE_DIR="$HOME/tde_src"           # TDE root folder
+
+USE_GIT_WORKTREES="n"             # If == "y", use git worktrees. Need consistent cloned repository to start.
+UPDATE_BRANCHES="master r14.1.x"  # Space separated list of branches to update. If using git worktrees,
+                                  # this list contains the branches for which worktrees will be created.
 DEFAULT_REPO_BRANCH="master"      # After update in completed, switch repo to this branch. Must be
                                   # one of the branches specified in UPDATE_BRANCHES
 
 #----------------------------
 # Build information
 #----------------------------
-TDE_RELEASE="14.1.0"              # TDE release number
+TDE_RELEASE="14.2.0"              # TDE release number
 DISTRO=""                         # Distro family (leave empty for auto-detection). For ex. debian
 DISTRO_NAME=""                    # Distro name of specific version (leave empty for auto-detection). For ex. buster
 ARCHITECTURE=""                   # Build for this architecture (leave empty for auto-detection). For ex. amd64
 USE_PREBUILD_EXTRA_DEPS="y"       # If == "y", use pre-built extra dependency packages
+USE_PREBUILD_PACKAGES="n"         # If == "y", use pre-built TDE packages to satisfy package dependencies
+                                  # This is useful to build individual packages without having to do a full TDE build
 BUILD_DEFAULT_OPTIONS="-g -lr"    # Default building options (pbuilder)
 GPG_SIGN_KEYID=""                 # Use this GPG key to sign packages. If null, packages will not be signed
 
diff --git a/debian/_buildscripts/local/internals/_pbuilder.sh b/debian/_buildscripts/local/internals/_pbuilder.sh
index b520a93af..f8056de82 100755
--- a/debian/_buildscripts/local/internals/_pbuilder.sh
+++ b/debian/_buildscripts/local/internals/_pbuilder.sh
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+source "$SCRIPT_DIR/internals/prebuilt_pkg_paths.txt"
+
 function run_pdebuild()
 {
   # pbuilder absolute paths
@@ -37,7 +39,9 @@ function run_pdebuild()
 (cd "$TDE_DEBS_DIR"; apt-ftparchive packages . > Packages)
 echo "deb [trusted=yes] file:$TDE_DEBS_DIR ./" >> /etc/apt/sources.list
 END_D05_01
-  if [[ "$USE_PREBUILD_EXTRA_DEPS" = "y" ]]; then
+
+  # -- prebuilt TDE packages
+  if [[ "$USE_PREBUILD_PACKAGES" = "y" ]]; then
     # Get building branch from .tdescminfo file
     if [[ -f "$MOD_BUILD_PATH/.tdescminfo" ]]; then
       BUILD_BRANCH=`sed -n -r "s/^Revision: ([^-]+)-.*/\1/p" "$MOD_BUILD_PATH/.tdescminfo"`
@@ -51,25 +55,58 @@ echo "deb [trusted=yes] $l_repo $DISTRO_NAME $l_component" >> /etc/apt/sources.l
 END_D05_02
           break
         fi
-      done <<< $(cat "$SCRIPT_DIR/internals/extra_deps.txt" | grep -E "^[[:space:]]*[^#[:space:]]+[[:space:]]+[^[:space:]]+.*$")
+      done <<< $(echo "$TDE_PREBUILT_PKGS" | grep -E "^[[:space:]]*[^#[:space:]]+[[:space:]]+[^[:space:]]+.*$")
       if [ "$bool_EDEPS_FOUND" != "y" ]; then
         # EDEPS repository not found, use default. This could happen when building from sub branches of the main package repo
+        while read l_branch l_repo l_component; do
+          if [ "$l_branch" = "default" ]; then
+            bool_EDEPS_FOUND="y"
+            cat <<END_D05_03 >> "$PBUILDER_DEPS_HOOK"
+echo "deb [trusted=yes] $l_repo $DISTRO_NAME $l_component" >> /etc/apt/sources.list
+END_D05_03
+            break
+          fi
+        done <<< $(echo "$TDE_PREBUILT_PKGS" | grep -E "^[[:space:]]*[^#[:space:]]+[[:space:]]+[^[:space:]]+.*$")
+      fi
+      IFS=$OLD_IFS
+    fi
+  fi
+
+  # -- prebuilt extra dependencies
+  if [[ "$USE_PREBUILD_EXTRA_DEPS" = "y" ]]; then
+    # Get building branch from .tdescminfo file
+    if [[ -f "$MOD_BUILD_PATH/.tdescminfo" ]]; then
+      BUILD_BRANCH=`sed -n -r "s/^Revision: ([^-]+)-.*/\1/p" "$MOD_BUILD_PATH/.tdescminfo"`
+      bool_EDEPS_FOUND="n"
+      OLD_IFS=$IFS && IFS=$' \t'
       while read l_branch l_repo l_component; do
-        if [ "$l_branch" = "default" ]; then
+        if [ "$l_branch" = "$BUILD_BRANCH" ]; then
           bool_EDEPS_FOUND="y"
-          cat <<END_D05_03 >> "$PBUILDER_DEPS_HOOK"
+          cat <<END_D05_04 >> "$PBUILDER_DEPS_HOOK"
 echo "deb [trusted=yes] $l_repo $DISTRO_NAME $l_component" >> /etc/apt/sources.list
-END_D05_03
+END_D05_04
           break
         fi
-      done <<< $(cat "$SCRIPT_DIR/internals/extra_deps.txt" | grep -E "^[[:space:]]*[^#[:space:]]+[[:space:]]+[^[:space:]]+.*$")
+      done <<< $(echo "$TDE_PREBUILT_EDEPS" | grep -E "^[[:space:]]*[^#[:space:]]+[[:space:]]+[^[:space:]]+.*$")
+      if [ "$bool_EDEPS_FOUND" != "y" ]; then
+        # EDEPS repository not found, use default. This could happen when building from sub branches of the main package repo
+        while read l_branch l_repo l_component; do
+          if [ "$l_branch" = "default" ]; then
+            bool_EDEPS_FOUND="y"
+            cat <<END_D05_05 >> "$PBUILDER_DEPS_HOOK"
+echo "deb [trusted=yes] $l_repo $DISTRO_NAME $l_component" >> /etc/apt/sources.list
+END_D05_05
+            break
+          fi
+        done <<< $(echo "$TDE_PREBUILT_EDEPS" | grep -E "^[[:space:]]*[^#[:space:]]+[[:space:]]+[^[:space:]]+.*$")
       fi
       IFS=$OLD_IFS
     fi
   fi
-  cat <<END_D05_04 >> "$PBUILDER_DEPS_HOOK"
+
+  cat <<END_D05_06 >> "$PBUILDER_DEPS_HOOK"
 apt-get update
-END_D05_04
+END_D05_06
   chmod a+x "$PBUILDER_DEPS_HOOK"
   # Build
   OPT_BUILD_PARALLEL=""
diff --git a/debian/_buildscripts/local/internals/extra_deps.txt b/debian/_buildscripts/local/internals/extra_deps.txt
deleted file mode 100644
index 521b16d0c..000000000
--- a/debian/_buildscripts/local/internals/extra_deps.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/bash
-
-# List of repositories for extra dependency packages.
-# The "default" repo will be used in case a match can't be found.
-EDEPS_REPO="
-	default  http://mirror.ppa.trinitydesktop.org/trinity-testing deps
-	master   http://mirror.ppa.trinitydesktop.org/trinity-testing deps
-	r14.1.x  http://mirror.ppa.trinitydesktop.org/trinity-sb      deps-r14
-"
diff --git a/debian/_buildscripts/local/internals/prebuilt_pkg_paths.txt b/debian/_buildscripts/local/internals/prebuilt_pkg_paths.txt
new file mode 100644
index 000000000..d2a6486c6
--- /dev/null
+++ b/debian/_buildscripts/local/internals/prebuilt_pkg_paths.txt
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+# List of repositories for TDE prebuilt packages.
+# The "default" repo will be used in case a match can't be found.
+TDE_PREBUILT_PKGS="
+	default  http://mirror.ppa.trinitydesktop.org/trinity-testing main
+	master   http://mirror.ppa.trinitydesktop.org/trinity-testing main
+	r14.1.x  http://mirror.ppa.trinitydesktop.org/trinity-sb      main
+"
+
+# List of repositories for extra dependency packages.
+# The "default" repo will be used in case a match can't be found.
+TDE_PREBUILT_EDEPS="
+	default  http://mirror.ppa.trinitydesktop.org/trinity-testing deps
+	master   http://mirror.ppa.trinitydesktop.org/trinity-testing deps
+	r14.1.x  http://mirror.ppa.trinitydesktop.org/trinity-sb      deps-r14
+"
-- 
cgit v1.2.3

