forked from libpnet/libpnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
121 lines (105 loc) · 2.86 KB
/
build.sh
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
#!/bin/bash
# Copyright (c) 2014 Robert Clipsham <[email protected]>
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
# Build script, since cargo doesn't currently work on FreeBSD
[[ "$VERBOSE" == "1" ]] && set -x
RUSTC=$(which rustc)
RUSTDOC=$(which rustdoc)
CARGO=$(which cargo)
SUDO=$(which sudo)
SYSTEM=$(uname -s)
TESTER="$CARGO test"
CC=$(which clang || which gcc)
CARGO_FLAGS=
# FIXME Need to get interface differently on Windows
PNET_TEST_IFACE=$(ifconfig | egrep 'UP| active' | \
perl -pe '/^[A-z0-9]+:([^\n]|\n\t)*status: active/' | \
grep active -B1 | head -n1 | cut -f1 -d:)
# FIXME Need to link libraries properly on Windows
build() {
if [[ -x "$CARGO" ]]; then
$CARGO build $CARGO_FLAGS --release
else
$RUSTC src/lib.rs
fi
}
build_doc() {
if [[ -x "$CARGO" ]]; then
$CARGO doc $CARGO_FLAGS
else
$RUSTDOC src/lib.rs -o target/doc --crate-name pnet
fi
}
build_test() {
if [[ -x "$CARGO" ]]; then
$CARGO test --no-run $CARGO_FLAGS
else
$RUSTC src/lib.rs --test --out-dir ./target/ -C extra-filename=-no-cargo
fi
}
run_test() {
build_test &&
echo "Setting permissions for test suite - enter sudo password if prompted" &&
case "$SYSTEM" in
Linux)
if [[ "$(id -u)" != "0" ]]; then
$SUDO setcap cap_net_raw+ep target/pnet-*;
fi
RUST_TEST_TASKS=1 $TESTER
;;
FreeBSD|Darwin)
$SUDO PNET_TEST_IFACE=$PNET_TEST_IFACE RUST_TEST_TASKS=1 $TESTER
;;
MINGW*|MSYS*)
PNET_TEST_IFACE=$PNET_TEST_IFACE RUST_TEST_TASKS=1 $TESTER
;;
*)
echo "Unsupported testing platform"
;;
esac
}
clean() {
if [[ -x "$CARGO" ]]; then
$CARGO clean $CARGO_FLAGS
else
rm -fr target
fi
}
benchmarks() {
[[ "$SYSTEM" != "Darwin" ]] && echo warning: C benchmarks only work on OS X
$CC -W -Wall -O2 benches/c_receiver.c -o target/benches/c_receiver
$CC -W -Wall -O2 benches/c_sender.c -o target/benches/c_sender
$RUSTC -O benches/rs_receiver.rs --out-dir target/benches -L target/release
$RUSTC -O benches/rs_sender.rs --out-dir target/benches -L target/release
}
mkdir -p target/doc
mkdir -p target/benches
if [[ "$VERBOSE" == "1" ]]; then
CARGO_FLAGS="--verbose"
TESTER="$TESTER $CARGO_FLAGS"
fi
if [[ ! -x "$CARGO" ]]; then
TESTER='./target/pnet-*'
fi
case "$1" in
test)
run_test
;;
doc)
build_doc
;;
clean)
clean
;;
benchmarks)
benchmarks
;;
*)
build
;;
esac