212d66fe2dbdbd203afd4124e2f3d3c33ce5bacb
[gentoo.git] / sys-apps / util-linux / util-linux-2.35_rc1.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python2_7 python3_{5,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 cryptsetup 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 DEPEND="
33         virtual/os-headers
34         caps? ( sys-libs/libcap-ng )
35         cramfs? ( sys-libs/zlib:= )
36         cryptsetup? ( sys-fs/cryptsetup )
37         ncurses? ( >=sys-libs/ncurses-5.2-r2:0=[unicode?] )
38         nls? ( virtual/libintl[${MULTILIB_USEDEP}] )
39         pam? ( sys-libs/pam )
40         python? ( ${PYTHON_DEPS} )
41         readline? ( sys-libs/readline:0= )
42         selinux? ( >=sys-libs/libselinux-2.2.2-r4[${MULTILIB_USEDEP}] )
43         slang? ( sys-libs/slang )
44         !build? ( systemd? ( sys-apps/systemd ) )
45         udev? ( virtual/libudev:= )"
46 BDEPEND="
47         virtual/pkgconfig
48         nls? ( sys-devel/gettext )
49         test? ( sys-devel/bc )
50 "
51 RDEPEND="${DEPEND}
52         hardlink? ( !app-arch/hardlink )
53         logger? ( !>=app-admin/sysklogd-2.0[logger] )
54         kill? (
55                 !sys-apps/coreutils[kill]
56                 !sys-process/procps[kill]
57         )
58         su? (
59                 !<sys-apps/shadow-4.7-r2
60                 !>=sys-apps/shadow-4.7-r2[su]
61         )
62         !net-wireless/rfkill
63         !sys-process/schedutils
64         !sys-apps/setarch
65         !<sys-apps/sysvinit-2.88-r7
66         !<sys-libs/e2fsprogs-libs-1.41.8
67         !<sys-fs/e2fsprogs-1.41.8
68         !<app-shells/bash-completion-2.7-r1"
69
70 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
71 RESTRICT="!test? ( test )"
72
73 S="${WORKDIR}/${MY_P}"
74
75 src_prepare() {
76         default
77
78         # Prevent uuidd test failure due to socket path limit. #593304
79         sed -i \
80                 -e "s|UUIDD_SOCKET=\"\$(mktemp -u \"\${TS_OUTDIR}/uuiddXXXXXXXXXXXXX\")\"|UUIDD_SOCKET=\"\$(mktemp -u \"${T}/uuiddXXXXXXXXXXXXX.sock\")\"|g" \
81                 tests/ts/uuid/uuidd || die "Failed to fix uuidd test"
82
83         if ! use userland_GNU; then
84                 # test runner is using GNU-specific xargs call
85                 sed -i -e 's:xargs:gxargs:' tests/run.sh || die
86                 # test requires util-linux uuidgen (which we don't build)
87                 rm tests/ts/uuid/oids || die
88         fi
89
90         if [[ ${PV} == 9999 ]] ; then
91                 po/update-potfiles
92                 eautoreconf
93         fi
94
95         # Undo bad ncurses handling by upstream. #601530
96         sed -i -E \
97                 -e '/NCURSES_/s:(ncursesw?)[56]-config:$PKG_CONFIG \1:' \
98                 -e 's:(ncursesw?)[56]-config --version:$PKG_CONFIG --exists --print-errors \1:' \
99                 configure || die
100
101         elibtoolize
102 }
103
104 lfs_fallocate_test() {
105         # Make sure we can use fallocate with LFS #300307
106         cat <<-EOF > "${T}"/fallocate.${ABI}.c
107                 #define _GNU_SOURCE
108                 #include <fcntl.h>
109                 main() { return fallocate(0, 0, 0, 0); }
110         EOF
111         append-lfs-flags
112         $(tc-getCC) ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} "${T}"/fallocate.${ABI}.c -o /dev/null >/dev/null 2>&1 \
113                 || export ac_cv_func_fallocate=no
114         rm -f "${T}"/fallocate.${ABI}.c
115 }
116
117 python_configure() {
118         local myeconfargs=(
119                 "${commonargs[@]}"
120                 --disable-all-programs
121                 --disable-bash-completion
122                 --without-systemdsystemunitdir
123                 --with-python
124         )
125         if use userland_GNU; then
126                 myeconfargs+=(
127                         --enable-libblkid
128                         --enable-libmount
129                         --enable-pylibmount
130                 )
131         fi
132         mkdir "${BUILD_DIR}" || die
133         pushd "${BUILD_DIR}" >/dev/null || die
134         ECONF_SOURCE="${S}" econf "${myeconfargs[@]}"
135         popd >/dev/null || die
136 }
137
138 multilib_src_configure() {
139         lfs_fallocate_test
140         # The scanf test in a run-time test which fails while cross-compiling.
141         # Blindly assume a POSIX setup since we require libmount, and libmount
142         # itself fails when the scanf test fails. #531856
143         tc-is-cross-compiler && export scanf_cv_alloc_modifier=ms
144         export ac_cv_header_security_pam_misc_h=$(multilib_native_usex pam) #485486
145         export ac_cv_header_security_pam_appl_h=$(multilib_native_usex pam) #545042
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                         $(use_with cryptsetup)
198                 )
199         else
200                 myeconfargs+=(
201                         --disable-all-programs
202                         --disable-bash-completion
203                         --without-systemdsystemunitdir
204                         # build libraries
205                         --enable-libuuid
206                         --enable-libblkid
207                         --enable-libsmartcols
208                         --enable-libfdisk
209                 )
210                 if use userland_GNU; then
211                         # those libraries don't work on *BSD
212                         myeconfargs+=(
213                                 --enable-libmount
214                         )
215                 fi
216         fi
217         ECONF_SOURCE="${S}" econf "${myeconfargs[@]}"
218
219         if multilib_is_native_abi && use python; then
220                 python_foreach_impl python_configure
221         fi
222 }
223
224 python_compile() {
225         pushd "${BUILD_DIR}" >/dev/null || die
226         emake all
227         popd >/dev/null || die
228 }
229
230 multilib_src_compile() {
231         emake all
232
233         if multilib_is_native_abi && use python; then
234                 python_foreach_impl python_compile
235         fi
236 }
237
238 python_test() {
239         pushd "${BUILD_DIR}" >/dev/null || die
240         emake check TS_OPTS="--parallel=$(makeopts_jobs) --nonroot"
241         popd >/dev/null || die
242 }
243
244 multilib_src_test() {
245         emake check TS_OPTS="--parallel=$(makeopts_jobs) --nonroot"
246         if multilib_is_native_abi && use python; then
247                 python_foreach_impl python_test
248         fi
249 }
250
251 python_install() {
252         pushd "${BUILD_DIR}" >/dev/null || die
253         emake DESTDIR="${D}" install
254         python_optimize
255         popd >/dev/null || die
256 }
257
258 multilib_src_install() {
259         if multilib_is_native_abi && use python; then
260                 python_foreach_impl python_install
261         fi
262
263         # This needs to be called AFTER python_install call (#689190)
264         emake DESTDIR="${D}" install
265
266         if multilib_is_native_abi && use userland_GNU; then
267                 # need the libs in /
268                 gen_usr_ldscript -a blkid fdisk mount smartcols uuid
269         fi
270 }
271
272 multilib_src_install_all() {
273         dodoc AUTHORS NEWS README* Documentation/{TODO,*.txt,releases/*}
274
275         # e2fsprogs-libs didnt install .la files, and .pc work fine
276         find "${ED}" -name "*.la" -delete || die
277
278         if ! use userland_GNU; then
279                 # manpage collisions
280                 # TODO: figure out a good way to keep them
281                 rm "${ED}"/usr/share/man/man3/uuid* || die
282         fi
283
284         if use pam; then
285                 newpamd "${FILESDIR}/runuser.pamd" runuser
286                 newpamd "${FILESDIR}/runuser-l.pamd" runuser-l
287         fi
288
289         # Note:
290         # Bash completion for "runuser" command is provided by same file which
291         # would also provide bash completion for "su" command. However, we don't
292         # use "su" command from this package.
293         # This triggers a known QA warning which we ignore for now to magically
294         # keep bash completion for "su" command which shadow package does not
295         # provide.
296 }
297
298 pkg_postinst() {
299         if ! use tty-helpers; then
300                 elog "The mesg/wall/write tools have been disabled due to USE=-tty-helpers."
301         fi
302
303         if [[ -z ${REPLACING_VERSIONS} ]]; then
304                 elog "The agetty util now clears the terminal by default. You"
305                 elog "might want to add --noclear to your /etc/inittab lines."
306         fi
307 }