@@ -23,42 +23,70 @@ NO_TTY=
2323while [[ $# -gt 0 ]]; do
2424 case $1 in
2525
26- --arch=x86) ARCH=" X86" ; shift ;;
27- --arch=arm) ARCH=" ARM" ; shift ;;
28- --arch=arm,x86) ARCH=" ARM\\ ;X86" ; shift ;;
29- --arch=x86,arm) ARCH=" X86 \\ ;ARM " ; shift ;;
26+ --arch=x86) ARCH=" X86" ; shift ;;
27+ --arch=arm) ARCH=" ARM" ; shift ;;
28+ --arch=arm,x86) ARCH=" ARM\\ ;X86" ; shift ;;
29+ --arch=x86,arm) ARCH=" ARM \\ ;X86 " ; shift ;;
3030
31- --verbose ) VERBOSE= " -v " ; shift ;;
32- --no-tty) NO_TTY=--no-tty ; shift ;;
31+ --variant=vanilla ) VARIANT= " vanilla " ; shift ;;
32+ --variant=obfuscator) VARIANT= " obfuscator " ; shift ;;
3333
34- * ) shift ;;
34+ --verbose) VERBOSE=" -v" ; shift ;;
35+ --no-tty) NO_TTY=--no-tty; shift ;;
36+
37+ * ) shift ;;
3538 esac
3639done
3740
3841if [[ -z " ${ARCH:- } " ]]; then
39- echo " Error: must specify --arch=<arm|x86>"
42+ echo " Error: must specify --arch=<arm|x86|arm,x86|x86,arm >"
4043 exit 1
4144fi
4245
43- set -x
44- # -DLLVM_BUILD_TOOLS:BOOL=FALSE \
46+ if [[ -z " ${VARIANT:- } " ]]; then
47+ echo " Error: must a variant to build --variant=<vanilla|obfuscator>"
48+ exit 1
49+ fi
50+
51+ CXX_FLAGS=" -L/toolchain/x86/x86_64-buildroot-linux-gnu/sysroot/lib \
52+ -L/toolchain/x86/x86_64-buildroot-linux-gnu/sysroot/usr/lib \
53+ -I/toolchain/x86/lib/gcc/x86_64-buildroot-linux-gnu/6.4.0/plugin/include"
54+
55+ if [[ " $VARIANT " == " obfuscator" ]]; then
56+ LLVM_REPO=" https://github.com/obfuscator-llvm/obfuscator.git"
57+ LLVM_BRANCH=" llvm-4.0"
58+ CLANG_REPO=" "
59+ CLANG_TOOLS_EXTRA_REPO=" "
60+ CPP_WRAPPER_DEFINE=" -DCMAKE_CXX_COMPILER=/bin/cpp_wrapper"
61+ PATCH_COMMAND=" { git apply /patches/*.patch || : ; }"
62+ COMPILE_CPP_WRAPPER=" cp -v /this_dir/cpp_wrapper.c /work/cpp_wrapper.c \
63+ && gcc -std=c99 -O3 -Wall /work/cpp_wrapper.c -o /bin/cpp_wrapper"
64+ else
65+ LLVM_REPO=" https://github.com/llvm-mirror/llvm.git"
66+ CLANG_REPO=" https://github.com/llvm-mirror/clang.git"
67+ CLANG_TOOLS_EXTRA_REPO=" https://github.com/llvm-mirror/clang-tools-extra.git"
68+ LLVM_BRANCH=" release_60"
69+ CPP_WRAPPER_DEFINE=" -DCMAKE_CXX_COMPILER=/toolchain/x86/bin/x86_64-linux-g++"
70+ PATCH_COMMAND=" true"
71+ COMPILE_CPP_WRAPPER=" true"
72+ CXX_FLAGS+=" -I/work/$VARIANT -llvm/tools/clang/include"
73+ CXX_FLAGS+=" -I/work/build/tools/clang/include"
74+ fi
4575
4676CMAKE_COMMAND=" \
4777 cmake -G Ninja \
48- /work/obfuscator -llvm \
49- -DCMAKE_INSTALL_PREFIX=/opt/llvm-obfuscator \
78+ /work/$VARIANT -llvm \
79+ -DCMAKE_INSTALL_PREFIX=/opt/llvm-$VARIANT \
5080 -DLLVM_TARGETS_TO_BUILD=$ARCH \
51- -DCMAKE_CXX_FLAGS='-DENDIAN_LITTLE=1 -I/toolchain/x86/lib/gcc/x86_64-buildroot-linux-gnu/6.4.0/plugin/include' \
81+ -DCMAKE_CXX_FLAGS='-DENDIAN_LITTLE=1 $CXX_FLAGS ' \
82+ -DLLVM_CCACHE_BUILD=ON \
83+ $CPP_WRAPPER_DEFINE \
5284 -DCMAKE_C_COMPILER=/toolchain/x86/bin/x86_64-linux-gcc \
53- -DCMAKE_CXX_COMPILER=/bin/cpp_wrapper \
5485 -DCMAKE_BUILD_TYPE=Release \
5586 -DLLVM_BINUTILS_INCDIR=/usr/include \
56- -DLLDB_DISABLE_CURSES:BOOL=TRUE \
5787 -DLLVM_ENABLE_TERMINFO=0 \
5888 -DLLVM_INCLUDE_TESTS=OFF"
5989
60- PATCH_COMMAND=" { git apply /patches/*.patch || : ; }"
61-
6290if [[ -z " $NO_TTY " ]]; then
6391 INTERACTIVE=(" -i" " -t" )
6492else
@@ -70,23 +98,21 @@ docker run ${INTERACTIVE[@]:-} --rm \
7098 -v " $PWD /output/opt:/opt" \
7199 -v " $PWD /patches:/patches" \
72100 -v " $PWD :/this_dir" \
73- -v obfuscator-llvm:/work/obfuscator-llvm \
74- -v obfuscator-llvm-build:/work/build \
75- " $DOCKER_NAMETAG " \
76- /bin/bash -c " if [ ! -d /work/obfuscator-llvm/.git ]; then \
77- git clone --depth=1 --single-branch -b llvm-4.0 \
78- https://github.com/obfuscator-llvm/obfuscator.git \
79- obfuscator-llvm;
80- else \
81- (cd /work/obfuscator-llvm && git pull); \
82- fi \
83- && cp -v /this_dir/cpp_wrapper.c /work/cpp_wrapper.c \
84- && gcc -std=c99 -O3 -Wall /work/cpp_wrapper.c -o /bin/cpp_wrapper \
85- && cd /work/obfuscator-llvm \
86- && $PATCH_COMMAND \
87- && cd /work/build \
88- && $CMAKE_COMMAND \
89- && ninja $VERBOSE \
90- && ninja $VERBOSE install"
91-
92- ./stage_sysroot.bash $NO_TTY
101+ -v $VARIANT -llvm-ccache:/work/ccache \
102+ -v $VARIANT -llvm:/work/$VARIANT -llvm \
103+ -v $VARIANT -llvm-build:/work/build \
104+ -e VARIANT=$VARIANT -e ARCH=$ARCH \
105+ -e VERBOSE=$VERBOSE -e NO_TTY=$NO_TTY \
106+ -e CPP_WRAPPER_DEFINE=$CPP_WRAPPER_DEFINE \
107+ -e CMAKE_COMMAND=" $CMAKE_COMMAND " \
108+ -e LLVM_REPO=$LLVM_REPO \
109+ -e LLVM_BRANCH=$LLVM_BRANCH \
110+ -e CLANG_REPO=$CLANG_REPO \
111+ -e CLANG_TOOLS_EXTRA_REPO=$CLANG_TOOLS_EXTRA_REPO \
112+ -e PATCH_COMMAND=$PATCH_COMMAND \
113+ -e COMPILE_CPP_WRAPPER=$COMPILE_CPP_WRAPPER \
114+ -e CCACHE_DIR=/work/ccache \
115+ " $DOCKER_NAMETAG -$VARIANT " \
116+ /bin/bash -c " /this_dir/do_clang_build.bash"
117+
118+ ./stage_sysroot.bash $NO_TTY " --variant=$VARIANT "
0 commit comments