2cf70d9af7ee3abdfbbcb616e4eb2eca13fccb13
[gentoo.git] / sys-apps / kmod / kmod-9999.ebuild
1 # Copyright 1999-2019 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_{5,6,7}} )
7
8 inherit bash-completion-r1 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 libressl lzma pkcs7 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         pkcs7? (
40                 !libressl? ( >=dev-libs/openssl-1.1.0:0= )
41                 libressl? ( dev-libs/libressl:0= )
42         )
43         zlib? ( >=sys-libs/zlib-1.2.6 )" #427130
44 DEPEND="${RDEPEND}
45         doc? ( dev-util/gtk-doc )
46         lzma? ( virtual/pkgconfig )
47         python? (
48                 dev-python/cython[${PYTHON_USEDEP}]
49                 virtual/pkgconfig
50                 )
51         zlib? ( virtual/pkgconfig )"
52 if [[ ${PV} == 9999* ]]; then
53         DEPEND="${DEPEND}
54                 dev-libs/libxslt"
55 fi
56
57 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
58
59 DOCS="NEWS README TODO"
60
61 src_prepare() {
62         default
63
64         if [[ ! -e configure ]] ; then
65                 if use doc; then
66                         gtkdocize --copy --docdir libkmod/docs || die
67                 else
68                         touch libkmod/docs/gtk-doc.make
69                 fi
70                 eautoreconf
71         else
72                 elibtoolize
73         fi
74
75         # Restore possibility of running --enable-static wrt #472608
76         sed -i \
77                 -e '/--enable-static is not supported by kmod/s:as_fn_error:echo:' \
78                 configure || die
79 }
80
81 src_configure() {
82         local myeconfargs=(
83                 --bindir="${EPREFIX}/bin"
84                 --enable-shared
85                 --with-bashcompletiondir="$(get_bashcompdir)"
86                 --with-rootlibdir="${EPREFIX}/$(get_libdir)"
87                 $(use_enable debug)
88                 $(use_enable doc gtk-doc)
89                 $(use_enable static-libs static)
90                 $(use_enable tools)
91                 $(use_with lzma xz)
92                 $(use_with pkcs7 openssl)
93                 $(use_with zlib)
94         )
95
96         local ECONF_SOURCE="${S}"
97
98         kmod_configure() {
99                 mkdir -p "${BUILD_DIR}" || die
100                 run_in_build_dir econf "${myeconfargs[@]}" "$@"
101         }
102
103         BUILD_DIR="${WORKDIR}/build"
104         kmod_configure --disable-python
105
106         if use python; then
107                 python_foreach_impl kmod_configure --enable-python
108         fi
109 }
110
111 src_compile() {
112         emake -C "${BUILD_DIR}"
113
114         if use python; then
115                 local native_builddir=${BUILD_DIR}
116
117                 python_compile() {
118                         emake -C "${BUILD_DIR}" -f Makefile -f - python \
119                                 VPATH="${native_builddir}:${S}" \
120                                 native_builddir="${native_builddir}" \
121                                 libkmod_python_kmod_{kmod,list,module,_util}_la_LIBADD='$(PYTHON_LIBS) $(native_builddir)/libkmod/libkmod.la' \
122                                 <<< 'python: $(pkgpyexec_LTLIBRARIES)'
123                 }
124
125                 python_foreach_impl python_compile
126         fi
127 }
128
129 src_install() {
130         emake -C "${BUILD_DIR}" DESTDIR="${D}" install
131         einstalldocs
132
133         if use python; then
134                 local native_builddir=${BUILD_DIR}
135
136                 python_install() {
137                         emake -C "${BUILD_DIR}" DESTDIR="${D}" \
138                                 VPATH="${native_builddir}:${S}" \
139                                 install-pkgpyexecLTLIBRARIES \
140                                 install-dist_pkgpyexecPYTHON
141                 }
142
143                 python_foreach_impl python_install
144         fi
145
146         find "${ED}" -name "*.la" -delete || die
147
148         if use tools; then
149                 local cmd
150                 for cmd in depmod insmod modprobe rmmod; do
151                         dosym ../bin/kmod /sbin/${cmd}
152                 done
153
154                 # These are also usable as normal user
155                 for cmd in lsmod modinfo; do
156                         dosym kmod /bin/${cmd}
157                 done
158         fi
159
160         cat <<-EOF > "${T}"/usb-load-ehci-first.conf
161         softdep uhci_hcd pre: ehci_hcd
162         softdep ohci_hcd pre: ehci_hcd
163         EOF
164
165         insinto /lib/modprobe.d
166         doins "${T}"/usb-load-ehci-first.conf #260139
167
168         newinitd "${FILESDIR}"/kmod-static-nodes-r1 kmod-static-nodes
169 }
170
171 pkg_postinst() {
172         if [[ -L ${EROOT%/}/etc/runlevels/boot/static-nodes ]]; then
173                 ewarn "Removing old conflicting static-nodes init script from the boot runlevel"
174                 rm -f "${EROOT%/}"/etc/runlevels/boot/static-nodes
175         fi
176
177         # Add kmod to the runlevel automatically if this is the first install of this package.
178         if [[ -z ${REPLACING_VERSIONS} ]]; then
179                 if [[ ! -d ${EROOT%/}/etc/runlevels/sysinit ]]; then
180                         mkdir -p "${EROOT%/}"/etc/runlevels/sysinit
181                 fi
182                 if [[ -x ${EROOT%/}/etc/init.d/kmod-static-nodes ]]; then
183                         ln -s /etc/init.d/kmod-static-nodes "${EROOT%/}"/etc/runlevels/sysinit/kmod-static-nodes
184                 fi
185         fi
186
187         if [[ -e ${EROOT%/}/etc/runlevels/sysinit ]]; then
188                 if [[ ! -e ${EROOT%/}/etc/runlevels/sysinit/kmod-static-nodes ]]; then
189                         ewarn
190                         ewarn "You need to add kmod-static-nodes to the sysinit runlevel for"
191                         ewarn "kernel modules to have required static nodes!"
192                         ewarn "Run this command:"
193                         ewarn "\trc-update add kmod-static-nodes sysinit"
194                 fi
195         fi
196 }