-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfigure
executable file
·153 lines (135 loc) · 4 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
#!/usr/bin/env bash
set -e
set -x
trap 'echo -e "\n\nConfiguration failed\n\n" >&2' ERR
rootdir=$(readlink -f $(dirname $0))
function usage() {
echo "'configure' configures UBBD to compile on supported platforms."
echo ""
echo "Usage: ./configure [OPTION]..."
echo ""
echo "Defaults for the options are specified in brackets."
echo ""
echo "General:"
echo " -h, --help Display this help and exit"
echo ""
echo " --prefix=path Configure installation prefix (default: /usr/local)"
echo " --enable-debug Configure for debug builds"
echo " --enable-asan Enable address sanitizer"
echo ""
echo "Backend:"
echo " --enable-rbd-backend Support RBD backend."
echo " --disable-rbd-backend Dont support RBD backend."
echo " --enable-s3-backend Support S3 backend."
echo " --disable-s3-backend Dont support S3 backend."
echo " --enable-ssh-backend Support SSH backend."
echo " --disablee-ssh-backend Dont support SSH backend."
echo " --enable-cache-backend Support CACHE backend."
echo " --disable-cache-backend Dont support CACHE backend."
echo ""
}
# Load default values
# Convert config to sourceable configuration file
sed -r 's/CONFIG_([[:alnum:]_]+)=(.*)/CONFIG[\1]=\2/g' $rootdir/CONFIG > $rootdir/CONFIG.sh
declare -A CONFIG
source $rootdir/CONFIG.sh
rm $rootdir/CONFIG.sh
CONFIG_RBD_BACKEND=y
CONFIG_S3_BACKEND=n
CONFIG_CACHE_BACKEND=n
CONFIG_SSH_BACKEND=n
for i in "$@"; do
case "$i" in
-h | --help)
usage
exit 0
;;
--prefix=*)
CONFIG[PREFIX]="${i#*=}"
;;
--enable-debug)
CONFIG[DEBUG]=y
;;
--disable-debug)
CONFIG[DEBUG]=n
;;
--enable-asan)
CONFIG[ASAN]=y
;;
--disable-asan)
CONFIG[ASAN]=n
;;
--enable-rbd-backend)
CONFIG[RBD_BACKEND]=y
;;
--disable-rbd-backend)
CONFIG[RBD_BACKEND]=n
;;
--enable-s3-backend)
CONFIG[S3_BACKEND]=y
;;
--disable-s3-backend)
CONFIG[S3_BACKEND]=n
;;
--enable-cache-backend)
CONFIG[CACHE_BACKEND]=y
;;
--disable-cache-backend)
CONFIG[CACHE_BACKEND]=n
;;
--enable-ssh-backend)
CONFIG[SSH_BACKEND]=y
;;
--disable-ssh-backend)
CONFIG[CACHE_BACKEND]=n
;;
*)
echo "Unrecognized option $i"
usage
exit 1
;;
esac
done
CC=gcc
if [[ $arch == x86_64* ]]; then
BUILD_CMD=($CC -o /dev/null -x c $CPPFLAGS $CFLAGS $LDFLAGS "-march=native")
else
BUILD_CMD=($CC -o /dev/null -x c $CPPFLAGS $CFLAGS $LDFLAGS)
fi
BUILD_CMD+=(-I/usr/local/include -L/usr/local/lib)
if [[ "${CONFIG[RBD]}" = "y" ]]; then
if ! echo -e '#include <rbd/librbd.h>\n#include <rados/librados.h>\n' \
'int main(void) { return 0; }\n' \
| "${BUILD_CMD[@]}" -lrados -lrbd - 2> /dev/null; then
echo "--enable-rbd-backend requires librados and librbd."
echo "Please install then re-run this script."
exit 1
fi
fi
if [[ "${CONFIG[ASAN]}" = "y" ]]; then
if ! echo -e 'int main(void) { return 0; }\n' \
| "${BUILD_CMD[@]}" -fsanitize=address - 2> /dev/null; then
echo "--enable-asan requires libasan."
echo "Please install then re-run this script."
exit 1
fi
fi
# We are now ready to generate final configuration. But first do sanity
# check to see if all keys in CONFIG array have its reflection in CONFIG file.
if (($(grep -cE "^\s*CONFIG_[[:alnum:]_]+=" "$rootdir/CONFIG") != ${#CONFIG[@]})); then
echo ""
echo "BUG: Some configuration options are not present in CONFIG file. Please update this file."
echo "Missing options in CONFIG (+) file and in current config (-): "
diff -u --label "CONFIG file" --label "CONFIG[@]" \
<(sed -r -e '/^[[:space:]]*$/d; /^[[:space:]]*#.*/d; s/(CONFIG_[[:alnum:]_]+)=.*/\1/g' CONFIG | sort) \
<(printf "CONFIG_%s\n" "${!CONFIG[@]}" | sort)
exit 1
fi
echo -n "Creating mk/config.mk..."
mkdir -p $rootdir/mk/
cp -f $rootdir/CONFIG $rootdir/mk/config.mk
for key in "${!CONFIG[@]}"; do
sed -i.bak -r "s#[[:space:]]*CONFIG_${key}=.*#CONFIG_${key}\?=${CONFIG[$key]}#g" $rootdir/mk/config.mk
done
echo "Type 'make' to build."
exit 0