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