net-firewall/xtables-addons: version bump to 2.12, fix bug #597404
[gentoo.git] / net-firewall / xtables-addons / xtables-addons-2.11.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI="5"
6
7 inherit eutils linux-info linux-mod multilib
8
9 DESCRIPTION="iptables extensions not yet accepted in the main kernel"
10 HOMEPAGE="http://xtables-addons.sourceforge.net/"
11 SRC_URI="mirror://sourceforge/xtables-addons/${P}.tar.xz"
12
13 LICENSE="GPL-2"
14 SLOT="0"
15 KEYWORDS="~amd64 ~x86"
16 IUSE="modules"
17
18 MODULES="quota2 psd pknock lscan length2 ipv4options ipp2p iface gradm geoip fuzzy condition tarpit sysrq logmark ipmark echo dnetmap dhcpmac delude chaos account"
19
20 for mod in ${MODULES}; do
21         IUSE="${IUSE} xtables_addons_${mod}"
22 done
23
24 DEPEND=">=net-firewall/iptables-1.4.5"
25
26 RDEPEND="${DEPEND}
27         xtables_addons_geoip? (
28                 app-arch/unzip
29                 dev-perl/Text-CSV_XS
30                 virtual/perl-Getopt-Long
31         )
32 "
33
34 DEPEND="${DEPEND}
35         virtual/linux-sources"
36
37 SKIP_MODULES=""
38
39 XA_check4internal_module() {
40         local mod=${1}
41         local version=${3}
42         local kconfigname=${3}
43
44         if use xtables_addons_${mod} && kernel_is -gt ${version}; then
45                 ewarn "${kconfigname} should be provided by the kernel. Skipping its build..."
46                 if ! linux_chkconfig_present ${kconfigname}; then
47                         ewarn "Please enable ${kconfigname} target in your kernel
48                         configuration or disable checksum module in ${PN}."
49                 fi
50                 # SKIP_MODULES in case we need to disable building of everything
51                 # like having this USE disabled
52                 SKIP_MODULES+=" ${mod}"
53         fi
54 }
55
56 pkg_setup()     {
57         if use modules; then
58                 get_version
59                 check_modules_supported
60                 CONFIG_CHECK="NF_CONNTRACK NF_CONNTRACK_MARK ~CONNECTOR"
61                 ERROR_CONNECTOR="Please, enable CONFIG_CONNECTOR if you wish to receive userspace notifications from pknock through netlink/connector"
62                 linux-mod_pkg_setup
63
64                 if ! linux_chkconfig_present IPV6; then
65                         SKIP_IPV6_MODULES="ip6table_rawpost"
66                         ewarn "No IPV6 support in kernel. Disabling: ${SKIP_IPV6_MODULES}"
67                 fi
68                 kernel_is -lt 3 7 && die "${P} requires kernel version >= 3.7, if you have older kernel please use 1.x version instead"
69         fi
70 }
71
72 # Helper for maintainer: cheks if all possible MODULES are listed.
73 XA_qa_check() {
74         local all_modules
75         all_modules=$(sed -n '/^build_/{s/build_\(.*\)=.*/\L\1/;G;s/\n/ /;s/ $//;h}; ${x;p}' "${S}/mconfig")
76         if [[ ${all_modules} != ${MODULES} ]]; then
77                 ewarn "QA: Modules in mconfig differ from \$MODULES in ebuild."
78                 ewarn "Please, update MODULES in ebuild."
79                 ewarn "'${all_modules}'"
80         fi
81 }
82
83 # Is there any use flag set?
84 XA_has_something_to_build() {
85         local mod
86         for mod in ${MODULES}; do
87                 use xtables_addons_${mod} && return
88         done
89
90         eerror "All modules are disabled. What do you want me to build?"
91         eerror "Please, set XTABLES_ADDONS to any combination of"
92         eerror "${MODULES}"
93         die "All modules are disabled."
94 }
95
96 # Parse Kbuid files and generates list of sources
97 XA_get_module_name() {
98         [[ $# != 1 ]] && die "XA_get_sources_for_mod: needs exactly one argument."
99         local mod objdir build_mod sources_list
100         mod=${1}
101         objdir=${S}/extensions
102         # Take modules name from mconfig
103         build_mod=$(sed -n "s/\(build_${mod}\)=.*/\1/Ip" "${S}/mconfig")
104         # strip .o, = and everything before = and print
105         sources_list=$(sed -n "/^obj-[$][{]${build_mod}[}]/\
106                 {s:obj-[^+]\+ [+]=[[:space:]]*::;s:[.]o::g;p}" \
107                                 "${objdir}/Kbuild")
108
109         if [[ -d ${S}/extensions/${sources_list} ]]; then
110                 objdir=${S}/extensions/${sources_list}
111                 sources_list=$(sed -n "/^obj-m/\
112                         {s:obj-[^+]\+ [+]=[[:space:]]*::;s:[.]o::g;p}" \
113                                 "${objdir}/Kbuild")
114         fi
115         for mod_src in ${sources_list}; do
116                 has ${mod_src} ${SKIP_IPV6_MODULES} || \
117                         echo " ${mod_src}(xtables_addons:${S}/extensions:${objdir})"
118         done
119 }
120
121 # Die on modules known to fail on certain kernel version.
122 XA_known_failure() {
123         local module_name=$1
124         local KV_max=$2
125
126         if use xtables_addons_${module_name} && kernel_is ge ${KV_max//./ }; then
127                 eerror
128                 eerror "XTABLES_ADDONS=${module_name} fails to build on linux ${KV_max} or above."
129                 eerror "Either remove XTABLES_ADDONS=${module_name} or use an earlier version of the kernel."
130                 eerror
131                 die
132         fi
133 }
134
135 src_prepare() {
136         XA_qa_check
137         XA_has_something_to_build
138
139         # Bug #553630#c2.  echo fails on linux-4 and above.
140         # This appears to be fixed, at least as of linux-4.2
141         # XA_known_failure "echo" 4
142
143         local mod module_name
144         if use modules; then
145                 MODULE_NAMES="compat_xtables(xtables_addons:${S}/extensions:)"
146         fi
147         for mod in ${MODULES}; do
148                 if ! has ${mod} ${SKIP_MODULES} && use xtables_addons_${mod}; then
149                         sed "s/\(build_${mod}=\).*/\1m/I" -i mconfig || die
150                         if use modules; then
151                                 for module_name in $(XA_get_module_name ${mod}); do
152                                         MODULE_NAMES+=" ${module_name}"
153                                 done
154                         fi
155                 else
156                         sed "s/\(build_${mod}=\).*/\1n/I" -i mconfig || die
157                 fi
158         done
159         einfo "${MODULE_NAMES}" # for debugging
160
161         sed -e 's/depmod -a/true/' -i Makefile.in || die
162         sed -e '/^all-local:/{s: modules::}' \
163                 -e '/^install-exec-local:/{s: modules_install::}' \
164                         -i extensions/Makefile.in || die
165
166         use xtables_addons_geoip || sed  -e '/^SUBDIRS/{s/geoip//}' -i Makefile.in
167 }
168
169 src_configure() {
170         set_arch_to_kernel # .. or it'll look for /arch/amd64/Makefile
171         econf --prefix="${EPREFIX}/" \
172                 --libexecdir="${EPREFIX}/$(get_libdir)/" \
173                 --with-kbuild="${KV_DIR}"
174 }
175
176 src_compile() {
177         emake CFLAGS="${CFLAGS}" CC="$(tc-getCC)" V=1
178         use modules && BUILD_PARAMS="V=1" BUILD_TARGETS="modules" linux-mod_src_compile
179 }
180
181 src_install() {
182         emake DESTDIR="${D}" install
183         use modules && linux-mod_src_install
184         dodoc -r README doc/*
185         find "${ED}" -type f -name '*.la' -exec rm -rf '{}' '+'
186 }