diff --git a/Makefile.config.in b/Makefile.config.in index e0263c2b1..0bfa5e20c 100644 --- a/Makefile.config.in +++ b/Makefile.config.in @@ -9,6 +9,7 @@ PLATFORM = $(shell uname) ABSOLUTE_ROOT_DIR = $(shell cd $(ROOT_DIR) && pwd) +FCP_DIR = $(ABSOLUTE_ROOT_DIR)/facebook-clang-plugins INFER_DIR = $(ABSOLUTE_ROOT_DIR)/infer DEPENDENCIES_DIR = $(ABSOLUTE_ROOT_DIR)/dependencies FCP_DIR = $(ABSOLUTE_ROOT_DIR)/facebook-clang-plugins diff --git a/Makefile.in b/Makefile.in index 356c87c9c..7fe3dc64e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -14,10 +14,35 @@ all: clang java java: $(MAKE) -C $(INFER_DIR) java -clang: +clang_setup: + export CC="@CC@" CFLAGS="@CFLAGS@"; \ + export CXX="@CXX@" CXXFLAGS="@CXXFLAGS@"; \ + export CPP="@CPP@" LDFLAGS="@LDFLAGS@" LIBS="@LIBS@"; \ + $(FCP_DIR)/clang/setup.sh + +clang_plugin: clang_setup + $(MAKE) -C $(FCP_DIR)/libtooling all \ + CC=@CC@ CXX=@CXX@ \ + CXX="@CXX@" CXXFLAGS="@CXXFLAGS@" \ + CPP="@CPP@" LDFLAGS="@LDFLAGS@" LIBS="@LIBS@" \ + LOCAL_CLANG=@CLANG_PREFIX@/bin/clang \ + CLANG_PREFIX=@CLANG_PREFIX@ \ + CLANG_INCLUDES=@CLANG_INCLUDES@ + $(MAKE) -C $(FCP_DIR)/clang-ocaml all \ + build/clang_ast_proj.ml build/clang_ast_proj.mli \ + CC=@CC@ CXX=@CXX@ \ + CXX="@CXX@" CXXFLAGS="@CXXFLAGS@" \ + CPP="@CPP@" LDFLAGS="@LDFLAGS@" LIBS="@LIBS@" \ + LOCAL_CLANG=@CLANG_PREFIX@/bin/clang \ + CLANG_PREFIX=@CLANG_PREFIX@ \ + CLANG_INCLUDES=@CLANG_INCLUDES@ + +clang: clang_plugin $(MAKE) -C $(INFER_DIR) clang clean: + $(MAKE) -C $(FCP_DIR) clean + $(MAKE) -C $(FCP_DIR)/clang-ocaml clean $(MAKE) -C $(INFER_DIR) clean -.PHONY: all clean clang java +.PHONY: all clean clang clang_plugin clang_setup java diff --git a/build-infer.sh b/build-infer.sh index 5bb5caede..29766bcd7 100755 --- a/build-infer.sh +++ b/build-infer.sh @@ -113,40 +113,35 @@ if [ "$BUILD_JAVA" = "1" ]; then fi if [ "$BUILD_CLANG" = "1" ]; then TARGETS+=" clang" - if [ ! -f .release ]; then - if ! facebook-clang-plugins/clang/setup.sh --only-check-install; then - echo "" - echo " Warning: you are not using a release of Infer. The C and" - echo " Objective-C analyses require a custom clang to be compiled" - echo " now. This step takes ~30-60 minutes, possibly more." - echo "" - echo " To speed this along, you are encouraged to use a release of" - echo " Infer instead:" - echo "" - echo " http://fbinfer.com/docs/getting-started.html" - echo "" - echo " If you are only interested in analyzing Java programs, simply" - echo " run this script with only the \"java\" argument:" - echo "" - echo " $0 java" - echo "" - - confirm="n" - printf "Are you sure you want to compile clang? (y/N) " - if [ "$INTERACTIVE" = "no" ]; then - confirm="y" - echo "$confirm" - else - read confirm - fi - - if [ "x$confirm" != "xy" ]; then - exit 0 - fi - - ./facebook-clang-plugins/clang/setup.sh + if ! facebook-clang-plugins/clang/setup.sh --only-check-install; then + echo "" + echo " Warning: you are not using a release of Infer. The C and" + echo " Objective-C analyses require a custom clang to be compiled" + echo " now. This step takes ~30-60 minutes, possibly more." + echo "" + echo " To speed this along, you are encouraged to use a release of" + echo " Infer instead:" + echo "" + echo " http://fbinfer.com/docs/getting-started.html" + echo "" + echo " If you are only interested in analyzing Java programs, simply" + echo " run this script with only the \"java\" argument:" + echo "" + echo " $0 java" + echo "" + + confirm="n" + printf "Are you sure you want to compile clang? (y/N) " + if [ "$INTERACTIVE" = "no" ]; then + confirm="y" + echo "$confirm" + else + read confirm + fi + + if [ "x$confirm" != "xy" ]; then + exit 0 fi - ./compile-fcp.sh fi fi diff --git a/compile-fcp.sh b/compile-fcp.sh deleted file mode 100755 index a311983eb..000000000 --- a/compile-fcp.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -# Copyright (c) 2015 - present Facebook, Inc. -# All rights reserved. -# -# This source code is licensed under the BSD style license found in the -# LICENSE file in the root directory of this source tree. An additional grant -# of patent rights can be found in the PATENTS file in the same directory. - -set -e -set -x - -# This script installs the facebook-clang-plugins - -INFER_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PLUGIN_DIR="$INFER_ROOT/facebook-clang-plugins" -CLANG_EXEC="$PLUGIN_DIR/clang/bin/clang" - -# check if clang is available -if [ ! -f $CLANG_EXEC ]; then - echo "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" - make_vars+=" CC=$CC" - [ -z "$CXX" ] && export CXX="$PLUGIN_DIR/clang/bin/clang++" - make_vars+=" CXX=$CXX" - [ -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_vars -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 BiniouASTExporter -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; } diff --git a/configure.ac b/configure.ac index 399045589..635e83348 100644 --- a/configure.ac +++ b/configure.ac @@ -15,12 +15,12 @@ AC_PREREQ([2.63]) AC_INIT([Infer],[0.4.0],[https://github.com/facebook/infer/issues/]) AC_CONFIG_SRCDIR([infer/src/backend/sil.ml]) -#AC_CONFIG_HEADERS([config.h]) -# Checks for programs. -AC_PROG_CXX +# prefer clang over gcc because the plugins makes use of +# clang-specific #pragma's +AC_PROG_CC(clang gcc) +AC_PROG_CXX(clang++ g++) AC_PROG_AWK -AC_PROG_CC AC_PROG_CPP AC_PROG_INSTALL AC_PROG_LN_S @@ -68,6 +68,17 @@ AC_SUBST([ATDGEN]) AC_CHECK_TOOL([XCODE_SELECT], [xcode-select], [no]) AC_SUBST([XCODE_SELECT]) +# to compile the facebook-clang-plugins +AC_ARG_VAR([CLANG_PREFIX], [directory where clang is installed (defaults=$PWD/facebook-clang-plugins/clang)]) +AS_IF([test "x$CLANG_PREFIX" = "x"], [ + CLANG_PREFIX="$(pwd)/facebook-clang-plugins/clang" +]) + +AC_ARG_VAR([CLANG_INCLUDES], [clang headers directories (defaults=$CLANG_PREFIX/include)]) +AS_IF([test "x$CLANG_INCLUDES" = "x"], [ + CLANG_INCLUDES="$CLANG_PREFIX/include" +]) + # Checks for header files. AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h locale.h malloc.h stddef.h stdint.h stdlib.h string.h sys/mount.h sys/param.h sys/socket.h sys/statfs.h sys/time.h unistd.h wchar.h wctype.h])