-
Notifications
You must be signed in to change notification settings - Fork 28
/
configure
executable file
·286 lines (263 loc) · 7.29 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/bash
function build_dpdk {
git submodule update --init --recursive $dpdk_path
if [ -d "$dpdk_path" ]; then
cd $dpdk_path
if [ $? != 0 ]; then
fail "can't go to dpdk submodule"
fi
export RTE_SDK=`pwd`
make config T=$dpdk_target
sed -i "s/CONFIG_RTE_LIBRTE_PMD_PCAP=n/CONFIG_RTE_LIBRTE_PMD_PCAP=y/" ./build/.config
sed -i "s/CONFIG_RTE_EAL_IGB_UIO=y/CONFIG_RTE_EAL_IGB_UIO=n/" ./build/.config
sed -i "s/CONFIG_RTE_KNI_KMOD=y/CONFIG_RTE_KNI_KMOD=n/" ./build/.config
echo "Building DPDK"
make EXTRA_CFLAGS='-fPIC -O2 -g'
if [ $? != 0 ]; then
fail "DPDK build fail\nYou are on your own\nGood Luck !"
fi
echo "DPDK set up done"
cd -
else
fail "something seems wrong with dpdk directory"
fi
}
function check_compiler {
echo -e "#include <stdio.h>\nint main() {\nprintf(\"hello world\\\n\");\n}" > hw.c
$1 -Wall hw.c -o cccheck.out 2> /dev/null
retcomp=$?
rm hw.c 2> /dev/null
retstr=$(./cccheck.out 2> /dev/null)
./cccheck.out > /dev/null 2>/dev/null
retexec=$?
rm ./cccheck.out 2> /dev/null
if [ $retcomp -ne 0 ] || [ "$retstr" != "hello world" ] || [ $retexec -ne 0 ]; then
(>&2 echo "ERROR: $CC cannot compile hello world")
exit
fi
}
function print_help {
echo " --- HELP --- "
echo "Usage : ./configure [options] [variable]"
echo "Options :"
echo -e " -h --help\t\t\tPrint this help and exit"
echo -e " -v --verbose\t\t\tAugment compilation verbose"
echo -e " -n --no-verbose\t\tReduce compilation verbose"
echo -e " -p --print\t\t\tPrint variables values"
echo -e " -P --modifiers\t\tPrint available variables"
echo -e " -b --with-benchmarks\t\tCompile benchmarks"
echo -e " -e --with-examples\t\tCompile examples"
echo -e " -c --with-coverage\t\t\tCoverage tests"
echo -e " --asan\t\t\tCompile with address sanitizers"
echo -e " --dpdk-autobuild\t\tAutomatically checkout dpdk and build it"
echo -e " --extra-cflags\t\tspecify compiler flags [-Wall -g -O2]"
echo -e " --march\t\t\ttarget architecture [core-avx-i]"
echo -e " --no-check-compiler\t\tDo not check compiler"
}
function print_modifiers {
echo " --- MODIFIERS --- "
echo "Variables : R = replace / A = add"
echo -e "Syntax : ./configure [options] CC=gcc EXTRA_CFLAGS=\"-g -O2 -j4 ...\""
echo -e " CC\t\tR\tCompiler"
echo -e " EXTRA_CFLAGS\tA\tCompiler option, adds to CFLAGS"
echo -e " RTE_SDK\tR\tRoot directory of DPDK"
echo -e " PG_NAME\tR\tName of the compiled library ({NAME}.a / {NAME}.so.x.y.z)"
}
function print_var {
echo " --- VARIABLES --- "
echo "srcdir=$srcdir"
echo "OS=$OS"
echo "CC=$CC"
echo "PG_NAME=$PG_NAME"
echo "GLIB_HEADERS=$GLIB_HEADERS"
echo "GLIB_LIBS=$GLIB_LIBS"
echo "RTE_SDK=$RTE_SDK"
echo "RTE_SDK_HEADERS=$RTE_SDK_HEADERS"
echo "RTE_SDK_LIBS=$RTE_SDK_LIBS"
echo -en "$newExport"
}
function check_option {
if [ "$1" == "--help" ]; then
print_help
exit
elif [ "$1" == "--verbose" ]; then
echo add verbose
elif [ "$1" == "--prefix" ]; then
export "PREFIX"="$2"
return 2
elif [ "$1" == "--no-verbose" ]; then
echo remove verbose
elif [ "$1" == "--print" ]; then
pv=print_var
elif [ "$1" == "--extra-cflags" ]; then
var_add "EXTRA_CFLAGS" "$2"
return 2
elif [ "$1" == "--march" ]; then
var_add "PG_MARCH" "$2"
return 2
elif [ "$1" == "--hell-march" ]; then
var_add "PG_MARCH" "native"
elif [ "$1" == "--modifiers" ]; then
print_modifiers
exit
elif [ "$1" == "--dpdk-autobuild" ]; then
build_dpdk
elif [ "$1" == "--with-benchmarks" ]; then
addBenchmark=true
elif [ "$1" == "--with-examples" ]; then
addExample=true
elif [ "$1" == "--no-check-compiler" ]; then
doCheckCompiler=false
elif [ "$1" == "--asan" ]; then
addAsan=true
elif [ "$1" == "--with-coverage" ]; then
addCoverage=true
fi
}
function check_option_single {
if [[ "$1" == *"h"* ]]; then
print_help
exit
fi
if [[ "$1" == *"v"* ]]; then
echo add verbose
fi
if [[ "$1" == *"n"* ]]; then
echo remove verbose
fi
if [[ "$1" == *"p"* ]]; then
pv=print_var
fi
if [[ "$1" == *"P"* ]]; then
print_modifiers
exit
fi
if [[ "$1" == *"b"* ]]; then
addBenchmark=true
fi
if [[ "$1" == *"e"* ]]; then
addExample=true
fi
if [[ "$1" == *"c"* ]]; then
addCoverage=true
fi
}
DIR=$( dirname "$0" )
DIR=$( readlink -f -- "$DIR" )
cd $DIR
source "$DIR"/configure-helper.sh
source "$DIR"/error_print.sh
rm -f "$DIR"/src/npf/libqsbr/qsbr/ebr.h
mkdir -p "$DIR"/src/npf/libqsbr/qsbr
ln --symbolic -t "$DIR"/src/npf/libqsbr/qsbr/ "$DIR"/src/npf/libqsbr/src/ebr.h
rm -f "$DIR"/src/npf/npf/src/kern/stand/net/npfkern.h
mkdir -p "$DIR"/src/npf/npf/src/kern/stand/net
ln --symbolic -t "$DIR"/src/npf/npf/src/kern/stand/net/ "$DIR"/src/npf/npf/src/kern/npfkern.h
modifiers=("CC" "EXTRA_CFLAGS" "RTE_SDK" "PG_NAME", "PG_MARCH")
addBenchmark=false
addExample=false
addAsan=false
addCoverage=false
doCheckCompiler=true
newExport=""
dpdk_target=x86_64-native-linuxapp-gcc
dpdk_path="$DIR"/3rdparty/dpdk/
while [ $# -ne 0 ] ; do
var=$1
shift_nb="1"
if [[ ${var:0:2} == "--" ]]; then
check_option "$var" "$2"
ret=$?
if [ "$ret" -gt "1" ]; then
shift_nb=$ret
fi
elif [[ ${var:0:1} == "-" && ${var:1:2} != "-" ]]; then
check_option_single "$var"
else
validMod=false
for i in "${modifiers[@]}"; do
if [ "$(sed 's,=.*,,' <<< $var)" == "$i" ]; then
validMod=true
fi
done
if $validMod; then
export "$var"
ret=$?
if (( ! ret ));then
newExport+="$var\n"
var_add "$(sed 's,=.*,,' <<< $var)"
else
(>&2 echo "ERROR: $var failed")
print_modifiers
fi
else
(>&2 echo "ERROR: $var failed")
print_modifiers
fi
fi
shift $shift_nb
done
echo "#####################################" > config.mk
echo "### Configuration for packetgraph ###" >> config.mk
echo "#####################################" >> config.mk
if $addBenchmark;then
echo "include benchmark.mk" >> config.mk
fi
if $addExample;then
echo "include example.mk" >> config.mk
fi
var_add srcdir "./"
var_add OS "$(uname)"
if [[ $CC == "" ]];then
case $OS in
Linux) CC=gcc;;
Darwin) CC=clang;;
*) CC=cc
esac
fi
hash "$CC"
ret=$?
while (( "$ret" )) || [ ! "$CC" ]; do
echo "[ Compiler = $CC ]"
(>&2 echo "ERROR: Compiler not found")
echo -n "Compiler name : "
read CC
CC=$CC
hash "$CC"
ret=$?
done
if $doCheckCompiler; then
check_compiler "$CC"
fi
export CC="$CC"
var_add CC
if $addAsan;then
if [[ "$CC" == "gcc" ]]; then
var_add PG_ASAN_CFLAGS "-fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-sanitize=alignment --param asan-globals=0"
else
var_add PG_ASAN_CFLAGS "-fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-sanitize=alignment"
fi
newExport+="PG_ASAN_CFLAGS=$PG_ASAN_CFLAGS\n"
fi
if $addCoverage; then
var_add PG_COV_CFLAGS "-g -O0 -fprofile-arcs -ftest-coverage"
var_add PG_COV_LFLAGS "-lgcov"
fi
"$DIR"/dpdk_symbols.sh
var_add PG_NAME "libpacketgraph"
var_add GLIB_HEADERS "$(pkg-config --cflags glib-2.0)"
var_add GLIB_LIBS "$(pkg-config --libs glib-2.0)"
var_add PG_MARCH "core-avx-i"
var_add PREFIX "/usr/local/"
var_add EXTRA_CFLAGS ""
if [ ! "$RTE_SDK" ]; then
echo
(>&2 echo "ERROR: RTE_SDK not set")
echo "Set RTE_SDK :"
echo " cd {DPDK root directory}"
echo " export RTE_SDK=\$(pwd)"
exit;
fi
var_add RTE_SDK_HEADERS "-I$RTE_SDK/build/include/"
var_add RTE_SDK_LIBS "-lm -lpthread -ldl -lpcap -lnuma -L$RTE_SDK/build/lib/ -ldpdk"
$pv