-
Notifications
You must be signed in to change notification settings - Fork 2
/
frr-build
executable file
·163 lines (146 loc) · 3.99 KB
/
frr-build
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
#!/bin/bash
#
# Copyright (C) 2022-2024 Rafael Zalamena
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
usage() {
cat <<EOF
Usage: $0
[-h] [--asan] [--doc] [--fpm] [--grpc] [--help] [--jobs=NUMBER]
[--scan-build] [--snmp] [--tsan]
Options:
--asan: build FRR with address sanitizer.
--tsan: build FRR with thread sanitizer.
--doc: configure FRR to enable documentation builds (requires sphinx).
--fpm: build FRR with forwarding plane manager.
--grpc: enable gRPC support.
--help or -h: this help message.
--jobs: amount of parallel build jobs (defaults to $jobs).
--scan-build: use clang static analyzer (compilation is way slower).
--snmp: build FRR with SNMP support.
EOF
exit 1
}
source_dir="/usr/src/frr"
flags=(
--enable-multipath=64
--prefix=/usr
--localstatedir=/var/run/frr
--sysconfdir=/etc/frr
--sbindir=/usr/lib/frr
--enable-user=frr
--enable-group=frr
--enable-vty-group=frrvty
--enable-nhrpd
--enable-sharpd
--enable-configfile-mask=0640
--enable-logfile-mask=0640
--enable-dev-build
--with-pkg-git-version
)
jobs=$(expr $(nproc))
scan_build=no
longopts='asan,doc,fpm,grpc,help,jobs:,scan-build,snmp,tsan'
shortopts='h'
options=$(getopt -u --longoptions "$longopts" "$shortopts" $*)
if [ $? -ne 0 ]; then
usage
exit 1
fi
set -- $options
while [ $# -ne 0 ]; do
case "$1" in
--asan)
flags+=(--enable-address-sanitizer);
shift
;;
--doc)
flags+=(--enable-doc)
flags+=(--enable-doc-html)
shift
;;
--fpm)
flags+=(--enable-fpm)
shift
;;
--grpc)
flags+=(--enable-grpc)
shift
;;
--jobs)
jobs="$2"
shift 2
;;
--scan-build)
scan_build=yes
shift
;;
--snmp)
flags+=(--enable-snmp=agentx)
shift
;;
--tsan)
flags+=(--enable-thread-sanitizer);
shift
;;
-h | --help)
usage
shift
;;
--) shift ;;
*) echo "unhandled argument '$1'" 2>&1 ; exit 1 ;;
esac
done
cd $source_dir
# Bootstrap the configure file
if [ ! -f configure ]; then
echo "=> Running bootstrap ..."
./bootstrap.sh
fi
# Configure if not configured
if [ ! -f Makefile ]; then
echo "=> Running configure ..."
./configure 'CFLAGS=-g' 'CXXFLAGS=-g' ${flags[@]}
fi
# Build
if [ $scan_build = 'no' ]; then
make --jobs=$jobs >/dev/null
else
scan-build make --jobs=$jobs >/dev/null
fi
# Install FRR binaries
make install >/dev/null
# Copy manual part
if [ ! -d /var/log/frr ]; then
install -m 775 -o frr -g frr -d /var/log/frr
fi
if [ ! -d /etc/frr ]; then
install -m 775 -o frr -g frrvty -d /etc/frr
install -m 640 -o frr -g frrvty $source_dir/tools/etc/frr/vtysh.conf \
/etc/frr/vtysh.conf
install -m 640 -o frr -g frr $source_dir/tools/etc/frr/frr.conf \
/etc/frr/frr.conf
install -m 640 -o frr -g frr $source_dir/tools/etc/frr/daemons \
/etc/frr/daemons
fi
if [ -f $source_dir/tools/frr.service ]; then
install -m 644 $source_dir/tools/frr.service \
/etc/systemd/system/frr.service
fi
sync
exit 0