Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

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

  1. #!/bin/sh
  2.  
  3. export QNXSDK_PATH="../qnx800"
  4. export QNXSDK_HOSTPATH="host/linux/x86_64"
  5. export QNXSDK_TARGETPATH="target/qnx"
  6. export BUILD_DIR_NAME="llvm-build"
  7. export LLVM_VERSION="18.1.4"
  8. export LLVM_SOURCES_FILE="llvmorg-${LLVM_VERSION}.tar.gz" # name of file containing LLVM version LLVM_VERSION sources
  9. export LLVM_SOURCES_URL="https://github.com/llvm/llvm-project/archive/refs/tags/${LLVM_SOURCES_FILE}" # download URL of LLVM_SOURCES_FILE
  10. export LLVM_SOURCES_DIR="llvm-project-llvmorg-${LLVM_VERSION}" # name of directory created when extracting LLVM_SOURCES_FILE
  11.  
  12. export TARGET_ARCH="x86_64"
  13. export TARGET_VENDOR="pc"
  14. #export TARGET_ARCH="aarch64"
  15. #export TARGET_VENDOR="unknown"
  16. export TARGET_KERNEL="nto"
  17. export TARGET_SYSTEM="qnx8.0.0"
  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."
  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"
  34.         echo "'host' and 'target' directories of the QNX SDP for the targeted version of QNX"
  35.         echo "and the ${TARGET_ARCH} platform. Please deploy these directories and try again."
  36.         echo "NOTE: if you're using a VMWare virtual machine and this path points to a shared"
  37.         echo "folder, you may need to initiate the share by unticking the 'Enable shared"
  38.         echo "folders' checkbox and ticking it again in the VM settings (VMWare bug)."
  39.         echo ""
  40.         exit 1
  41. fi
  42.  
  43. # verify that we have wget, python3, cmake, gcc, g++ and ninja
  44. if    ! wget    --version > /dev/null 2>&1 \
  45.    || ! python3 --version > /dev/null 2>&1 \
  46.    || ! cmake   --version > /dev/null 2>&1 \
  47.    || ! gcc     --version > /dev/null 2>&1 \
  48.    || ! g++     --version > /dev/null 2>&1 \
  49.    || ! ninja   --version > /dev/null 2>&1; then
  50.         echo ""
  51.         echo "Error: this script requires at the very least the following tools installed:"
  52.         echo "  wget"
  53.         echo "  python3"
  54.         echo "  cmake"
  55.         echo "  gcc"
  56.         echo "  g++"
  57.         echo "  ninja"
  58.         echo "Please install them (possibly as binary packages with apt-get) and try again."
  59.         echo ""
  60.         exit 1
  61. fi
  62.  
  63. # verify that the symlinks are deployed in the SDK -- just test one of them
  64. if [ ! -e "${QNXSDK_PATH}/${QNXSDK_TARGETPATH}/usr/include/readline.h" ]; then
  65.         echo ""
  66.         echo "Error: the toolchain platform-specific symbolic links have not been deployed in"
  67.         echo "this QNX SDK. Please run"
  68.         echo "(on a POSIX machine:)"
  69.         echo "  cd ${QNXSDK_PATH}"
  70.         echo "  find . -name symlinks.lst -exec ./symlinks.sh {} create \\; && printf 'present' > .symlinks-state"
  71.         echo "(else on a Windows machine:)"
  72.         echo "  cd ${QNXSDK_PATH}"
  73.         echo "  host\\win64\\${TARGET_ARCH}\\usr\\bin\\busybox.exe sh -c \"" \
  74.                "find . -name symlinks.lst -exec ./symlinks.sh {} create \\; && printf 'present' > .symlinks-state" \
  75.                "\""
  76.         echo "Note that this step WILL take time on a Win32 machine, but is only done once."
  77.         echo ""
  78.         exit 1
  79. fi
  80.  
  81. # construct the target triple (actually a quadruple)
  82. export TARGET_TRIPLE="${TARGET_ARCH}-${TARGET_VENDOR}-${TARGET_KERNEL}-${TARGET_SYSTEM}"
  83. echo "Will build LLVM for ${TARGET_TRIPLE}"
  84.  
  85. # change to an immediately visible path
  86. cd ~/Desktop
  87.  
  88. # create a symlink in /tmp that will lead to the QNX platform SDK so as to avoid spaces in paths
  89. # (this is totally prohibitive with the official QNX toolchain)
  90. test -L /tmp/qnxsdk && rm /tmp/qnxsdk
  91. ln -fs "${CURRENT_DIR}/${QNXSDK_PATH}" /tmp/qnxsdk
  92.  
  93. # setup the environment
  94. export QNX_HOST="/tmp/qnxsdk/${QNXSDK_HOSTPATH}"
  95. export QNX_TARGET="/tmp/qnxsdk/${QNXSDK_TARGETPATH}"
  96. export MAKEFLAGS="-I${QNX_TARGET}/usr/include"
  97. export PATH="${QNX_HOST}/usr/bin:${PATH}"
  98. #export PYTHONDONTWRITEBYTECODE="1"
  99. #export PYTHONPATH=""
  100.  
  101. # download the LLVM source package and unpack it if not done yet
  102. if [ ! -d "${LLVM_SOURCES_DIR}" ]; then
  103.         if [ ! -f "${CURRENT_DIR}/${LLVM_SOURCES_FILE}" ]; then
  104.                 echo "Downloading LLVM ${LLVM_VERSION} sources from LLVM GitHub..."
  105.                 wget "${LLVM_SOURCES_URL}" || exit 1
  106.         fi
  107.         echo "Extracting LLVM ${LLVM_VERSION} sources..."
  108.         cd "$(dirname "${LLVM_SOURCES_DIR}")"
  109.         tar xzf "${CURRENT_DIR}/${LLVM_SOURCES_FILE}" || exit 1
  110.         if [ ! -d "${LLVM_SOURCES_DIR}" ]; then
  111.                 echo "Error: couldn't find ${LLVM_SOURCES_DIR} in extracted LLVM sources."
  112.                 exit 1
  113.         fi
  114. fi
  115.  
  116. # create the build directory
  117. echo "Wiping out build directory..."
  118. test -e "${BUILD_DIR_NAME}" && rm -rf "${BUILD_DIR_NAME}"
  119. mkdir "${BUILD_DIR_NAME}" || exit 1
  120. cd "${BUILD_DIR_NAME}" || exit 1
  121.  
  122. # print the build environment
  123. echo "QNX_HOST=${QNX_HOST}"
  124. echo "QNX_TARGET=${QNX_TARGET}"
  125. echo "MAKEFLAGS=${MAKEFLAGS}"
  126.  
  127. # create the QNX CMake toolchain file
  128. echo '# '${TARGET_TRIPLE}' CMake toolchain file by Pierre-Marie Baty <pm@pmbaty.com>
  129.  
  130. SET(CMAKE_SYSTEM_NAME "QNX")
  131. SET(CMAKE_SYSTEM_VERSION "8.0.0")
  132.  
  133. SET(QNX "1")
  134. SET(QNXNTO "1")
  135. if ("$ENV{QNX_HOST}" STREQUAL "")
  136.         message(FATAL_ERROR "the QNX_HOST environment variable is not set")
  137. endif()
  138. SET(QNX_HOST "$ENV{QNX_HOST}")
  139. if ("$ENV{QNX_TARGET}" STREQUAL "")
  140.         message(FATAL_ERROR "the QNX_TARGET environment variable is not set")
  141. endif()
  142. SET(QNX_TARGET "$ENV{QNX_TARGET}")
  143. SET(QNX_PROCESSOR "'${TARGET_ARCH}'")
  144.  
  145. SET(CMAKE_ASM_COMPILER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-gcc")
  146. SET(CMAKE_ASM_COMPILER_TARGET "gcc_nto${QNX_PROCESSOR}")
  147.  
  148. SET(CMAKE_C_COMPILER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-gcc")
  149. SET(CMAKE_C_COMPILER_TARGET "gcc_nto${QNX_PROCESSOR}")
  150. SET(CMAKE_C_FLAGS_DEBUG "-g")
  151. SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
  152. SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
  153. SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
  154. SET(CMAKE_C_FLAGS "-D_QNX_SOURCE=1 -I${QNX_TARGET}/usr/include/devs/include_'${TARGET_ARCH}' -I${QNX_TARGET}/usr/include/devs -DLLVM_BUILD=1")
  155.  
  156. SET(CMAKE_CXX_COMPILER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-g++")
  157. SET(CMAKE_CXX_COMPILER_TARGET "gcc_nto${QNX_PROCESSOR}")
  158. SET(CMAKE_CXX_FLAGS_DEBUG "-g")
  159. SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
  160. SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
  161. SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
  162. SET(CMAKE_CXX_FLAGS "-D_QNX_SOURCE=1 -I${QNX_TARGET}/usr/include/devs/include_'${TARGET_ARCH}' -I${QNX_TARGET}/usr/include/devs -DLLVM_BUILD=1")
  163.  
  164. SET(CMAKE_LINKER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ld.bfd")
  165. SET(CMAKE_EXE_LINKER_FLAGS "-lsocket")
  166.  
  167. SET(CMAKE_RANLIB "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ranlib")
  168.  
  169. SET(CMAKE_AR "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ar")
  170.  
  171. SET(CMAKE_FIND_ROOT_PATH "${QNX_TARGET}")
  172. SET(CMAKE_FIND_ROOT_PATH_HOST_PROGRAM NEVER)
  173. SET(CMAKE_FIND_ROOT_PATH_HOST_LIBRARY ONLY)
  174. SET(CMAKE_FIND_ROOT_PATH_HOST_INCLUDE ONLY)
  175. ' > "${TARGET_TRIPLE}.cmake"
  176.  
  177. # now configure LLVM
  178. echo "Configuring LLVM build..."
  179. # TODO: add compiler-rt project (requires probably QNX-specific work)
  180. cmake \
  181.     -D CMAKE_TOOLCHAIN_FILE="${TARGET_TRIPLE}.cmake" \
  182.     -D CMAKE_BUILD_TYPE="MinSizeRel" \
  183.     -D CMAKE_INSTALL_PREFIX="/tmp/qnxsdk/host/qnx8" \
  184.     -D CMAKE_STAGING_PREFIX="/usr/bin" \
  185.     -D LLVM_HOST_TRIPLE="${TARGET_TRIPLE}" \
  186.     -D LLVM_ENABLE_PROJECTS="clang;lld;lldb" \
  187.     -D LLVM_TARGETS_TO_BUILD="AArch64;X86" \
  188.     -G Ninja \
  189.     "../${LLVM_SOURCES_DIR}/llvm" || exit 1
  190.  
  191. # and do the Lord's work. https://youtu.be/jcyYmCnkbEE
  192. echo "Building LLVM..."
  193. cmake --build . || exit 1
  194.  
  195. echo "Champagne, James. Champagne."
  196. exit 0
  197.  
  198.