|
| 1 | +# Copyright 1999-2023 Gentoo Authors |
| 2 | +# Distributed under the terms of the GNU General Public License v2 |
| 3 | + |
| 4 | +EAPI=8 |
| 5 | + |
| 6 | +inherit edo toolchain-funcs |
| 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="https://www.kernel.org/pub/linux/utils/net/${PN}/${P}.tar.xz" |
| 13 | + KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~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 bpf caps elf +iptables minimal nfs selinux split-usr" |
| 22 | +# Needs root |
| 23 | +RESTRICT="test" |
| 24 | + |
| 25 | +# We could make libmnl optional, but it's tiny, so eh |
| 26 | +RDEPEND=" |
| 27 | + !net-misc/arpd |
| 28 | + !minimal? ( net-libs/libmnl:= ) |
| 29 | + atm? ( net-dialup/linux-atm ) |
| 30 | + berkdb? ( sys-libs/db:= ) |
| 31 | + bpf? ( dev-libs/libbpf:= ) |
| 32 | + caps? ( sys-libs/libcap ) |
| 33 | + elf? ( virtual/libelf:= ) |
| 34 | + iptables? ( >=net-firewall/iptables-1.4.20:= ) |
| 35 | + nfs? ( net-libs/libtirpc:= ) |
| 36 | + selinux? ( sys-libs/libselinux ) |
| 37 | +" |
| 38 | +# We require newer linux-headers for ipset support (bug #549948) and some defines (bug #553876) |
| 39 | +DEPEND=" |
| 40 | + ${RDEPEND} |
| 41 | + >=sys-kernel/linux-headers-3.16 |
| 42 | +" |
| 43 | +BDEPEND=" |
| 44 | + app-arch/xz-utils |
| 45 | + >=sys-devel/bison-2.4 |
| 46 | + sys-devel/flex |
| 47 | + virtual/pkgconfig |
| 48 | +" |
| 49 | + |
| 50 | +PATCHES=( |
| 51 | + "${FILESDIR}"/${PN}-6.5.0-mtu.patch # bug #291907 |
| 52 | + "${FILESDIR}"/${PN}-6.5.0-configure-nomagic-nolibbsd.patch # bug #643722 & #911727 |
| 53 | + "${FILESDIR}"/${PN}-5.7.0-mix-signal.h-include.patch |
| 54 | + "${FILESDIR}"/${PN}-6.4.0-disable-libbsd-fallback.patch # bug #911727 |
| 55 | +) |
| 56 | + |
| 57 | +src_prepare() { |
| 58 | + default |
| 59 | + |
| 60 | + # Fix version if necessary |
| 61 | + local versionfile="include/version.h" |
| 62 | + if [[ ${PV} != 9999 ]] && ! grep -Fq "${PV}" ${versionfile} ; then |
| 63 | + einfo "Fixing version string" |
| 64 | + sed -i "s@\"[[:digit:]\.]\+\"@\"${PV}\"@" \ |
| 65 | + ${versionfile} || die |
| 66 | + fi |
| 67 | + |
| 68 | + # echo -n is not POSIX compliant |
| 69 | + sed -i 's@echo -n@printf@' configure || die |
| 70 | + |
| 71 | + sed -i \ |
| 72 | + -e '/^CC :\?=/d' \ |
| 73 | + -e "/^LIBDIR/s:=.*:=/$(get_libdir):" \ |
| 74 | + -e "s|-O2|${CFLAGS} ${CPPFLAGS}|" \ |
| 75 | + -e "/^HOSTCC/s:=.*:= $(tc-getBUILD_CC):" \ |
| 76 | + -e "/^DBM_INCLUDE/s:=.*:=${T}:" \ |
| 77 | + Makefile || die |
| 78 | + |
| 79 | + # Build against system headers |
| 80 | + rm -r include/netinet || die #include/linux include/ip{,6}tables{,_common}.h include/libiptc |
| 81 | + sed -i 's:TCPI_OPT_ECN_SEEN:16:' misc/ss.c || die |
| 82 | + |
| 83 | + if use minimal ; then |
| 84 | + sed -i -e '/^SUBDIRS=/s:=.*:=lib tc ip:' Makefile || die |
| 85 | + fi |
| 86 | +} |
| 87 | + |
| 88 | +src_configure() { |
| 89 | + tc-export AR CC PKG_CONFIG |
| 90 | + |
| 91 | + # This sure is ugly. Should probably move into toolchain-funcs at some point. |
| 92 | + local setns |
| 93 | + pushd "${T}" >/dev/null || die |
| 94 | + printf '#include <sched.h>\nint main(){return setns(0, 0);}\n' > test.c || die |
| 95 | + if ${CC} ${CFLAGS} ${CPPFLAGS} -D_GNU_SOURCE ${LDFLAGS} test.c >&/dev/null ; then |
| 96 | + setns=y |
| 97 | + else |
| 98 | + setns=n |
| 99 | + fi |
| 100 | + |
| 101 | + echo 'int main(){return 0;}' > test.c || die |
| 102 | + if ! ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} test.c -lresolv >&/dev/null ; then |
| 103 | + sed -i '/^LDLIBS/s:-lresolv::' "${S}"/Makefile || die |
| 104 | + fi |
| 105 | + popd >/dev/null || die |
| 106 | + |
| 107 | + # run "configure" script first which will create "config.mk"... |
| 108 | + # Using econf breaks since 5.14.0 (a9c3d70d902a0473ee5c13336317006a52ce8242) |
| 109 | + edo ./configure --libbpf_force $(usex bpf on off) |
| 110 | + |
| 111 | + # Remove the definitions made by configure and allow them to be overridden |
| 112 | + # by USE flags below. |
| 113 | + # We have to do the cheesy only-sed-if-disabled because otherwise |
| 114 | + # the *_FLAGS etc stuff found by configure will be used but result |
| 115 | + # in a broken build. |
| 116 | + if ! use berkdb ; then |
| 117 | + sed -i -e '/HAVE_BERKELEY_DB/d' config.mk || die |
| 118 | + fi |
| 119 | + |
| 120 | + if ! use caps ; then |
| 121 | + sed -i -e '/HAVE_CAP/d' config.mk || die |
| 122 | + fi |
| 123 | + |
| 124 | + if use minimal ; then |
| 125 | + sed -i -e '/HAVE_MNL/d' config.mk || die |
| 126 | + fi |
| 127 | + |
| 128 | + if ! use elf ; then |
| 129 | + sed -i -e '/HAVE_ELF/d' config.mk || die |
| 130 | + fi |
| 131 | + |
| 132 | + if ! use nfs ; then |
| 133 | + sed -i -e '/HAVE_RPC/d' config.mk || die |
| 134 | + fi |
| 135 | + |
| 136 | + if ! use selinux ; then |
| 137 | + sed -i -e '/HAVE_SELINUX/d' config.mk || die |
| 138 | + fi |
| 139 | + |
| 140 | + # ...Now switch on/off requested features via USE flags |
| 141 | + # this is only useful if the test did not set other things, per bug #643722 |
| 142 | + # Keep in sync with ifs above, or refactor to be unified. |
| 143 | + cat <<-EOF >> config.mk |
| 144 | + TC_CONFIG_ATM := $(usex atm y n) |
| 145 | + TC_CONFIG_XT := $(usex iptables y n) |
| 146 | + TC_CONFIG_NO_XT := $(usex iptables n y) |
| 147 | + # We've locked in recent enough kernel headers, bug #549948 |
| 148 | + TC_CONFIG_IPSET := y |
| 149 | + HAVE_BERKELEY_DB := $(usex berkdb y n) |
| 150 | + HAVE_CAP := $(usex caps y n) |
| 151 | + HAVE_MNL := $(usex minimal n y) |
| 152 | + HAVE_ELF := $(usex elf y n) |
| 153 | + HAVE_RPC := $(usex nfs y n) |
| 154 | + HAVE_SELINUX := $(usex selinux y n) |
| 155 | + IP_CONFIG_SETNS := ${setns} |
| 156 | + # Use correct iptables dir, bug #144265, bug #293709 |
| 157 | + IPT_LIB_DIR := $(use iptables && ${PKG_CONFIG} xtables --variable=xtlibdir) |
| 158 | + EOF |
| 159 | +} |
| 160 | + |
| 161 | +src_compile() { |
| 162 | + emake V=1 NETNS_RUN_DIR=/run/netns |
| 163 | +} |
| 164 | + |
| 165 | +src_test() { |
| 166 | + emake check |
| 167 | +} |
| 168 | + |
| 169 | +src_install() { |
| 170 | + if use minimal ; then |
| 171 | + into / |
| 172 | + dosbin tc/tc |
| 173 | + dobin ip/ip |
| 174 | + return 0 |
| 175 | + fi |
| 176 | + |
| 177 | + emake \ |
| 178 | + DESTDIR="${D}" \ |
| 179 | + PREFIX="${EPREFIX}/usr" \ |
| 180 | + LIBDIR="${EPREFIX}"/$(get_libdir) \ |
| 181 | + SBINDIR="${EPREFIX}"/sbin \ |
| 182 | + CONFDIR="${EPREFIX}"/etc/iproute2 \ |
| 183 | + DOCDIR="${EPREFIX}"/usr/share/doc/${PF} \ |
| 184 | + MANDIR="${EPREFIX}"/usr/share/man \ |
| 185 | + ARPDDIR="${EPREFIX}"/var/lib/arpd \ |
| 186 | + install |
| 187 | + |
| 188 | + dodir /bin |
| 189 | + mv "${ED}"/{s,}bin/ip || die # bug #330115 |
| 190 | + |
| 191 | + dolib.a lib/libnetlink.a |
| 192 | + insinto /usr/include |
| 193 | + doins include/libnetlink.h |
| 194 | + |
| 195 | + # Collides with net-analyzer/ifstat |
| 196 | + # https://bugs.gentoo.org/868321 |
| 197 | + mv "${ED}"/sbin/ifstat{,-iproute2} || die |
| 198 | + |
| 199 | + if use split-usr ; then |
| 200 | + # Can remove compatibility symlink in a year: 2023-05-28. |
| 201 | + # bug #547264 |
| 202 | + mv "${ED}"/sbin/ss "${ED}"/bin/ss || die |
| 203 | + dosym -r /bin/ss /sbin/ss |
| 204 | + fi |
| 205 | + |
| 206 | + if use berkdb ; then |
| 207 | + keepdir /var/lib/arpd |
| 208 | + # bug #47482, arpd doesn't need to be in /sbin |
| 209 | + dodir /usr/bin |
| 210 | + mv "${ED}"/sbin/arpd "${ED}"/usr/bin/ || die |
| 211 | + elif [[ -d "${ED}"/var/lib/arpd ]]; then |
| 212 | + rmdir --ignore-fail-on-non-empty -p "${ED}"/var/lib/arpd || die |
| 213 | + fi |
| 214 | +} |
0 commit comments