blob: 88cbdb825689c1e257a656141ff89caf792215df [file] [log] [blame]
osdl.net!shemminger449bf1f2004-06-25 21:14:22 +00001#! /bin/bash
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -08002# This is not an autoconf generated configure
osdl.net!shemminger449bf1f2004-06-25 21:14:22 +00003#
osdl.net!shemminger4b1bbd92004-08-09 16:35:28 +00004INCLUDE=${1:-"$PWD/include"}
osdl.net!shemminger449bf1f2004-06-25 21:14:22 +00005
Stephen Hemmingere557d1a2012-02-15 10:03:39 -08006# Make a temp directory in build tree.
7TMPDIR=$(mktemp -d config.XXXXXX)
Mathias Krausec2f7d6c2012-09-01 20:55:29 +02008trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
Stephen Hemmingere557d1a2012-02-15 10:03:39 -08009
vadimk10ed8b72014-11-30 18:08:25 +020010check_prog()
11{
12 echo -n "$2"
13 command -v $1 >/dev/null 2>&1 && (echo "$3:=y" >> Config; echo "yes") || (echo "no"; return 1)
14}
15
16check_docs()
17{
18 if check_prog latex " latex: " HAVE_LATEX; then
19 check_prog pdflatex " pdflatex: " HAVE_PDFLATEX || echo " WARNING: no PDF docs can be built from LaTeX files"
20 check_prog sgml2latex " sgml2latex: " HAVE_SGML2LATEX || echo " WARNING: no LaTeX files can be build from SGML files"
21 else
22 echo " WARNING: no docs can be built from LaTeX files"
23 fi
24
25 check_prog sgml2html " sgml2html: " HAVE_SGML2HTML || echo " WARNING: no HTML docs can be built from SGML"
26}
27
Mike Frysinger601f60e2012-12-16 17:09:15 -050028check_toolchain()
29{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080030 : ${PKG_CONFIG:=pkg-config}
31 : ${AR=ar}
32 : ${CC=gcc}
Stephen Hemmingerae7b9a02012-12-19 16:01:39 -080033 echo "PKG_CONFIG:=${PKG_CONFIG}" >>Config
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080034 echo "AR:=${AR}" >>Config
35 echo "CC:=${CC}" >>Config
Mike Frysinger601f60e2012-12-16 17:09:15 -050036}
37
Andreas Henriksson14743a72010-01-01 23:20:30 +010038check_atm()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000039{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080040 cat >$TMPDIR/atmtest.c <<EOF
osdl.net!shemmingerc830d772004-07-02 17:47:53 +000041#include <atm.h>
42int main(int argc, char **argv) {
43 struct atm_qos qos;
44 (void) text2qos("aal5,ubr:sdu=9180,rx:none",&qos,0);
45 return 0;
46}
47EOF
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080048
49 $CC -I$INCLUDE -o $TMPDIR/atmtest $TMPDIR/atmtest.c -latm >/dev/null 2>&1
50 if [ $? -eq 0 ]
51 then
52 echo "TC_CONFIG_ATM:=y" >>Config
53 echo yes
54 else
55 echo no
56 fi
57 rm -f $TMPDIR/atmtest.c $TMPDIR/atmtest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000058}
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -050059
Daniel Borkmann4710e462016-10-18 14:13:09 +020060check_xtables()
61{
62 if ! ${PKG_CONFIG} xtables --exists
63 then
64 echo "TC_CONFIG_NO_XT:=y" >>Config
65 fi
66}
67
Andreas Henriksson14743a72010-01-01 23:20:30 +010068check_xt()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000069{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080070 #check if we have xtables from iptables >= 1.4.5.
71 cat >$TMPDIR/ipttest.c <<EOF
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010072#include <xtables.h>
73#include <linux/netfilter.h>
74static struct xtables_globals test_globals = {
75 .option_offset = 0,
76 .program_name = "tc-ipt",
77 .program_version = XTABLES_VERSION,
78 .orig_opts = NULL,
79 .opts = NULL,
80 .exit_err = NULL,
81};
82
83int main(int argc, char **argv)
84{
85 xtables_init_all(&test_globals, NFPROTO_IPV4);
86 return 0;
87}
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010088EOF
89
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080090 if $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL \
91 $(${PKG_CONFIG} xtables --cflags --libs) -ldl >/dev/null 2>&1
92 then
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010093 echo "TC_CONFIG_XT:=y" >>Config
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000094 echo "using xtables"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080095 fi
96 rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000097}
98
Andreas Henriksson14743a72010-01-01 23:20:30 +010099check_xt_old()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000100{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800101 # bail if previous XT checks has already succeded.
102 if grep -q TC_CONFIG_XT Config
103 then
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000104 return
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800105 fi
Andreas Henrikssona36ceb82009-12-02 16:11:50 +0100106
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800107 #check if we dont need our internal header ..
108 cat >$TMPDIR/ipttest.c <<EOF
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500109#include <xtables.h>
110char *lib_dir;
111unsigned int global_option_offset = 0;
112const char *program_version = XTABLES_VERSION;
113const char *program_name = "tc-ipt";
114struct afinfo afinfo = {
115 .libprefix = "libxt_",
116};
117
118void exit_error(enum exittype status, const char *msg, ...)
119{
120}
121
122int main(int argc, char **argv) {
123
124 return 0;
125}
126
127EOF
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500128
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800129 $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
130 if [ $? -eq 0 ]
131 then
Andreas Henriksson80d689d2009-12-02 16:11:21 +0100132 echo "TC_CONFIG_XT_OLD:=y" >>Config
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000133 echo "using old xtables (no need for xt-internal.h)"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800134 fi
135 rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000136}
137
Andreas Henriksson14743a72010-01-01 23:20:30 +0100138check_xt_old_internal_h()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000139{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800140 # bail if previous XT checks has already succeded.
141 if grep -q TC_CONFIG_XT Config
142 then
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000143 return
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800144 fi
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500145
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800146 #check if we need our own internal.h
147 cat >$TMPDIR/ipttest.c <<EOF
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500148#include <xtables.h>
149#include "xt-internal.h"
150char *lib_dir;
151unsigned int global_option_offset = 0;
152const char *program_version = XTABLES_VERSION;
153const char *program_name = "tc-ipt";
154struct afinfo afinfo = {
155 .libprefix = "libxt_",
156};
157
158void exit_error(enum exittype status, const char *msg, ...)
159{
160}
161
162int main(int argc, char **argv) {
163
164 return 0;
165}
166
167EOF
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800168 $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500169
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800170 if [ $? -eq 0 ]
171 then
172 echo "using old xtables with xt-internal.h"
173 echo "TC_CONFIG_XT_OLD_H:=y" >>Config
174 fi
175 rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000176}
177
Andreas Henriksson14743a72010-01-01 23:20:30 +0100178check_ipt()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000179{
180 if ! grep TC_CONFIG_XT Config > /dev/null
181 then
182 echo "using iptables"
183 fi
184}
185
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000186check_ipt_lib_dir()
187{
Mike Frysingere4fc4ad2012-11-08 11:41:17 -0500188 IPT_LIB_DIR=$(${PKG_CONFIG} --variable=xtlibdir xtables)
Li Weida7fbb22012-08-20 09:41:47 +0800189 if [ -n "$IPT_LIB_DIR" ]; then
190 echo $IPT_LIB_DIR
191 echo "IPT_LIB_DIR:=$IPT_LIB_DIR" >> Config
192 return
193 fi
194
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000195 for dir in /lib /usr/lib /usr/local/lib
196 do
Dan McGee44e743e2011-07-15 08:52:24 +0000197 for file in $dir/{xtables,iptables}/lib*t_*so ; do
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000198 if [ -f $file ]; then
Dan McGee44e743e2011-07-15 08:52:24 +0000199 echo ${file%/*}
200 echo "IPT_LIB_DIR:=${file%/*}" >> Config
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000201 return
202 fi
203 done
204 done
205 echo "not found!"
206}
207
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000208check_setns()
209{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800210 cat >$TMPDIR/setnstest.c <<EOF
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000211#include <sched.h>
Vadim Kochand116ff32015-03-07 08:30:58 +0200212int main(int argc, char **argv)
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000213{
214 (void)setns(0,0);
215 return 0;
216}
217EOF
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800218 $CC -I$INCLUDE -o $TMPDIR/setnstest $TMPDIR/setnstest.c >/dev/null 2>&1
219 if [ $? -eq 0 ]
220 then
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000221 echo "IP_CONFIG_SETNS:=y" >>Config
222 echo "yes"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800223 else
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000224 echo "no"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800225 fi
226 rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000227}
228
Florian Westphal81944112012-08-09 09:18:50 +0000229check_ipset()
230{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800231 cat >$TMPDIR/ipsettest.c <<EOF
Florian Westphal81944112012-08-09 09:18:50 +0000232#include <linux/netfilter/ipset/ip_set.h>
233#ifndef IP_SET_INVALID
234#define IPSET_DIM_MAX 3
235typedef unsigned short ip_set_id_t;
236#endif
237#include <linux/netfilter/xt_set.h>
238
239struct xt_set_info info;
240#if IPSET_PROTOCOL == 6
241int main(void)
242{
243 return IPSET_MAXNAMELEN;
244}
245#else
246#error unknown ipset version
247#endif
248EOF
249
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800250 if $CC -I$INCLUDE -o $TMPDIR/ipsettest $TMPDIR/ipsettest.c >/dev/null 2>&1
251 then
Florian Westphal81944112012-08-09 09:18:50 +0000252 echo "TC_CONFIG_IPSET:=y" >>Config
253 echo "yes"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800254 else
Florian Westphal81944112012-08-09 09:18:50 +0000255 echo "no"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800256 fi
257 rm -f $TMPDIR/ipsettest.c $TMPDIR/ipsettest
Florian Westphal81944112012-08-09 09:18:50 +0000258}
259
Daniel Borkmann11c39b52015-03-16 19:37:41 +0100260check_elf()
261{
262 cat >$TMPDIR/elftest.c <<EOF
263#include <libelf.h>
264#include <gelf.h>
265int main(void)
266{
Stephen Hemminger9f9ccc82016-12-14 19:09:55 -0800267 Elf_Scn *scn __attribute__((__unused__));
268 GElf_Shdr shdr __attribute__((__unused__));;
Daniel Borkmann11c39b52015-03-16 19:37:41 +0100269 return elf_version(EV_CURRENT);
270}
271EOF
272
273 if $CC -I$INCLUDE -o $TMPDIR/elftest $TMPDIR/elftest.c -lelf >/dev/null 2>&1
274 then
Daniel Borkmanne4225662016-11-10 01:20:59 +0100275 echo "HAVE_ELF:=y" >>Config
Daniel Borkmann11c39b52015-03-16 19:37:41 +0100276 echo "yes"
277 else
278 echo "no"
279 fi
280 rm -f $TMPDIR/elftest.c $TMPDIR/elftest
281}
282
Richard Haines116ac922014-03-07 10:36:52 +0000283check_selinux()
284# SELinux is a compile time option in the ss utility
285{
286 if ${PKG_CONFIG} libselinux --exists
287 then
288 echo "HAVE_SELINUX:=y" >>Config
289 echo "yes"
290 else
291 echo "no"
292 fi
293}
294
Vadim Kochanb6907402015-05-29 13:27:41 +0300295check_mnl()
296{
297 if ${PKG_CONFIG} libmnl --exists
298 then
299 echo "HAVE_MNL:=y" >>Config
Vadim Kochana25df482015-09-18 19:17:13 +0300300 echo "yes"
Vadim Kochanb6907402015-05-29 13:27:41 +0300301 else
Vadim Kochana25df482015-09-18 19:17:13 +0300302 echo "no"
Vadim Kochanb6907402015-05-29 13:27:41 +0300303 fi
304}
305
Vadim Kochana25df482015-09-18 19:17:13 +0300306check_berkeley_db()
307{
308 cat >$TMPDIR/dbtest.c <<EOF
309#include <fcntl.h>
310#include <stdlib.h>
311#include <db_185.h>
312int main(int argc, char **argv) {
313 dbopen("/tmp/xxx_test_db.db", O_CREAT|O_RDWR, 0644, DB_HASH, NULL);
314 return 0;
315}
316EOF
317 $CC -I$INCLUDE -o $TMPDIR/dbtest $TMPDIR/dbtest.c -ldb >/dev/null 2>&1
318 if [ $? -eq 0 ]
319 then
320 echo "HAVE_BERKELEY_DB:=y" >>Config
321 echo "yes"
322 else
323 echo "no"
324 fi
325 rm -f $TMPDIR/dbtest.c $TMPDIR/dbtest
326}
327
David Ahern57bdf8b2016-05-24 15:04:49 -0700328quiet_config()
329{
330 cat <<EOF
331# user can control verbosity similar to kernel builds (e.g., V=1)
332ifeq ("\$(origin V)", "command line")
333 VERBOSE = \$(V)
334endif
335ifndef VERBOSE
336 VERBOSE = 0
337endif
338ifeq (\$(VERBOSE),1)
339 Q =
340else
341 Q = @
342endif
343
344ifeq (\$(VERBOSE), 0)
345 QUIET_CC = @echo ' CC '\$@;
346 QUIET_AR = @echo ' AR '\$@;
347 QUIET_LINK = @echo ' LINK '\$@;
348 QUIET_YACC = @echo ' YACC '\$@;
349 QUIET_LEX = @echo ' LEX '\$@;
350endif
351EOF
352}
353
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000354echo "# Generated config based on" $INCLUDE >Config
David Ahern57bdf8b2016-05-24 15:04:49 -0700355quiet_config >> Config
356
Mike Frysinger601f60e2012-12-16 17:09:15 -0500357check_toolchain
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000358
359echo "TC schedulers"
360
361echo -n " ATM "
362check_atm
363
Daniel Borkmann4710e462016-10-18 14:13:09 +0200364check_xtables
365if ! grep -q TC_CONFIG_NO_XT Config
366then
367 echo -n " IPT "
368 check_xt
369 check_xt_old
370 check_xt_old_internal_h
371 check_ipt
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000372
Daniel Borkmann4710e462016-10-18 14:13:09 +0200373 echo -n " IPSET "
374 check_ipset
375fi
Florian Westphal81944112012-08-09 09:18:50 +0000376
Stephen Hemmingeraaf70452015-06-25 15:10:22 -0400377echo
Daniel Borkmann4710e462016-10-18 14:13:09 +0200378if ! grep -q TC_CONFIG_NO_XT Config
379then
380 echo -n "iptables modules directory: "
381 check_ipt_lib_dir
382fi
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000383
384echo -n "libc has setns: "
385check_setns
Richard Haines116ac922014-03-07 10:36:52 +0000386
387echo -n "SELinux support: "
388check_selinux
vadimk10ed8b72014-11-30 18:08:25 +0200389
Daniel Borkmann11c39b52015-03-16 19:37:41 +0100390echo -n "ELF support: "
391check_elf
392
Vadim Kochanb6907402015-05-29 13:27:41 +0300393echo -n "libmnl support: "
394check_mnl
Vadim Kochanb6907402015-05-29 13:27:41 +0300395
Vadim Kochana25df482015-09-18 19:17:13 +0300396echo -n "Berkeley DB: "
397check_berkeley_db
398
Stephen Hemmingeraaf70452015-06-25 15:10:22 -0400399echo
400echo -n "docs:"
vadimk10ed8b72014-11-30 18:08:25 +0200401check_docs
Stephen Hemmingeraaf70452015-06-25 15:10:22 -0400402echo
David Ahern57bdf8b2016-05-24 15:04:49 -0700403
404echo >> Config
405echo "%.o: %.c" >> Config
406echo ' $(QUIET_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<' >> Config