summaryrefslogtreecommitdiffstats
path: root/debian/rules
blob: 0e77aa5b418e8c3cea7b31e1d22dc71b0673fa84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#! /usr/bin/make -f

#export DH_VERBOSE = 1
#export DEB_BUILD_OPTIONS = nostrip

export LC_ALL = C.UTF-8

include /usr/share/dpkg/default.mk
include /usr/share/debhelper/dh_package_notes/package-notes.mk

ifeq (amd64,$(DEB_HOST_ARCH))
export TEMPLATE_EFI_ARCH=x64
else ifeq (arm64,$(DEB_HOST_ARCH))
export TEMPLATE_EFI_ARCH=aa64
endif


ifeq ($(DEB_VENDOR),Ubuntu)
    DEFAULT_NTP_SERVERS = ntp.ubuntu.com
    SUPPORT_URL = http://www.ubuntu.com/support
    CONFFLAGS_DISTRO = \
		-Duser-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
		-Ddefault-llmnr=no \
		-Ddefault-mdns=no

else
    DEFAULT_NTP_SERVERS = 2.progress.pool.ntp.org
    SUPPORT_URL = https://support.progress-linux.org
    CONFFLAGS_DISTRO = \
		-Duser-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games \
		-Ddefault-llmnr=no \
		-Ddefault-mdns=no
endif

TEST_TIMEOUT_MULTIPLIER = "-t 10"

# Fail on missing files and symbol changes on distro builds, but not if we
# build/test upstream master. Also, don't put the debian revision in the version
# tag when we build/test upstream as it doesn't have any meaning in that case
# and it allows using the current date as the debian revision without causing
# unnecessary rebuilds all the time.
ifeq (, $(filter pkg.systemd.upstream, $(DEB_BUILD_PROFILES)))
    DH_MISSING ?= --fail-missing
    GENSYMBOLS_LEVEL ?= 4
    VERSION_TAG = $(DEB_VERSION)
else
    DH_MISSING ?= --list-missing
    GENSYMBOLS_LEVEL ?= 1
    VERSION_TAG = $(DEB_VERSION_UPSTREAM)
endif

# Make sure that DEB_BUILD_OPTIONS can be used by users to override any options
# we set here (By default DEB_BUILD_MAINT_OPTIONS overrides DEB_BUILD_OPTIONS).
export DEB_BUILD_MAINT_OPTIONS = optimize=+lto hardening=+pie $(DEB_BUILD_OPTIONS)

CONFFLAGS = \
	-Dstatic-libsystemd=true \
	-Dmode=release \
	-Dversion-tag="$(VERSION_TAG)" \
	-Dquotaon-path=/usr/sbin/quotaon \
	-Dquotacheck-path=/usr/sbin/quotacheck \
	-Dkmod-path=/usr/bin/kmod \
	-Dkexec-path=/usr/sbin/kexec \
	-Dsulogin-path=/usr/sbin/sulogin \
	-Dmount-path=/usr/bin/mount \
	-Dumount-path=/usr/bin/umount \
	-Dloadkeys-path=/usr/bin/loadkeys \
	-Dsetfont-path=/usr/bin/setfont \
	-Dnologin-path=/usr/sbin/nologin \
	-Dsysvinit-path=/etc/init.d \
	-Dsysvrcnd-path=/etc \
	-Dlocalegen-path=/usr/sbin/locale-gen \
	-Ddebug-shell=/usr/bin/bash \
	-Dzshcompletiondir=/usr/share/zsh/vendor-completions \
	-Ddbuspolicydir=/usr/share/dbus-1/system.d/ \
	-Dsupport-url=$(SUPPORT_URL) \
	-Ddefault-kill-user-processes=false \
	-Ddefault-dnssec=no \
	-Dpamconfdir=no \
	-Dpamlibdir=/usr/lib/$(DEB_HOST_MULTIARCH)/security \
	-Drpmmacrosdir=no \
	-Dvconsole=false \
	-Dfirstboot=true \
	-Dxkbcommon=disabled \
	-Dwheel-group=false \
	-Doomd=true \
	-Durlify=true \
	-Dgnutls=disabled \
	-Dlink-udev-shared=false \
	-Dlink-systemctl-shared=false \
	-Dntp-servers="$(DEFAULT_NTP_SERVERS)" \
	-Dsystem-uid-max=999 \
	-Dsystem-gid-max=999 \
	-Dnobody-user=nobody \
	-Dnobody-group=nogroup \
	-Ddev-kvm-mode=0660 \
	-Dgroup-render-mode=0660 \
	-Dsbat-distro-url=https://tracker.debian.org/pkg/systemd \
	-Drepart=enabled \
	-Dfdisk=enabled \
	-Dsysext=true \
	-Dnscd=true \
	-Dselinux=enabled \
	-Dhwdb=true \
	-Dsysusers=true \
	-Dinstall-tests=$(if $(filter noinsttest,$(DEB_BUILD_PROFILES)),false,true) \
	-Dman=$(if $(filter nodoc,$(DEB_BUILD_PROFILES)),disabled,enabled) \
	-Ddbus-interfaces-dir=$(if $(filter nodoc,$(DEB_BUILD_PROFILES)),no,yes) \
	-Dtranslations=true \
	-Dnss-myhostname=true \
	-Dnss-mymachines=enabled \
	-Dnss-resolve=enabled \
	-Dnss-systemd=true \
	-Dresolve=true \
	-Dstatus-unit-format-default=combined \
	-Dstandalone-binaries=true \
	-Dmode=$(if $(filter pkg.systemd.upstream,$(DEB_BUILD_PROFILES)),developer,release)

