blob: 9fd3a5f52585d2644d95f86240cbeefac3b018c6 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001require util-linux.inc
2
Patrick Williams705982a2024-01-12 09:51:57 -06003inherit autotools gettext manpages pkgconfig systemd update-alternatives python3-dir bash-completion ptest gtk-doc
Patrick Williams92b42cb2022-09-03 06:53:57 -05004DEPENDS = "libcap-ng ncurses virtual/crypt zlib util-linux-libuuid"
5
6PACKAGES =+ "${PN}-swaponoff"
7PACKAGES += "${@bb.utils.contains('PACKAGECONFIG', 'pylibmount', '${PN}-pylibmount', '', d)}"
8
9python util_linux_binpackages () {
10 def pkg_hook(f, pkg, file_regex, output_pattern, modulename):
11 pn = d.getVar('PN')
12 d.appendVar('RRECOMMENDS:%s' % pn, ' %s' % pkg)
13
14 if d.getVar('ALTERNATIVE:' + pkg):
15 return
16 if d.getVarFlag('ALTERNATIVE_LINK_NAME', modulename):
17 d.setVar('ALTERNATIVE:' + pkg, modulename)
18
19 bindirs = sorted(list(set(d.expand("${base_sbindir} ${base_bindir} ${sbindir} ${bindir}").split())))
20 for dir in bindirs:
21 do_split_packages(d, root=dir,
22 file_regex=r'(.*)', output_pattern='${PN}-%s',
23 description='${PN} %s',
24 hook=pkg_hook, extra_depends='')
25
26 # There are some symlinks for some binaries which we have ignored
27 # above. Add them to the package owning the binary they are
28 # pointing to
29 extras = {}
30 dvar = d.getVar('PKGD')
31 for root in bindirs:
32 for walkroot, dirs, files in os.walk(dvar + root):
33 for f in files:
34 file = os.path.join(walkroot, f)
35 if not os.path.islink(file):
36 continue
37
38 pkg = os.path.basename(os.readlink(file))
39 extras.setdefault(pkg, [])
40 extras[pkg].append(file.replace(dvar, '', 1))
41
42 pn = d.getVar('PN')
43 for pkg, links in extras.items():
44 of = d.getVar('FILES:' + pn + '-' + pkg)
45 links = of + " " + " ".join(sorted(links))
46 d.setVar('FILES:' + pn + '-' + pkg, links)
47}
48
49# we must execute before update-alternatives PACKAGE_PREPROCESS_FUNCS
50PACKAGE_PREPROCESS_FUNCS =+ "util_linux_binpackages "
51
52# skip libuuid as it will be packaged by the util-linux-libuuid recipe
53python util_linux_libpackages() {
54 do_split_packages(d, root=d.getVar('UTIL_LINUX_LIBDIR'), file_regex=r'^lib(?!uuid)(.*)\.so\..*$',
55 output_pattern='${PN}-lib%s',
56 description='${PN} lib%s',
57 extra_depends='', prepend=True, allow_links=True)
58}
59
60PACKAGESPLITFUNCS =+ "util_linux_libpackages"
61
62PACKAGES_DYNAMIC = "^${PN}-.*"
63
Patrick Williams92b42cb2022-09-03 06:53:57 -050064UTIL_LINUX_LIBDIR = "${libdir}"
65UTIL_LINUX_LIBDIR:class-target = "${base_libdir}"
66EXTRA_OECONF = "\
67 --enable-libuuid --enable-libblkid \
68 \
69 --enable-fsck --enable-kill --enable-last --enable-mesg \
70 --enable-mount --enable-partx --enable-rfkill \
71 --enable-unshare --enable-write \
72 \
73 --disable-bfs --disable-login \
74 --disable-makeinstall-chown --disable-minix --disable-newgrp \
75 --disable-use-tty-group --disable-vipw --disable-raw \
76 \
77 --without-udev \
78 \
79 usrsbin_execdir='${sbindir}' \
80 --libdir='${UTIL_LINUX_LIBDIR}' \
81"
82
83EXTRA_OECONF:append:class-target = " --enable-setpriv"
84EXTRA_OECONF:append:class-native = " --without-cap-ng --disable-setpriv"
85EXTRA_OECONF:append:class-nativesdk = " --without-cap-ng --disable-setpriv"
86EXTRA_OECONF:append = " --disable-hwclock-gplv3"
87
88# enable pcre2 for native/nativesdk to match host distros
89# this helps to keep same expectations when using the SDK or
90# build host versions during development
91#
92PACKAGECONFIG ?= "pcre2"
93PACKAGECONFIG:class-target ?= "${@bb.utils.contains('DISTRO_FEATURES', 'pam', 'chfn-chsh pam', '', d)}"
94# inherit manpages requires this to be present, however util-linux does not have
95# configuration options, and installs manpages always
96PACKAGECONFIG[manpages] = ""
97PACKAGECONFIG[pam] = "--enable-su --enable-runuser,--disable-su --disable-runuser, libpam,"
98# Respect the systemd feature for uuidd
99PACKAGECONFIG[systemd] = "--with-systemd --with-systemdsystemunitdir=${systemd_system_unitdir}, --without-systemd --without-systemdsystemunitdir,systemd"
100# Build python bindings for libmount
101PACKAGECONFIG[pylibmount] = "--with-python=3 --enable-pylibmount,--without-python --disable-pylibmount,python3"
102# Readline support
103PACKAGECONFIG[readline] = "--with-readline,--without-readline,readline"
104# PCRE support in hardlink
105PACKAGECONFIG[pcre2] = ",,libpcre2"
106PACKAGECONFIG[cryptsetup] = "--with-cryptsetup,--without-cryptsetup,cryptsetup"
107PACKAGECONFIG[chfn-chsh] = "--enable-chfn-chsh,--disable-chfn-chsh,"
Andrew Geissler517393d2023-01-13 08:55:19 -0600108PACKAGECONFIG[selinux] = "--with-selinux,--without-selinux,libselinux"
Patrick Williams92b42cb2022-09-03 06:53:57 -0500109
110EXTRA_OEMAKE = "ARCH=${TARGET_ARCH} CPU= CPUOPT= 'OPT=${CFLAGS}'"
111
112ALLOW_EMPTY:${PN} = "1"
113FILES:${PN} = ""
114FILES:${PN}-doc += "${datadir}/getopt/getopt-*.*"
115FILES:${PN}-dev += "${PYTHON_SITEPACKAGES_DIR}/libmount/pylibmount.la"
116FILES:${PN}-mount = "${sysconfdir}/default/mountall"
117FILES:${PN}-runuser = "${sysconfdir}/pam.d/runuser*"
118FILES:${PN}-su = "${sysconfdir}/pam.d/su-l"
119CONFFILES:${PN}-su = "${sysconfdir}/pam.d/su-l"
120FILES:${PN}-pylibmount = "${PYTHON_SITEPACKAGES_DIR}/libmount/pylibmount.so \
121 ${PYTHON_SITEPACKAGES_DIR}/libmount/__init__.* \
122 ${PYTHON_SITEPACKAGES_DIR}/libmount/__pycache__/*"
123
124# Util-linux' blkid replaces the e2fsprogs one
125RCONFLICTS:${PN}-blkid = "${MLPREFIX}e2fsprogs-blkid"
126RREPLACES:${PN}-blkid = "${MLPREFIX}e2fsprogs-blkid"
127
128RRECOMMENDS:${PN}:class-native = ""
129RRECOMMENDS:${PN}:class-nativesdk = ""
130RDEPENDS:${PN}:class-native = ""
131RDEPENDS:${PN}:class-nativesdk = ""
132
133RDEPENDS:${PN} += " util-linux-libuuid"
134RDEPENDS:${PN}-dev += " util-linux-libuuid-dev"
135
136RPROVIDES:${PN}-dev = "${PN}-libblkid-dev ${PN}-libmount-dev"
137
138RDEPENDS:${PN}-bash-completion += "${PN}-lsblk"
Patrick Williams169d7bc2024-01-05 11:33:25 -0600139RDEPENDS:${PN}-ptest += "bash bc btrfs-tools coreutils e2fsprogs findutils grep iproute2 kmod procps sed socat which xz"
Patrick Williams92b42cb2022-09-03 06:53:57 -0500140RRECOMMENDS:${PN}-ptest += "kernel-module-scsi-debug kernel-module-sd-mod kernel-module-loop kernel-module-algif-hash"
141RDEPENDS:${PN}-swaponoff = "${PN}-swapon ${PN}-swapoff"
142ALLOW_EMPTY:${PN}-swaponoff = "1"
143
144#SYSTEMD_PACKAGES = "${PN}-uuidd ${PN}-fstrim"
145SYSTEMD_SERVICE:${PN}-uuidd = "uuidd.socket uuidd.service"
146SYSTEMD_AUTO_ENABLE:${PN}-uuidd = "disable"
147SYSTEMD_SERVICE:${PN}-fstrim = "fstrim.timer fstrim.service"
148SYSTEMD_AUTO_ENABLE:${PN}-fstrim = "disable"
149
150do_install () {
151 # with ccache the timestamps on compiled files may
152 # end up earlier than on their inputs, this allows
153 # for the resultant compilation in the install step.
154 oe_runmake 'CC=${CC}' 'LD=${LD}' \
155 'LDFLAGS=${LDFLAGS}' 'DESTDIR=${D}' install
156
157 mkdir -p ${D}${base_bindir}
158
159 sbinprogs="agetty ctrlaltdel cfdisk vipw vigr"
160 sbinprogs_a="pivot_root hwclock mkswap losetup swapon swapoff fdisk fsck blkid blockdev fstrim sulogin switch_root nologin"
161 binprogs_a="dmesg getopt kill more umount mount login su mountpoint"
162
163 if [ "${base_sbindir}" != "${sbindir}" ]; then
164 mkdir -p ${D}${base_sbindir}
165 for p in $sbinprogs $sbinprogs_a; do
166 if [ -f "${D}${sbindir}/$p" ]; then
167 mv "${D}${sbindir}/$p" "${D}${base_sbindir}/$p"
168 fi
169 done
170 fi
171
172 if [ "${base_bindir}" != "${bindir}" ]; then
173 mkdir -p ${D}${base_bindir}
174 for p in $binprogs_a; do
175 if [ -f "${D}${bindir}/$p" ]; then
176 mv "${D}${bindir}/$p" "${D}${base_bindir}/$p"
177 fi
178 done
179 fi
180
181 install -d ${D}${sysconfdir}/default/
182 echo 'MOUNTALL="-t nonfs,nosmbfs,noncpfs"' > ${D}${sysconfdir}/default/mountall
183
184 rm -f ${D}${bindir}/chkdupexe
185}
186
187do_install:append:class-target () {
188 if [ "${@bb.utils.filter('PACKAGECONFIG', 'pam', d)}" ]; then
189 install -d ${D}${sysconfdir}/pam.d
190 install -m 0644 ${WORKDIR}/runuser.pamd ${D}${sysconfdir}/pam.d/runuser
191 install -m 0644 ${WORKDIR}/runuser-l.pamd ${D}${sysconfdir}/pam.d/runuser-l
192 # Required for "su -" aka "su --login" because
193 # otherwise it uses "other", which has "auth pam_deny.so"
194 # and thus prevents the operation.
195 ln -s su ${D}${sysconfdir}/pam.d/su-l
196 fi
197}
198# nologin causes a conflict with shadow-native
199# kill causes a conflict with coreutils-native (if ${bindir}==${base_bindir})
200do_install:append:class-native () {
201 rm -f ${D}${base_sbindir}/nologin
202 rm -f ${D}${base_bindir}/kill
203}
204
205# dm-verity support introduces a circular build dependency, so util-linux-libuuid is split out for target builds
206# Need to build libuuid for uuidgen, but then delete it and let the other recipe ship it
207do_install:append () {
208 rm -rf ${D}${includedir}/uuid ${D}${libdir}/pkgconfig/uuid.pc ${D}${libdir}/libuuid* ${D}${base_libdir}/libuuid*
209}
210
211ALTERNATIVE_PRIORITY = "80"
212
213ALTERNATIVE_LINK_NAME[blkid] = "${base_sbindir}/blkid"
214ALTERNATIVE_LINK_NAME[blockdev] = "${base_sbindir}/blockdev"
215ALTERNATIVE_LINK_NAME[cal] = "${bindir}/cal"
216ALTERNATIVE_LINK_NAME[chfn] = "${bindir}/chfn"
217ALTERNATIVE_LINK_NAME[chsh] = "${bindir}/chsh"
218ALTERNATIVE_LINK_NAME[chrt] = "${bindir}/chrt"
219ALTERNATIVE_LINK_NAME[dmesg] = "${base_bindir}/dmesg"
220ALTERNATIVE_LINK_NAME[eject] = "${bindir}/eject"
221ALTERNATIVE_LINK_NAME[fallocate] = "${bindir}/fallocate"
222ALTERNATIVE_LINK_NAME[fdisk] = "${base_sbindir}/fdisk"
223ALTERNATIVE_LINK_NAME[findfs] = "${sbindir}/findfs"
224ALTERNATIVE_LINK_NAME[flock] = "${bindir}/flock"
225ALTERNATIVE_LINK_NAME[fsck] = "${base_sbindir}/fsck"
226ALTERNATIVE_LINK_NAME[fsfreeze] = "${sbindir}/fsfreeze"
227ALTERNATIVE_LINK_NAME[fstrim] = "${base_sbindir}/fstrim"
228ALTERNATIVE_LINK_NAME[getopt] = "${base_bindir}/getopt"
229ALTERNATIVE:${PN}-agetty = "getty"
230ALTERNATIVE_LINK_NAME[getty] = "${base_sbindir}/getty"
231ALTERNATIVE_TARGET[getty] = "${base_sbindir}/agetty"
232ALTERNATIVE_LINK_NAME[hexdump] = "${bindir}/hexdump"
233ALTERNATIVE_LINK_NAME[hwclock] = "${base_sbindir}/hwclock"
234ALTERNATIVE_LINK_NAME[ionice] = "${bindir}/ionice"
Andrew Geissler8f840682023-07-21 09:09:43 -0500235ALTERNATIVE_LINK_NAME[ipcrm] = "${bindir}/ipcrm"
236ALTERNATIVE_LINK_NAME[ipcs] = "${bindir}/ipcs"
Patrick Williams92b42cb2022-09-03 06:53:57 -0500237ALTERNATIVE_LINK_NAME[kill] = "${base_bindir}/kill"
238ALTERNATIVE:${PN}-last = "last lastb"
239ALTERNATIVE_LINK_NAME[last] = "${bindir}/last"
240ALTERNATIVE_LINK_NAME[lastb] = "${bindir}/lastb"
241ALTERNATIVE_LINK_NAME[logger] = "${bindir}/logger"
242ALTERNATIVE_LINK_NAME[losetup] = "${base_sbindir}/losetup"
243ALTERNATIVE_LINK_NAME[mesg] = "${bindir}/mesg"
244ALTERNATIVE_LINK_NAME[mkswap] = "${base_sbindir}/mkswap"
245ALTERNATIVE_LINK_NAME[mcookie] = "${bindir}/mcookie"
246ALTERNATIVE_LINK_NAME[more] = "${base_bindir}/more"
247ALTERNATIVE_LINK_NAME[mount] = "${base_bindir}/mount"
248ALTERNATIVE_LINK_NAME[mountpoint] = "${base_bindir}/mountpoint"
249ALTERNATIVE_LINK_NAME[nologin] = "${base_sbindir}/nologin"
250ALTERNATIVE_LINK_NAME[nsenter] = "${bindir}/nsenter"
251ALTERNATIVE_LINK_NAME[pivot_root] = "${base_sbindir}/pivot_root"
252ALTERNATIVE_LINK_NAME[prlimit] = "${bindir}/prlimit"
253ALTERNATIVE_LINK_NAME[readprofile] = "${sbindir}/readprofile"
254ALTERNATIVE_LINK_NAME[renice] = "${bindir}/renice"
255ALTERNATIVE_LINK_NAME[rev] = "${bindir}/rev"
256ALTERNATIVE_LINK_NAME[rfkill] = "${sbindir}/rfkill"
257ALTERNATIVE_LINK_NAME[rtcwake] = "${sbindir}/rtcwake"
258ALTERNATIVE_LINK_NAME[setpriv] = "${bindir}/setpriv"
259ALTERNATIVE_LINK_NAME[setsid] = "${bindir}/setsid"
260ALTERNATIVE_LINK_NAME[su] = "${base_bindir}/su"
261ALTERNATIVE_LINK_NAME[sulogin] = "${base_sbindir}/sulogin"
262ALTERNATIVE_LINK_NAME[swapoff] = "${base_sbindir}/swapoff"
263ALTERNATIVE_LINK_NAME[swapon] = "${base_sbindir}/swapon"
264ALTERNATIVE_LINK_NAME[switch_root] = "${base_sbindir}/switch_root"
265ALTERNATIVE_LINK_NAME[taskset] = "${bindir}/taskset"
266ALTERNATIVE_LINK_NAME[umount] = "${base_bindir}/umount"
267ALTERNATIVE_LINK_NAME[unshare] = "${bindir}/unshare"
268ALTERNATIVE_LINK_NAME[utmpdump] = "${bindir}/utmpdump"
269ALTERNATIVE_LINK_NAME[uuidgen] = "${bindir}/uuidgen"
270ALTERNATIVE_LINK_NAME[wall] = "${bindir}/wall"
271
272ALTERNATIVE:${PN}-doc = "\
273blkid.8 eject.1 findfs.8 fsck.8 kill.1 last.1 lastb.1 libblkid.3 logger.1 mesg.1 \
274mountpoint.1 nologin.8 rfkill.8 sulogin.8 utmpdump.1 uuid.3 wall.1\
275"
276ALTERNATIVE:${PN}-doc += "${@bb.utils.contains('PACKAGECONFIG', 'pam', 'su.1', '', d)}"
277
278ALTERNATIVE_LINK_NAME[blkid.8] = "${mandir}/man8/blkid.8"
279ALTERNATIVE_LINK_NAME[eject.1] = "${mandir}/man1/eject.1"
280ALTERNATIVE_LINK_NAME[findfs.8] = "${mandir}/man8/findfs.8"
281ALTERNATIVE_LINK_NAME[fsck.8] = "${mandir}/man8/fsck.8"
282ALTERNATIVE_LINK_NAME[kill.1] = "${mandir}/man1/kill.1"
283ALTERNATIVE_LINK_NAME[last.1] = "${mandir}/man1/last.1"
284ALTERNATIVE_LINK_NAME[lastb.1] = "${mandir}/man1/lastb.1"
285ALTERNATIVE_LINK_NAME[libblkid.3] = "${mandir}/man3/libblkid.3"
286ALTERNATIVE_LINK_NAME[logger.1] = "${mandir}/man1/logger.1"
287ALTERNATIVE_LINK_NAME[mesg.1] = "${mandir}/man1/mesg.1"
288ALTERNATIVE_LINK_NAME[mountpoint.1] = "${mandir}/man1/mountpoint.1"
289ALTERNATIVE_LINK_NAME[nologin.8] = "${mandir}/man8/nologin.8"
290ALTERNATIVE_LINK_NAME[rfkill.8] = "${mandir}/man8/rfkill.8"
291ALTERNATIVE_LINK_NAME[setpriv.1] = "${mandir}/man1/setpriv.1"
292ALTERNATIVE_LINK_NAME[su.1] = "${mandir}/man1/su.1"
293ALTERNATIVE_LINK_NAME[sulogin.8] = "${mandir}/man8/sulogin.8"
294ALTERNATIVE_LINK_NAME[utmpdump.1] = "${mandir}/man1/utmpdump.1"
295ALTERNATIVE_LINK_NAME[uuid.3] = "${mandir}/man3/uuid.3"
296ALTERNATIVE_LINK_NAME[wall.1] = "${mandir}/man1/wall.1"
297
298BBCLASSEXTEND = "native nativesdk"
299
300PTEST_BINDIR = "1"
301do_compile_ptest() {
302 oe_runmake buildtest-TESTS
303}
304
305do_install_ptest() {
306 mkdir -p ${D}${PTEST_PATH}/tests/ts
307 find . -name 'test*' -maxdepth 1 -type f -perm -111 -exec cp {} ${D}${PTEST_PATH} \;
308 find ./.libs -name 'sample*' -maxdepth 1 -type f -perm -111 -exec cp {} ${D}${PTEST_PATH} \;
309 find ./.libs -name 'test*' -maxdepth 1 -type f -perm -111 -exec cp {} ${D}${PTEST_PATH} \;
310
311 cp ${S}/tests/*.sh ${D}${PTEST_PATH}/tests/
312 cp -pR ${S}/tests/expected ${D}${PTEST_PATH}/tests/expected
313 cp -pR ${S}/tests/ts ${D}${PTEST_PATH}/tests/
314 cp ${WORKDIR}/build/config.h ${D}${PTEST_PATH}
315
316 sed -i 's|@base_sbindir@|${base_sbindir}|g' ${D}${PTEST_PATH}/run-ptest
317
318 # chfn needs PAM
319 if ! ${@bb.utils.contains('PACKAGECONFIG', 'pam', 'true', 'false', d)}; then
320 rm -rf ${D}${PTEST_PATH}/tests/ts/chfn
321 fi
Patrick Williams169d7bc2024-01-05 11:33:25 -0600322 # remove raid tests, known failures and avoid dependency on mdadm therefore
323 # See https://github.com/util-linux/util-linux/commit/7519c3edab120b14623931d5ddb16fdc6e7cad5d
324 rm -rf ${D}${PTEST_PATH}/tests/ts/blkid/md-raid0-whole
325 rm -rf ${D}${PTEST_PATH}/tests/ts/blkid/md-raid1-part
326 rm -rf ${D}${PTEST_PATH}/tests/ts/blkid/md-raid1-whole
327 rm -rf ${D}${PTEST_PATH}/tests/ts/fdisk/align-512-4K-md
Patrick Williams92b42cb2022-09-03 06:53:57 -0500328}
Andrew Geissler220dafd2023-10-04 10:18:08 -0500329
330# Delete tests not working on musl
331do_install_ptest:append:libc-musl() {
332 for t in tests/ts/col/multibyte \
333 tests/ts/lib/timeutils \
334 tests/ts/dmesg/limit; do
335 rm -rf ${D}${PTEST_PATH}/$t
336 done
337}