]> git.proxmox.com Git - mirror_iproute2.git/blob - configure
configure: move toolchain init to a function
[mirror_iproute2.git] / configure
1 #! /bin/bash
2 # This is not an autconf generated configure
3 #
4 INCLUDE=${1:-"$PWD/include"}
5
6 # Make a temp directory in build tree.
7 TMPDIR=$(mktemp -d config.XXXXXX)
8 trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
9
10 check_toolchain()
11 {
12 : ${PKG_CONFIG:=pkg-config}
13 : ${CC=gcc}
14 echo "CC:=${CC}" >>Config
15 echo "PKG_CONFIG:=${PKG_CONFIG}" >>Config
16 }
17
18 check_atm()
19 {
20 cat >$TMPDIR/atmtest.c <<EOF
21 #include <atm.h>
22 int main(int argc, char **argv) {
23 struct atm_qos qos;
24 (void) text2qos("aal5,ubr:sdu=9180,rx:none",&qos,0);
25 return 0;
26 }
27 EOF
28 $CC -I$INCLUDE -o $TMPDIR/atmtest $TMPDIR/atmtest.c -latm >/dev/null 2>&1
29 if [ $? -eq 0 ]
30 then
31 echo "TC_CONFIG_ATM:=y" >>Config
32 echo yes
33 else
34 echo no
35 fi
36 rm -f $TMPDIR/atmtest.c $TMPDIR/atmtest
37 }
38
39 check_xt()
40 {
41 #check if we have xtables from iptables >= 1.4.5.
42 cat >$TMPDIR/ipttest.c <<EOF
43 #include <xtables.h>
44 #include <linux/netfilter.h>
45 static struct xtables_globals test_globals = {
46 .option_offset = 0,
47 .program_name = "tc-ipt",
48 .program_version = XTABLES_VERSION,
49 .orig_opts = NULL,
50 .opts = NULL,
51 .exit_err = NULL,
52 };
53
54 int main(int argc, char **argv)
55 {
56 xtables_init_all(&test_globals, NFPROTO_IPV4);
57 return 0;
58 }
59
60 EOF
61
62 if $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL $(${PKG_CONFIG} xtables --cflags --libs) -ldl >/dev/null 2>&1
63 then
64 echo "TC_CONFIG_XT:=y" >>Config
65 echo "using xtables"
66 fi
67 rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
68 }
69
70 check_xt_old()
71 {
72 # bail if previous XT checks has already succeded.
73 if grep TC_CONFIG_XT Config > /dev/null
74 then
75 return
76 fi
77
78 #check if we dont need our internal header ..
79 cat >$TMPDIR/ipttest.c <<EOF
80 #include <xtables.h>
81 char *lib_dir;
82 unsigned int global_option_offset = 0;
83 const char *program_version = XTABLES_VERSION;
84 const char *program_name = "tc-ipt";
85 struct afinfo afinfo = {
86 .libprefix = "libxt_",
87 };
88
89 void exit_error(enum exittype status, const char *msg, ...)
90 {
91 }
92
93 int main(int argc, char **argv) {
94
95 return 0;
96 }
97
98 EOF
99 $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
100
101 if [ $? -eq 0 ]
102 then
103 echo "TC_CONFIG_XT_OLD:=y" >>Config
104 echo "using old xtables (no need for xt-internal.h)"
105 fi
106 rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
107 }
108
109 check_xt_old_internal_h()
110 {
111 # bail if previous XT checks has already succeded.
112 if grep TC_CONFIG_XT Config > /dev/null
113 then
114 return
115 fi
116
117 #check if we need our own internal.h
118 cat >$TMPDIR/ipttest.c <<EOF
119 #include <xtables.h>
120 #include "xt-internal.h"
121 char *lib_dir;
122 unsigned int global_option_offset = 0;
123 const char *program_version = XTABLES_VERSION;
124 const char *program_name = "tc-ipt";
125 struct afinfo afinfo = {
126 .libprefix = "libxt_",
127 };
128
129 void exit_error(enum exittype status, const char *msg, ...)
130 {
131 }
132
133 int main(int argc, char **argv) {
134
135 return 0;
136 }
137
138 EOF
139 $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
140
141 if [ $? -eq 0 ]
142 then
143 echo "using old xtables with xt-internal.h"
144 echo "TC_CONFIG_XT_OLD_H:=y" >>Config
145 fi
146 rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
147 }
148
149 check_ipt()
150 {
151 if ! grep TC_CONFIG_XT Config > /dev/null
152 then
153 echo "using iptables"
154 fi
155 }
156
157 check_ipt_lib_dir()
158 {
159 IPT_LIB_DIR=$(${PKG_CONFIG} --variable=xtlibdir xtables)
160 if [ -n "$IPT_LIB_DIR" ]; then
161 echo $IPT_LIB_DIR
162 echo "IPT_LIB_DIR:=$IPT_LIB_DIR" >> Config
163 return
164 fi
165
166 for dir in /lib /usr/lib /usr/local/lib
167 do
168 for file in $dir/{xtables,iptables}/lib*t_*so ; do
169 if [ -f $file ]; then
170 echo ${file%/*}
171 echo "IPT_LIB_DIR:=${file%/*}" >> Config
172 return
173 fi
174 done
175 done
176 echo "not found!"
177 }
178
179 check_setns()
180 {
181 cat >$TMPDIR/setnstest.c <<EOF
182 #include <sched.h>
183 int main(int argc, char **argv)
184 {
185 (void)setns(0,0);
186 return 0;
187 }
188 EOF
189 $CC -I$INCLUDE -o $TMPDIR/setnstest $TMPDIR/setnstest.c >/dev/null 2>&1
190 if [ $? -eq 0 ]
191 then
192 echo "IP_CONFIG_SETNS:=y" >>Config
193 echo "yes"
194 else
195 echo "no"
196 fi
197 rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest
198 }
199
200 check_ipset()
201 {
202 cat >$TMPDIR/ipsettest.c <<EOF
203 #include <linux/netfilter/ipset/ip_set.h>
204 #ifndef IP_SET_INVALID
205 #define IPSET_DIM_MAX 3
206 typedef unsigned short ip_set_id_t;
207 #endif
208 #include <linux/netfilter/xt_set.h>
209
210 struct xt_set_info info;
211 #if IPSET_PROTOCOL == 6
212 int main(void)
213 {
214 return IPSET_MAXNAMELEN;
215 }
216 #else
217 #error unknown ipset version
218 #endif
219 EOF
220
221 if $CC -I$INCLUDE -o $TMPDIR/ipsettest $TMPDIR/ipsettest.c >/dev/null 2>&1
222 then
223 echo "TC_CONFIG_IPSET:=y" >>Config
224 echo "yes"
225 else
226 echo "no"
227 fi
228 rm -f $TMPDIR/ipsettest.c $TMPDIR/ipsettest
229 }
230
231 echo "# Generated config based on" $INCLUDE >Config
232 check_toolchain
233
234 echo "TC schedulers"
235
236 echo -n " ATM "
237 check_atm
238
239 echo -n " IPT "
240 check_xt
241 check_xt_old
242 check_xt_old_internal_h
243 check_ipt
244
245 echo -n " IPSET "
246 check_ipset
247
248 echo -n "iptables modules directory: "
249 check_ipt_lib_dir
250
251 echo -n "libc has setns: "
252 check_setns