ifeq ($(filter nocheck,$(DEB_BUILD_PROFILES))$(filter noinsttest,$(DEB_BUILD_PROFILES)),nochecknoinsttest)
CONFFLAGS += -Dtests=false
else
CONFFLAGS += -Dtests=true
endif

ifeq (, $(filter stage1, $(DEB_BUILD_PROFILES)))
CONFFLAGS += \
	-Daudit=enabled \
	-Dlibcryptsetup=enabled \
	-Dlibcryptsetup-plugins=enabled \
	-Dcoredump=true \
	-Delfutils=enabled \
	-Dapparmor=enabled \
	-Dlibidn2=enabled \
	-Dlibiptc=enabled \
	-Dlibcurl=enabled \
	-Dimportd=enabled \
	-Dmicrohttpd=enabled \
	-Dopenssl=enabled \
	-Dcryptolib=openssl \
	-Ddns-over-tls=openssl \
	-Dlibfido2=enabled \
	-Dtpm2=enabled \
	-Dp11kit=enabled \
	-Dqrencode=enabled \
	-Dpwquality=enabled \
	-Dhomed=enabled \
	-Duserdb=true \
	-Dpcre2=enabled \
	-Dukify=enabled \
	-Dbootloader=$(if $(filter amd64 i386 arm64 armhf riscv64,$(DEB_HOST_ARCH)),enabled,disabled) \
	-Dsysupdate=enabled
else
CONFFLAGS += \
	-Daudit=disabled \
	-Dlibcryptsetup=disabled \
	-Dlibcryptsetup-plugins=disabled \
	-Dcoredump=false \
	-Delfutils=disabled \
	-Dapparmor=disabled \
	-Dlibidn2=disabled \
	-Dlibiptc=disabled \
	-Dlibcurl=disabled \
	-Dimportd=disabled \
	-Dmicrohttpd=disabled \
	-Dopenssl=disabled \
	-Dlibfido2=disabled \
	-Dtpm2=disabled \
	-Dp11kit=disabled \
	-Dqrencode=disabled \
	-Dpwquality=disabled \
	-Dhomed=disabled \
	-Duserdb=false \
	-Dpcre2=disabled \
	-Dukify=disabled \
	-Dbootloader=disabled \
	-Dsysupdate=disabled
endif

# BPF/BTF are only enabled and usable on a few architectures
ifeq (, $(filter $(DEB_BUILD_PROFILES), stage1 pkg.systemd.nobpf))
ifneq (,$(filter $(DEB_TARGET_ARCH), amd64 arm64 ppc64el riscv64 s390x))
CONFFLAGS += \
	-Dbpf-framework=enabled \
	-Dbpf-compiler=clang

ifeq ($(DEB_VENDOR),Ubuntu)
# Source: https://git.launchpad.net/ubuntu/+source/xdp-tools/tree/debian/rules
# On Ubuntu, the `bpftool` in path is a shell wrapper pointing at
# the binary corresponding to runtime kernel version.
#
# We do not know the kernel version being used on the system building
# this package, and in sbuild/container environments uname might not
# even match anything available to the build.
# Gladly for the build we only need the tool to generate skeleton code.
#
# If any /usr/lib/linux-tools/*/bpftool exists, locate the most recent
# version and point to that, otherwise `bpftool` from PATH will be
# used.
bpftool_binary := $(shell find /usr/lib/linux-tools/ -name 'bpftool' -perm /u=x 2>/dev/null | sort | head -n1)
ifneq ($(bpftool_binary),)
export PATH := $(shell dirname $(bpftool_binary)):$(PATH)
endif
endif

