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