Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Rev 9 | Rev 11 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #!/bin/sh
  2. # LLVM/Clang toolchain cross-compilation script for QNX 8.0 by Pierre-Marie Baty <pm@pmbaty.com>
  3.  
  4. # NOTE TO SELF: DO NOT USE $0 AS THIS SCRIPT CAN BE RUN *OR* SOURCED! (see build-llvm.sh in the VM)
  5.  
  6. export QNXSDK_VERSION="8.0.0" # version of the QNX SDK in use, in <major>.<minor>.<revision> format
  7. export QNXSDK_PATH="../qnx800" # relative location from the path of this script where to find the QNX platform SDK
  8. export QNXSDK_HOSTPATH="host/linux/x86_64" # relative location in QNXSDK_PATH of the tree containing the build tools that are runnable on the build host
  9. export QNXSDK_TARGETPATH="target/qnx" # relative location in QNXSDK_PATH of the tree containing the QNX8 system header files
  10.  
  11. export BUILD_DIR_NAME="llvm-build" # name of the directory on the build host's desktop where the LLVM sources will be built
  12. export BUILD_TARGET_ARCH="x86_64" # CPU architecture to build LLVM for, either "x86_64" or "aarch64"
  13.  
  14. export LLVM_VERSION="17.0.6" # version of LLVM that will be built
  15. export LLVM_SOURCES_FILE="llvmorg-${LLVM_VERSION}.tar.gz" # name of the file containing LLVM version LLVM_VERSION sources
  16. export LLVM_SOURCES_URL="https://github.com/llvm/llvm-project/archive/refs/tags/${LLVM_SOURCES_FILE}" # download URL of LLVM_SOURCES_FILE
  17. export LLVM_SOURCES_DIR="llvm-project-llvmorg-${LLVM_VERSION}" # name of directory created when extracting LLVM_SOURCES_FILE
  18.  
  19. # see where we are
  20. export CURRENT_DIR="$(pwd)"
  21.  
  22. # verify we're a x86_64 Linux host
  23. if [ ! "$(uname)" = "Linux" ] || [ ! "$(uname -m)" = "x86_64" ]; then
  24.         echo ""
  25.         echo "Error: this script requires a x86_64 Linux machine (possibly a virtual machine) as the build host." | fold -s -w 79
  26.         echo ""
  27.         exit 1
  28. fi
  29.  
  30. # verify that we have the QNX platform SDK
  31. if [ ! -d "${QNXSDK_PATH}/${QNXSDK_HOSTPATH}" ] || [ ! -d "${QNXSDK_PATH}/${QNXSDK_TARGETPATH}" ]; then
  32.         echo ""
  33.         echo "Error: the ${QNXSDK_PATH} path doesn't contain a QNX SDK. It must contain the 'host' and 'target' directories of the QNX SDP for the targeted version of QNX and the ${BUILD_TARGET_ARCH} platform. Please deploy these directories and try again." | fold -s -w 79
  34.         echo ""
  35.         exit 1
  36. fi
  37.  
  38. # verify that we have wget, python3, cmake, gcc, g++ and ninja
  39. if    ! wget    --version > /dev/null 2>&1 \
  40.    || ! python3 --version > /dev/null 2>&1 \
  41.    || ! cmake   --version > /dev/null 2>&1 \
  42.    || ! gcc     --version > /dev/null 2>&1 \
  43.    || ! g++     --version > /dev/null 2>&1 \
  44.    || ! ninja   --version > /dev/null 2>&1; then
  45.         echo ""
  46.         echo "Error: this script requires at the very least the following tools installed:"
  47.         echo "  wget"
  48.         echo "  python3"
  49.         echo "  cmake"
  50.         echo "  gcc"
  51.         echo "  g++"
  52.         echo "  ninja"
  53.         echo "Please install them (possibly as binary packages with apt-get) and try again."
  54.         echo ""
  55.         exit 1
  56. fi
  57.  
  58. # verify that the symlinks are deployed in the SDK -- just test one of them
  59. if [ ! -e "${QNXSDK_PATH}/${QNXSDK_TARGETPATH}/usr/include/readline.h" ]; then
  60.         echo ""
  61.         echo "Error: the toolchain platform-specific symbolic links have not been deployed in this QNX SDK. Please run" | fold -s -w 79
  62.         echo "(on a POSIX machine:)"
  63.         echo "  cd ${QNXSDK_PATH}" | fold -s -w 79
  64.         echo "  find . -name symlinks.lst -exec ./symlinks.sh {} create \\; && printf 'present' > .symlinks-state" | fold -s -w 79
  65.         echo "(else on a Windows machine:)"
  66.         echo "  cd ${QNXSDK_PATH}" | fold -s -w 79
  67.         echo "  host\\win64\\x86_64\\usr\\bin\\busybox.exe sh -c \"" \
  68.                "find . -name symlinks.lst -exec ./symlinks.sh {} create \\; && printf 'present' > .symlinks-state" \
  69.                "\"" | fold -s -w 79
  70.         echo "Note that this step WILL take time on a Win32 machine, but is only done once." | fold -s -w 79
  71.         echo ""
  72.         exit 1
  73. fi
  74.  
  75. # construct the target triple (actually a quadruple)
  76. export TARGET_ARCH="${BUILD_TARGET_ARCH}"
  77. test "${BUILD_TARGET_ARCH}" = "x86_64" && export TARGET_VENDOR="pc" || export TARGET_VENDOR="unknown"
  78. export TARGET_KERNEL="nto"
  79. export TARGET_SYSTEM="qnx${QNXSDK_VERSION}"
  80. export TARGET_TRIPLE="${TARGET_ARCH}-${TARGET_VENDOR}-${TARGET_KERNEL}-${TARGET_SYSTEM}"
  81. echo "Will build LLVM for ${TARGET_TRIPLE}"
  82.  
  83. # change to an immediately visible path, i.e. the user's desktop (failsafe to $HOME if xdg-user-dir is unavailable)
  84. STAGING_PATH="$(xdg-user-dir DESKTOP 2>/dev/null || echo "${HOME}")"
  85. cd "${STAGING_PATH}"
  86.  
  87. # create a symlink in /tmp that will lead to the QNX platform SDK so as to avoid spaces in paths if it doesn't exist already
  88. # (this is totally prohibitive with the official QNX toolchain)
  89. if [ ! -L /tmp/qnxsdk ] || [ ! "$(readlink /tmp/qnxsdk)" = "$(realpath "${CURRENT_DIR}/${QNXSDK_PATH}")" ]; then
  90.         echo "Creating symlink to QNX toolchain in /tmp/qnxsdk..."
  91.         rm -rf /tmp/qnxsdk 2>/dev/null
  92.         ln -fs "$(realpath "${CURRENT_DIR}/${QNXSDK_PATH}")" /tmp/qnxsdk || exit 1
  93. fi
  94.  
  95. # setup the environment
  96. export QNX_HOST="/tmp/qnxsdk/${QNXSDK_HOSTPATH}"
  97. export QNX_TARGET="/tmp/qnxsdk/${QNXSDK_TARGETPATH}"
  98. export MAKEFLAGS="-I${QNX_TARGET}/usr/include"
  99. export PATH="${QNX_HOST}/usr/bin:${PATH}"
  100.  
  101. # download the involved source packages and unpack them if not done yet
  102. download_and_unpack_if_necessary()
  103. {
  104.         # helper function that downloads a sources tarball, extracts it and patches it if necessary
  105.         # args: <sources dirname> <sources filename> <download URL> <patchset URL or empty string>
  106.         if [ ! -d "${1}" ]; then
  107.                 if [ ! -f "${CURRENT_DIR}/${2}" ]; then
  108.                         echo "Downloading ${1} sources from ${3}..."
  109.                         wget -O "${CURRENT_DIR}/${2}" "${3}" || exit 1
  110.                 fi
  111.                 echo "Extracting ${1} sources..."
  112.                 cd "$(dirname "${1}")"
  113.                 if echo "${2}"|grep -q "\.tar\.bz2$"; then
  114.                         tar xjf "${CURRENT_DIR}/${2}" || exit 1
  115.                 elif echo "${2}"|grep -q "\.tar\.xz$"; then
  116.                         tar xJf "${CURRENT_DIR}/${2}" || exit 1
  117.                 elif echo "${2}"|grep -q "\.tar\.gz$"; then
  118.                         tar xzf "${CURRENT_DIR}/${2}" || exit 1
  119.                 else
  120.                         echo "Error: unsupported file extension. Please improve the download_and_unpack_if_necessary() shell function to support it."
  121.                         exit 1
  122.                 fi
  123.                 if [ ! -d "${1}" ]; then
  124.                         echo "Error: couldn't find ${1} in extracted sources."
  125.                         exit 1
  126.                 fi
  127.                 if [ -n "${4}" ]; then
  128.                         echo "Downloading ${1} patchset from ${4}..."
  129.                         wget -O "${CURRENT_DIR}/${2}.patchset" "${4}" || exit 1
  130.                         echo "Applying patchset..."
  131.                         OLDDIR="$(pwd)"
  132.                         cd "${1}"
  133.                         patch -N -Z -p1 < "${CURRENT_DIR}/${2}.patchset" || exit 1
  134.                         cd "${OLDDIR}"
  135.                         unset OLDDIR
  136.                 fi
  137.         fi
  138.         return 0
  139. }
  140. download_and_unpack_if_necessary "${LLVM_SOURCES_DIR}" "${LLVM_SOURCES_FILE}" "${LLVM_SOURCES_URL}" || exit 1
  141.  
  142. # download the LLVM source package and unpack it if not done yet
  143. if [ ! -d "${LLVM_SOURCES_DIR}" ]; then
  144.         if [ ! -f "${CURRENT_DIR}/${LLVM_SOURCES_FILE}" ]; then
  145.                 echo "Downloading LLVM ${LLVM_VERSION} sources from LLVM GitHub..."
  146.                 wget "${LLVM_SOURCES_URL}" || exit 1
  147.         fi
  148.         echo "Extracting LLVM ${LLVM_VERSION} sources..."
  149.         cd "$(dirname "${LLVM_SOURCES_DIR}")"
  150.         tar xzf "${CURRENT_DIR}/${LLVM_SOURCES_FILE}" || exit 1
  151.         if [ ! -d "${LLVM_SOURCES_DIR}" ]; then
  152.                 echo "Error: couldn't find ${LLVM_SOURCES_DIR} in extracted LLVM sources."
  153.                 exit 1
  154.         fi
  155. fi
  156.  
  157. # create the build directory
  158. echo "Wiping out build directory..."
  159. test -e "${BUILD_DIR_NAME}" && rm -rf "${BUILD_DIR_NAME}"
  160. mkdir "${BUILD_DIR_NAME}" || exit 1
  161. cd "${BUILD_DIR_NAME}" || exit 1
  162.  
  163. # print the build environment
  164. echo "QNX_HOST=${QNX_HOST}"
  165. echo "QNX_TARGET=${QNX_TARGET}"
  166. echo "MAKEFLAGS=${MAKEFLAGS}"
  167.  
  168. # create the QNX CMake toolchain file
  169. test -e "${TARGET_TRIPLE}.cmake" || echo '# '${TARGET_TRIPLE}' CMake toolchain file by Pierre-Marie Baty <pm@pmbaty.com>
  170.  
  171. SET(CMAKE_SYSTEM_NAME "QNX")
  172. SET(CMAKE_SYSTEM_VERSION "'${QNXSDK_VERSION}'")
  173.  
  174. SET(QNX "1")
  175. SET(QNXNTO "1")
  176. SET(QNX_HOST "$ENV{QNX_HOST}")
  177. SET(QNX_TARGET "$ENV{QNX_TARGET}")
  178. SET(QNX_PROCESSOR "'${TARGET_ARCH}'")
  179.  
  180. SET(CMAKE_ASM_COMPILER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-gcc")
  181. SET(CMAKE_ASM_COMPILER_TARGET "gcc_nto${QNX_PROCESSOR}")
  182.  
  183. SET(CMAKE_C_COMPILER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-gcc")
  184. SET(CMAKE_C_COMPILER_TARGET "gcc_nto${QNX_PROCESSOR}")
  185. SET(CMAKE_C_FLAGS_DEBUG "-g")
  186. SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
  187. SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
  188. SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
  189. SET(CMAKE_C_FLAGS "-D_QNX_SOURCE=1 -I${QNX_TARGET}/usr/include/devs/include_'${TARGET_ARCH}' -I${QNX_TARGET}/usr/include/devs -DDONT_DEFINE_BSD -DDONT_DEFINE___FreeBSD_kernel__ -DDONT_DEFINE_FSCALE -DDONT_DEFINE_MACHINE")
  190.  
  191. SET(CMAKE_CXX_COMPILER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-g++")
  192. SET(CMAKE_CXX_COMPILER_TARGET "gcc_nto${QNX_PROCESSOR}")
  193. SET(CMAKE_CXX_FLAGS_DEBUG "-g")
  194. SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
  195. SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
  196. SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
  197. SET(CMAKE_CXX_FLAGS "-D_QNX_SOURCE=1 -I${QNX_TARGET}/usr/include/devs/include_'${TARGET_ARCH}' -I${QNX_TARGET}/usr/include/devs -DDONT_DEFINE_BSD -DDONT_DEFINE___FreeBSD_kernel__ -DDONT_DEFINE_FSCALE -DDONT_DEFINE_MACHINE")
  198.  
  199. SET(CMAKE_LINKER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ld.bfd")
  200. SET(CMAKE_SHARED_LINKER_FLAGS "-lsocket")
  201. SET(CMAKE_EXE_LINKER_FLAGS "-lsocket")
  202.  
  203. SET(CMAKE_RANLIB "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ranlib")
  204.  
  205. SET(CMAKE_NM "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-nm")
  206.  
  207. SET(CMAKE_AR "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ar")
  208.  
  209. SET(CMAKE_FIND_ROOT_PATH "${QNX_TARGET}")
  210. SET(CMAKE_FIND_ROOT_PATH_HOST_PROGRAM NEVER)
  211. SET(CMAKE_FIND_ROOT_PATH_HOST_LIBRARY ONLY)
  212. SET(CMAKE_FIND_ROOT_PATH_HOST_INCLUDE ONLY)
  213. ' > "${TARGET_TRIPLE}.cmake"
  214.  
  215. backup_and_patch_if_necessary()
  216. {
  217.         # handy function that patches a file in LLVM_SOURCES_DIR with a given sed replacement regex if necessary, creating backups
  218.         # args: <file pathname> <grep_string_to_test_for_presence_of_patch> <sed regex>
  219.         # test if already patched
  220.         grep -q "${2}" "../${LLVM_SOURCES_DIR}/${1}" && return
  221.         # tell what we're about to do
  222.         echo "Patching ${1}..."
  223.         # have a backup first
  224.         test -f "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ORIGINAL]" || cp "../${LLVM_SOURCES_DIR}/${1}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ORIGINAL]" || exit 1
  225.         # perform the patch
  226.         sed -E "${3}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ORIGINAL]" > "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [PATCHED]"
  227.         # verify that we did it successfully
  228.         if ! grep -q "${2}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [PATCHED]"; then
  229.                 echo "Error: the file ${1} could not be patched. Please investigate and fix manually." | fold -s -w 79; exit 1
  230.         fi
  231.         # and put the patched file in place
  232.         cp -f "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [PATCHED]" "../${LLVM_SOURCES_DIR}/${1}" || exit 1
  233. }
  234.  
  235. # patch llvm/Support/Unix/Path.inc if not done yet
  236. # replace [defined(__FreeBSD_kernel__)] with [(defined(__FreeBSD_kernel__) || defined(__QNXNTO__))]
  237. # RATIONALE: the concerned parts of the QNX platform SDK (/usr/include/devs/*) are actually largely based on FreeBSD code, to conveniently use the FreeBSD network stack.
  238. # NONETHELESS, QNX *IS NOT* FreeBSD and "__FreeBSD_kernel__" *SHOULD NOT* be defined, else userland code may falsely assume a genuine FreeBSD include tree to be available,
  239. # which leads to compilation errors caused by include files assumed to be there whereas they are in fact nowhere to be found (ex: /usr/include/sys/user.h, among others).
  240. # The QNX8 platform SDK has thus been patched to NOT define __FreeBSD_kernel__ when the -DDONT_DEFINE___FreeBSD_kernel__ flag is passed, and the feature tests in Path.inc
  241. # that branch into FreeBSD APIs (which ones *are* exposed in the QNX libc since QNX largely shares FreeBSD code) are about to be patched right now to accept __QNXNTO__ too.
  242. # Additionally, support for statfs()/fstatfs() has been restored in the QNX8 platform SDK in /usr/include/devs/sys/mount.h where it was claimed but absent from the QNX8 libc.
  243. # FIXME: these hacks should be moved elsewhere not to pollute the QNX8 platform SDK -- it *SHOULD* be possible to build without devs
  244. backup_and_patch_if_necessary "llvm/lib/Support/Unix/Path.inc" __QNXNTO__ 's/defined\(__FreeBSD_kernel__\)/\(defined\(__FreeBSD_kernel__\) \|\| \defined\(__QNXNTO__\)\)/g'
  245.  
  246. # patch lldb/Source/Host/common/Host.cpp if not done yet
  247. # replace [defined(SIGINFO)] with [(defined(SIGINFO) && !defined(__QNXNTO__))]
  248. # RATIONALE: the QNX people defined SIGINFO to the value of SIGUSR1 for a mysterious reason, defeating the purpose of SIGUSR1
  249. # which should be a User-Definable signal as mandated by POSIX. Consequently, userland code that enumerates POSIX signals
  250. # hits twice the same value and all is left to solve this problem is to filter either one out. Since SIGINFO, contrarily to SIGUSR1,
  251. # is an optional signal, this is the value that will be left out - even if on QNX nobody can actually use SIGUSR1's value.
  252. backup_and_patch_if_necessary "lldb/source/Host/common/Host.cpp" __QNXNTO__ 's/defined\(SIGINFO\)/\(defined\(SIGINFO\) \&\& \!defined\(__QNXNTO__\)\)/g'
  253.  
  254. # FIXME: another patch is needed for LLDB. Basically, the ptrace() POSIX system call doesn't exist on QNX. Instead
  255. # QNX use their own debug utility: pdebug. Note the /proc filesystem can be used to access a debuggee's virtual memory space.
  256. # in lldb/source/Host/posix/ProcessLauncherPosixFork.cpp line 196:
  257. #   if (ptrace(PT_TRACE_ME, 0, nullptr, 0) == -1) // <--- undefined: ptrace, PT_TRACE_ME
  258.  
  259. #    -D LLVM_ENABLE_PROJECTS="clang;lld;lldb" \
  260.  
  261. # patch compiler-rt/lib/builtins/enable_execute_stack.c if not done yet
  262. # replace [#include "int_lib.h"] with [#ifdef __QNXNTO__\n#define _QNX_SOURCE 1\n#endif\n#include "int_lib.h"]
  263. # RATIONALE: the QNX people decided to hide most of the UNIX APIs of their libc behind a mandatory _QNX_SOURCE definition to separate the Neutrino primitives from the rest maybe.
  264. # This name does not "enforce" any standard at all (like _POSIX_SOURCE and similar names), it's just a convenient hack for the QNX people to hide stuff.
  265. # To put things back on track and expose the POSIX interfaces of their libc to the world, _QNX_SOURCE has been added to the toolchain CMake file, but it happens that
  266. # when building compiler-rt specifically, the CMAKE_C_FLAGS directive is ignored. Patching the source file seems like the best option to fix that.
  267. backup_and_patch_if_necessary "compiler-rt/lib/builtins/enable_execute_stack.c" __QNXNTO__ 's/#include "int_lib.h"/#ifdef __QNXNTO__\n#define _QNX_SOURCE 1\n#endif\n#include "int_lib.h"/g'
  268.  
  269. # patch libunwind/src/RWMutex.hpp
  270. # replace [#include <pthread.h>] with [#ifdef __QNXNTO__\n#define __EXT_QNX\n#define __EXT_POSIX1_200112\n#endif\n#include <pthread.h>]
  271. # RATIONALE: the pthreads implementation in QNX 'steals' things from the POSIX.1 standard and hides them behind the __EXT_QNX macro,
  272. # which is defined when either _QNX_SOURCE or __EXT without anything else is defined. This is not correct and low-level libraries
  273. # such as libunwind that do not define either of those fail to build. Also note that a FreeBSD-compatible header was added to the QNX8
  274. # platform SDK: /usr/include/link.h, which defines Elf types as Elf64/Elf32 types depending on the architecture and adds some glue.
  275. backup_and_patch_if_necessary "libunwind/src/RWMutex.hpp" __QNXNTO__ 's/#include <pthread.h>/#ifdef __QNXNTO__\n#define __EXT_QNX\n#define __EXT_POSIX1_200112\n#endif\n#include <pthread.h>/g'
  276.  
  277. # patch libunwind/src/libunwind.cpp
  278. # replace [#include <libunwind.h>] with [#ifdef __QNXNTO__\n#include <sys/link.h>\n#include <link.h>\n#endif\n#include <libunwind.h>]
  279. # RATIONALE: the ELF type definitions for QNX are incomplete. They renamed everything to Elf32 and Elf64, and now the original Elf type names point to nowhere.
  280. # Additionally, since QNX claims to be a "FreeBSD kernel", it must expose a /usr/include/link.h file too, and the workaround for the aforementioned problem is there.
  281. # Consequently, load the QNX <sys/link.h> THEN our BSD glue <link.h> headers before compiling libunwind.cpp which needs common ELF definitions (and not Elf32/Elf64).
  282. backup_and_patch_if_necessary "libunwind/src/libunwind.cpp" __QNXNTO__ 's,#include <libunwind.h>,#ifdef __QNXNTO__\n#include <sys/link.h>\n#include <link.h>\n#endif\n#include <libunwind.h>,g'
  283.  
  284. # now configure LLVM -- and use ccache
  285. echo "Configuring LLVM build..."
  286. export CCACHE_DIR="$(realpath "../${LLVM_SOURCES_DIR}/.ccache")"
  287. cmake \
  288.     -D CMAKE_TOOLCHAIN_FILE="${TARGET_TRIPLE}.cmake" \
  289.     -D CMAKE_BUILD_TYPE="MinSizeRel" \
  290.     -D CMAKE_INSTALL_PREFIX="/tmp/qnxsdk/host/qnx$(echo "${QNXSDK_VERSION}"|awk -F. '{print $1}')/${BUILD_TARGET_ARCH}" \
  291.     -D CMAKE_STAGING_PREFIX="/usr/bin" \
  292.     -D CMAKE_C_COMPILER_LAUNCHER="ccache" \
  293.     -D CMAKE_CXX_COMPILER_LAUNCHER="ccache" \
  294.     -D LLVM_HOST_TRIPLE="${TARGET_TRIPLE}" \
  295.     -D LLVM_ENABLE_PROJECTS="clang;lld" \
  296.     -D LLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
  297.     -D LLVM_TARGETS_TO_BUILD="AArch64;X86" \
  298.     -D COMPILER_RT_BUILD_SANITIZERS="OFF" \
  299.     -G Ninja \
  300.     "../${LLVM_SOURCES_DIR}/llvm" || exit 1
  301.  
  302. # hijack the "bin" and "lib/clang" output directories and redirect them to the hypervisor's filesystem
  303. test -e "${CURRENT_DIR}/llvm-build" && rm -rf "${CURRENT_DIR}/llvm-build"
  304. mkdir -p "${CURRENT_DIR}/llvm-build"
  305. test -d bin && mv bin "${CURRENT_DIR}/llvm-build/bin" || mkdir "${CURRENT_DIR}/llvm-build/bin"
  306. ln -s "${CURRENT_DIR}/llvm-build/bin" bin
  307. mkdir -p "${CURRENT_DIR}/llvm-build/lib"
  308. test -d lib/clang && mv lib/clang "${CURRENT_DIR}/llvm-build/lib/clang" || mkdir "${CURRENT_DIR}/llvm-build/lib/clang"
  309. ln -s "${CURRENT_DIR}/llvm-build/lib/clang" lib/clang
  310.  
  311. # and do the Lord's work. https://youtu.be/jcyYmCnkbEE
  312. echo "Building LLVM..."
  313. cmake --build . || exit 1
  314.  
  315. echo "Champagne, James. Champagne."
  316. exit 0
  317.