Makes it easier to test locally and keeps the manifests dry.
---

I implemented this for w3m a few days ago and was wondering if this
might be of interest for mutt. The idea is that all build configurations
live in a shell script rather then being split over multiple build
manifests. This allows to test all configurations locally by just
calling the script. It also avoid having to write the same config over
and over again for every manifest.

Note that this currently breaks the CI as I found out, that the
'original' task was different depending on the image we were building
on. E.g. on Alpine we use --with-sasl while on OpenBSD we used
--without-sasl.

That I found the above already IMHO shows that having a central place
for configurations has value.

The build manifests still use one task to call one config to make it
easier to spot what breaks.

Please bikeshed the script name 'build' and if it should be placed in
the root directory. I kept the name from w3m, but there it is placed
in the test directory which makes it more obvious what the intend is.

If there is interest I will continue to fix the build problems and unify
the build configurations.

 .builds/alpine.yml    | 31 +++------------
 .builds/archlinux.yml | 31 +++------------
 .builds/debian.yml    | 30 +++-----------
 .builds/freebsd.yml   | 28 +++----------
 .builds/openbsd.yml   | 46 +++-------------------
 build                 | 92 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 120 insertions(+), 138 deletions(-)
 create mode 100755 build

diff --git a/.builds/alpine.yml b/.builds/alpine.yml
index bdd8934c..4d8a435f 100644
--- a/.builds/alpine.yml
+++ b/.builds/alpine.yml
@@ -15,6 +15,8 @@ packages:
 - tcc-libs-static
 sources:
 - https://git.sr.ht/~mutt/mutt
+environment:
+  NPROC: '8'
 tasks:
 - check: |
     cd mutt
@@ -24,37 +26,16 @@ tasks:
 
 - default: |
     cd mutt
-    autoreconf -if
-    ./configure
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build default
 
 - without-wc-funcs: |
     cd mutt
-    autoreconf -if
-    ./configure \
-        --without-wc-funcs
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build without_wc_funcs
 
 - original: |
     cd mutt
-    autoreconf -if
-    ./configure \
-        --enable-gpgme \
-        --enable-pop \
-        --enable-imap \
-        --enable-smtp \
-        --enable-hcache \
-        --enable-sidebar \
-        --without-included-gettext \
-        --with-mailpath=/var/spool/mail \
-        --with-curses \
-        --with-ssl \
-        --with-sasl \
-        --with-idn2
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build original
 
 - tcc: |
     cd mutt
-    autoreconf -if
-    CC=tcc ./configure
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build tcc
diff --git a/.builds/archlinux.yml b/.builds/archlinux.yml
index dd34b98b..89ca1eb9 100644
--- a/.builds/archlinux.yml
+++ b/.builds/archlinux.yml
@@ -15,6 +15,8 @@ packages:
 - tcc-libs-static
 sources:
 - https://git.sr.ht/~mutt/mutt
+environment:
+  NPROC: '8'
 tasks:
 - check: |
     cd mutt
@@ -24,37 +26,16 @@ tasks:
 
 - default: |
     cd mutt
-    autoreconf -if
-    ./configure
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build default
 
 - without-wc-funcs: |
     cd mutt
-    autoreconf -if
-    ./configure \
-        --without-wc-funcs
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build without_wc_funcs
 
 - original: |
     cd mutt
-    autoreconf -if
-    ./configure \
-        --enable-gpgme \
-        --enable-pop \
-        --enable-imap \
-        --enable-smtp \
-        --enable-hcache \
-        --enable-sidebar \
-        --without-included-gettext \
-        --with-mailpath=/var/spool/mail \
-        --with-curses \
-        --with-ssl \
-        --with-sasl \
-        --with-idn2
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build original
 
 - tcc: |
     cd mutt
-    autoreconf -if
-    CC=tcc ./configure
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build tcc
diff --git a/.builds/debian.yml b/.builds/debian.yml
index b536ebbf..90afd61e 100644
--- a/.builds/debian.yml
+++ b/.builds/debian.yml
@@ -16,6 +16,8 @@ packages:
 - tcc
 sources:
 - https://git.sr.ht/~mutt/mutt
+environment:
+  NPROC: '8'
 tasks:
 - check: |
     cd mutt
@@ -25,36 +27,16 @@ tasks:
 
 - default: |
     cd mutt
-    autoreconf -if
-    ./configure
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build default
 
 - without-wc-funcs: |
     cd mutt
-    autoreconf -if
-    ./configure \
-        --without-wc-funcs
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build without_wc_funcs
 
 - original: |
     cd mutt
-    autoreconf -if
-    ./configure \
-        --enable-gpgme \
-        --enable-pop \
-        --enable-imap \
-        --enable-smtp \
-        --enable-hcache \
-        --enable-sidebar \
-        --without-included-gettext \
-        --with-mailpath=/var/spool/mail \
-        --with-curses \
-        --with-ssl \
-        --with-sasl
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build original
 
 - tcc: |
     cd mutt
-    autoreconf -if
-    CC=tcc ./configure
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build tcc
diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml
index 0e17d23b..394fd210 100644
--- a/.builds/freebsd.yml
+++ b/.builds/freebsd.yml
@@ -17,6 +17,8 @@ packages:
 - urlview
 sources:
 - https://git.sr.ht/~mutt/mutt
+environment:
+  NPROC: '8'
 tasks:
 - check: |
     cd mutt
@@ -26,32 +28,12 @@ tasks:
 
 - default: |
     cd mutt
