+# Build type
+# oot : out-of-tree build
+# dist : build via make dist
+# oot-dist: build via make dist out-of-tree
+# * : normal tree build
+#
+# Make sure to move to the build directory and run configure
+# before continuing.
+case "$build" in
+oot)
+ echo "Out of tree build"
+
+ # Create and enter a temporary build directory
+ builddir=$(mktemp -d)
+ cd "$builddir"
+
+ "$SRCDIR/configure" "${CONF_OPTS[@]}"
+ ;;
+
+dist)
+ echo "Distribution in-tree build"
+
+ # Run configure and generate the tar file
+ # in the source directory
+ ./configure
+ $MAKE dist
+
+ # Create and enter a temporary build directory
+ builddir=$(mktemp -d)
+ cd "$builddir"
+
+ # Extract the distribution tar in the build directory,
+ # ignore the first directory level
+ $TAR xvf "$SRCDIR"/*.tar.* --strip 1
+
+ # Build in extracted source tree
+ ./configure "${CONF_OPTS[@]}"
+ ;;
+
+oot-dist)
+ echo "Distribution out of tree build"
+
+ # Create and enter a temporary build directory
+ builddir=$(mktemp -d)
+ cd "$builddir"
+
+ # Run configure out of tree and generate the tar file
+ "$SRCDIR/configure"
+ $MAKE dist
+
+ dist_srcdir="$(mktemp -d)"
+ cd "$dist_srcdir"
+
+ # Extract the distribution tar in the new source directory,
+ # ignore the first directory level
+ $TAR xvf "$builddir"/*.tar.* --strip 1
+
+ # Create and enter a second temporary build directory
+ builddir="$(mktemp -d)"
+ cd "$builddir"
+
+ # Run configure from the extracted distribution tar,
+ # out of the source tree
+ "$dist_srcdir/configure" "${CONF_OPTS[@]}"
+ ;;
+
+*)
+ echo "Standard in-tree build"
+ ./configure "${CONF_OPTS[@]}"
+ ;;
+esac
+
+# We are now inside a configured build directory
+
+# BUILD!
+$MAKE -j "$($NPROC)" V=1
+
+# Install in the workspace
+$MAKE install DESTDIR="$WORKSPACE"
+
+# Run tests, don't fail now, we want to run the archiving steps
+failed_tests=0
+$MAKE --keep-going check || failed_tests=1