#!/usr/bin/env bash # SPDX-License-Identifier: LGPL-2.1-or-later set -e if [[ "$1" == "clangd" ]]; then exit 0 fi if [[ ! -d "pkg/$PKG_SUBDIR/debian" ]]; then echo "deb rules not found at pkg/$PKG_SUBDIR/debian, run mkosi once with -ff to make sure the rules are cloned" >&2 exit 1 fi . mkosi/mkosi.functions # We transplant the debian/ folder from the deb package sources into the upstream sources. mount --mkdir --bind "$SRCDIR/pkg/$PKG_SUBDIR/debian" "$SRCDIR"/debian # We hide the patches so they don't get applied. if [[ -d "$SRCDIR/debian/patches" ]]; then mkdir /tmp/patches mount --bind /tmp/patches "$SRCDIR/debian/patches" fi # While the build directory can be specified through DH_OPTIONS, the default one is hardcoded everywhere so # we have to use that. Because it is architecture dependent, we query it using dpkg-architecture first. DEB_HOST_GNU_TYPE="$(dpkg-architecture --query DEB_HOST_GNU_TYPE)" mount --mkdir --bind "$BUILDDIR" "$SRCDIR/obj-$DEB_HOST_GNU_TYPE" TS="${SOURCE_DATE_EPOCH:-$(date +%s)}" # Add a new changelog entry to update the version. We use a fixed date since a dynamic one causes a full # rebuild every time. cat >/tmp/changelog < $(date --rfc-email --date "@$TS") EOF cat debian/changelog >>/tmp/changelog mount --bind /tmp/changelog "$PWD/debian/changelog" DEB_BUILD_PROFILES="$(awk '$1=$1' <<<"\ $( ((WITH_TESTS)) || echo nocheck) \ $( ((WITH_DOCS)) || echo nodoc) \ pkg.systemd.upstream \ ")" # TODO: Drop GENSYMBOLS_LEVEL once https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=986746 is fixed. # Note that CXXFLAGS is for the C++ compiler, and CPPFLAGS is for the C/C++ preprocessor, they are not the same: # https://en.wikipedia.org/wiki/CFLAGS build() { env \ CC="$( ((CC)) && echo "$CC" || ((LLVM)) && echo clang || echo gcc)" \ CXX="$( ((CXX)) && echo "$CXX" || ((LLVM)) && echo clang++ || echo g++)" \ CC_LD="$( ((LD)) && echo "$LD" || ((LLVM)) && echo lld)" \ CXX_LD="$( ((LD)) && echo "$LD" || ((LLVM)) && echo lld)" \ DEB_BUILD_OPTIONS="$(awk '$1=$1' <<<"\ $( ((WITH_TESTS)) || echo nocheck) \ $( ((WITH_DOCS)) || echo nodoc) \ $( ((WITH_DEBUG)) && echo debug || echo nostrip) \ $( ! ((MESON_VERBOSE)) && echo terse) \ optimize=-lto \ hardening=-fortify \ ")" \ DEB_BUILD_PROFILES="$DEB_BUILD_PROFILES" \ DEB_CFLAGS_APPEND="$MKOSI_CFLAGS $CFLAGS" \ DEB_CXXFLAGS_APPEND="$MKOSI_CFLAGS $CFLAGS" \ DEB_CPPFLAGS_APPEND="$CPPFLAGS" \ DEB_LDFLAGS_APPEND="$MKOSI_LDFLAGS $LDFLAGS" \ DPKG_FORCE="unsafe-io" \ DPKG_DEB_COMPRESSOR_TYPE="none" \ DH_MISSING="--fail-missing" \ CONFFLAGS_UPSTREAM="$MKOSI_MESON_OPTIONS $MESON_OPTIONS" \ GENSYMBOLS_LEVEL="$( ((LLVM)) && echo 0 || echo 1)" \ dpkg-buildpackage \ --no-pre-clean \ --unsigned-changes \ --build=binary EXIT_STATUS=$? # Make sure we don't reconfigure twice. MKOSI_MESON_OPTIONS="${MKOSI_MESON_OPTIONS//"--wipe"/}" return $EXIT_STATUS } trap 'umount "$SRCDIR/obj-$DEB_HOST_GNU_TYPE" && DEB_BUILD_PROFILES="$DEB_BUILD_PROFILES" dpkg-buildpackage -T clean' EXIT if ! build; then # debhelper installs files for each package to debian/ so we figure out which files were # packaged by querying all the package names from debian/control and running find on each of the # corresponding package directory in debian/. grep "Package:" debian/control | sed "s/Package: //" | xargs -d '\n' -I {} sh -c "[ -d debian/{} ] && (cd debian/{} && find . ! -type d ! -path "*dh-exec*" -printf '%P\n')" | # Remove compression suffix from compressed manpages as the manpages in debian/tmp will be uncompressed. sed --regexp-extended 's/([0-9])\.gz$/\1/' >/tmp/packaged-files # We figure out the installed files by running find on debian/tmp/ which contains the files installed # by meson install. (cd debian/tmp/ && find . ! -type d ! -path "*dh-exec*" -printf '%P\n' | sort --unique) >/tmp/installed-files if [[ -f debian/not-installed ]]; then pushd debian/tmp grep --invert-match "^#" ../not-installed | xargs -I {} sh -c "test -d '{}' && echo '{}/**/*' || echo '{}'" | xargs -I {} bash -O nullglob -O globstar -c "printf '%s\n' {}" | sed --expression "/^$/d" --expression "s#//*#/#g" | xargs -I {} sh -c "test -f '{}' && echo '{}' || true" >>/tmp/packaged-files popd fi sort --unique --output /tmp/packaged-files /tmp/packaged-files # We get all the installed files that were not packaged by finding entries in the installed file that are # not in the packaged file. comm -23 /tmp/installed-files /tmp/packaged-files > /tmp/unpackaged-files # If there are no unpackaged files something else went wrong. if [[ ! -s /tmp/unpackaged-files ]]; then exit 1 fi echo -e "::warning title=UNPACKAGED-FILES::The following files were not picked up by the package, please update the packaging recipe to include: $(tr '\n' ' ' >/tmp/systemd.install mount --bind /tmp/systemd.install "$PWD/debian/systemd.install" build fi ( shopt -s nullglob rm -f "$BUILDDIR"/*.deb "$BUILDDIR"/*.ddeb cp ../*.deb ../*.ddeb "$PACKAGEDIR" cp ../*.deb ../*.ddeb "$BUILDDIR" # These conflict with the packages that we actually want to install, so remove them rm -f "$BUILDDIR"/systemd-standalone-*.deb "$BUILDDIR"/systemd-standalone-*.ddeb )