*/*: Clean PYTHON_COMPAT of obsolete impls
[gentoo.git] / sys-apps / kmod / kmod-25.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 PYTHON_COMPAT=( python{2_7,3_6} )
7
8 inherit bash-completion-r1 ltprune multilib python-r1
9
10 if [[ ${PV} == 9999* ]]; then
11         EGIT_REPO_URI="https://git.kernel.org/pub/scm/utils/kernel/${PN}/${PN}.git"
12         inherit autotools git-r3
13 else
14         SRC_URI="https://www.kernel.org/pub/linux/utils/kernel/kmod/${P}.tar.xz"
15         KEYWORDS="alpha amd64 arm arm64 hppa ia64 m68k ~mips ppc ppc64 s390 sh sparc x86"
16         inherit libtool
17 fi
18
19 DESCRIPTION="library and tools for managing linux kernel modules"
20 HOMEPAGE="https://git.kernel.org/?p=utils/kernel/kmod/kmod.git"
21
22 LICENSE="LGPL-2"
23 SLOT="0"
24 IUSE="debug doc lzma python static-libs +tools zlib"
25
26 # Upstream does not support running the test suite with custom configure flags.
27 # I was also told that the test suite is intended for kmod developers.
28 # So we have to restrict it.
29 # See bug #408915.
30 RESTRICT="test"
31
32 # Block systemd below 217 for -static-nodes-indicate-that-creation-of-static-nodes-.patch
33 RDEPEND="!sys-apps/module-init-tools
34         !sys-apps/modutils
35         !<sys-apps/openrc-0.13.8
36         !<sys-apps/systemd-216-r3
37         lzma? ( >=app-arch/xz-utils-5.0.4-r1 )
38         python? ( ${PYTHON_DEPS} )
39         zlib? ( >=sys-libs/zlib-1.2.6 )" #427130
40 DEPEND="${RDEPEND}
41         doc? ( dev-util/gtk-doc )
42         lzma? ( virtual/pkgconfig )
43         python? (
44                 dev-python/cython[${PYTHON_USEDEP}]
45                 virtual/pkgconfig
46                 )
47         zlib? ( virtual/pkgconfig )"
48 if [[ ${PV} == 9999* ]]; then
49         DEPEND="${DEPEND}
50                 dev-libs/libxslt"
51 fi
52
53 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
54
55 DOCS="NEWS README TODO"
56
57 src_prepare() {
58         default
59
60         if [ ! -e configure ]; then
61                 if use doc; then
62                         gtkdocize --copy --docdir libkmod/docs || die
63                 else
64                         touch libkmod/docs/gtk-doc.make
65                 fi
66                 eautoreconf
67         else
68                 elibtoolize
69         fi
70
71         # Restore possibility of running --enable-static wrt #472608
72         sed -i \
73                 -e '/--enable-static is not supported by kmod/s:as_fn_error:echo:' \
74                 configure || die
75 }
76
77 src_configure() {
78         local myeconfargs=(
79                 --bindir="${EPREFIX}/bin"
80                 --enable-shared
81                 --with-bashcompletiondir="$(get_bashcompdir)"
82                 --with-rootlibdir="${EPREFIX}/$(get_libdir)"
83                 $(use_enable debug)
84                 $(use_enable doc gtk-doc)
85                 $(use_enable static-libs static)
86                 $(use_enable tools)
87                 $(use_with lzma xz)
88                 $(use_with zlib)
89         )
90
91         local ECONF_SOURCE="${S}"
92
93         kmod_configure() {
94                 mkdir -p "${BUILD_DIR}" || die
95                 run_in_build_dir econf "${myeconfargs[@]}" "$@"
96         }
97
98         BUILD_DIR="${WORKDIR}/build"
99         kmod_configure --disable-python
100
101         if use python; then
102                 python_foreach_impl kmod_configure --enable-python
103         fi
104 }
105
106 src_compile() {
107         emake -C "${BUILD_DIR}"
108
109         if use python; then
110                 local native_builddir=${BUILD_DIR}
111
112                 python_compile() {
113                         emake -C "${BUILD_DIR}" -f Makefile -f - python \
114                                 VPATH="${native_builddir}:${S}" \
115                                 native_builddir="${native_builddir}" \
116                                 libkmod_python_kmod_{kmod,list,module,_util}_la_LIBADD='$(PYTHON_LIBS) $(native_builddir)/libkmod/libkmod.la' \
117                                 <<< 'python: $(pkgpyexec_LTLIBRARIES)'
118                 }
119
120                 python_foreach_impl python_compile
121         fi
122 }
123
124 src_install() {
125         emake -C "${BUILD_DIR}" DESTDIR="${D}" install
126         einstalldocs
127
128         if use python; then
129                 local native_builddir=${BUILD_DIR}
130
131                 python_install() {
132                         emake -C "${BUILD_DIR}" DESTDIR="${D}" \
133                                 VPATH="${native_builddir}:${S}" \
134                                 install-pkgpyexecLTLIBRARIES \
135                                 install-dist_pkgpyexecPYTHON
136                 }
137
138                 python_foreach_impl python_install
139         fi
140
141         prune_libtool_files --modules
142
143         if use tools; then
144                 local bincmd sbincmd
145                 for sbincmd in depmod insmod lsmod modinfo modprobe rmmod; do
146                         dosym ../bin/kmod /sbin/${sbincmd}
147                 done
148
149                 # These are also usable as normal user
150                 for bincmd in lsmod modinfo; do
151                         dosym kmod /bin/${bincmd}
152                 done
153         fi
154
155         cat <<-EOF > "${T}"/usb-load-ehci-first.conf
156         softdep uhci_hcd pre: ehci_hcd
157         softdep ohci_hcd pre: ehci_hcd
158         EOF
159
160         insinto /lib/modprobe.d
161         doins "${T}"/usb-load-ehci-first.conf #260139
162
163         newinitd "${FILESDIR}"/kmod-static-nodes-r1 kmod-static-nodes
164 }
165
166 pkg_postinst() {
167         if [[ -L ${EROOT%/}/etc/runlevels/boot/static-nodes ]]; then
168                 ewarn "Removing old conflicting static-nodes init script from the boot runlevel"
169                 rm -f "${EROOT%/}"/etc/runlevels/boot/static-nodes
170         fi
171
172         # Add kmod to the runlevel automatically if this is the first install of this package.
173         if [[ -z ${REPLACING_VERSIONS} ]]; then
174                 if [[ ! -d ${EROOT%/}/etc/runlevels/sysinit ]]; then
175                         mkdir -p "${EROOT%/}"/etc/runlevels/sysinit
176                 fi
177                 if [[ -x ${EROOT%/}/etc/init.d/kmod-static-nodes ]]; then
178                         ln -s /etc/init.d/kmod-static-nodes "${EROOT%/}"/etc/runlevels/sysinit/kmod-static-nodes
179                 fi
180         fi
181
182         if [[ -e ${EROOT%/}/etc/runlevels/sysinit ]]; then
183                 if [[ ! -e ${EROOT%/}/etc/runlevels/sysinit/kmod-static-nodes ]]; then
184                         ewarn
185                         ewarn "You need to add kmod-static-nodes to the sysinit runlevel for"
186                         ewarn "kernel modules to have required static nodes!"
187                         ewarn "Run this command:"
188                         ewarn "\trc-update add kmod-static-nodes sysinit"
189                 fi
190         fi
191 }