]> git.ipfire.org Git - thirdparty/systemd.git/blob - mkosi.images/system/mkosi.conf.d/10-debian-ubuntu/mkosi.build.chroot
mkosi: Simply remove all the debian patches instead of mounting over them
[thirdparty/systemd.git] / mkosi.images / system / mkosi.conf.d / 10-debian-ubuntu / mkosi.build.chroot
1 #!/bin/bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -e
4
5 # shellcheck source=/dev/null
6 . /usr/lib/os-release
7
8 if [ ! -d "pkg/$ID/debian" ]; then
9 echo "deb rules not found at pkg/$ID/debian, run mkosi once with -ff to make sure the rules are cloned" >&2
10 exit 1
11 fi
12
13 # We transplant the debian/ folder from the deb package sources into the upstream sources.
14 mount --mkdir --bind "$SRCDIR/pkg/$ID/debian" "$SRCDIR"/debian
15
16 # We remove the patches so they don't get applied.
17 rm -rf "$SRCDIR"/debian/patches/*
18
19 # While the build directory can be specified through DH_OPTIONS, the default one is hardcoded everywhere so
20 # we have to use that. Because it is architecture dependent, we query it using dpkg-architecture first.
21 DEB_HOST_GNU_TYPE="$(dpkg-architecture --query DEB_HOST_GNU_TYPE)"
22 mount --mkdir --bind "$BUILDDIR" "$SRCDIR/obj-$DEB_HOST_GNU_TYPE"
23
24 if [ -d .git/ ] && [ -z "$(git status --porcelain)" ]; then
25 TS="$(git show --no-patch --format=%ct HEAD)"
26 else
27 TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
28 fi
29
30 # Add a new changelog entry to update the version. We use a fixed date since a dynamic one causes a full
31 # rebuild every time.
32 cat >debian/changelog.new <<EOF
33 systemd ($(cat meson.version)-$(date "+%Y%m%d%H%M%S" --date "@$TS")) UNRELEASED; urgency=low
34
35 * Automatic build from mkosi
36
37 -- systemd test <systemd-devel@lists.freedesktop.org> $(date --rfc-email --date "@$TS")
38
39 EOF
40 cat debian/changelog >>debian/changelog.new
41 mv debian/changelog.new debian/changelog
42
43 build() {
44 DEB_BUILD_OPTIONS=$(awk '$1=$1' <<<"\
45 $( ((WITH_TESTS)) || echo nocheck) \
46 $( ((WITH_DOCS)) || echo nodoc) \
47 $( ((WITH_DEBUG)) && echo debug || echo nostrip) \
48 terse \
49 optimize=-lto \
50 hardening=-fortify \
51 ") \
52 DEB_BUILD_PROFILES=$(awk '$1=$1' <<<"\
53 $( ((WITH_TESTS)) || echo nocheck) \
54 $( ((WITH_DOCS)) || echo nodoc) \
55 pkg.systemd.upstream \
56 ") \
57 DEB_CFLAGS_APPEND="-O${OPTIMIZATION:-0}" \
58 DPKG_FORCE="unsafe-io" \
59 DPKG_DEB_COMPRESSOR_TYPE="none" \
60 DH_MISSING="--fail-missing" \
61 CONFFLAGS_UPSTREAM="-D mode=developer -D b_sanitize=${SANITIZERS:-none}" \
62 dpkg-buildpackage \
63 --no-pre-clean \
64 --unsigned-changes \
65 --build=binary
66 }
67
68 if ! build; then
69 # debhelper installs files for each package to debian/<package> so we figure out which files were
70 # packaged by querying all the package names from debian/control and running find on each of the
71 # corresponding package directory in debian/.
72 grep "Package:" debian/control |
73 sed "s/Package: //" |
74 xargs -d '\n' -I {} sh -c "[ -d debian/{} ] && (cd debian/{} && find . ! -type d ! -path "*dh-exec*" -printf '%P\n')" |
75 # Remove compression suffix from compressed manpages as the manpages in debian/tmp will be uncompressed.
76 sed --regexp-extended 's/([0-9])\.gz$/\1/' |
77 sort --unique >/tmp/packaged-files
78
79 # We figure out the installed files by running find on debian/tmp/ which contains the files installed
80 # by meson install.
81 (cd debian/tmp/ && find . ! -type d ! -path "*dh-exec*" -printf '%P\n') >/tmp/installed-files
82
83 if [ -f debian/not-installed ]; then
84 grep --invert-match "^#" debian/not-installed >>/tmp/installed-files
85 fi
86
87 sort --unique --output /tmp/installed-files /tmp/installed-files
88
89 # We get all the installed files that were not packaged by finding entries in the installed file that are
90 # not in the packaged file.
91 comm -23 /tmp/installed-files /tmp/packaged-files > /tmp/unpackaged-files
92 # If there are no unpackaged files something else went wrong.
93 if [ ! -s /tmp/unpackaged-files ]; then
94 exit 1
95 fi
96
97 # Otherwise, we append the unpackaged files to the filelist for the systemd package and retry the build.
98 cat /tmp/unpackaged-files >>debian/systemd.install
99 build
100 fi
101
102 (
103 shopt -s nullglob
104 cp ../*.deb ../*.ddeb "$PACKAGEDIR"
105 cp ../*.deb ../*.ddeb "$OUTPUTDIR"
106 )