sys-apps/util-linux: Don't RDEPEND on virtual/os-headers
[gentoo.git] / sys-apps / util-linux / util-linux-2.34-r3.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python3_{6,7} )
7
8 inherit toolchain-funcs libtool flag-o-matic bash-completion-r1 usr-ldscript \
9         pam python-r1 multilib-minimal multiprocessing systemd
10
11 MY_PV="${PV/_/-}"
12 MY_P="${PN}-${MY_PV}"
13
14 if [[ ${PV} == 9999 ]] ; then
15         inherit git-r3 autotools
16         EGIT_REPO_URI="https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git"
17 else
18         [[ "${PV}" = *_rc* ]] || \
19         KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sh ~sparc ~x86 ~amd64-linux ~x86-linux"
20         SRC_URI="https://www.kernel.org/pub/linux/utils/util-linux/v${PV:0:4}/${MY_P}.tar.xz"
21 fi
22
23 DESCRIPTION="Various useful Linux utilities"
24 HOMEPAGE="https://www.kernel.org/pub/linux/utils/util-linux/ https://github.com/karelzak/util-linux"
25
26 LICENSE="GPL-2 LGPL-2.1 BSD-4 MIT public-domain"
27 SLOT="0"
28 IUSE="build caps +cramfs fdformat hardlink kill +logger ncurses nls pam python +readline selinux slang static-libs su +suid systemd test tty-helpers udev unicode userland_GNU"
29
30 # Most lib deps here are related to programs rather than our libs,
31 # so we rarely need to specify ${MULTILIB_USEDEP}.
32 RDEPEND="
33         caps? ( sys-libs/libcap-ng )
34         cramfs? ( sys-libs/zlib:= )
35         ncurses? ( >=sys-libs/ncurses-5.2-r2:0=[unicode?] )
36         nls? ( virtual/libintl[${MULTILIB_USEDEP}] )
37         pam? ( sys-libs/pam )
38         python? ( ${PYTHON_DEPS} )
39         readline? ( sys-libs/readline:0= )
40         selinux? ( >=sys-libs/libselinux-2.2.2-r4[${MULTILIB_USEDEP}] )
41         slang? ( sys-libs/slang )
42         !build? ( systemd? ( sys-apps/systemd ) )
43         udev? ( virtual/libudev:= )"
44 BDEPEND="
45         virtual/pkgconfig
46         nls? ( sys-devel/gettext )
47         test? ( sys-devel/bc )
48 "
49 DEPEND="
50         ${RDEPEND}
51         virtual/os-headers
52 "
53 RDEPEND+="
54         hardlink? ( !app-arch/hardlink )
55         logger? ( !>=app-admin/sysklogd-2.0[logger] )
56         kill? (
57                 !sys-apps/coreutils[kill]
58                 !sys-process/procps[kill]
59         )
60         su? (
61                 !<sys-apps/shadow-4.7-r2
62                 !>=sys-apps/shadow-4.7-r2[su]
63         )
64         !net-wireless/rfkill
65         !sys-process/schedutils
66         !sys-apps/setarch
67         !<sys-apps/sysvinit-2.88-r7
68         !<sys-libs/e2fsprogs-libs-1.41.8
69         !<sys-fs/e2fsprogs-1.41.8
70         !<app-shells/bash-completion-2.7-r1"
71
72 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
73 RESTRICT="!test? ( test )"
74
75 S="${WORKDIR}/${MY_P}"
76
77 src_prepare() {
78         default
79
80         # Prevent uuidd test failure due to socket path limit. #593304
81         sed -i \
82                 -e "s|UUIDD_SOCKET=\"\$(mktemp -u \"\${TS_OUTDIR}/uuiddXXXXXXXXXXXXX\")\"|UUIDD_SOCKET=\"\$(mktemp -u \"${T}/uuiddXXXXXXXXXXXXX.sock\")\"|g" \
83                 tests/ts/uuid/uuidd || die "Failed to fix uuidd test"
84
85         if ! use userland_GNU; then
86                 # test runner is using GNU-specific xargs call
87                 sed -i -e 's:xargs:gxargs:' tests/run.sh || die
88                 # test requires util-linux uuidgen (which we don't build)
89                 rm tests/ts/uuid/oids || die
90         fi
91
92         if [[ ${PV} == 9999 ]] ; then
93                 po/update-potfiles
94                 eautoreconf
95         fi
96
97         elibtoolize
98 }
99
100 lfs_fallocate_test() {
101         # Make sure we can use fallocate with LFS #300307
102         cat <<-EOF > "${T}"/fallocate.${ABI}.c
103                 #define _GNU_SOURCE
104                 #include <fcntl.h>
105                 main() { return fallocate(0, 0, 0, 0); }
106         EOF
107         append-lfs-flags
108         $(tc-getCC) ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} "${T}"/fallocate.${ABI}.c -o /dev/null >/dev/null 2>&1 \
109                 || export ac_cv_func_fallocate=no
110         rm -f "${T}"/fallocate.${ABI}.c
111 }
112
113 python_configure() {
114         local myeconfargs=(
115                 "${commonargs[@]}"
116                 --disable-all-programs
117                 --disable-bash-completion
118                 --without-systemdsystemunitdir
119                 --with-python
120         )
121         if use userland_GNU; then
122                 myeconfargs+=(
123                         --enable-libblkid
124                         --enable-libmount
125                         --enable-pylibmount
126                 )
127         fi
128         mkdir "${BUILD_DIR}" || die
129         pushd "${BUILD_DIR}" >/dev/null || die
130         ECONF_SOURCE="${S}" econf "${myeconfargs[@]}"
131         popd >/dev/null || die
132 }
133
134 multilib_src_configure() {
135         lfs_fallocate_test
136         # The scanf test in a run-time test which fails while cross-compiling.
137         # Blindly assume a POSIX setup since we require libmount, and libmount
138         # itself fails when the scanf test fails. #531856
139         tc-is-cross-compiler && export scanf_cv_alloc_modifier=ms
140         export ac_cv_header_security_pam_misc_h=$(multilib_native_usex pam) #485486
141         export ac_cv_header_security_pam_appl_h=$(multilib_native_usex pam) #545042
142
143         # Undo bad ncurses handling by upstream. Fall back to pkg-config. #601530
144         export NCURSES6_CONFIG=false NCURSES5_CONFIG=false
145         export NCURSESW6_CONFIG=false NCURSESW5_CONFIG=false
146
147         # configure args shared by python and non-python builds
148         local commonargs=(
149                 --enable-fs-paths-extra="${EPREFIX}/usr/sbin:${EPREFIX}/bin:${EPREFIX}/usr/bin"
150         )
151
152         local myeconfargs=(
153                 "${commonargs[@]}"
154                 --with-bashcompletiondir="$(get_bashcompdir)"
155                 --without-python
156                 $(multilib_native_use_enable suid makeinstall-chown)
157                 $(multilib_native_use_enable suid makeinstall-setuid)
158                 $(multilib_native_use_with readline)
159                 $(multilib_native_use_with slang)
160                 $(multilib_native_use_with systemd)
161                 $(multilib_native_use_with udev)
162                 $(multilib_native_usex ncurses "$(use_with unicode ncursesw)" '--without-ncursesw')
163                 $(multilib_native_usex ncurses "$(use_with !unicode ncurses)" '--without-ncurses')
164                 $(tc-has-tls || echo --disable-tls)
165                 $(use_enable nls)
166                 $(use_enable unicode widechar)
167                 $(use_enable static-libs static)
168                 $(use_with ncurses tinfo)
169                 $(use_with selinux)
170         )
171         # build programs only on GNU, on *BSD we want libraries only
172         if multilib_is_native_abi && use userland_GNU; then
173                 myeconfargs+=(
174                         --disable-chfn-chsh
175                         --disable-login
176                         --disable-nologin
177                         --disable-pylibmount
178                         --enable-agetty
179                         --enable-bash-completion
180                         --enable-line
181                         --enable-partx
182                         --enable-raw
183                         --enable-rename
184                         --enable-rfkill
185                         --enable-schedutils
186                         --with-systemdsystemunitdir="$(systemd_get_systemunitdir)"
187                         $(use_enable caps setpriv)
188                         $(use_enable cramfs)
189                         $(use_enable fdformat)
190                         $(use_enable hardlink)
191                         $(use_enable kill)
192                         $(use_enable logger)
193                         $(use_enable su)
194                         $(use_enable tty-helpers mesg)
195                         $(use_enable tty-helpers wall)
196                         $(use_enable tty-helpers write)
197                 )
198         else
199                 myeconfargs+=(
200                         --disable-all-programs
201                         --disable-bash-completion
202                         --without-systemdsystemunitdir
203                         # build libraries
204                         --enable-libuuid
205                         --enable-libblkid
206                         --enable-libsmartcols
207                         --enable-libfdisk
208                 )
209                 if use userland_GNU; then
210                         # those libraries don't work on *BSD
211                         myeconfargs+=(
212                                 --enable-libmount
213                         )
214                 fi
215         fi
216         ECONF_SOURCE="${S}" econf "${myeconfargs[@]}"
217
218         if multilib_is_native_abi && use python; then
219                 python_foreach_impl python_configure
220         fi
221 }
222
223 python_compile() {
224         pushd "${BUILD_DIR}" >/dev/null || die
225         emake all
226         popd >/dev/null || die
227 }
228
229 multilib_src_compile() {
230         emake all
231
232         if multilib_is_native_abi && use python; then
233                 python_foreach_impl python_compile
234         fi
235 }
236
237 python_test() {
238         pushd "${BUILD_DIR}" >/dev/null || die
239         emake check TS_OPTS="--parallel=$(makeopts_jobs) --nonroot"
240         popd >/dev/null || die
241 }
242
243 multilib_src_test() {
244         emake check TS_OPTS="--parallel=$(makeopts_jobs) --nonroot"
245         if multilib_is_native_abi && use python; then
246                 python_foreach_impl python_test
247         fi
248 }
249
250 python_install() {
251         pushd "${BUILD_DIR}" >/dev/null || die
252         emake DESTDIR="${D}" install
253         python_optimize
254         popd >/dev/null || die
255 }
256
257 multilib_src_install() {
258         if multilib_is_native_abi && use python; then
259                 python_foreach_impl python_install
260         fi
261
262         # This needs to be called AFTER python_install call (#689190)
263         emake DESTDIR="${D}" install
264
265         if multilib_is_native_abi && use userland_GNU; then
266                 # need the libs in /
267                 gen_usr_ldscript -a blkid fdisk mount smartcols uuid
268         fi
269 }
270
271 multilib_src_install_all() {
272         dodoc AUTHORS NEWS README* Documentation/{TODO,*.txt,releases/*}
273
274         # e2fsprogs-libs didnt install .la files, and .pc work fine
275         find "${ED}" -name "*.la" -delete || die
276
277         if ! use userland_GNU; then
278                 # manpage collisions
279                 # TODO: figure out a good way to keep them
280                 rm "${ED}"/usr/share/man/man3/uuid* || die
281         fi
282
283         if use pam; then
284                 newpamd "${FILESDIR}/runuser.pamd" runuser
285                 newpamd "${FILESDIR}/runuser-l.pamd" runuser-l
286         fi
287
288         # Note:
289         # Bash completion for "runuser" command is provided by same file which
290         # would also provide bash completion for "su" command. However, we don't
291         # use "su" command from this package.
292         # This triggers a known QA warning which we ignore for now to magically
293         # keep bash completion for "su" command which shadow package does not
294         # provide.
295 }
296
297 pkg_postinst() {
298         if ! use tty-helpers; then
299                 elog "The mesg/wall/write tools have been disabled due to USE=-tty-helpers."
300         fi
301
302         if [[ -z ${REPLACING_VERSIONS} ]]; then
303                 elog "The agetty util now clears the terminal by default. You"
304                 elog "might want to add --noclear to your /etc/inittab lines."
305         fi
306 }