# This is a build script for OS image generation using mkosi (https://github.com/systemd/mkosi).
# Simply invoke "mkosi" in the project directory to build an OS image.
-export LC_CTYPE=C.UTF-8
-meson build
-ninja -C build all
-ninja -C build test
-ninja -C build install
+# If mkosi.builddir/ exists mkosi will set $BUILDDIR to it, let's then use it
+# as out-of-tree build dir. Otherwise, let's make up our own builddir.
+[ -z "$BUILDDIR" ] && BUILDDIR=build
-mkdir -p $DESTDIR/etc
+export LC_CTYPE=en_US.UTF-8
-cat > $DESTDIR/etc/issue <<EOF
+sysvinit_path=`realpath /etc/init.d`
+
+[ -f "$BUILDDIR"/build.ninja ] || meson "$BUILDDIR" -D "sysvinit-path=$sysvinit_path" -D default-hierarchy=unified -D man=false
+ninja -C "$BUILDDIR" all
+[ "$WITH_TESTS" = 0 ] || ninja -C "$BUILDDIR" test || ( RET="$?" ; cat "$BUILDDIR"/meson-logs/testlog.txt ; exit "$RET" )
+ninja -C "$BUILDDIR" install
+
+mkdir -p "$DESTDIR"/etc
+
+cat > "$DESTDIR"/etc/issue <<EOF
\S (built from systemd tree)
Kernel \r on an \m (\l)