From 4d1cadfa53ea9394e7389e8c6d4bb9a83687d90b Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 24 Jun 2025 14:47:48 +0200 Subject: [PATCH 1/8] configure: Removed code duplication The code for adding the correct "configure" feature selection options (i.e., --with-dep=/path/to/dep/, --without-dep) based on the dependencies had a lot of repetitive code. I created a for loop for those that are nearly identical. Signed-off-by: Lars Erik Wik --- build-scripts/configure | 46 ++++++++++++----------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/build-scripts/configure b/build-scripts/configure index a8ef9b9e7..7157ee59f 100755 --- a/build-scripts/configure +++ b/build-scripts/configure @@ -21,46 +21,26 @@ if [ $EMBEDDED_DB = lmdb ] then var_append ARGS "--with-lmdb=$P" fi + +for dep in "ldap" "libxml2" "libyaml" "librsync" "leech" "libacl" "libvirt" "libcurl" +do + case "$DEPS" in + *"$dep"*) + var_append ARGS "--with-$dep=$P" + ;; + *) + var_append ARGS "--without-$dep" + ;; + esac +done + case "$DEPS" in *pthreads-w32*) var_append ARGS "--with-pthreads=$P" ;; esac -case "$DEPS" in - *openldap*) var_append ARGS "--with-ldap=$P" ;; - *) var_append ARGS "--without-ldap" ;; -esac -case "$DEPS" in - *libxml2*) var_append ARGS "--with-libxml2=$P" ;; - *) var_append ARGS "--without-libxml2" ;; -esac -case "$DEPS" in - *libyaml*) var_append ARGS "--with-libyaml=$P" ;; - *) var_append ARGS "--without-libyaml" ;; -esac -case "$DEPS" in - *librsync*) var_append ARGS "--with-librsync=$P" ;; - *) var_append ARGS "--without-librsync" ;; -esac -case "$DEPS" in - *leech*) var_append ARGS "--with-leech=$P" ;; - *) var_append ARGS "--without-leech" ;; -esac case "$DEPS" in *postgresql*) var_append ARGS "--with-postgresql=$P --without-mysql" ;; *) var_append ARGS "--without-sql" ;; esac -case "$DEPS" in - *libacl*) var_append ARGS "--with-libacl=$P" ;; - *) var_append ARGS "--without-libacl" ;; -esac -case "$DEPS" in - *libvirt*) var_append ARGS "--with-libvirt=$P" ;; - *) var_append ARGS "--without-libvirt" ;; -esac -# both libcurl or libcurl-hub are valid -case "$DEPS" in - *libcurl*) var_append ARGS "--with-libcurl=$P" ;; - *) var_append ARGS "--without-libcurl" ;; -esac case "$ROLE" in hub) var_append ARGS "--with-cfmod --with-enterprise-api --with-postgresql=$P" ;; agent) var_append ARGS "--without-cfmod --without-postgresql" ;; From 8c53183a4a706e770fa507b4a6fb65a6392cea92 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 24 Jun 2025 15:23:03 +0200 Subject: [PATCH 2/8] configure: Reformatted case statements for consistency Signed-off-by: Lars Erik Wik --- build-scripts/configure | 118 +++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 45 deletions(-) diff --git a/build-scripts/configure b/build-scripts/configure index 7157ee59f..618a34d15 100755 --- a/build-scripts/configure +++ b/build-scripts/configure @@ -7,9 +7,15 @@ . version case "$PROJECT" in - community) NOVA=no ;; - nova) NOVA=yes ;; - *) fatal "Unknown project: $PROJECT" ;; + community) + NOVA=no + ;; + nova) + NOVA=yes + ;; + *) + fatal "Unknown project: $PROJECT" + ;; esac @@ -35,20 +41,39 @@ do done case "$DEPS" in - *pthreads-w32*) var_append ARGS "--with-pthreads=$P" ;; + *pthreads-w32*) + var_append ARGS "--with-pthreads=$P" + ;; esac + case "$DEPS" in - *postgresql*) var_append ARGS "--with-postgresql=$P --without-mysql" ;; - *) var_append ARGS "--without-sql" ;; + *postgresql*) + var_append ARGS "--with-postgresql=$P --without-mysql" + ;; + *) + var_append ARGS "--without-sql" + ;; esac + case "$ROLE" in - hub) var_append ARGS "--with-cfmod --with-enterprise-api --with-postgresql=$P" ;; - agent) var_append ARGS "--without-cfmod --without-postgresql" ;; - *) fatal "Unknown ROLE: $ROLE" ;; + hub) + var_append ARGS "--with-cfmod --with-enterprise-api --with-postgresql=$P" + ;; + agent) + var_append ARGS "--without-cfmod --without-postgresql" + ;; + *) + fatal "Unknown ROLE: $ROLE" + ;; esac + case "$WITH_SYSTEMD" in - yes) var_append ARGS "--with-systemd-service" ;; - *) var_append ARGS "--without-systemd-service" ;; + yes) + var_append ARGS "--with-systemd-service" + ;; + *) + var_append ARGS "--without-systemd-service" + ;; esac # RHEL 8 requires an SELinux policy @@ -58,45 +83,48 @@ fi # Cross-compiling Windows? case "$ARCH-${OS_FAMILY}" in - x86-mingw) var_append ARGS "--host=i686-w64-mingw32" ;; - x64-mingw) var_append ARGS "--host=x86_64-w64-mingw32" ;; + x86-mingw) + var_append ARGS "--host=i686-w64-mingw32" + ;; + x64-mingw) + var_append ARGS "--host=x86_64-w64-mingw32" + ;; esac case "$BUILD_TYPE" in - - RELEASE) - CFLAGS="-g2 -O2 -DNDEBUG $CFLAGS" - ;; - DEBUG) - ARGS="$ARGS --enable-debug" - # Override the default "-g3 -O0" that comes with ./configure --enable-debug - # in order to reduce the size of the packages - CFLAGS="-g2 -O1 $CFLAGS" - ;; - CODE_COVERAGE) - ARGS="$ARGS --enable-debug" - # lcov is not found in Windows and other platforms - case "${OS}-${OS_VERSION}" in - mingw*) - ;; - hpux*) + RELEASE) + CFLAGS="-g2 -O2 -DNDEBUG $CFLAGS" + ;; + DEBUG) + ARGS="$ARGS --enable-debug" + # Override the default "-g3 -O0" that comes with ./configure --enable-debug + # in order to reduce the size of the packages + CFLAGS="-g2 -O1 $CFLAGS" + ;; + CODE_COVERAGE) + ARGS="$ARGS --enable-debug" + # lcov is not found in Windows and other platforms + case "${OS}-${OS_VERSION}" in + mingw*) + ;; + hpux*) + ;; + solaris*) + ;; + rhel-4.*) + ;; + aix*) + ;; + *) + ARGS="$ARGS --enable-coverage" + ;; + esac + ;; + *) + echo "Unknown build type: $BUILD_TYPE" + exit 42 ;; - solaris*) - ;; - rhel-4.*) - ;; - aix*) - ;; - *) - ARGS="$ARGS --enable-coverage" - ;; - esac - ;; - *) - echo "Unknown build type: $BUILD_TYPE" - exit 42 - ;; esac if [ "x$OS" = "xsolaris" ] From 59622d309c01b5b55a1348e696872b4eb0fc8cf1 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 24 Jun 2025 16:03:13 +0200 Subject: [PATCH 3/8] configure: Remove CODE_COVERAGE build type Because we don't use it. Signed-off-by: Lars Erik Wik --- build-scripts/configure | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/build-scripts/configure b/build-scripts/configure index 618a34d15..0a528ffce 100755 --- a/build-scripts/configure +++ b/build-scripts/configure @@ -102,25 +102,6 @@ case "$BUILD_TYPE" in # in order to reduce the size of the packages CFLAGS="-g2 -O1 $CFLAGS" ;; - CODE_COVERAGE) - ARGS="$ARGS --enable-debug" - # lcov is not found in Windows and other platforms - case "${OS}-${OS_VERSION}" in - mingw*) - ;; - hpux*) - ;; - solaris*) - ;; - rhel-4.*) - ;; - aix*) - ;; - *) - ARGS="$ARGS --enable-coverage" - ;; - esac - ;; *) echo "Unknown build type: $BUILD_TYPE" exit 42 From 2b8bea62c3afe52862714a7609667d6cd01717a2 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 24 Jun 2025 16:10:31 +0200 Subject: [PATCH 4/8] configure: Fixed some of the shellcheck issues Signed-off-by: Lars Erik Wik --- build-scripts/configure | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/build-scripts/configure b/build-scripts/configure index 0a528ffce..2d3c28249 100755 --- a/build-scripts/configure +++ b/build-scripts/configure @@ -1,7 +1,7 @@ #!/bin/sh -x -. `dirname "$0"`/functions +. "$(dirname "$0")"/functions . detect-environment . compile-options . version @@ -77,7 +77,7 @@ case "$WITH_SYSTEMD" in esac # RHEL 8 requires an SELinux policy -if [ "x$OS" = "xrhel" ] && [ "${OS_VERSION%\.*}" -gt "7" ]; then +if [ "$OS" = "rhel" ] && [ "${OS_VERSION%\.*}" -gt "7" ]; then var_append ARGS "--with-selinux-policy" fi @@ -108,21 +108,21 @@ case "$BUILD_TYPE" in ;; esac -if [ "x$OS" = "xsolaris" ] +if [ "$OS" = solaris ] then export PKG_CONFIG_PATH="$BUILDPREFIX/lib/pkgconfig" fi -( cd $BASEDIR/core && env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS ) +( cd "$BASEDIR"/core && env "$OPTS" CFLAGS="$CFLAGS" ./configure "$ARGS" ) -if [ "x$NOVA" = "xyes" ] +if [ "$NOVA" = yes ] then - ( cd $BASEDIR/enterprise && env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS ) - if [ "x$ROLE" = "xhub" ] + ( cd "$BASEDIR"/enterprise && env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) + if [ "$ROLE" = hub ] then - ( cd $BASEDIR/nova && env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS ) + ( cd "$BASEDIR"/nova && env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) fi fi -( cd $BASEDIR/masterfiles && env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS ) +( cd "$BASEDIR"/masterfiles && env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) From 3d8548b5c9a7c00e2e9957e247f9d091b45dbe44 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 24 Jun 2025 16:51:38 +0200 Subject: [PATCH 5/8] configure: Decrease verbosity of script Signed-off-by: Lars Erik Wik --- build-scripts/configure | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/build-scripts/configure b/build-scripts/configure index 2d3c28249..8c2ff6a99 100755 --- a/build-scripts/configure +++ b/build-scripts/configure @@ -1,4 +1,4 @@ -#!/bin/sh -x +#!/bin/sh . "$(dirname "$0")"/functions @@ -14,7 +14,7 @@ case "$PROJECT" in NOVA=yes ;; *) - fatal "Unknown project: $PROJECT" + fatal "$(basename "$0"): Unknown project: $PROJECT" ;; esac @@ -63,7 +63,7 @@ case "$ROLE" in var_append ARGS "--without-cfmod --without-postgresql" ;; *) - fatal "Unknown ROLE: $ROLE" + fatal "$(basename "$0"): Unknown ROLE: $ROLE" ;; esac @@ -103,8 +103,7 @@ case "$BUILD_TYPE" in CFLAGS="-g2 -O1 $CFLAGS" ;; *) - echo "Unknown build type: $BUILD_TYPE" - exit 42 + fatal "$(basename "$0"): Unknown BUILD_TYPE '$BUILD_TYPE'" ;; esac @@ -113,16 +112,19 @@ then export PKG_CONFIG_PATH="$BUILDPREFIX/lib/pkgconfig" fi - -( cd "$BASEDIR"/core && env "$OPTS" CFLAGS="$CFLAGS" ./configure "$ARGS" ) +log_debug running configure on core repo... +( cd "$BASEDIR"/core && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) if [ "$NOVA" = yes ] then - ( cd "$BASEDIR"/enterprise && env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) + log_debug running configure on enterprise repo... + ( cd "$BASEDIR"/enterprise && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) if [ "$ROLE" = hub ] then - ( cd "$BASEDIR"/nova && env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) + log_debug running configure on nova repo... + ( cd "$BASEDIR"/nova && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) fi fi -( cd "$BASEDIR"/masterfiles && env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) +log_debug running configure on masterfiles repo... +( cd "$BASEDIR"/masterfiles && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) From e256e2451adaf5571441126f635c91201a778327 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 25 Jul 2025 15:28:57 +0200 Subject: [PATCH 6/8] configure: Documented the script Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/configure | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/build-scripts/configure b/build-scripts/configure index 8c2ff6a99..1133aea0e 100755 --- a/build-scripts/configure +++ b/build-scripts/configure @@ -1,11 +1,32 @@ #!/bin/sh +# +# This script runs configure on each of the CFEngine repositories. +# It determines which configure options and compiler flags to use based on the dependencies found in compile-options script. +# +# The script expects the following repositories to exist side by side: +# . +# ├── buildscripts +# ├── core +# ├── enterprise +# ├── nova +# └── masterfiles +# +# ^ When building community you won't need enterprise, nova. +# +# The script can be run as follows: +# ``` +# $ PROJECT=[nova|community] BUILD_TYPE=[DEBUG|RELEASE] EXPLICIT_ROLE=[hub|agent] ./buildscripts/build-scripts/configure +# ``` +# + . "$(dirname "$0")"/functions . detect-environment . compile-options . version +# Make sure the PROJECT variable is set correctly case "$PROJECT" in community) NOVA=no @@ -92,6 +113,7 @@ case "$ARCH-${OS_FAMILY}" in esac +# Select configure options and compiler flags based on BUILD_TYPE case "$BUILD_TYPE" in RELEASE) CFLAGS="-g2 -O2 -DNDEBUG $CFLAGS" @@ -109,6 +131,7 @@ esac if [ "$OS" = solaris ] then + # Otherwise, we pick wrong pkg-config file (from OS), with a lower version of libxml dependency than we would like to have. export PKG_CONFIG_PATH="$BUILDPREFIX/lib/pkgconfig" fi From e2159171c1a3de6b9e7f8160b0de41038a641b49 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 31 Jul 2025 12:52:09 +0200 Subject: [PATCH 7/8] Always compile with lmdb Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/configure | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/build-scripts/configure b/build-scripts/configure index 1133aea0e..63c999b64 100755 --- a/build-scripts/configure +++ b/build-scripts/configure @@ -42,12 +42,7 @@ esac P=$BUILDPREFIX -ARGS="--prefix=$P --libdir=$P/lib --with-workdir=$P --sysconfdir=/etc --with-openssl=$P --with-pcre2=$P --with-librsync=$P --with-init-script" - -if [ $EMBEDDED_DB = lmdb ] -then - var_append ARGS "--with-lmdb=$P" -fi +ARGS="--prefix=$P --libdir=$P/lib --with-workdir=$P --sysconfdir=/etc --with-openssl=$P --with-pcre2=$P --with-librsync=$P --with-init-script --with-lmdb=$P" for dep in "ldap" "libxml2" "libyaml" "librsync" "leech" "libacl" "libvirt" "libcurl" do From 90d190b83f5078eb044565427a0cf38732ddfcda Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 4 Aug 2025 11:25:49 +0200 Subject: [PATCH 8/8] Removed double quotes from configure arguments variable We want word splitting so that the arguments are not interpreted as one string. Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/configure | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/build-scripts/configure b/build-scripts/configure index 63c999b64..71792605b 100755 --- a/build-scripts/configure +++ b/build-scripts/configure @@ -131,18 +131,22 @@ then fi log_debug running configure on core repo... -( cd "$BASEDIR"/core && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) +# shellcheck disable=SC2086 +( cd "$BASEDIR"/core && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS ) if [ "$NOVA" = yes ] then log_debug running configure on enterprise repo... - ( cd "$BASEDIR"/enterprise && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) + # shellcheck disable=SC2086 + ( cd "$BASEDIR"/enterprise && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS ) if [ "$ROLE" = hub ] then log_debug running configure on nova repo... - ( cd "$BASEDIR"/nova && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) + # shellcheck disable=SC2086 + ( cd "$BASEDIR"/nova && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS ) fi fi log_debug running configure on masterfiles repo... -( cd "$BASEDIR"/masterfiles && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure "$ARGS" ) +# shellcheck disable=SC2086 +( cd "$BASEDIR"/masterfiles && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS )