11#! /bin/bash
2- set -e # Exit immediately on error (were trapping the exit signal)
3- trap ' previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
4- trap ' echo -e "\nINSTALL FAILED ON COMMAND: $previous_command\n"' EXIT
2+ . $INCLUDEOS_SRC /etc/set_traps.sh
53
6- #
7- # NOTE THE FOLLOWING VARIABLES HAS TO BE DEFINED:
8- #
9- # llvm_src -> path to clone llvm repo
10- # llvm_build-> path to build llvm-libs. (must beoutside of llvm)
11- # INCLUDEOS_SRC -> InclueOS git source (i.e =$HOME/IncludeOS)
12- # newlib_inc -> Include-path for newlib headers
4+ # Download, configure, compile and install llvm
135
6+ newlib_inc=$TEMP_INSTALL_DIR /i686-elf/include # path for newlib headers
7+ IncludeOS_posix=$INCLUDEOS_SRC /api/posix
8+ libcxx_inc=$BUILD_DIR /llvm/projects/libcxx/include
9+ libcxxabi_inc=$BUILD_DIR /llvm/projects/libcxxabi/include
1410
15- # OPTIONALS (required the first time, but optional later):
16- #
17- # $install_llvm_dependencies: required paackages, cmake, ninja etc.
18- # $download_llvm: Clone llvm svn sources
11+ # sysroot=$BUILD_DIR/IncludeOS_TEMP_install/i686-elf
1912
13+ # Install dependencies
14+ sudo apt-get install -y cmake ninja-build subversion zlib1g-dev libtinfo-dev
2015
21- IncludeOS_posix=$INCLUDEOS_SRC /api/posix
22- libcxx_inc=$BUILD_DIR /$llvm_src /projects/libcxx/include
23- # LLVM_TAG=RELEASE_381/final
16+ cd $BUILD_DIR
2417
25- if [ ! -z $install_llvm_dependencies ]; then
26- # Dependencies
27- sudo apt-get install -y cmake ninja-build subversion zlib1g-dev libtinfo-dev
28- fi
18+ download_llvm=${download_llvm:- " 1" } # This should be more dynamic
2919
3020if [ ! -z $download_llvm ]; then
3121 # Clone LLVM
32- svn co http://llvm.org/svn/llvm-project/llvm/tags/$LLVM_TAG $llvm_src
33- # git clone http://llvm.org/git/llvm
34-
35- # Clone CLANG - not necessary to build only libc++ and libc++abi
36- # cd llvm/tools
37- # svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
38- # svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
22+ svn co http://llvm.org/svn/llvm-project/llvm/tags/$LLVM_TAG llvm
3923
4024 # Clone libc++, libc++abi, and some extra stuff (recommended / required for clang)
41- cd $llvm_src /projects
25+ pushd llvm /projects
4226
4327 # Compiler-rt
4428 svn co http://llvm.org/svn/llvm-project/compiler-rt/tags/$LLVM_TAG compiler-rt
@@ -57,87 +41,52 @@ if [ ! -z $download_llvm ]; then
5741 # git clone http://llvm.org/git/libunwind
5842
5943 # Back to start
60- cd ../../
44+ popd
6145fi
6246
6347# Make a build-directory
64- mkdir -p $llvm_build
65- cd $llvm_build
48+ mkdir -p build_llvm
49+ pushd build_llvm
6650
6751if [ ! -z $clear_llvm_build_cache ]; then
6852 rm CMakeCache.txt
6953fi
7054
71- # General options
72- OPTS=-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" "
73-
74- # LLVM General options
75- OPTS+=-DBUILD_SHARED_LIBS=OFF" "
76- OPTS+=-DCMAKE_BUILD_TYPE=MinSizeRel" "
77- # OPTS+=-DCMAKE_BUILD_TYPE=Release" "
78-
79- # Can't build libc++ with g++ unless it's a cross compiler (need to specify target)
80- OPTS+=-DCMAKE_C_COMPILER=clang-$clang_version " "
81- OPTS+=-DCMAKE_CXX_COMPILER=clang++-$clang_version " " # -std=c++11" "
82-
8355TRIPLE=i686-pc-none-elf
84-
85- OPTS+=-DTARGET_TRIPLE=$TRIPLE " "
86- OPTS+=-DLLVM_BUILD_32_BITS=ON" "
87- OPTS+=-DLLVM_INCLUDE_TESTS=OFF" "
88- OPTS+=-DLLVM_ENABLE_THREADS=OFF" "
89- OPTS+=-DLLVM_DEFAULT_TARGET_TRIPLE=$TRIPLE " "
90-
91- # libc++-specific options
92- OPTS+=-DLIBCXX_ENABLE_SHARED=OFF" "
93- OPTS+=-DLIBCXX_ENABLE_THREADS=OFF" "
94- OPTS+=-DLIBCXX_TARGET_TRIPLE=$TRIPLE " "
95- OPTS+=-DLIBCXX_BUILD_32_BITS=ON" "
96-
97- # OPTS+=-DLIBCXX_GCC_TOOLCHAIN=/usr/local/IncludeOS/i686/" "
98- OPTS+=-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON" "
99-
100- OPTS+=-DLIBCXX_CXX_ABI=libcxxabi" "
101- OPTS+=-DLIBCXX_CXX_ABI_INCLUDE_PATHS=$INCLUDEOS_SRC /src/include" "
102-
103-
104- # libunwind-specific options
105- OPTS+=-DLIBUNWIND_ENABLE_SHARED=OFF" "
106- OPTS+=-LIBCXXABI_USE_LLVM_UNWINDER=ON" "
107-
108- echo " LLVM CMake Build options:" $OPTS
109-
110- # CXX flags
111- CXX_FLAGS=" -std=c++14 -nostdlibinc -mavx -maes -mfma"
56+ CXX_FLAGS=" -std=c++14 -msse3"
11257
11358# CMAKE configure step
11459#
115- # NOTE: It seems impossible to pass in cxx-flags like this; I've tried \' \\" \\\" etc.
116- #
11760# Include-path ordering:
11861# 1. IncludeOS_posix has to come first, as it provides lots of C11 prototypes that libc++ relies on, but which newlib does not provide (see our math.h)
11962# 2. libcxx_inc must come before newlib, due to math.h function wrappers around C99 macros (signbit, nan etc)
12063# 3. newlib_inc provodes standard C headers
121- cmake -GNinja $OPTS -DCMAKE_CXX_FLAGS=" $CXX_FLAGS -I$IncludeOS_posix -I$libcxx_inc -I$newlib_inc " $BUILD_DIR /$llvm_src
64+ cmake -GNinja $OPTS \
65+ -DCMAKE_CXX_FLAGS=" $CXX_FLAGS -I$IncludeOS_posix -I$libcxxabi_inc -I$libcxx_inc -I$newlib_inc " $BUILD_DIR /llvm \
66+ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
67+ -DBUILD_SHARED_LIBS=OFF \
68+ -DCMAKE_C_COMPILER=clang-$clang_version \
69+ -DCMAKE_CXX_COMPILER=clang++-$clang_version \
70+ -DTARGET_TRIPLE=$TRIPLE \
71+ -DLLVM_BUILD_32_BITS=ON \
72+ -DLLVM_INCLUDE_TESTS=OFF \
73+ -DLLVM_ENABLE_THREADS=OFF \
74+ -DLLVM_DEFAULT_TARGET_TRIPLE=$TRIPLE \
75+ -DLIBCXX_ENABLE_SHARED=OFF \
76+ -DLIBCXX_ENABLE_THREADS=OFF \
77+ -DLIBCXX_TARGET_TRIPLE=$TRIPLE \
78+ -DLIBCXX_BUILD_32_BITS=ON \
79+ -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \
80+ -DLIBCXX_CXX_ABI=libcxxabi \
81+ -DLIBCXXABI_TARGET_TRIPLE=$TRIPLE \
82+ -DLIBCXXABI_ENABLE_THREADS=OFF \
83+ -DLIBCXXABI_HAS_PTHREAD_API=OFF
12284
12385
124- #
12586# MAKE
126- #
127- # Using ninja
128- #
129- # ninja libc++abi.a
130- ninja libc++.a
131- # ninja libunwind.a
132- # ninja compiler-rt
133-
134- #
135- # MAKE
136- #
137- # Using makefiles
138- # make cxx
139- # make cxxabi
140- # unwind
87+ ninja libc++abi.a
88+ ninja libc++.a
14189
90+ popd
14291
14392trap - EXIT
0 commit comments