# The vmlinux.h we want is in the headers package that linux-headers-ARCH depends on,
# which itself is the package that provides linux-headers-generic that we build depend on.
# This is available since Trixie. If we can't find it, default to auto for the upstream CI
# so that it is generated at build time, or disabled for distribution builds, as we don't
# want to depend on the buildd kernels.
ifeq ($(DEB_VENDOR),Ubuntu)
HEADERS_PACKAGE = $(shell dpkg-query --showformat='$${Depends}' --show linux-headers-generic | sed "s/.*\(linux-headers-.*)\)-generic.*/\1/")
else
HEADERS_PACKAGE = $(shell dpkg-query --showformat='$${Depends}' --show linux-headers-$(DEB_HOST_ARCH) | sed "s/.*\(linux-headers-.*-$(DEB_HOST_ARCH)\).*/\1/")
endif

ifneq ("$(wildcard /usr/src/$(HEADERS_PACKAGE)/vmlinux.h)","")
CONFFLAGS += -Dvmlinux-h=provided -Dvmlinux-h-path=/usr/src/$(HEADERS_PACKAGE)/vmlinux.h
else
ifneq (, $(filter pkg.systemd.upstream, $(DEB_BUILD_PROFILES)))
CONFFLAGS += -Dvmlinux-h=auto
else
CONFFLAGS += -Dvmlinux-h=disabled
endif
endif
endif
endif

ifeq (, $(filter pkg.systemd.upstream, $(DEB_BUILD_PROFILES)))
CONFFLAGS += -Ddns-servers=''
endif

override_dh_auto_configure:
	dh_auto_configure \
		-- $(CONFFLAGS) $(CONFFLAGS_DISTRO) $(CONFFLAGS_UPSTREAM)

execute_before_dh_auto_build:
	# blhc false positives: C++ fuzz test program, cc -E flags listing, PE-COFF EFI binaries
	@echo 'blhc: ignore-line-regexp: .* -o test-bus-vtable-cc.*'
	@echo 'blhc: ignore-line-regexp: .*cc -E.*'
	@echo 'blhc: ignore-line-regexp: .* -o src/boot/efi.*'

execute_after_dh_auto_build:
	# generate POT file for translators
	ninja -C obj-$(DEB_HOST_GNU_TYPE) systemd-pot

execute_before_dh_auto_clean:
ifneq (, $(filter pkg.systemd.upstream, $(DEB_BUILD_PROFILES)))
	debian/extra/checkout-upstream
endif

execute_after_dh_auto_clean:
	rm -f debian/shlibs.local
	# remove Python byte code files
	rm -rf src/ukify/test/__pycache__/
	rm -rf src/ukify/__pycache__/
	rm -rf tools/__pycache__/
	rm -rf tools/chromiumos/__pycache__/
	rm -f po/systemd.pot

