xtables-addons-2.8.ebuild 5.3 KB

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