#!/bin/bash
# Simple installation script for llvm/clang.

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
CLANG_SRC="$REPO_ROOT/clang/src/clang-3.6dev.tgz"
CLANG_PREFIX="$REPO_ROOT/clang"

platform=`uname`

if [ $platform == 'Darwin' ]; then
    echo "Installing clang..."

    TMP=`mktemp -d /tmp/clang-setup.XXXXXX`
    cd "$TMP"

    tar xzf "$CLANG_SRC"
    llvm/configure --prefix="$CLANG_PREFIX" --enable-libcpp --enable-cxx11 --disable-assertions --enable-optimized

    mkdir -p "$CLANG_PREFIX"
    make -j 8 && make install
    cp Release/bin/clang "$CLANG_PREFIX/bin/clang"
    strip -x "$CLANG_PREFIX/bin/clang"
    
    rm -rf "$TMP"
else
    echo "This installation script currently supports only Mac OS X."
fi

#!/bin/bash
set -x

# Simple installation script for llvm/clang.

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
CLANG_SRC="$REPO_ROOT/clang/src/clang-3.6dev.tgz"
CLANG_PREFIX="$REPO_ROOT/clang"

platform=`uname`

if [ $platform == 'Darwin' ]; then
    CONFIGURE_ARGS=(
        --prefix="$CLANG_PREFIX"
        --enable-libcpp
        --enable-cxx11
        --disable-assertions
        --enable-optimized
    )
elif [ $platform == 'Linux' ]; then
    CONFIGURE_ARGS=(
        --prefix="$CLANG_PREFIX"
        --enable-cxx11
        --disable-assertions
        --enable-optimized
    )
else
    echo "Clang setup: platform $platform is currently not supported by this script"; exit 1
fi

# start the installation
echo "Installing clang..."
TMP=`mktemp -d /tmp/clang-setup.XXXXXX`
pushd "$TMP"
tar xzf "$CLANG_SRC"
llvm/configure "${CONFIGURE_ARGS[@]}"

mkdir -p "$CLANG_PREFIX"
make -j 8 && make install
cp Release/bin/clang "$CLANG_PREFIX/bin/clang"
strip -x "$CLANG_PREFIX/bin/clang"
popd

rm -rf "$TMP"

Add support to install Clang on Linux platforms
[Clang] Add support to install Clang on Linux platforms

Summary: Add support to install Clang on Linux platforms.

Test Plan:
Tested on Ubuntu 14.04 with gcc/g++ 4.8.2 (in general gcc/g++ >= 4.7.3 should be fine).
To compile Clang on Linux, running the `clang/setup.sh` script works in the general case.
If the compilation of clang fails, then some environment variables can be customized to point to different locations:
  export CC=/path/to/gcc
  export CXX=/path/to/g++
  export LDFLAGS="-static-libstdc++"
then run `clang/setup.sh` again.

After clang is compiled, running `./clang/bin/clang --version` should print something similar to:
  clang version 3.6.0
  Target: x86_64-unknown-linux-gnu
  Thread model: posix

This version of clang will then be used to compile the plugins on Linux. Exporting the following variables should work in the general case to compile the plugins:
  #assuming $FCP_ROOT is the absolute path to the facebook-clang-plugins, then:
  export CC="$FCP_ROOT/clang/bin/clang"
  export CXX="$FCP_ROOT/clang/bin/clang++"
  export CFLAGS="-std=c++11 -fPIC"
  export LDFLAGS="-shared -static-libstdc++"
  export CLANG_PREFIX="$FCP_ROOT/clang"
  export LLVM_INCLUDES="$FCP_ROOT/clang/include"
  export CLANG_INCLUDES="$LLVM_INCLUDES $CLANG_PREFIX/include"
  export SDKPATH=""
then run
  make

If the compilation of the plugins fails, then some environment variables can be customized to point to different locations:
  export CC=/path/to/gcc
  export CXX=/path/to/g++
  export LDFLAGS_FCP="-shared -static-libstdc++"
  export CFLAGS_FCP="-std=c++11 -fPIC"
then run `make` again.

After the plugins are compiled, running:
  #assuming $FCP_ROOT is the absolute path to the facebook-clang-plugins, then:
  echo "int main() { return 0; }" | $FCP_ROOT/clang/bin/clang -o /dev/null -x c -Xclang -load -Xclang $FCP_ROOT/libtooling/build/FacebookClangPlugin.dylib -Xclang -plugin -Xclang YojsonASTExporter -c -
should print a simple AST in yjson format.

Reviewers: adek, martinoluca

Reviewed By: martinoluca

Subscribers: mathieubaudet

Differential Revision: https://phabricator.fb.com/D1946193

Tasks: 6472783

Signature: t1:1946193:1427400035:9455d8afc0dd5705836ef2202cca7e513bee7bf1