execute_before_dh_install:
	# remove unnecessary / unused files
	rm -rf debian/tmp/usr/share/doc/systemd/LICENSES/
	rm -f debian/tmp/usr/share/doc/systemd/LICENSE.*
	rm -f debian/tmp/etc/init.d/README
	rm -f debian/tmp/usr/lib/*.d/README
	rm -f debian/tmp/usr/lib/udev/*.d/README
	rm -f debian/tmp/usr/lib/sysctl.d/50-default.conf
	rm -f debian/tmp/etc/X11/xinit/xinitrc.d/50-systemd-user.sh
	if [ -d debian/tmp/etc/X11/xinit/xinitrc.d/ ]; then \
		rmdir -p --ignore-fail-on-non-empty debian/tmp/etc/X11/xinit/xinitrc.d/; \
	fi
	# remove etc.conf and usr/share/factory for now, we are not using them yet
	find debian/tmp/ -name etc.conf -print -delete
	rm -rf debian/tmp/usr/share/factory/
	# replace upstream sysusers.d/basic.conf with proper users for Debian
	if [ -d debian/tmp/usr/lib/sysusers.d/ ]; then \
		debian/extra/make-sysusers-basic > debian/tmp/usr/lib/sysusers.d/basic.conf; \
	fi
	# remove obsolete compat symlink
	rm -f debian/tmp/usr/bin/systemd-resolve
	# we don't want the repart standalone binary for now
	rm -f debian/tmp/usr/bin/systemd-repart.standalone
	# files shipped by cryptsetup
ifeq (, $(filter stage1, $(DEB_BUILD_PROFILES)))
	rm -f debian/tmp/usr/share/man/man5/crypttab.5
endif
	# print empty directories, makes it easier to keep *.install files up-to-date
	find debian/tmp -type d -empty -print

execute_after_dh_install-arch:
	# disable ctrl-alt-del.target
	rm debian/systemd/usr/lib/systemd/system/ctrl-alt-del.target

	# Ubuntu specific files
ifeq ($(DEB_VENDOR),Ubuntu)
	install -D --mode=644 debian/extra/udev.py debian/udev/usr/share/apport/package-hooks/udev.py
	install -D --mode=644 debian/extra/systemd.py debian/systemd/usr/share/apport/package-hooks/systemd.py
	install --mode=644 debian/extra/rules-ubuntu/*.rules debian/udev/usr/lib/udev/rules.d/
	install -D --mode=644 debian/extra/resolved.conf.d/cache-no-negative.conf debian/systemd-resolved/usr/lib/systemd/resolved.conf.d/cache-no-negative.conf
	cp -a debian/extra/units-ubuntu/* debian/systemd/usr/lib/systemd/system/
else
	install --mode=644 debian/extra/rules-ubuntu/78-graphics-card.rules debian/udev/usr/lib/udev/rules.d/
	install -D --mode=644 debian/extra/resolved.conf.d/cache-no-negative.conf debian/systemd-resolved/usr/lib/systemd/resolved.conf.d/cache-no-negative.conf
endif

ifeq (, $(filter pkg.systemd.upstream, $(DEB_BUILD_PROFILES)))
ifeq ($(DEB_VENDOR),Debian)
ifneq ($(TEMPLATE_EFI_ARCH),)
	debian/extra/gen-signing-template $(DEB_VERSION) $(DEB_HOST_ARCH) $(TEMPLATE_EFI_ARCH)
endif
endif
endif

	# Remove empty directories from /usr/lib.
	# Those are not strictly needed and can trigger piuparts errors due to
	# accidential directory removal by dpkg on merged-/usr systems.
	if [ -d debian/systemd/usr/lib ]; then \
		find debian/systemd/usr/lib -type d -empty -print -delete; \
	fi

	# Can be dropped once upstream CI stops running on Jammy, which needs
	# the old pkla config files, which are created only when building with
	# old polkit versions.
ifneq (, $(filter pkg.systemd.upstream, $(DEB_BUILD_PROFILES)))
	if [ -f debian/tmp/var/lib/polkit-1/localauthority/10-vendor.d/systemd-networkd.pkla ]; then \
		dh_install -psystemd var/lib/polkit-1/localauthority/10-vendor.d/systemd-networkd.pkla; \
	fi
endif

override_dh_missing:
	dh_missing $(DH_MISSING)

override_dh_installsystemd:
	dh_installsystemd -psystemd-timesyncd
	dh_installsystemd -psystemd-oomd systemd-oomd.service
	dh_installsystemd -psystemd-oomd --no-stop-on-upgrade systemd-oomd.socket
	dh_installsystemd -psystemd-container --no-stop-on-upgrade machines.target
	dh_installsystemd -psystemd-userdbd --no-stop-on-upgrade systemd-userdbd.socket
	dh_installsystemd -psystemd-homed --no-also systemd-homed.service systemd-homed-activate.service
	dh_installsystemd -psystemd-resolved
	dh_installsystemd -pudev systemd-udevd.service

override_dh_installsystemduser:

execute_after_dh_installsysusers:
	dh_installsysusers -pudev --name=debian-udev

PROJECT_VERSION ?= $(shell awk '/(PROJECT|PACKAGE)_VERSION / {print $$3}' obj-$(DEB_HOST_GNU_TYPE)/config.h | tr -d \")

# The SysV compat tools (which are symlinks to systemctl) are
# quasi-essential, so add their dependencies to Pre-Depends
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=753589
override_dh_shlibdeps:
	dh_shlibdeps -psystemd -Llibsystemd-shared -- \
		-dPre-Depends -edebian/systemd/usr/bin/systemctl \
		-dDepends
	dh_shlibdeps -plibsystemd-shared -lusr/lib/$(DEB_HOST_MULTIARCH)/systemd
	dh_shlibdeps --remaining-packages -Llibsystemd-shared

override_dh_makeshlibs:
	sed 's/SHARED_LIB_VERSION/$(PROJECT_VERSION)/' debian/shlibs.local.in > debian/shlibs.local
	dh_makeshlibs -plibudev1 --add-udeb=libudev1-udeb -- -c$(GENSYMBOLS_LEVEL)
	dh_makeshlibs -plibsystemd-shared -Xlibsystemd-shared -Xlibsystemd-core -- -c$(GENSYMBOLS_LEVEL)
	dh_makeshlibs --remaining-packages -- -c$(GENSYMBOLS_LEVEL)

override_dh_auto_test:
ifeq (, $(filter nocheck, $(DEB_BUILD_OPTIONS)))
	# some tests hang under fakeroot, so disable fakeroot
	env -u LD_PRELOAD meson test -C obj-$(DEB_HOST_GNU_TYPE) --print-errorlogs $(TEST_TIMEOUT_MULTIPLIER)
endif

%:
	dh $@