sys-apps/iproute2: Bump to version 5.1.0
[gentoo.git] / sys-apps / iproute2 / iproute2-5.1.0.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 inherit toolchain-funcs flag-o-matic multilib
7
8 if [[ ${PV} == "9999" ]] ; then
9         EGIT_REPO_URI="https://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git"
10         inherit git-r3
11 else
12         SRC_URI="mirror://kernel/linux/utils/net/${PN}/${P}.tar.xz"
13         KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sh ~sparc ~x86"
14 fi
15
16 DESCRIPTION="kernel routing and traffic control utilities"
17 HOMEPAGE="https://wiki.linuxfoundation.org/networking/iproute2"
18
19 LICENSE="GPL-2"
20 SLOT="0"
21 IUSE="atm berkdb caps elf +iptables ipv6 minimal selinux"
22
23 # We could make libmnl optional, but it's tiny, so eh
24 RDEPEND="
25         !net-misc/arpd
26         dev-libs/libbsd
27         !minimal? ( net-libs/libmnl )
28         caps? ( sys-libs/libcap )
29         elf? ( virtual/libelf )
30         iptables? ( >=net-firewall/iptables-1.4.20:= )
31         berkdb? ( sys-libs/db:= )
32         atm? ( net-dialup/linux-atm )
33         selinux? ( sys-libs/libselinux )
34 "
35 DEPEND="
36         ${RDEPEND}
37 "
38 # We require newer linux-headers for ipset support #549948 and some defines #553876
39 BDEPEND="
40         app-arch/xz-utils
41         >=sys-devel/bison-2.4
42         sys-devel/flex
43         >=sys-kernel/linux-headers-3.16
44         virtual/pkgconfig
45         elibc_glibc? ( >=sys-libs/glibc-2.7 )
46 "
47
48 PATCHES=(
49         "${FILESDIR}"/${PN}-3.1.0-mtu.patch #291907
50         "${FILESDIR}"/${PN}-4.20.0-configure-nomagic.patch # bug 643722
51 )
52
53 src_prepare() {
54         if ! use ipv6 ; then
55                 PATCHES+=(
56                         "${FILESDIR}"/${PN}-4.20.0-no-ipv6.patch #326849
57                 )
58         fi
59
60         default
61
62         sed -i \
63                 -e '/^CC :\?=/d' \
64                 -e "/^LIBDIR/s:=.*:=/$(get_libdir):" \
65                 -e "s|-O2|${CFLAGS} ${CPPFLAGS}|" \
66                 -e "/^HOSTCC/s:=.*:= $(tc-getBUILD_CC):" \
67                 -e "/^DBM_INCLUDE/s:=.*:=${T}:" \
68                 Makefile || die
69
70         # Use /run instead of /var/run.
71         sed -i \
72                 -e 's:/var/run:/run:g' \
73                 include/namespace.h \
74                 man/man8/ip-netns.8 || die
75
76         # build against system headers
77         rm -r include/netinet || die #include/linux include/ip{,6}tables{,_common}.h include/libiptc
78         sed -i 's:TCPI_OPT_ECN_SEEN:16:' misc/ss.c || die
79
80         if use minimal ; then
81                 sed -i -e '/^SUBDIRS=/s:=.*:=lib tc ip:' Makefile || die
82         fi
83 }
84
85 src_configure() {
86         tc-export AR CC PKG_CONFIG
87
88         # This sure is ugly.  Should probably move into toolchain-funcs at some point.
89         local setns
90         pushd "${T}" >/dev/null
91         printf '#include <sched.h>\nint main(){return setns(0, 0);}\n' > test.c
92         ${CC} ${CFLAGS} ${CPPFLAGS} -D_GNU_SOURCE ${LDFLAGS} test.c >&/dev/null && setns=y || setns=n
93         echo 'int main(){return 0;}' > test.c
94         ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} test.c -lresolv >&/dev/null || sed -i '/^LDLIBS/s:-lresolv::' "${S}"/Makefile
95         popd >/dev/null
96
97         # run "configure" script first which will create "config.mk"...
98         econf
99
100         # ...now switch on/off requested features via USE flags
101         # this is only useful if the test did not set other things, per bug #643722
102         cat <<-EOF >> config.mk
103         TC_CONFIG_ATM := $(usex atm y n)
104         TC_CONFIG_XT  := $(usex iptables y n)
105         TC_CONFIG_NO_XT := $(usex iptables n y)
106         # We've locked in recent enough kernel headers #549948
107         TC_CONFIG_IPSET := y
108         HAVE_BERKELEY_DB := $(usex berkdb y n)
109         HAVE_CAP      := $(usex caps y n)
110         HAVE_MNL      := $(usex minimal n y)
111         HAVE_ELF      := $(usex elf y n)
112         HAVE_SELINUX  := $(usex selinux y n)
113         IP_CONFIG_SETNS := ${setns}
114         # Use correct iptables dir, #144265 #293709
115         IPT_LIB_DIR := $(use iptables && ${PKG_CONFIG} xtables --variable=xtlibdir)
116         EOF
117 }
118
119 src_compile() {
120         emake V=1
121 }
122
123 src_install() {
124         if use minimal ; then
125                 into /
126                 dosbin tc/tc
127                 dobin ip/ip
128                 return 0
129         fi
130
131         emake \
132                 DESTDIR="${D}" \
133                 LIBDIR="${EPREFIX}"/$(get_libdir) \
134                 SBINDIR="${EPREFIX}"/sbin \
135                 CONFDIR="${EPREFIX}"/etc/iproute2 \
136                 DOCDIR="${EPREFIX}"/usr/share/doc/${PF} \
137                 MANDIR="${EPREFIX}"/usr/share/man \
138                 ARPDDIR="${EPREFIX}"/var/lib/arpd \
139                 install
140
141         dodir /bin
142         mv "${ED}"/{s,}bin/ip || die #330115
143
144         dolib.a lib/libnetlink.a
145         insinto /usr/include
146         doins include/libnetlink.h
147         # This local header pulls in a lot of linux headers it
148         # doesn't directly need.  Delete this header that requires
149         # linux-headers-3.8 until that goes stable.  #467716
150         sed -i '/linux\/netconf.h/d' "${ED}"/usr/include/libnetlink.h || die
151
152         if use berkdb ; then
153                 keepdir /var/lib/arpd
154                 # bug 47482, arpd doesn't need to be in /sbin
155                 dodir /usr/bin
156                 mv "${ED}"/sbin/arpd "${ED}"/usr/bin/ || die
157         fi
158 }