From 9e62056e078defc6fa52529b8253c1ed56070404 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 6 Jun 2025 14:22:32 +0200 Subject: [PATCH 01/26] detect-environment: Fixed shellcheck issues Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 35 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 6b3a14e68..9db43620f 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -39,11 +39,11 @@ detect_os() SunOS) OS_FAMILY=solaris OS=solaris - OS_VERSION=`echo $UNAME_R | sed -e 's/^5\.//'` + OS_VERSION=$(echo "$UNAME_R" | sed -e 's/^5\.//') ;; AIX) OS_FAMILY=aix - OS_VERSION=`uname -v`.$UNAME_R + OS_VERSION=$(uname -v).$UNAME_R OS=aix unset LIBPATH ;; @@ -82,7 +82,7 @@ detect_distribution() case "$REL" in "CentOS "*) VER="$(echo "$REL" | sed -e 's/^CentOS.* release \([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/')" - if ! echo "$VER" | egrep '^[0-9]+\.[0-9]+$' > /dev/null + if ! echo "$VER" | grep -E '^[0-9]+\.[0-9]+$' > /dev/null then echo "Unknown CentOS version: $VER" exit 42 @@ -116,7 +116,7 @@ detect_distribution() "Red Hat Enterprise Linux Server release "*) VER=${REL#Red Hat Enterprise Linux Server release } VER=${VER% \(*}; - if ! echo "$VER" | egrep '^[0-9]+.[0-9]+$' > /dev/null + if ! echo "$VER" | grep -E '^[0-9]+.[0-9]+$' > /dev/null then echo "Unknown RHEL Server version: $VER" exit 42 @@ -129,7 +129,7 @@ detect_distribution() "Red Hat Enterprise Linux release "*) VER=${REL#Red Hat Enterprise Linux release } VER=${VER% \(*}; - if ! echo "$VER" | egrep '^[0-9]+.[0-9]+$' > /dev/null + if ! echo "$VER" | grep -E '^[0-9]+.[0-9]+$' > /dev/null then echo "Unknown RHEL Server version: $VER" exit 42 @@ -158,7 +158,7 @@ detect_distribution() OS_VERSION="$REL" elif [ -f /etc/debian_version ]; then REL=$(cat /etc/debian_version) - if ! echo "$REL" | egrep '^[0-9]+\.[0-9]+(\.[0-9]+)?$' > /dev/null + if ! echo "$REL" | grep -E '^[0-9]+\.[0-9]+(\.[0-9]+)?$' > /dev/null then case "$REL" in wheezy*) @@ -191,7 +191,7 @@ detect_distribution() MAJOR=$(grep '^VERSION' /etc/SuSE-release | awk '{print $3}') MINOR=$(grep '^PATCHLEVEL' /etc/SuSE-release | awk '{print $3}') - if [ -z "$MAJOR" -o -z "$MINOR" ]; then + if [ -z "$MAJOR" ] || [ -z "$MINOR" ]; then echo "Unable to detect version of SLES: $MAJOR.$MINOR" fi @@ -270,9 +270,9 @@ detect_arch() { case "$DEP_PACKAGING" in deb) - ARCH=`dpkg --print-architecture`;; + ARCH=$(dpkg --print-architecture);; rpm) - ARCH=`rpm --eval '%{_arch}'`;; + ARCH=$(rpm --eval '%{_arch}');; solaris) case $UNAME_M in sun*) @@ -313,7 +313,7 @@ detect_tools() { # We look for GNU Make because # various dependencies have various requirements - MAKE=`func_whereis gmake make` + MAKE=$(func_whereis gmake make) if $MAKE -v | grep GNU then @@ -322,17 +322,17 @@ detect_tools() fatal "GNU Make not found" fi - if [ "x$OS" = "xaix" ] && [ "x$OS_VERSION" = "x5.3" ]; then + if [ "$OS" = "aix" ] && [ "$OS_VERSION" = "5.3" ]; then RPMBUILD_CMD=rpm else RPMBUILD_CMD=rpmbuild fi export RPMBUILD_CMD - FUSER=`func_whereis fuser` + FUSER=$(func_whereis fuser) export FUSER - PATCH=`func_whereis gpatch patch` + PATCH=$(func_whereis gpatch patch) export PATCH } @@ -341,16 +341,17 @@ detect_cores() case "$OS_FAMILY" in aix) echo "Detected OS family is aix" - NUM_CORES="$(lscfg | grep proc | wc -l)";; + NUM_CORES="$(lscfg | grep -c proc)";; solaris) echo "Detected OS family is solaris" NUM_CORES="$(psrinfo |wc -l)";; linux) echo "Detected OS family is linux" - NUM_CORES="$(cat /proc/cpuinfo | grep '^processor' | wc -l)";; + NUM_CORES="$(grep -c '^processor' /proc/cpuinfo)" + ;; hpux) echo "Detected OS family is hpux" - NUM_CORES="$(ioscan -k -C processor |grep processor | wc -l)";; + NUM_CORES="$(ioscan -k -C processor | grep -c processor)";; *) echo "Detected OS family is UNKNOWN, defaulting amount of CPU cores to 1" NUM_CORES=1;; @@ -358,7 +359,7 @@ detect_cores() # Make number of jobs one higher than core count, to account for I/O, network, etc. echo "Detected amount of CPU cores is $NUM_CORES" - MAKEFLAGS="${MAKEFLAGS:--j$(($NUM_CORES + 1))}" + MAKEFLAGS="${MAKEFLAGS:--j$((NUM_CORES + 1))}" export MAKEFLAGS } From 5dd5779ce51914b957a49ebed2002266c52543bb Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 6 Jun 2025 14:45:06 +0200 Subject: [PATCH 02/26] detect-environment: Refactored cross target detection Renamed function `detect_labels` to `detect_cross_target`, because this is really what it does. Furthermore, I added a comment explaining the code, as well as code to inform about the detection of cross target. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 9db43620f..4e56716de 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -13,8 +13,11 @@ then exit 100 fi - -detect_labels() +# Detects and sets the CROSS_TARGET environment variable based on patterns +# in the label variable (see labels.txt), specifically for MinGW cross- +# compilation targets. However, if CROSS_TARGET is already set in the +# environment it will take precedence. +detect_cross_target() { case "$label" in *_x86_64_mingw*) @@ -26,6 +29,12 @@ detect_labels() export CROSS_TARGET ;; esac + + if [ -n "$CROSS_TARGET" ]; then + echo "Detected cross target $CROSS_TARGET" + else + echo "No cross target detected" + fi } detect_os() @@ -365,7 +374,7 @@ detect_cores() detect_environment() { - detect_labels + detect_cross_target detect_os detect_packaging detect_arch From 4525c4bb30b617a4172c8cba1035ab1c868c4113 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 6 Jun 2025 15:17:16 +0200 Subject: [PATCH 03/26] detect-environment: Consistent identation in detect_os Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 40 +++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 4e56716de..713408afe 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -42,43 +42,51 @@ detect_os() case "$CROSS_TARGET" in '') case "$UNAME_S" in - Linux) + Linux) OS_FAMILY=linux - detect_distribution;; - SunOS) + detect_distribution + ;; + SunOS) OS_FAMILY=solaris OS=solaris OS_VERSION=$(echo "$UNAME_R" | sed -e 's/^5\.//') ;; - AIX) + AIX) OS_FAMILY=aix OS_VERSION=$(uname -v).$UNAME_R OS=aix unset LIBPATH ;; - Darwin) + Darwin) OS_FAMILY=darwin - OS=darwin;; - FreeBSD) + OS=darwin + ;; + FreeBSD) OS_FAMILY=freebsd - OS=freebsd;; - NetBSD) + OS=freebsd + ;; + NetBSD) OS_FAMILY=netbsd - OS=netbsd;; + OS=netbsd + ;; HP-UX) OS_FAMILY=hpux - OS=hpux;; - *) - echo "Unable to detect operating system: $UNAME_S" - exit 42;; + OS=hpux + ;; + *) + echo "Unable to detect operating system: $UNAME_S" + exit 42 + ;; esac ;; *-mingw) OS_FAMILY=mingw - OS=mingw;; + OS=mingw + ;; *) echo "Unknown cross-compilation target: $CROSS_TARGET" - exit 42;; + exit 42 + ;; esac export OS OS_VERSION From 972bc83e09f0a7f2684322b4f29304ebbad83d0e Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 9 Jun 2025 12:18:00 +0200 Subject: [PATCH 04/26] detect-environment: Fix indentation in "functions" sourced check The rest of the file uses two space indentation. Hence, the check to see if the functions script was sourced should also have two space indentation for consitency. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 713408afe..6628d41e6 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -9,8 +9,8 @@ if [ "$_IS_FUNCTIONS_SOURCED" != yes ] then - echo 'FATAL: You must source "functions" script before "detect-environment"!' - exit 100 + echo 'FATAL: You must source "functions" script before "detect-environment"!' + exit 100 fi # Detects and sets the CROSS_TARGET environment variable based on patterns From dcaee37225474cd396d2619e6279ebdfaa7f3d10 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 9 Jun 2025 10:27:23 +0200 Subject: [PATCH 05/26] detect-environment: Document detect_os function Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 6628d41e6..e6d29c5d7 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -37,10 +37,21 @@ detect_cross_target() fi } +# This function exports operating system specific variables: +# - OS usually contains a specific distribution (e.g. Debian) +# - OS_VERSION operating system version (but is not always defined) +# +# Furthermore, the following variable is set, but it's not exported: +# - OS_FAMILY usually contains the kernel name (e.g. Linux) detect_os() { case "$CROSS_TARGET" in '') + # The UNAME_S, UNAME_R and UNAME_V variables are set in the "functions" + # script from the command substitution of `uname -s`, `uname -r` and + # `uname -v` which outputs the kernel name, the kernel release and the + # kernel version respectively. + case "$UNAME_S" in Linux) OS_FAMILY=linux @@ -55,6 +66,10 @@ detect_os() OS_FAMILY=aix OS_VERSION=$(uname -v).$UNAME_R OS=aix + # LIBPATH on AIX serves the same function as LD_LIBRARY_PATH on + # Linux. However, Java also uses this environment variable, and it + # apparently messes with the library look-ups during packaging. This + # line definitely doesn't belong here. But I'll leave it for now. unset LIBPATH ;; Darwin) From c4686444bd50e98eab2405407e9afee494a2c1bd Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 9 Jun 2025 12:46:06 +0200 Subject: [PATCH 06/26] detect-environment: Put ;; on separate line Put the pattern block terminators on separate lines, in the detect_distribution function, for the sake of consistency. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index e6d29c5d7..1fbbec7f7 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -127,10 +127,12 @@ detect_distribution() VER=${REL#Red Hat Enterprise Linux AS release } case "$VER" in [0-9]" "*) - MAJOR=${VER%% *};; + MAJOR=${VER%% *} + ;; *) echo "Unknown RHEL AS major version: $VER" - exit 42;; + exit 42 + ;; esac case "$VER" in @@ -139,7 +141,8 @@ detect_distribution() MINOR=${MINOR%\)};; *) echo "Unknnown RHEL AS minor version: $VER" - exit 42;; + exit 42 + ;; esac OS=rhel @@ -173,7 +176,8 @@ detect_distribution() *) echo "Unknown RedHat-like distribution: $REL" - exit 42;; + exit 42 + ;; esac elif [ -f /etc/lsb-release ] && grep -q Ubuntu /etc/lsb-release; then REL=$(grep DISTRIB_RELEASE= /etc/lsb-release) @@ -183,7 +187,8 @@ detect_distribution() ;; *) echo "Unknown Ubuntu release: $REL" - exit 42;; + exit 42 + ;; esac OS=ubuntu @@ -207,7 +212,8 @@ detect_distribution() ;; *) echo "Unable to detect version of Debian: $REL" - exit 42;; + exit 42 + ;; esac fi @@ -237,7 +243,8 @@ detect_distribution() ;; *) echo "Unknown SUSE distribution: $REL" - exit 42;; + exit 42 + ;; esac elif [ -f /etc/os-release ]; then # see https://en.opensuse.org/SDB:Find_openSUSE_version for rules of From b85559c2c784ad26b9c27b781c02a216f4acee6e Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 9 Jun 2025 13:21:48 +0200 Subject: [PATCH 07/26] detect-environment: Removed version substitution of code-names Removed version substitution of the Debian release code-names (e.g., jessie, buster, etc.) from /etc/debian_version. Looking through the [changelog](https://launchpad.net/debian/+source/base-files/+changelog) for the base-files package in Debian, you can easily see that it has never contained the code-names. At least not since version 5.0.3. Furthermore, we have not updated the version substitution since Debian 10 which is End-of-Life. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 1fbbec7f7..0fcfbc909 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -197,24 +197,8 @@ detect_distribution() REL=$(cat /etc/debian_version) if ! echo "$REL" | grep -E '^[0-9]+\.[0-9]+(\.[0-9]+)?$' > /dev/null then - case "$REL" in - wheezy*) - REL=7.0 - ;; - jessie*) - REL=8.0 - ;; - stretch*) - REL=9.0 - ;; - buster*) - REL=10.0 - ;; - *) - echo "Unable to detect version of Debian: $REL" - exit 42 - ;; - esac + echo "Unable to detect version of Debian: $REL" + exit 42 fi OS=debian From 58af4d6af613b2123358b5c41d1fd8bdde0d0f02 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 9 Jun 2025 13:54:03 +0200 Subject: [PATCH 08/26] detect-environment: Don't look for a 1-digit major release number There has not been a 1-digit major release of ubuntu for a long time. Hence, there is no point in looking for it when verifying the version number extracted from /etc/lsb-release. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 0fcfbc909..ce2a31c8a 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -183,7 +183,7 @@ detect_distribution() REL=$(grep DISTRIB_RELEASE= /etc/lsb-release) REL=${REL#DISTRIB_RELEASE=} case "$REL" in - [0-9].[0-9][0-9]|[0-9][0-9].[0-9][0-9]) + [0-9][0-9].[0-9][0-9]) ;; *) echo "Unknown Ubuntu release: $REL" From b9236cd12983a76ee78a8cb0937bc0e9bccd492a Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 9 Jun 2025 12:44:19 +0200 Subject: [PATCH 09/26] detect-environment: Document the detect_distribution Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index ce2a31c8a..0ac9e5597 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -107,12 +107,18 @@ detect_os() export OS OS_VERSION } +# The uname command does not reveal the specific distribution on Linux. Hence, +# we'll need to parse it from different files located in the /etc/ directory. +# Unfortunately, there is no standard across the existing distributions. Thus, +# this is going to be a bit messy. detect_distribution() { if [ -f /etc/redhat-release ]; then REL=$(cat /etc/redhat-release) case "$REL" in "CentOS "*) + # Example output for CentOS: + # CentOS Linux release 7.6.1810 (Core) VER="$(echo "$REL" | sed -e 's/^CentOS.* release \([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/')" if ! echo "$VER" | grep -E '^[0-9]+\.[0-9]+$' > /dev/null then @@ -180,8 +186,29 @@ detect_distribution() ;; esac elif [ -f /etc/lsb-release ] && grep -q Ubuntu /etc/lsb-release; then + # This file was introduced by Linux Standard Base (LSB) which an attempt to + # standardize the Linux ecosystem. Unfortunately it was not adopted by many + # Linux distributions. Ubuntu dropped the support for LSB in 2015. However, + # the /etc/lsb-release file is still available as of Ubuntu 24. + # + # It might be naive to assume the file will continue to exist and that the + # existence of the file is only present in Ubuntu. Hence, if this breaks in + # the future, you'll know why. + # + # Example output of /etc/lsb-release: + # + # DISTRIB_ID=Ubuntu + # DISTRIB_RELEASE=24.04 + # DISTRIB_CODENAME=noble + # DISTRIB_DESCRIPTION="Ubuntu 24.04.2 LTS" + + # Get the line containing 'DISTRIB_RELEASE=' REL=$(grep DISTRIB_RELEASE= /etc/lsb-release) + + # Remove the 'DISTRIB_RELEASE=' part REL=${REL#DISTRIB_RELEASE=} + + # Verify that we can find a valid version number case "$REL" in [0-9][0-9].[0-9][0-9]) ;; @@ -194,6 +221,11 @@ detect_distribution() OS=ubuntu OS_VERSION="$REL" elif [ -f /etc/debian_version ]; then + # This file contains only the version number. + # + # Example output of /etc/debian_version + # 12.11 + REL=$(cat /etc/debian_version) if ! echo "$REL" | grep -E '^[0-9]+\.[0-9]+(\.[0-9]+)?$' > /dev/null then @@ -233,6 +265,17 @@ detect_distribution() elif [ -f /etc/os-release ]; then # see https://en.opensuse.org/SDB:Find_openSUSE_version for rules of # parsing this file + + # Example output for /etc/os-release: + # + # NAME="SLES" + # VERSION="12-SP5" + # VERSION_ID="12.5" + # PRETTY_NAME="SUSE Linux Enterprise Server 12 SP5" + # ID="sles" + # ANSI_COLOR="0;32" + # CPE_NAME="cpe:/o:suse:sles:12:sp5" + os="$(sh -c ". /etc/os-release; echo \$ID")" ver="$(sh -c ". /etc/os-release; echo \$VERSION_ID")" if [ "$os" = "sles" ]; then From ede6c7236ec5aea37c3c33d98677e46fe075d4b1 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 9 Jun 2025 20:23:29 +0200 Subject: [PATCH 10/26] detect-environment: Simplified RHEL distro detection Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 75 ++++++++------------------------ 1 file changed, 17 insertions(+), 58 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 0ac9e5597..bebe21b04 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -119,72 +119,31 @@ detect_distribution() "CentOS "*) # Example output for CentOS: # CentOS Linux release 7.6.1810 (Core) - VER="$(echo "$REL" | sed -e 's/^CentOS.* release \([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/')" - if ! echo "$VER" | grep -E '^[0-9]+\.[0-9]+$' > /dev/null - then - echo "Unknown CentOS version: $VER" - exit 42 - fi - OS=centos - OS_VERSION="$VER" - ;; - "Red Hat Enterprise Linux AS release "*) - VER=${REL#Red Hat Enterprise Linux AS release } - case "$VER" in - [0-9]" "*) - MAJOR=${VER%% *} - ;; - *) - echo "Unknown RHEL AS major version: $VER" - exit 42 - ;; - esac - - case "$VER" in - *Update" "[0-9]")") - MINOR=${VER#*Update } - MINOR=${MINOR%\)};; - *) - echo "Unknnown RHEL AS minor version: $VER" - exit 42 - ;; - esac - - OS=rhel - OS_VERSION="$MAJOR.$MINOR" - ;; - "Red Hat Enterprise Linux Server release "*) - VER=${REL#Red Hat Enterprise Linux Server release } - VER=${VER% \(*}; - if ! echo "$VER" | grep -E '^[0-9]+.[0-9]+$' > /dev/null - then - echo "Unknown RHEL Server version: $VER" - exit 42 - fi - - OS=rhel - OS_VERSION="$VER" ;; - - "Red Hat Enterprise Linux release "*) - VER=${REL#Red Hat Enterprise Linux release } - VER=${VER% \(*}; - if ! echo "$VER" | grep -E '^[0-9]+.[0-9]+$' > /dev/null - then - echo "Unknown RHEL Server version: $VER" - exit 42 - fi - + "Red Hat Enterprise Linux "*) + # Example output for RHEL: + # Red Hat Enterprise Linux release 8.10 (Ootpa) OS=rhel - OS_VERSION="$VER" ;; - *) - echo "Unknown RedHat-like distribution: $REL" + echo "Error: Could not determine Linux distro from /etc/redhat-release: $REL" exit 42 ;; esac + + # Common for all of these is that the version number starts just after the + # substring 'release '. Hence we reset the match (with \K) just after + # substring and extract the major and minor version. + version_string=$(echo "$REL" | grep -oP 'release \K\d+\.\d+') + + # Make sure we actually found a match + if [ -z "$version_string" ]; then + echo "Error: Could not determine version number from /etc/redhat-release: $REL" + exit 42 + fi + OS_VERSION=$version_string + elif [ -f /etc/lsb-release ] && grep -q Ubuntu /etc/lsb-release; then # This file was introduced by Linux Standard Base (LSB) which an attempt to # standardize the Linux ecosystem. Unfortunately it was not adopted by many From eec2842c866810f8466bd236b01c5700b29d7558 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 10:28:35 +0200 Subject: [PATCH 11/26] detect-environment: Remove parsing of /etc/SuSE-release On SUSE 12 the /etc/SuSE-release file exists with a deprecation warning. However, /etc/os-release also exists. So we might as well remove the parsing of the former and rely on the latter. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index bebe21b04..120128395 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -194,33 +194,6 @@ detect_distribution() OS=debian OS_VERSION="$REL" - elif [ -f /etc/SuSE-release ]; then - # This file is gone starting with suse 13 or something. This whole section - # can be removed when support for suse 12 and lower is dropped. I wish to - # see that day. - REL=$(head -n1 /etc/SuSE-release) - case "$REL" in - "SUSE Linux Enterprise Server "*) - MAJOR=$(grep '^VERSION' /etc/SuSE-release | awk '{print $3}') - MINOR=$(grep '^PATCHLEVEL' /etc/SuSE-release | awk '{print $3}') - - if [ -z "$MAJOR" ] || [ -z "$MINOR" ]; then - echo "Unable to detect version of SLES: $MAJOR.$MINOR" - fi - - OS=sles - OS_VERSION="$MAJOR.$MINOR" - ;; - "openSUSE "*) - VERSION=$(grep '^VERSION' /etc/SuSE-release | awk '{print $3}') - OS=opensuse - OS_VERSION="$VERSION" - ;; - *) - echo "Unknown SUSE distribution: $REL" - exit 42 - ;; - esac elif [ -f /etc/os-release ]; then # see https://en.opensuse.org/SDB:Find_openSUSE_version for rules of # parsing this file From d1cdd42ddcd6357dfbc3a1898156fe47ff12fce1 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 10:37:15 +0200 Subject: [PATCH 12/26] detect-environment: changed two if's to if/elif If the former if condition is true, then the latter implicitly cannot be true. Hence, there is no point in evaluating it. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 120128395..73e174bc1 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -213,8 +213,8 @@ detect_distribution() if [ "$os" = "sles" ]; then OS=sles OS_VERSION="$ver" - fi - if expr "$os" : "opensuse" >/dev/null; then + elif expr "$os" : "opensuse" >/dev/null; then + # If the string begins with "opensuse", then strip the remaining part. It # can be "opensuse-leap" or "opensuse-tumbleweed" OS=opensuse OS_VERSION="$ver" From 846657e2bcf209f48d76beb98cefa07560569f3e Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 11:27:09 +0200 Subject: [PATCH 13/26] detect-environment: Put ;; on separate line Put the pattern block terminators on separate lines, in the detect_packaging function, for the sake of consistency. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 73e174bc1..26dfaabbb 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -254,9 +254,11 @@ detect_packaging() case "$OS" in aix) - PACKAGING=lpp;; + PACKAGING=lpp + ;; mingw) - PACKAGING=msi;; + PACKAGING=msi + ;; *) PACKAGING=$DEP_PACKAGING;; esac From b8a47169597552743b832345b7a367e1adc4fe08 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 10:54:50 +0200 Subject: [PATCH 14/26] detect-environment: Document detect_packaging function Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 26dfaabbb..3bc89a87c 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -232,6 +232,10 @@ detect_distribution() fi } +# This function determines which dependency packaging scripts shall be used +# based on the operating system and available packaging tools. E.g., if rpm is +# detected, then the "pkg-build-rpm" script will be called from the +# "install-dependencies" script. detect_packaging() { if [ -f /bin/rpm ]; then From db2d94ad5101ed1bf4b4aa4ee5ed1289ea79a84d Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 10:59:03 +0200 Subject: [PATCH 15/26] detect-environment: Put ;; on separate line Put the pattern block terminators on separate lines, in the detect_arch function, for the sake of consistency. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 36 +++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 3bc89a87c..020ce0cf9 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -274,40 +274,52 @@ detect_arch() { case "$DEP_PACKAGING" in deb) - ARCH=$(dpkg --print-architecture);; + ARCH=$(dpkg --print-architecture) + ;; rpm) - ARCH=$(rpm --eval '%{_arch}');; + ARCH=$(rpm --eval '%{_arch}') + ;; solaris) case $UNAME_M in sun*) - ARCH=sparc;; + ARCH=sparc + ;; i86pc) - ARCH=i86pc;; + ARCH=i86pc + ;; *) - echo "Unknown Solaris architecture: $UNAME_M";; - esac;; + echo "Unknown Solaris architecture: $UNAME_M" + ;; + esac + ;; freebsd) ARCH=$UNAME_M - OS_VERSION=$UNAME_R ;; + OS_VERSION=$UNAME_R + ;; hpux) ARCH=$UNAME_M - OS_VERSION=$UNAME_R ;; + OS_VERSION=$UNAME_R + ;; *) echo "Unknown packaging system" - exit 42;; + exit 42 + ;; esac case "$CROSS_TARGET" in '') ;; x86-*) - ARCH=x86;; + ARCH=x86 + ;; x64-*) - ARCH=x64;; + ARCH=x64 + ;; *) echo "Unknown cross-compilation target: $CROSS_TARGET" - exit 42;; + exit 42 + ;; esac export ARCH From 669311b6ba5eddfd68863f420c11b7a2eb0b44df Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 11:13:34 +0200 Subject: [PATCH 16/26] detect-environment: Moved version detection to detect_os For some reason the version detection for FreeBSD and HP-UX was in the detect_arch function. However, it belongs in the detect_os function. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 020ce0cf9..2030ab61d 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -79,6 +79,7 @@ detect_os() FreeBSD) OS_FAMILY=freebsd OS=freebsd + OS_VERSION=$UNAME_R ;; NetBSD) OS_FAMILY=netbsd @@ -87,6 +88,7 @@ detect_os() HP-UX) OS_FAMILY=hpux OS=hpux + OS_VERSION=$UNAME_R ;; *) echo "Unable to detect operating system: $UNAME_S" @@ -295,11 +297,9 @@ detect_arch() freebsd) ARCH=$UNAME_M - OS_VERSION=$UNAME_R ;; hpux) ARCH=$UNAME_M - OS_VERSION=$UNAME_R ;; *) echo "Unknown packaging system" From a503829afea34ef1adf9dd3ccb61e7cce8826cb9 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 11:25:12 +0200 Subject: [PATCH 17/26] detect-environment: Document the detect_arch function Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 2030ab61d..86f6626b0 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -272,6 +272,9 @@ detect_packaging() export DEP_PACKAGING PACKAGING } +# This function determines which architecture to build for based on the system +# we're building on. Unless we are cross compiling, then it's determined by the +# CROSS_TARGET variable. detect_arch() { case "$DEP_PACKAGING" in @@ -307,6 +310,9 @@ detect_arch() ;; esac + # Windows is build on Debian. Hence we need to determine the architecture + # based on the 'CROSS_TARGET' variable which is derived from the 'label' + # variable instead of the system that we are building on. case "$CROSS_TARGET" in '') ;; From f69964f7bf1ca2c354c4ed9548f2583173e71dcd Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 11:39:06 +0200 Subject: [PATCH 18/26] detect-environment: Removed RPMBUILD_CMD environment variable AIX 5.3 is no longer supported, so we don't need this environment variable anymore. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 7 ------- build-scripts/package | 2 +- deps-packaging/pkg-build-rpm | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 86f6626b0..d207a2d21 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -344,13 +344,6 @@ detect_tools() fatal "GNU Make not found" fi - if [ "$OS" = "aix" ] && [ "$OS_VERSION" = "5.3" ]; then - RPMBUILD_CMD=rpm - else - RPMBUILD_CMD=rpmbuild - fi - export RPMBUILD_CMD - FUSER=$(func_whereis fuser) export FUSER diff --git a/build-scripts/package b/build-scripts/package index a026cdaca..9dc875336 100755 --- a/build-scripts/package +++ b/build-scripts/package @@ -178,7 +178,7 @@ case "$PACKAGING" in # - argv[2] = a b # Also note that $RPMBUILD_OPTIONS might have spaces # which must be preserved - eval "$RPMBUILD_CMD" -bb \ + eval rpmbuild -bb \ --define "'_topdir $BASEDIR/$PKG'" \ --define "'buildprefix $BUILDPREFIX'" \ --define "'_basedir $BASEDIR'" \ diff --git a/deps-packaging/pkg-build-rpm b/deps-packaging/pkg-build-rpm index 4f71b4196..2039562aa 100755 --- a/deps-packaging/pkg-build-rpm +++ b/deps-packaging/pkg-build-rpm @@ -112,7 +112,7 @@ fi # example cmd --define 'a b': # - argv[1] = --define # - argv[2] = a b -eval $RPMBUILD_CMD -bb \ +eval rpmbuild -bb \ --define "'_topdir $BASEDIR/$PKGNAME'" \ --define "'version $VERSION'" \ --define "'buildprefix $BUILDPREFIX'" \ From 5e87c9d60a3f00ea22132dbb1476cc27062bab99 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 16 Jun 2025 16:39:21 +0200 Subject: [PATCH 19/26] Maybe we need this after all? Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index d207a2d21..28275840b 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -344,6 +344,8 @@ detect_tools() fatal "GNU Make not found" fi + export RPMBUILD_CMD=rpmbuild + FUSER=$(func_whereis fuser) export FUSER From 652e3835f1411f0a0eccee7a332bb7444c1b91b3 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 11:44:46 +0200 Subject: [PATCH 20/26] detect-environment: Remove call to function fatal The function "fatal" is not defined in this script. So it may not be available. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 28275840b..b0e542eea 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -341,7 +341,8 @@ detect_tools() then export MAKE else - fatal "GNU Make not found" + echo "Error: GNU Make not found" + exit 42 fi export RPMBUILD_CMD=rpmbuild From 20005aa946c9f0548d768db8ff3be111a9543203 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 13:02:18 +0200 Subject: [PATCH 21/26] detect-environment: Document the detect_tools function Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index b0e542eea..6b9ce815b 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -331,6 +331,9 @@ detect_arch() export ARCH } +# This function detects the path to various tools needed by the build system. +# It's useful if the specified tool is not in PATH, or if the PATH resolution +# picks up the wrong tool, or if e.g. gmake is preferred over make. detect_tools() { # We look for GNU Make because @@ -347,9 +350,12 @@ detect_tools() export RPMBUILD_CMD=rpmbuild + # fuser displays the PIDs of processes using specified files or file + # systems. We use it to kill processes that can mess with the build process. FUSER=$(func_whereis fuser) export FUSER + # We use it to submit patches to the dependencies. PATCH=$(func_whereis gpatch patch) export PATCH } From 2cc69b5415a4ab030ff099f0f9d7b06259c86825 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 13:07:14 +0200 Subject: [PATCH 22/26] detect-environment: Put ;; on separate line Put the pattern block terminators on separate lines, in the detect_cores function, for the sake of consistency. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 6b9ce815b..54ad9d600 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -365,20 +365,24 @@ detect_cores() case "$OS_FAMILY" in aix) echo "Detected OS family is aix" - NUM_CORES="$(lscfg | grep -c proc)";; + NUM_CORES="$(lscfg | grep -c proc)" + ;; solaris) echo "Detected OS family is solaris" - NUM_CORES="$(psrinfo |wc -l)";; + NUM_CORES="$(psrinfo |wc -l)" + ;; linux) echo "Detected OS family is linux" NUM_CORES="$(grep -c '^processor' /proc/cpuinfo)" ;; hpux) echo "Detected OS family is hpux" - NUM_CORES="$(ioscan -k -C processor | grep -c processor)";; + NUM_CORES="$(ioscan -k -C processor | grep -c processor)" + ;; *) echo "Detected OS family is UNKNOWN, defaulting amount of CPU cores to 1" - NUM_CORES=1;; + NUM_CORES=1 + ;; esac # Make number of jobs one higher than core count, to account for I/O, network, etc. From 1f0a1ac22ab44bd020be5113da57916ff38c7863 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 13:21:37 +0200 Subject: [PATCH 23/26] detect-environment: Document the detect_cores function Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 4 ++++ build-scripts/install-dependencies | 2 ++ 2 files changed, 6 insertions(+) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 54ad9d600..7067731b2 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -360,6 +360,10 @@ detect_tools() export PATCH } +# This function appends the -j/--jobs option to the MAKEFLAGS environment +# variable based on the number of cores. However, the variable is overwritten in +# the "install-dependencies" script. I created a ticket fix this (see +# ENT-13041). detect_cores() { case "$OS_FAMILY" in diff --git a/build-scripts/install-dependencies b/build-scripts/install-dependencies index 053d1efd6..64dd7cb11 100755 --- a/build-scripts/install-dependencies +++ b/build-scripts/install-dependencies @@ -8,6 +8,8 @@ PATH=$PATH:$BASEDIR/buildscripts/deps-packaging # Not all dependencies support building in parallel. +# TODO: Investigate if this is still the case or disable parallel jobs for only +# the dependencies that not support it. (ENT-13041) MAKEFLAGS=-j1 set -x From 2e6755025e3109b97d3faac02010f601562cb342 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 13:27:39 +0200 Subject: [PATCH 24/26] detect-environment: Filter the output of env The detect-environment script is quite noicy due to the fact that it prints the environment every time it's sourced. Hence, modified it to print only the environment variables that the script affects. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 7067731b2..b4074200b 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -419,7 +419,7 @@ detect_environment echo echo echo "==================== Current environment ========================" -env +env | grep -E "^(label|CROSS_TARGET|UNAME|OS|OS_VERSION|DEP_PACKAGING|PACKAGING|ARCH|MAKE|FUSER|PATCH|MAKEFLAGS)=" echo "=================================================================" echo echo From d02fbb98e28fd65e59790b6f768ce5b606d7d7e4 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 10 Jun 2025 13:38:32 +0200 Subject: [PATCH 25/26] detect-environment: Added some log messages If we disable -x to decrease the verbosity of the build scripts. Then these log messages will come in handy. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/detect-environment | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index b4074200b..c5787c66d 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -106,6 +106,7 @@ detect_os() ;; esac + echo "Detected OS $OS $OS_VERSION" export OS OS_VERSION } @@ -269,6 +270,8 @@ detect_packaging() PACKAGING=$DEP_PACKAGING;; esac + echo "Detected dependency packaging $DEP_PACKAGING" + echo "Detected packaging $PACKAGING" export DEP_PACKAGING PACKAGING } @@ -328,6 +331,7 @@ detect_arch() ;; esac + echo "Detected architecture $ARCH" export ARCH } @@ -343,6 +347,7 @@ detect_tools() if $MAKE -v | grep GNU then export MAKE + echo "Detected make path $MAKE" else echo "Error: GNU Make not found" exit 42 @@ -354,10 +359,12 @@ detect_tools() # systems. We use it to kill processes that can mess with the build process. FUSER=$(func_whereis fuser) export FUSER + echo "Detected fuser path $FUSER" # We use it to submit patches to the dependencies. PATCH=$(func_whereis gpatch patch) export PATCH + echo "Detected patch path $PATCH" } # This function appends the -j/--jobs option to the MAKEFLAGS environment From 5c636f1034ee5dc86e43a363cc99fb02308793e9 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Wed, 18 Jun 2025 12:28:47 +0200 Subject: [PATCH 26/26] configure: replace reference to $VER with $OS_VERSION Signed-off-by: Lars Erik Wik --- build-scripts/configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-scripts/configure b/build-scripts/configure index 931fa0319..a8ef9b9e7 100755 --- a/build-scripts/configure +++ b/build-scripts/configure @@ -72,7 +72,7 @@ case "$WITH_SYSTEMD" in esac # RHEL 8 requires an SELinux policy -if [ "x$OS" = "xrhel" ] && [ "${VER%\.*}" -gt "7" ]; then +if [ "x$OS" = "xrhel" ] && [ "${OS_VERSION%\.*}" -gt "7" ]; then var_append ARGS "--with-selinux-policy" fi