forked from facebook/infer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile-fcp.sh
executable file
·48 lines (42 loc) · 1.75 KB
/
compile-fcp.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
#!/bin/bash
set -e
set -x
# This script installs the facebook-clang-plugins
#
# TODO (t5939566): ADD INSTRUCTIONS ON HOW TO CUSTOMIZE THE ENVVARS FOR
# THE INSTALLATION OF THE PLUGINS.
INFER_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PLUGIN_DIR="$INFER_ROOT/../facebook-clang-plugin"
CLANG_EXEC="$PLUGIN_DIR/clang/bin/clang"
# check if clang is available
if ! $CLANG_EXEC --version 2>&1 | grep -q '3\.6'; then
echo "The required version of clang has not been found in $CLANG_EXEC" && exit 1
fi
# install facebook-clang-plugins
pushd "$PLUGIN_DIR"
# prepare flags for the compilation on the Linux platform
platform="$(uname)"
if [ "$platform" == 'Linux' ]; then
export SDKPATH=""
export PATH="$PLUGIN_DIR/clang/bin:$PATH"
[ -z "$CC" ] && export CC="$PLUGIN_DIR/clang/bin/clang"
[ -z "$CXX" ] && export CXX="$PLUGIN_DIR/clang/bin/clang++"
[ -z "$CFLAGS" ] && export CFLAGS="-std=c++11 -fPIC"
[ -z "$LDFLAGS" ] && export LDFLAGS="-shared"
[ -z "$CLANG_PREFIX" ] && export CLANG_PREFIX="$PLUGIN_DIR/clang"
[ -z "$LLVM_INCLUDES" ] && export LLVM_INCLUDES="$PLUGIN_DIR/clang/include"
[ -z "$CLANG_INCLUDES" ] && export CLANG_INCLUDES="$LLVM_INCLUDES $CLANG_PREFIX/include"
fi
# compile
make clean
make -C clang-ocaml clean
make
make -C clang-ocaml all build/clang_ast_proj.ml build/clang_ast_proj.mli
popd
# check YojsonASTExporter works with clang
echo "int main() { return 0; }" | \
$CLANG_EXEC -o /dev/null -x c \
-Xclang -load -Xclang $PLUGIN_DIR/libtooling/build/FacebookClangPlugin.dylib \
-Xclang -plugin -Xclang YojsonASTExporter -c - > /dev/null \
|| { echo "$CLANG_EXEC and the facebook-clang-plugins are not working.";
echo "Check you're using the right revision of clang, then retry"; exit 1; }