1SUMMARY = "Netfilter Tables userspace utillites"
2SECTION = "net"
3LICENSE = "GPL-2.0-only"
4LIC_FILES_CHKSUM = "file://COPYING;md5=81ec33bb3e47b460fc993ac768c74b62"
5
6DEPENDS = "libmnl libnftnl bison-native \
7           ${@bb.utils.contains('PACKAGECONFIG', 'mini-gmp', '', 'gmp', d)}"
8
9SRC_URI = "http://www.netfilter.org/projects/nftables/files/${BP}.tar.xz \
10           file://run-ptest \
11          "
12SRC_URI[sha256sum] = "a3c304cd9ba061239ee0474f9afb938a9bb99d89b960246f66f0c3a0a85e14cd"
13
14inherit autotools manpages pkgconfig ptest
15
16PACKAGECONFIG ?= "python readline json"
17PACKAGECONFIG[editline] = "--with-cli=editline, , libedit, , , linenoise readline"
18PACKAGECONFIG[json] = "--with-json, --without-json, jansson"
19PACKAGECONFIG[linenoise] = "--with-cli=linenoise, , linenoise, , , editline readline"
20PACKAGECONFIG[manpages] = "--enable-man-doc, --disable-man-doc, asciidoc-native"
21PACKAGECONFIG[mini-gmp] = "--with-mini-gmp, --without-mini-gmp"
22PACKAGECONFIG[python] = ",, python3-setuptools-native"
23PACKAGECONFIG[readline] = "--with-cli=readline, , readline, , , editline linenoise"
24PACKAGECONFIG[xtables] = "--with-xtables, --without-xtables, iptables"
25
26EXTRA_OECONF = " \
27    ${@bb.utils.contains_any('PACKAGECONFIG', 'editline linenoise readline', '', '--without-cli', d)}"
28
29SETUPTOOLS_SETUP_PATH = "${S}/py"
30
31inherit ${@bb.utils.contains('PACKAGECONFIG', 'python', 'setuptools3', '', d)}
32
33RRECOMMENDS:${PN} += "kernel-module-nf-tables"
34
35PACKAGES =+ "${PN}-python"
36FILES:${PN}-python = "${PYTHON_SITEPACKAGES_DIR}"
37RDEPENDS:${PN}-python = "python3-core python3-json ${PN}"
38
39# Explicitly define do_configure, do_compile and do_install because both autotools and setuptools3
40# have EXPORT_FUNCTIONS do_configure do_compile do_install
41do_configure() {
42    autotools_do_configure
43    if ${@bb.utils.contains('PACKAGECONFIG', 'python', 'true', 'false', d)}; then
44        setuptools3_do_configure
45    fi
46}
47
48do_compile() {
49    autotools_do_compile
50    if ${@bb.utils.contains('PACKAGECONFIG', 'python', 'true', 'false', d)}; then
51        setuptools3_do_compile
52    fi
53}
54
55do_install() {
56    autotools_do_install
57    if ${@bb.utils.contains('PACKAGECONFIG', 'python', 'true', 'false', d)}; then
58        setuptools3_do_install
59    fi
60}
61
62RDEPENDS:${PN}-ptest += " ${PN}-python bash make iproute2 iputils-ping procps python3-core python3-ctypes python3-json python3-misc sed util-linux"
63
64TESTDIR = "tests"
65
66PRIVATE_LIBS:${PN}-ptest:append = " libnftables.so.1"
67
68do_install_ptest() {
69    cp -rf ${S}/build-aux ${D}${PTEST_PATH}
70    cp -rf ${S}/src ${D}${PTEST_PATH}
71    mkdir -p ${D}${PTEST_PATH}/src/.libs
72    cp -rf ${B}/src/.libs/* ${D}${PTEST_PATH}/src/.libs
73    cp -rf ${B}/src/.libs/nft ${D}${PTEST_PATH}/src/
74    cp -rf ${S}/${TESTDIR} ${D}${PTEST_PATH}/${TESTDIR}
75    sed -i 's#/usr/bin/python#/usr/bin/python3#' ${D}${PTEST_PATH}/${TESTDIR}/json_echo/run-test.py
76    sed -i 's#/usr/bin/env python#/usr/bin/env python3#' ${D}${PTEST_PATH}/${TESTDIR}/py/nft-test.py
77    # handle multilib
78    sed -i s:@libdir@:${libdir}:g ${D}${PTEST_PATH}/run-ptest
79}
80