blob: 9a50c75e77d150711cc4af3a8cbc2a31e4d14384 [file] [log] [blame]
Andrew Geissler95ac1b82021-03-31 14:34:31 -05001require util-linux.inc
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003#gtk-doc is not enabled as it requires xmlto which requires util-linux
Andrew Geissler09036742021-06-25 14:25:14 -05004inherit autotools gettext pkgconfig systemd update-alternatives python3-dir bash-completion ptest
Andrew Geissler95ac1b82021-03-31 14:34:31 -05005DEPENDS = "libcap-ng ncurses virtual/crypt zlib util-linux-libuuid"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006
Brad Bishop19323692019-04-05 15:28:33 -04007PACKAGES =+ "${PN}-swaponoff"
8PACKAGES += "${@bb.utils.contains('PACKAGECONFIG', 'pylibmount', '${PN}-pylibmount', '', d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009
Brad Bishop19323692019-04-05 15:28:33 -040010python util_linux_binpackages () {
11 def pkg_hook(f, pkg, file_regex, output_pattern, modulename):
12 pn = d.getVar('PN')
13 d.appendVar('RRECOMMENDS_%s' % pn, ' %s' % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014
Brad Bishop19323692019-04-05 15:28:33 -040015 if d.getVar('ALTERNATIVE_' + pkg):
16 return
17 if d.getVarFlag('ALTERNATIVE_LINK_NAME', modulename):
18 d.setVar('ALTERNATIVE_' + pkg, modulename)
19
20 bindirs = sorted(list(set(d.expand("${base_sbindir} ${base_bindir} ${sbindir} ${bindir}").split())))
21 for dir in bindirs:
22 do_split_packages(d, root=dir,
23 file_regex=r'(.*)', output_pattern='${PN}-%s',
24 description='${PN} %s',
25 hook=pkg_hook, extra_depends='')
26
27 # There are some symlinks for some binaries which we have ignored
28 # above. Add them to the package owning the binary they are
29 # pointing to
30 extras = {}
31 dvar = d.getVar('PKGD')
32 for root in bindirs:
33 for walkroot, dirs, files in os.walk(dvar + root):
34 for f in files:
35 file = os.path.join(walkroot, f)
36 if not os.path.islink(file):
37 continue
38
39 pkg = os.path.basename(os.readlink(file))
40 extras[pkg] = extras.get(pkg, '') + ' ' + 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 + 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
Andrew Geissler95ac1b82021-03-31 14:34:31 -050052# skip libuuid as it will be packaged by the util-linux-libuuid recipe
Brad Bishop19323692019-04-05 15:28:33 -040053python util_linux_libpackages() {
Andrew Geissler95ac1b82021-03-31 14:34:31 -050054 do_split_packages(d, root=d.getVar('UTIL_LINUX_LIBDIR'), file_regex=r'^lib(?!uuid)(.*)\.so\..*$',
Brad Bishop19323692019-04-05 15:28:33 -040055 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
64CACHED_CONFIGUREVARS += "scanf_cv_alloc_modifier=ms"
65UTIL_LINUX_LIBDIR = "${libdir}"
66UTIL_LINUX_LIBDIR_class-target = "${base_libdir}"
67EXTRA_OECONF = "\
68 --enable-libuuid --enable-libblkid \
69 \
70 --enable-fsck --enable-kill --enable-last --enable-mesg \
71 --enable-mount --enable-partx --enable-raw --enable-rfkill \
72 --enable-unshare --enable-write \
73 \
74 --disable-bfs --disable-chfn-chsh --disable-login \
75 --disable-makeinstall-chown --disable-minix --disable-newgrp \
76 --disable-use-tty-group --disable-vipw \
77 \
78 --without-udev \
79 \
80 usrsbin_execdir='${sbindir}' \
81 --libdir='${UTIL_LINUX_LIBDIR}' \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082"
83
Brad Bishop15ae2502019-06-18 21:44:24 -040084EXTRA_OECONF_append_class-target = " --enable-setpriv"
85EXTRA_OECONF_append_class-native = " --without-cap-ng --disable-setpriv"
86EXTRA_OECONF_append_class-nativesdk = " --without-cap-ng --disable-setpriv"
Andrew Geissler82c905d2020-04-13 13:39:40 -050087EXTRA_OECONF_append = " --disable-hwclock-gplv3"
Brad Bishop15ae2502019-06-18 21:44:24 -040088
Andrew Geissler82c905d2020-04-13 13:39:40 -050089# enable pcre2 for native/nativesdk to match host distros
90# this helps to keep same expectations when using the SDK or
91# build host versions during development
92#
93PACKAGECONFIG ?= "pcre2"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094PACKAGECONFIG_class-target ?= "${@bb.utils.filter('DISTRO_FEATURES', 'pam', d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095PACKAGECONFIG[pam] = "--enable-su --enable-runuser,--disable-su --disable-runuser, libpam,"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050096# Respect the systemd feature for uuidd
Brad Bishop19323692019-04-05 15:28:33 -040097PACKAGECONFIG[systemd] = "--with-systemd --with-systemdsystemunitdir=${systemd_system_unitdir}, --without-systemd --without-systemdsystemunitdir,systemd"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050098# Build python bindings for libmount
Patrick Williamsc0f7c042017-02-23 20:41:17 -060099PACKAGECONFIG[pylibmount] = "--with-python=3 --enable-pylibmount,--without-python --disable-pylibmount,python3"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500100# Readline support
101PACKAGECONFIG[readline] = "--with-readline,--without-readline,readline"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500102# PCRE support in hardlink
103PACKAGECONFIG[pcre2] = ",,libpcre2"
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500104PACKAGECONFIG[cryptsetup] = "--with-cryptsetup,--without-cryptsetup,cryptsetup"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500105
Brad Bishop19323692019-04-05 15:28:33 -0400106EXTRA_OEMAKE = "ARCH=${TARGET_ARCH} CPU= CPUOPT= 'OPT=${CFLAGS}'"
107
108ALLOW_EMPTY_${PN} = "1"
109FILES_${PN} = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500110FILES_${PN}-doc += "${datadir}/getopt/getopt-*.*"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600111FILES_${PN}-dev += "${PYTHON_SITEPACKAGES_DIR}/libmount/pylibmount.la"
Brad Bishop19323692019-04-05 15:28:33 -0400112FILES_${PN}-mount = "${sysconfdir}/default/mountall"
113FILES_${PN}-runuser = "${sysconfdir}/pam.d/runuser*"
114FILES_${PN}-su = "${sysconfdir}/pam.d/su-l"
115CONFFILES_${PN}-su = "${sysconfdir}/pam.d/su-l"
116FILES_${PN}-pylibmount = "${PYTHON_SITEPACKAGES_DIR}/libmount/pylibmount.so \
117 ${PYTHON_SITEPACKAGES_DIR}/libmount/__init__.* \
118 ${PYTHON_SITEPACKAGES_DIR}/libmount/__pycache__/*"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500119
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500120# Util-linux' blkid replaces the e2fsprogs one
Brad Bishop19323692019-04-05 15:28:33 -0400121RCONFLICTS_${PN}-blkid = "${MLPREFIX}e2fsprogs-blkid"
122RREPLACES_${PN}-blkid = "${MLPREFIX}e2fsprogs-blkid"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500123
124RRECOMMENDS_${PN}_class-native = ""
125RRECOMMENDS_${PN}_class-nativesdk = ""
126RDEPENDS_${PN}_class-native = ""
127RDEPENDS_${PN}_class-nativesdk = ""
128
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500129RDEPENDS_${PN} += " util-linux-libuuid"
130RDEPENDS_${PN}-dev += " util-linux-libuuid-dev"
131
132RPROVIDES_${PN}-dev = "${PN}-libblkid-dev ${PN}-libmount-dev"
Brad Bishop19323692019-04-05 15:28:33 -0400133
134RDEPENDS_${PN}-bash-completion += "${PN}-lsblk"
Brad Bishop15ae2502019-06-18 21:44:24 -0400135RDEPENDS_${PN}-ptest += "bash bc btrfs-tools coreutils e2fsprogs grep iproute2 kmod mdadm procps sed socat which xz"
136RRECOMMENDS_${PN}-ptest += "kernel-module-scsi-debug"
Brad Bishop19323692019-04-05 15:28:33 -0400137RDEPENDS_${PN}-swaponoff = "${PN}-swapon ${PN}-swapoff"
138ALLOW_EMPTY_${PN}-swaponoff = "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139
140#SYSTEMD_PACKAGES = "${PN}-uuidd ${PN}-fstrim"
141SYSTEMD_SERVICE_${PN}-uuidd = "uuidd.socket uuidd.service"
142SYSTEMD_AUTO_ENABLE_${PN}-uuidd = "disable"
143SYSTEMD_SERVICE_${PN}-fstrim = "fstrim.timer fstrim.service"
144SYSTEMD_AUTO_ENABLE_${PN}-fstrim = "disable"
145
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500146do_install () {
147 # with ccache the timestamps on compiled files may
148 # end up earlier than on their inputs, this allows
149 # for the resultant compilation in the install step.
Brad Bishop19323692019-04-05 15:28:33 -0400150 oe_runmake 'CC=${CC}' 'LD=${LD}' \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500151 'LDFLAGS=${LDFLAGS}' 'DESTDIR=${D}' install
152
153 mkdir -p ${D}${base_bindir}
154
155 sbinprogs="agetty ctrlaltdel cfdisk vipw vigr"
Brad Bishop19323692019-04-05 15:28:33 -0400156 sbinprogs_a="pivot_root hwclock mkswap losetup swapon swapoff fdisk fsck blkid blockdev fstrim sulogin switch_root nologin"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400157 binprogs_a="dmesg getopt kill more umount mount login su mountpoint"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158
159 if [ "${base_sbindir}" != "${sbindir}" ]; then
160 mkdir -p ${D}${base_sbindir}
161 for p in $sbinprogs $sbinprogs_a; do
162 if [ -f "${D}${sbindir}/$p" ]; then
163 mv "${D}${sbindir}/$p" "${D}${base_sbindir}/$p"
164 fi
165 done
166 fi
167
168 if [ "${base_bindir}" != "${bindir}" ]; then
169 mkdir -p ${D}${base_bindir}
170 for p in $binprogs_a; do
171 if [ -f "${D}${bindir}/$p" ]; then
172 mv "${D}${bindir}/$p" "${D}${base_bindir}/$p"
173 fi
174 done
175 fi
176
177 install -d ${D}${sysconfdir}/default/
178 echo 'MOUNTALL="-t nonfs,nosmbfs,noncpfs"' > ${D}${sysconfdir}/default/mountall
179
180 rm -f ${D}${bindir}/chkdupexe
Brad Bishopc68388fc2019-08-26 01:33:31 -0400181}
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500182
Brad Bishopc68388fc2019-08-26 01:33:31 -0400183do_install_append_class-target () {
184 if [ "${@bb.utils.filter('PACKAGECONFIG', 'pam', d)}" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500185 install -d ${D}${sysconfdir}/pam.d
186 install -m 0644 ${WORKDIR}/runuser.pamd ${D}${sysconfdir}/pam.d/runuser
187 install -m 0644 ${WORKDIR}/runuser-l.pamd ${D}${sysconfdir}/pam.d/runuser-l
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500188 # Required for "su -" aka "su --login" because
189 # otherwise it uses "other", which has "auth pam_deny.so"
190 # and thus prevents the operation.
191 ln -s su ${D}${sysconfdir}/pam.d/su-l
192 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500193}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400194# nologin causes a conflict with shadow-native
195# kill causes a conflict with coreutils-native (if ${bindir}==${base_bindir})
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500196do_install_append_class-native () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500197 rm -f ${D}${base_sbindir}/nologin
Brad Bishop316dfdd2018-06-25 12:45:53 -0400198 rm -f ${D}${base_bindir}/kill
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500199}
200
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500201# dm-verity support introduces a circular build dependency, so util-linux-libuuid is split out for target builds
202# Need to build libuuid for uuidgen, but then delete it and let the other recipe ship it
203do_install_append () {
204 rm -rf ${D}${includedir}/uuid ${D}${libdir}/pkgconfig/uuid.pc ${D}${libdir}/libuuid* ${D}${base_libdir}/libuuid*
205}
206
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500207ALTERNATIVE_PRIORITY = "80"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500208
Brad Bishop19323692019-04-05 15:28:33 -0400209ALTERNATIVE_LINK_NAME[blkid] = "${base_sbindir}/blkid"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500210ALTERNATIVE_LINK_NAME[blockdev] = "${base_sbindir}/blockdev"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800211ALTERNATIVE_LINK_NAME[cal] = "${bindir}/cal"
Brad Bishop19323692019-04-05 15:28:33 -0400212ALTERNATIVE_LINK_NAME[chrt] = "${bindir}/chrt"
213ALTERNATIVE_LINK_NAME[dmesg] = "${base_bindir}/dmesg"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500214ALTERNATIVE_LINK_NAME[eject] = "${bindir}/eject"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800215ALTERNATIVE_LINK_NAME[fallocate] = "${bindir}/fallocate"
Brad Bishop19323692019-04-05 15:28:33 -0400216ALTERNATIVE_LINK_NAME[fdisk] = "${base_sbindir}/fdisk"
217ALTERNATIVE_LINK_NAME[flock] = "${bindir}/flock"
218ALTERNATIVE_LINK_NAME[fsck] = "${base_sbindir}/fsck"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800219ALTERNATIVE_LINK_NAME[fsfreeze] = "${sbindir}/fsfreeze"
Brad Bishop19323692019-04-05 15:28:33 -0400220ALTERNATIVE_LINK_NAME[fstrim] = "${base_sbindir}/fstrim"
221ALTERNATIVE_LINK_NAME[getopt] = "${base_bindir}/getopt"
222ALTERNATIVE_${PN}-agetty = "getty"
223ALTERNATIVE_LINK_NAME[getty] = "${base_sbindir}/getty"
224ALTERNATIVE_TARGET[getty] = "${base_sbindir}/agetty"
225ALTERNATIVE_LINK_NAME[hexdump] = "${bindir}/hexdump"
226ALTERNATIVE_LINK_NAME[hwclock] = "${base_sbindir}/hwclock"
227ALTERNATIVE_LINK_NAME[ionice] = "${bindir}/ionice"
228ALTERNATIVE_LINK_NAME[kill] = "${base_bindir}/kill"
229ALTERNATIVE_${PN}-last = "last lastb"
230ALTERNATIVE_LINK_NAME[last] = "${bindir}/last"
231ALTERNATIVE_LINK_NAME[lastb] = "${bindir}/lastb"
232ALTERNATIVE_LINK_NAME[logger] = "${bindir}/logger"
233ALTERNATIVE_LINK_NAME[losetup] = "${base_sbindir}/losetup"
234ALTERNATIVE_LINK_NAME[mesg] = "${bindir}/mesg"
235ALTERNATIVE_LINK_NAME[mkswap] = "${base_sbindir}/mkswap"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500236ALTERNATIVE_LINK_NAME[mcookie] = "${bindir}/mcookie"
Brad Bishop19323692019-04-05 15:28:33 -0400237ALTERNATIVE_LINK_NAME[more] = "${base_bindir}/more"
238ALTERNATIVE_LINK_NAME[mount] = "${base_bindir}/mount"
239ALTERNATIVE_LINK_NAME[mountpoint] = "${base_bindir}/mountpoint"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500240ALTERNATIVE_LINK_NAME[nologin] = "${base_sbindir}/nologin"
Brad Bishop19323692019-04-05 15:28:33 -0400241ALTERNATIVE_LINK_NAME[nsenter] = "${bindir}/nsenter"
242ALTERNATIVE_LINK_NAME[pivot_root] = "${base_sbindir}/pivot_root"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500243ALTERNATIVE_LINK_NAME[prlimit] = "${bindir}/prlimit"
Brad Bishop19323692019-04-05 15:28:33 -0400244ALTERNATIVE_LINK_NAME[readprofile] = "${sbindir}/readprofile"
245ALTERNATIVE_LINK_NAME[renice] = "${bindir}/renice"
246ALTERNATIVE_LINK_NAME[rev] = "${bindir}/rev"
247ALTERNATIVE_LINK_NAME[rfkill] = "${sbindir}/rfkill"
Andrew Geissler4ed12e12020-06-05 18:00:41 -0500248ALTERNATIVE_LINK_NAME[rtcwake] = "${sbindir}/rtcwake"
Brad Bishop15ae2502019-06-18 21:44:24 -0400249ALTERNATIVE_LINK_NAME[setpriv] = "${bindir}/setpriv"
Brad Bishop19323692019-04-05 15:28:33 -0400250ALTERNATIVE_LINK_NAME[setsid] = "${bindir}/setsid"
251ALTERNATIVE_LINK_NAME[su] = "${base_bindir}/su"
252ALTERNATIVE_LINK_NAME[sulogin] = "${base_sbindir}/sulogin"
253ALTERNATIVE_LINK_NAME[swapoff] = "${base_sbindir}/swapoff"
254ALTERNATIVE_LINK_NAME[swapon] = "${base_sbindir}/swapon"
255ALTERNATIVE_LINK_NAME[switch_root] = "${base_sbindir}/switch_root"
256ALTERNATIVE_LINK_NAME[taskset] = "${bindir}/taskset"
257ALTERNATIVE_LINK_NAME[umount] = "${base_bindir}/umount"
258ALTERNATIVE_LINK_NAME[unshare] = "${bindir}/unshare"
259ALTERNATIVE_LINK_NAME[utmpdump] = "${bindir}/utmpdump"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500260ALTERNATIVE_LINK_NAME[uuidgen] = "${bindir}/uuidgen"
Brad Bishop19323692019-04-05 15:28:33 -0400261ALTERNATIVE_LINK_NAME[wall] = "${bindir}/wall"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500262
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500263BBCLASSEXTEND = "native nativesdk"
264
Brad Bishopc342db32019-05-15 21:57:59 -0400265PTEST_BINDIR = "1"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500266do_compile_ptest() {
267 oe_runmake buildtest-TESTS
268}
269
270do_install_ptest() {
271 mkdir -p ${D}${PTEST_PATH}/tests/ts
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500272 find . -name 'test*' -maxdepth 1 -type f -perm -111 -exec cp {} ${D}${PTEST_PATH} \;
273 find ./.libs -name 'sample*' -maxdepth 1 -type f -perm -111 -exec cp {} ${D}${PTEST_PATH} \;
274 find ./.libs -name 'test*' -maxdepth 1 -type f -perm -111 -exec cp {} ${D}${PTEST_PATH} \;
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500275
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500276 cp ${S}/tests/*.sh ${D}${PTEST_PATH}/tests/
277 cp -pR ${S}/tests/expected ${D}${PTEST_PATH}/tests/expected
278 cp -pR ${S}/tests/ts ${D}${PTEST_PATH}/tests/
279 cp ${WORKDIR}/build/config.h ${D}${PTEST_PATH}
280
281 # The original paths of executables to be tested point to a local folder containing
282 # the executables. We want to test the installed executables, not the local copies.
283 # So strip the paths, the executables will be located via "which"
284 sed -i \
285 -e '/^TS_CMD/ s|$top_builddir/||g' \
286 -e '/^TS_HELPER/ s|$top_builddir|${PTEST_PATH}|g' \
287 ${D}${PTEST_PATH}/tests/commands.sh
288
289 # Change 'if [ ! -x "$1" ]' to 'if [ ! -x "`which $1 2>/dev/null`"]'
290 sed -i -e \
291 '/^\tif[[:space:]]\[[[:space:]]![[:space:]]-x[[:space:]]"$1"/s|$1|`which $1 2>/dev/null`|g' \
292 ${D}${PTEST_PATH}/tests/functions.sh
293
Brad Bishopc342db32019-05-15 21:57:59 -0400294 # Running "kill" without the the complete path would use the shell's built-in kill
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500295 sed -i -e \
Brad Bishopc342db32019-05-15 21:57:59 -0400296 '/^TS_CMD_KILL/ s|kill|${PTEST_PATH}/bin/kill|g' \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500297 ${D}${PTEST_PATH}/tests/commands.sh
Brad Bishop15ae2502019-06-18 21:44:24 -0400298
299
300 sed -i 's|@base_sbindir@|${base_sbindir}|g' ${D}${PTEST_PATH}/run-ptest
301
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500302}