#!/usr/bin/env bash
#
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
# ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
#

set -u
set -e

source="${BASH_SOURCE[0]}"
while [ -h "$source" ] ; do
    prev_source="$source"
    source="$(readlink "$source")";
    if [[ "$source" != /* ]]; then
        # if the link was relative, it was relative to where it came from
        dir="$( cd -P "$( dirname "$prev_source" )" && pwd )"
        source="$dir/$source"
    fi
done
location="$( cd -P "$( dirname "$source" )" && pwd )"

CLANG="${CLANG:-clang}"
LLVM_DIR="${location}/../"
SANDBOXED_SYSROOT="${LLVM_DIR}/sandboxed"
SANDBOXED_CFLAGS="-emit-llvm -target x86_64-unknown-linux-gnu --sysroot ${SANDBOXED_SYSROOT} -g -O1 -I${LLVM_DIR} -I${SANDBOXED_SYSROOT}/include"

${CLANG} ${SANDBOXED_CFLAGS} $@