-    autoreconf -if
-    ./configure
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build default
 
 - without-wc-funcs: |
     cd mutt
-    autoreconf -if
-    ./configure \
-        --without-wc-funcs
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build without_wc_funcs
 
 - original: |
     cd mutt
-    autoreconf -if
-    ./configure \
-        --enable-gpgme \
-        --enable-pop \
-        --enable-imap \
-        --enable-smtp \
-        --enable-hcache \
-        --enable-sidebar \
-        --with-kyotocabinet=/usr/local \
-        --with-mailpath=/var/spool/mail \
-        --with-curses \
-        --with-ssl \
-        --without-sasl \
-        --with-libiconv-prefix=/usr/local \
-        --with-libintl-prefix=/usr/local
-      make -j4 CFLAGS='-Wall -Werror'
+    ./build original
diff --git a/.builds/openbsd.yml b/.builds/openbsd.yml
index bdfee93c..7c914c6b 100644
--- a/.builds/openbsd.yml
+++ b/.builds/openbsd.yml
@@ -20,6 +20,7 @@ environment:
   AUTOCONF_VERSION: 2.72
   AUTOMAKE_VERSION: 1.18
   LDFLAGS: -L/usr/local/lib
+  NPROC: '8'
 tasks:
 - check: |
     cd mutt
@@ -29,53 +30,16 @@ tasks:
 
 - default: |
     cd mutt
-    autoreconf -if
-    ./configure
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build default
 
 - without-wc-funcs: |
     cd mutt
-    autoreconf -if
-    ./configure \
-        --without-wc-funcs
-    make -j4 CFLAGS='-Wall -Werror'
+    ./build without_wc_funcs
 
 - original: |
     cd mutt
-    autoreconf -if
-    ./configure \
-        --enable-gpgme \
-        --enable-pop \
-        --enable-imap \
-        --enable-smtp \
-        --enable-hcache \
-        --enable-sidebar \
-        --with-kyotocabinet=/usr/local \
-        --with-mailpath=/var/spool/mail \
-        --with-curses \
-        --with-ssl \
-        --without-sasl \
-        --with-libiconv-prefix=/usr/local \
-        --with-libintl-prefix=/usr/local
-      make -j4 CFLAGS='-Wall -Werror'
+    ./build original
 
 - openbsd: |
     cd mutt
-    autoreconf -if
-    ./configure \
-      --enable-compressed \
-      --enable-debug \
-      --enable-external_dotlock \
-      --disable-fcntl \
-      --enable-flock \
-      --with-idn2 \
-      --enable-imap \
-      --enable-pop \
-      --enable-sidebar \
-      --enable-smtp \
-      --mandir=${PREFIX}/man \
-      --with-docdir="${PREFIX}/share/doc/mutt" \
-      --with-ssl \
-      --enable-hcache \
-      --with-qdbm
-      make -j4 CFLAGS='-Wall -Werror'
+    ./build openbsd
diff --git a/build b/build
new file mode 100755
index 00000000..251b7b8c
--- /dev/null
+++ b/build
@@ -0,0 +1,92 @@
+#!/bin/sh
+
+# Build and test multiple build configurations
+# USAGE: build [conf]...
+
+# Environment: CFLAGS and NPROC, see below.
+
+# If the script is called without any arguments it will automagically collect
+# all build configurations and run them all.
+
+# Every build configuration is a function. Make sure the function name is at
+# the start of the line and does only contain characters a-z and '_'. Function
+# names starting with an underscore are utility functions and will not be
+# collected.
+
+cflags="-Werror $CFLAGS"
+dft_flags="$cflags"
+nproc=${NPROC:-1}
+
+_die()
+{
+       >&2 printf "FAILED: Task: %s Step: %s\n" "$2" "$3"
+       exit "$1"
+}
+
+
+default()
+{
+       ./configure
+}
+
+openbsd()
+{
+       ./configure \
+               --enable-compressed \
+               --enable-debug \
+               --enable-external_dotlock \
+               --disable-fcntl \
+               --enable-flock \
+               --with-idn2 \
+               --enable-imap \
+               --enable-pop \
+               --enable-sidebar \
+               --enable-smtp \
+               --mandir=${PREFIX}/man \
+               --with-docdir="${PREFIX}/share/doc/mutt" \
+               --with-ssl \
+               --enable-hcache \
+               --with-qdbm
+}
+
+original()
+{
+       ./configure \
+               --enable-gpgme \
+               --enable-pop \
+               --enable-imap \
+               --enable-smtp \
+               --enable-hcache \
+               --enable-sidebar \
+               --without-included-gettext \
+               --with-mailpath=/var/spool/mail \
+               --with-curses \
+               --with-ssl \
+               --with-sasl \
+               --with-idn2
+}
+
+tcc()
+{
+    CC=tcc ./configure
+}
+
+without_wc_funcs()
+{
+       ./configure \
+               --without-wc-funcs
+}
+
+# If no arguments were passed, get all the above function names (except _die)
+# and drop the parentheses.
+# shellcheck disable=SC2046
+test "$1" || set -- $(sed -n '/^[a-z][a-z_]\{1,\}()$/s/()//p' "$0")
+
+for conf
+do
+       cflags="$dft_flags"
+       make distclean || :
+       autoreconf -fi || _die "$?" "$conf" autoreconf
+       $conf || _die "$?" "$conf" configure
+       make -j"$nproc" CFLAGS="$cflags" || _die "$?" "$conf" make
+done
-- 
2.51.0

Reply via email to