Blame configure

Packit Service 3880ab
#!/bin/sh
Packit Service 3880ab
# SPDX-License-Identifier: GPL-2.0
Packit Service 3880ab
# This is not an autoconf generated configure
Packit Service 3880ab
#
Packit Service 3880ab
INCLUDE=${1:-"$PWD/include"}
Packit Service 3880ab
Packit Service 3880ab
# Output file which is input to Makefile
Packit Service 3880ab
CONFIG=config.mk
Packit Service 3880ab
Packit Service 3880ab
# Make a temp directory in build tree.
Packit Service 3880ab
TMPDIR=$(mktemp -d config.XXXXXX)
Packit Service 3880ab
trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
Packit Service 3880ab
Packit Service 3880ab
check_toolchain()
Packit Service 3880ab
{
Packit Service 3880ab
    : ${PKG_CONFIG:=pkg-config}
Packit Service 3880ab
    : ${AR=ar}
Packit Service 3880ab
    : ${CC=gcc}
Packit Service 3880ab
    : ${YACC=bison}
Packit Service 3880ab
    echo "PKG_CONFIG:=${PKG_CONFIG}" >>$CONFIG
Packit Service 3880ab
    echo "AR:=${AR}" >>$CONFIG
Packit Service 3880ab
    echo "CC:=${CC}" >>$CONFIG
Packit Service 3880ab
    echo "YACC:=${YACC}" >>$CONFIG
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_atm()
Packit Service 3880ab
{
Packit Service 3880ab
    cat >$TMPDIR/atmtest.c <
Packit Service 3880ab
#include <atm.h>
Packit Service 3880ab
int main(int argc, char **argv) {
Packit Service 3880ab
	struct atm_qos qos;
Packit Service 3880ab
	(void) text2qos("aal5,ubr:sdu=9180,rx:none",&qos,0);
Packit Service 3880ab
	return 0;
Packit Service 3880ab
}
Packit Service 3880ab
EOF
Packit Service 3880ab
Packit Service 3880ab
    if $CC -I$INCLUDE -o $TMPDIR/atmtest $TMPDIR/atmtest.c -latm >/dev/null 2>&1; then
Packit Service 3880ab
	echo "TC_CONFIG_ATM:=y" >>$CONFIG
Packit Service 3880ab
	echo yes
Packit Service 3880ab
    else
Packit Service 3880ab
	echo no
Packit Service 3880ab
    fi
Packit Service 3880ab
    rm -f $TMPDIR/atmtest.c $TMPDIR/atmtest
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_xtables()
Packit Service 3880ab
{
Packit Service 3880ab
	if ! ${PKG_CONFIG} xtables --exists; then
Packit Service 3880ab
		echo "TC_CONFIG_NO_XT:=y" >>$CONFIG
Packit Service 3880ab
	fi
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_xt()
Packit Service 3880ab
{
Packit Service 3880ab
    #check if we have xtables from iptables >= 1.4.5.
Packit Service 3880ab
    cat >$TMPDIR/ipttest.c <
Packit Service 3880ab
#include <xtables.h>
Packit Service 3880ab
#include <linux/netfilter.h>
Packit Service 3880ab
static struct xtables_globals test_globals = {
Packit Service 3880ab
	.option_offset = 0,
Packit Service 3880ab
	.program_name = "tc-ipt",
Packit Service 3880ab
	.program_version = XTABLES_VERSION,
Packit Service 3880ab
	.orig_opts = NULL,
Packit Service 3880ab
	.opts = NULL,
Packit Service 3880ab
	.exit_err = NULL,
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
int main(int argc, char **argv)
Packit Service 3880ab
{
Packit Service 3880ab
	xtables_init_all(&test_globals, NFPROTO_IPV4);
Packit Service 3880ab
	return 0;
Packit Service 3880ab
}
Packit Service 3880ab
EOF
Packit Service 3880ab
Packit Service 3880ab
    if $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL \
Packit Service 3880ab
	$(${PKG_CONFIG} xtables --cflags --libs) -ldl >/dev/null 2>&1; then
Packit Service 3880ab
	echo "TC_CONFIG_XT:=y" >>$CONFIG
Packit Service 3880ab
	echo "using xtables"
Packit Service 3880ab
    fi
Packit Service 3880ab
    rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_xt_old()
Packit Service 3880ab
{
Packit Service 3880ab
    # bail if previous XT checks has already succeeded.
Packit Service 3880ab
    grep -q TC_CONFIG_XT $CONFIG && return
Packit Service 3880ab
Packit Service 3880ab
    #check if we don't need our internal header ..
Packit Service 3880ab
    cat >$TMPDIR/ipttest.c <
Packit Service 3880ab
#include <xtables.h>
Packit Service 3880ab
char *lib_dir;
Packit Service 3880ab
unsigned int global_option_offset = 0;
Packit Service 3880ab
const char *program_version = XTABLES_VERSION;
Packit Service 3880ab
const char *program_name = "tc-ipt";
Packit Service 3880ab
struct afinfo afinfo = {
Packit Service 3880ab
	.libprefix      = "libxt_",
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
void exit_error(enum exittype status, const char *msg, ...)
Packit Service 3880ab
{
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
int main(int argc, char **argv) {
Packit Service 3880ab
Packit Service 3880ab
	return 0;
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
EOF
Packit Service 3880ab
Packit Service 3880ab
    if $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1; then
Packit Service 3880ab
	echo "TC_CONFIG_XT_OLD:=y" >>$CONFIG
Packit Service 3880ab
	echo "using old xtables (no need for xt-internal.h)"
Packit Service 3880ab
    fi
Packit Service 3880ab
    rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_xt_old_internal_h()
Packit Service 3880ab
{
Packit Service 3880ab
    # bail if previous XT checks has already succeeded.
Packit Service 3880ab
    grep -q TC_CONFIG_XT $CONFIG && return
Packit Service 3880ab
Packit Service 3880ab
    #check if we need our own internal.h
Packit Service 3880ab
    cat >$TMPDIR/ipttest.c <
Packit Service 3880ab
#include <xtables.h>
Packit Service 3880ab
#include "xt-internal.h"
Packit Service 3880ab
char *lib_dir;
Packit Service 3880ab
unsigned int global_option_offset = 0;
Packit Service 3880ab
const char *program_version = XTABLES_VERSION;
Packit Service 3880ab
const char *program_name = "tc-ipt";
Packit Service 3880ab
struct afinfo afinfo = {
Packit Service 3880ab
	.libprefix      = "libxt_",
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
void exit_error(enum exittype status, const char *msg, ...)
Packit Service 3880ab
{
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
int main(int argc, char **argv) {
Packit Service 3880ab
Packit Service 3880ab
	return 0;
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
EOF
Packit Service 3880ab
	if $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1; then
Packit Service 3880ab
	    echo "using old xtables with xt-internal.h"
Packit Service 3880ab
	    echo "TC_CONFIG_XT_OLD_H:=y" >>$CONFIG
Packit Service 3880ab
	fi
Packit Service 3880ab
	rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_ipt()
Packit Service 3880ab
{
Packit Service 3880ab
	if ! grep TC_CONFIG_XT $CONFIG > /dev/null; then
Packit Service 3880ab
		echo "using iptables"
Packit Service 3880ab
	fi
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_ipt_lib_dir()
Packit Service 3880ab
{
Packit Service 3880ab
	IPT_LIB_DIR=$(${PKG_CONFIG} --variable=xtlibdir xtables)
Packit Service 3880ab
	if [ -n "$IPT_LIB_DIR" ]; then
Packit Service 3880ab
		echo $IPT_LIB_DIR
Packit Service 3880ab
		echo "IPT_LIB_DIR:=$IPT_LIB_DIR" >> $CONFIG
Packit Service 3880ab
		return
Packit Service 3880ab
	fi
Packit Service 3880ab
Packit Service 3880ab
	for dir in /lib /usr/lib /usr/local/lib; do
Packit Service 3880ab
		for file in "xtables" "iptables"; do
Packit Service 3880ab
			file="$dir/$file/lib*t_*so"
Packit Service 3880ab
			if [ -f $file ]; then
Packit Service 3880ab
				echo ${file%/*}
Packit Service 3880ab
				echo "IPT_LIB_DIR:=${file%/*}" >> $CONFIG
Packit Service 3880ab
				return
Packit Service 3880ab
			fi
Packit Service 3880ab
		done
Packit Service 3880ab
	done
Packit Service 3880ab
	echo "not found!"
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_setns()
Packit Service 3880ab
{
Packit Service 3880ab
    cat >$TMPDIR/setnstest.c <
Packit Service 3880ab
#include <sched.h>
Packit Service 3880ab
int main(int argc, char **argv)
Packit Service 3880ab
{
Packit Service 3880ab
	(void)setns(0,0);
Packit Service 3880ab
	return 0;
Packit Service 3880ab
}
Packit Service 3880ab
EOF
Packit Service 3880ab
    if $CC -I$INCLUDE -o $TMPDIR/setnstest $TMPDIR/setnstest.c >/dev/null 2>&1; then
Packit Service 3880ab
	echo "IP_CONFIG_SETNS:=y" >>$CONFIG
Packit Service 3880ab
	echo "yes"
Packit Service 3880ab
	echo "CFLAGS += -DHAVE_SETNS" >>$CONFIG
Packit Service 3880ab
    else
Packit Service 3880ab
	echo "no"
Packit Service 3880ab
    fi
Packit Service 3880ab
    rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_ipset()
Packit Service 3880ab
{
Packit Service 3880ab
    cat >$TMPDIR/ipsettest.c <
Packit Service 3880ab
#include <linux/netfilter/ipset/ip_set.h>
Packit Service 3880ab
#ifndef IP_SET_INVALID
Packit Service 3880ab
#define IPSET_DIM_MAX 3
Packit Service 3880ab
typedef unsigned short ip_set_id_t;
Packit Service 3880ab
#endif
Packit Service 3880ab
#include <linux/netfilter/xt_set.h>
Packit Service 3880ab
Packit Service 3880ab
struct xt_set_info info;
Packit Service 3880ab
#if IPSET_PROTOCOL == 6 || IPSET_PROTOCOL == 7
Packit Service 3880ab
int main(void)
Packit Service 3880ab
{
Packit Service 3880ab
	return IPSET_MAXNAMELEN;
Packit Service 3880ab
}
Packit Service 3880ab
#else
Packit Service 3880ab
#error unknown ipset version
Packit Service 3880ab
#endif
Packit Service 3880ab
EOF
Packit Service 3880ab
Packit Service 3880ab
    if $CC -I$INCLUDE -o $TMPDIR/ipsettest $TMPDIR/ipsettest.c >/dev/null 2>&1; then
Packit Service 3880ab
	echo "TC_CONFIG_IPSET:=y" >>$CONFIG
Packit Service 3880ab
	echo "yes"
Packit Service 3880ab
    else
Packit Service 3880ab
	echo "no"
Packit Service 3880ab
    fi
Packit Service 3880ab
    rm -f $TMPDIR/ipsettest.c $TMPDIR/ipsettest
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_elf()
Packit Service 3880ab
{
Packit Service 3880ab
    if ${PKG_CONFIG} libelf --exists; then
Packit Service 3880ab
	echo "HAVE_ELF:=y" >>$CONFIG
Packit Service 3880ab
	echo "yes"
Packit Service 3880ab
Packit Service 3880ab
	echo 'CFLAGS += -DHAVE_ELF' `${PKG_CONFIG} libelf --cflags` >> $CONFIG
Packit Service 3880ab
	echo 'LDLIBS += ' `${PKG_CONFIG} libelf --libs` >>$CONFIG
Packit Service 3880ab
    else
Packit Service 3880ab
	echo "no"
Packit Service 3880ab
    fi
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_selinux()
Packit Service 3880ab
# SELinux is a compile time option in the ss utility
Packit Service 3880ab
{
Packit Service 3880ab
	if ${PKG_CONFIG} libselinux --exists; then
Packit Service 3880ab
		echo "HAVE_SELINUX:=y" >>$CONFIG
Packit Service 3880ab
		echo "yes"
Packit Service 3880ab
Packit Service 3880ab
		echo 'LDLIBS +=' `${PKG_CONFIG} --libs libselinux` >>$CONFIG
Packit Service 3880ab
		echo 'CFLAGS += -DHAVE_SELINUX' `${PKG_CONFIG} --cflags libselinux` >>$CONFIG
Packit Service 3880ab
	else
Packit Service 3880ab
		echo "no"
Packit Service 3880ab
	fi
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_mnl()
Packit Service 3880ab
{
Packit Service 3880ab
	if ${PKG_CONFIG} libmnl --exists; then
Packit Service 3880ab
		echo "HAVE_MNL:=y" >>$CONFIG
Packit Service 3880ab
		echo "yes"
Packit Service 3880ab
Packit Service 3880ab
		echo 'CFLAGS += -DHAVE_LIBMNL' `${PKG_CONFIG} libmnl --cflags` >>$CONFIG
Packit Service 3880ab
		echo 'LDLIBS +=' `${PKG_CONFIG} libmnl --libs` >> $CONFIG
Packit Service 3880ab
	else
Packit Service 3880ab
		echo "no"
Packit Service 3880ab
	fi
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_berkeley_db()
Packit Service 3880ab
{
Packit Service 3880ab
    cat >$TMPDIR/dbtest.c <
Packit Service 3880ab
#include <fcntl.h>
Packit Service 3880ab
#include <stdlib.h>
Packit Service 3880ab
#include <db_185.h>
Packit Service 3880ab
int main(int argc, char **argv) {
Packit Service 3880ab
	dbopen("/tmp/xxx_test_db.db", O_CREAT|O_RDWR, 0644, DB_HASH, NULL);
Packit Service 3880ab
	return 0;
Packit Service 3880ab
}
Packit Service 3880ab
EOF
Packit Service 3880ab
    if $CC -I$INCLUDE -o $TMPDIR/dbtest $TMPDIR/dbtest.c -ldb >/dev/null 2>&1; then
Packit Service 3880ab
	echo "HAVE_BERKELEY_DB:=y" >>$CONFIG
Packit Service 3880ab
	echo "yes"
Packit Service 3880ab
    else
Packit Service 3880ab
	echo "no"
Packit Service 3880ab
    fi
Packit Service 3880ab
    rm -f $TMPDIR/dbtest.c $TMPDIR/dbtest
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_strlcpy()
Packit Service 3880ab
{
Packit Service 3880ab
    cat >$TMPDIR/strtest.c <
Packit Service 3880ab
#include <string.h>
Packit Service 3880ab
int main(int argc, char **argv) {
Packit Service 3880ab
	char dst[10];
Packit Service 3880ab
	strlcpy(dst, "test", sizeof(dst));
Packit Service 3880ab
	return 0;
Packit Service 3880ab
}
Packit Service 3880ab
EOF
Packit Service 3880ab
    if $CC -I$INCLUDE -o $TMPDIR/strtest $TMPDIR/strtest.c >/dev/null 2>&1; then
Packit Service 3880ab
	echo "no"
Packit Service 3880ab
    else
Packit Service 3880ab
	if ${PKG_CONFIG} libbsd --exists; then
Packit Service 3880ab
		echo 'CFLAGS += -DHAVE_LIBBSD' `${PKG_CONFIG} libbsd --cflags` >>$CONFIG
Packit Service 3880ab
		echo 'LDLIBS +=' `${PKG_CONFIG} libbsd --libs` >> $CONFIG
Packit Service 3880ab
		echo "no"
Packit Service 3880ab
	else
Packit Service 3880ab
		echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG
Packit Service 3880ab
		echo "yes"
Packit Service 3880ab
	fi
Packit Service 3880ab
    fi
Packit Service 3880ab
    rm -f $TMPDIR/strtest.c $TMPDIR/strtest
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
check_cap()
Packit Service 3880ab
{
Packit Service 3880ab
	if ${PKG_CONFIG} libcap --exists; then
Packit Service 3880ab
		echo "HAVE_CAP:=y" >>$CONFIG
Packit Service 3880ab
		echo "yes"
Packit Service 3880ab
Packit Service 3880ab
		echo 'CFLAGS += -DHAVE_LIBCAP' `${PKG_CONFIG} libcap --cflags` >>$CONFIG
Packit Service 3880ab
		echo 'LDLIBS +=' `${PKG_CONFIG} libcap --libs` >> $CONFIG
Packit Service 3880ab
	else
Packit Service 3880ab
		echo "no"
Packit Service 3880ab
	fi
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
quiet_config()
Packit Service 3880ab
{
Packit Service 3880ab
	cat <
Packit Service 3880ab
# user can control verbosity similar to kernel builds (e.g., V=1)
Packit Service 3880ab
ifeq ("\$(origin V)", "command line")
Packit Service 3880ab
  VERBOSE = \$(V)
Packit Service 3880ab
endif
Packit Service 3880ab
ifndef VERBOSE
Packit Service 3880ab
  VERBOSE = 0
Packit Service 3880ab
endif
Packit Service 3880ab
ifeq (\$(VERBOSE),1)
Packit Service 3880ab
  Q =
Packit Service 3880ab
else
Packit Service 3880ab
  Q = @
Packit Service 3880ab
endif
Packit Service 3880ab
Packit Service 3880ab
ifeq (\$(VERBOSE), 0)
Packit Service 3880ab
    QUIET_CC       = @echo '    CC       '\$@;
Packit Service 3880ab
    QUIET_AR       = @echo '    AR       '\$@;
Packit Service 3880ab
    QUIET_LINK     = @echo '    LINK     '\$@;
Packit Service 3880ab
    QUIET_YACC     = @echo '    YACC     '\$@;
Packit Service 3880ab
    QUIET_LEX      = @echo '    LEX      '\$@;
Packit Service 3880ab
endif
Packit Service 3880ab
EOF
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
echo "# Generated config based on" $INCLUDE >$CONFIG
Packit Service 3880ab
quiet_config >> $CONFIG
Packit Service 3880ab
Packit Service 3880ab
check_toolchain
Packit Service 3880ab
Packit Service 3880ab
echo "TC schedulers"
Packit Service 3880ab
Packit Service 3880ab
echo -n " ATM	"
Packit Service 3880ab
check_atm
Packit Service 3880ab
Packit Service 3880ab
check_xtables
Packit Service 3880ab
if ! grep -q TC_CONFIG_NO_XT $CONFIG; then
Packit Service 3880ab
	echo -n " IPT	"
Packit Service 3880ab
	check_xt
Packit Service 3880ab
	check_xt_old
Packit Service 3880ab
	check_xt_old_internal_h
Packit Service 3880ab
	check_ipt
Packit Service 3880ab
Packit Service 3880ab
	echo -n " IPSET  "
Packit Service 3880ab
	check_ipset
Packit Service 3880ab
fi
Packit Service 3880ab
Packit Service 3880ab
echo
Packit Service 3880ab
if ! grep -q TC_CONFIG_NO_XT $CONFIG; then
Packit Service 3880ab
	echo -n "iptables modules directory: "
Packit Service 3880ab
	check_ipt_lib_dir
Packit Service 3880ab
fi
Packit Service 3880ab
Packit Service 3880ab
echo -n "libc has setns: "
Packit Service 3880ab
check_setns
Packit Service 3880ab
Packit Service 3880ab
echo -n "SELinux support: "
Packit Service 3880ab
check_selinux
Packit Service 3880ab
Packit Service 3880ab
echo -n "ELF support: "
Packit Service 3880ab
check_elf
Packit Service 3880ab
Packit Service 3880ab
echo -n "libmnl support: "
Packit Service 3880ab
check_mnl
Packit Service 3880ab
Packit Service 3880ab
echo -n "Berkeley DB: "
Packit Service 3880ab
check_berkeley_db
Packit Service 3880ab
Packit Service 3880ab
echo -n "need for strlcpy: "
Packit Service 3880ab
check_strlcpy
Packit Service 3880ab
Packit Service 3880ab
echo -n "libcap support: "
Packit Service 3880ab
check_cap
Packit Service 3880ab
Packit Service 3880ab
echo >> $CONFIG
Packit Service 3880ab
echo "%.o: %.c" >> $CONFIG
Packit Service 3880ab
echo '	$(QUIET_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CPPFLAGS) -c -o $@ $<' >> $CONFIG