Rev 6 | Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 6 | Rev 7 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | #!/bin/sh |
1 | #!/bin/sh |
| 2 | # LLVM/Clang toolchain cross-compilation script for QNX 8.0 by Pierre-Marie Baty <pm@pmbaty.com> |
2 | # LLVM/Clang toolchain cross-compilation script for QNX 8.0 by Pierre-Marie Baty <pm@pmbaty.com> |
| 3 | 3 | ||
| 4 | # NOTE TO SELF: DO NOT USE $0 AS THIS SCRIPT CAN BE RUN *OR* SOURCED! (see build-llvm.sh in the VM) |
4 | # NOTE TO SELF: DO NOT USE $0 AS THIS SCRIPT CAN BE RUN *OR* SOURCED! (see build-llvm.sh in the VM) |
| 5 | 5 | ||
| - | 6 | export QNXSDK_VERSION="8.0.0" # version of the QNX SDK in use, in <major>.<minor>.<revision> format |
|
| 6 | export QNXSDK_PATH="../qnx800" |
7 | export QNXSDK_PATH="../qnx800" # relative location from the path of this script where to find the QNX platform SDK |
| 7 | export QNXSDK_HOSTPATH="host/linux/x86_64" |
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 |
| 8 | export QNXSDK_TARGETPATH="target/qnx" |
9 | export QNXSDK_TARGETPATH="target/qnx" # relative location in QNXSDK_PATH of the tree containing the QNX8 system header files |
| - | 10 | ||
| 9 | export BUILD_DIR_NAME="llvm-build" |
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 | ||
| 10 | export LLVM_VERSION="18.1.4" |
14 | export LLVM_VERSION="18.1.4" # version of LLVM that will be built |
| 11 | export LLVM_SOURCES_FILE="llvmorg-${LLVM_VERSION}.tar.gz" # name of file containing LLVM version LLVM_VERSION sources |
15 | export LLVM_SOURCES_FILE="llvmorg-${LLVM_VERSION}.tar.gz" # name of the file containing LLVM version LLVM_VERSION sources |
| 12 | export LLVM_SOURCES_URL="https://github.com/llvm/llvm-project/archive/refs/tags/${LLVM_SOURCES_FILE}" # download URL of LLVM_SOURCES_FILE |
16 | export LLVM_SOURCES_URL="https://github.com/llvm/llvm-project/archive/refs/tags/${LLVM_SOURCES_FILE}" # download URL of LLVM_SOURCES_FILE |
| 13 | export LLVM_SOURCES_DIR="llvm-project-llvmorg-${LLVM_VERSION}" # name of directory created when extracting LLVM_SOURCES_FILE |
17 | export LLVM_SOURCES_DIR="llvm-project-llvmorg-${LLVM_VERSION}" # name of directory created when extracting LLVM_SOURCES_FILE |
| 14 | - | ||
| 15 | # target triple settings |
- | |
| 16 | export TARGET_ARCH="x86_64" |
- | |
| 17 | #export TARGET_ARCH="aarch64" |
- | |
| 18 | test "${TARGET_ARCH}" = "x86_64" && export TARGET_VENDOR="pc" || export TARGET_VENDOR="unknown" |
- | |
| 19 | export TARGET_KERNEL="nto" |
- | |
| 20 | export TARGET_SYSTEM="qnx8.0.0" |
- | |
| 21 | 18 | ||
| 22 | # see where we are |
19 | # see where we are |
| 23 | export CURRENT_DIR="$(pwd)" |
20 | export CURRENT_DIR="$(pwd)" |
| 24 | 21 | ||
| 25 | # verify we're a x86_64 Linux host |
22 | # verify we're a x86_64 Linux host |
| Line 31... | Line 28... | ||
| 31 | fi |
28 | fi |
| 32 | 29 | ||
| 33 | # verify that we have the QNX platform SDK |
30 | # verify that we have the QNX platform SDK |
| 34 | if [ ! -d "${QNXSDK_PATH}/${QNXSDK_HOSTPATH}" ] || [ ! -d "${QNXSDK_PATH}/${QNXSDK_TARGETPATH}" ]; then |
31 | if [ ! -d "${QNXSDK_PATH}/${QNXSDK_HOSTPATH}" ] || [ ! -d "${QNXSDK_PATH}/${QNXSDK_TARGETPATH}" ]; then |
| 35 | echo "" |
32 | echo "" |
| 36 | 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 ${ |
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 |
| 37 | echo "" |
34 | echo "" |
| 38 | exit 1 |
35 | exit 1 |
| 39 | fi |
36 | fi |
| 40 | 37 | ||
| 41 | # verify that we have wget, python3, cmake, gcc, g++ and ninja |
38 | # verify that we have wget, python3, cmake, gcc, g++ and ninja |
| Line 74... | Line 71... | ||
| 74 | echo "" |
71 | echo "" |
| 75 | exit 1 |
72 | exit 1 |
| 76 | fi |
73 | fi |
| 77 | 74 | ||
| 78 | # construct the target triple (actually a quadruple) |
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}" |
|
| 79 | export TARGET_TRIPLE="${TARGET_ARCH}-${TARGET_VENDOR}-${TARGET_KERNEL}-${TARGET_SYSTEM}" |
80 | export TARGET_TRIPLE="${TARGET_ARCH}-${TARGET_VENDOR}-${TARGET_KERNEL}-${TARGET_SYSTEM}" |
| 80 | echo "Will build LLVM for ${TARGET_TRIPLE}" |
81 | echo "Will build LLVM for ${TARGET_TRIPLE}" |
| 81 | 82 | ||
| 82 | # change to an immediately visible |
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}")" |
|
| 83 | cd |
85 | cd "${STAGING_PATH}" |
| 84 | 86 | ||
| 85 | # create a symlink in /tmp that will lead to the QNX platform SDK so as to avoid spaces in paths |
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 |
| 86 | # (this is totally prohibitive with the official QNX toolchain) |
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..." |
|
| 87 |
|
91 | rm -rf /tmp/qnxsdk 2>/dev/null |
| 88 | ln -fs "${CURRENT_DIR} |
92 | ln -fs "$(realpath "${CURRENT_DIR}/${QNXSDK_PATH}")" /tmp/qnxsdk || exit 1 |
| - | 93 | fi |
|
| 89 | 94 | ||
| 90 | # setup the environment |
95 | # setup the environment |
| 91 | export QNX_HOST="/tmp/qnxsdk/${QNXSDK_HOSTPATH}" |
96 | export QNX_HOST="/tmp/qnxsdk/${QNXSDK_HOSTPATH}" |
| 92 | export QNX_TARGET="/tmp/qnxsdk/${QNXSDK_TARGETPATH}" |
97 | export QNX_TARGET="/tmp/qnxsdk/${QNXSDK_TARGETPATH}" |
| 93 | export MAKEFLAGS="-I${QNX_TARGET}/usr/include" |
98 | export MAKEFLAGS="-I${QNX_TARGET}/usr/include" |
| 94 | export PATH="${QNX_HOST}/usr/bin:${PATH}" |
99 | export PATH="${QNX_HOST}/usr/bin:${PATH}" |
| 95 | #export PYTHONDONTWRITEBYTECODE="1" |
- | |
| 96 | #export PYTHONPATH="" |
- | |
| 97 | 100 | ||
| 98 | # download the LLVM source package and unpack it if not done yet |
101 | # download the LLVM source package and unpack it if not done yet |
| 99 | if [ ! -d "${LLVM_SOURCES_DIR}" ]; then |
102 | if [ ! -d "${LLVM_SOURCES_DIR}" ]; then |
| 100 | if [ ! -f "${CURRENT_DIR}/${LLVM_SOURCES_FILE}" ]; then |
103 | if [ ! -f "${CURRENT_DIR}/${LLVM_SOURCES_FILE}" ]; then |
| 101 | echo "Downloading LLVM ${LLVM_VERSION} sources from LLVM GitHub..." |
104 | echo "Downloading LLVM ${LLVM_VERSION} sources from LLVM GitHub..." |
| Line 123... | Line 126... | ||
| 123 | 126 | ||
| 124 | # create the QNX CMake toolchain file |
127 | # create the QNX CMake toolchain file |
| 125 | echo '# '${TARGET_TRIPLE}' CMake toolchain file by Pierre-Marie Baty <pm@pmbaty.com> |
128 | echo '# '${TARGET_TRIPLE}' CMake toolchain file by Pierre-Marie Baty <pm@pmbaty.com> |
| 126 | 129 | ||
| 127 | SET(CMAKE_SYSTEM_NAME "QNX") |
130 | SET(CMAKE_SYSTEM_NAME "QNX") |
| 128 | SET(CMAKE_SYSTEM_VERSION " |
131 | SET(CMAKE_SYSTEM_VERSION "'${QNXSDK_VERSION}'") |
| 129 | 132 | ||
| 130 | SET(QNX "1") |
133 | SET(QNX "1") |
| 131 | SET(QNXNTO "1") |
134 | SET(QNXNTO "1") |
| 132 | if ("$ENV{QNX_HOST}" STREQUAL "") |
- | |
| 133 | message(FATAL_ERROR "the QNX_HOST environment variable is not set") |
- | |
| 134 | endif() |
- | |
| 135 | SET(QNX_HOST "$ENV{QNX_HOST}") |
135 | SET(QNX_HOST "$ENV{QNX_HOST}") |
| 136 | if ("$ENV{QNX_TARGET}" STREQUAL "") |
- | |
| 137 | message(FATAL_ERROR "the QNX_TARGET environment variable is not set") |
- | |
| 138 | endif() |
- | |
| 139 | SET(QNX_TARGET "$ENV{QNX_TARGET}") |
136 | SET(QNX_TARGET "$ENV{QNX_TARGET}") |
| 140 | SET(QNX_PROCESSOR "'${TARGET_ARCH}'") |
137 | SET(QNX_PROCESSOR "'${TARGET_ARCH}'") |
| 141 | 138 | ||
| 142 | SET(CMAKE_ASM_COMPILER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-gcc") |
139 | SET(CMAKE_ASM_COMPILER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-gcc") |
| 143 | SET(CMAKE_ASM_COMPILER_TARGET "gcc_nto${QNX_PROCESSOR}") |
140 | SET(CMAKE_ASM_COMPILER_TARGET "gcc_nto${QNX_PROCESSOR}") |
| Line 146... | Line 143... | ||
| 146 | SET(CMAKE_C_COMPILER_TARGET "gcc_nto${QNX_PROCESSOR}") |
143 | SET(CMAKE_C_COMPILER_TARGET "gcc_nto${QNX_PROCESSOR}") |
| 147 | SET(CMAKE_C_FLAGS_DEBUG "-g") |
144 | SET(CMAKE_C_FLAGS_DEBUG "-g") |
| 148 | SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG") |
145 | SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG") |
| 149 | SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG") |
146 | SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG") |
| 150 | SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g") |
147 | SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g") |
| 151 | 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") |
148 | 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") |
| 152 | 149 | ||
| 153 | SET(CMAKE_CXX_COMPILER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-g++") |
150 | SET(CMAKE_CXX_COMPILER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-g++") |
| 154 | SET(CMAKE_CXX_COMPILER_TARGET "gcc_nto${QNX_PROCESSOR}") |
151 | SET(CMAKE_CXX_COMPILER_TARGET "gcc_nto${QNX_PROCESSOR}") |
| 155 | SET(CMAKE_CXX_FLAGS_DEBUG "-g") |
152 | SET(CMAKE_CXX_FLAGS_DEBUG "-g") |
| 156 | SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") |
153 | SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") |
| 157 | SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") |
154 | SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") |
| 158 | SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") |
155 | SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") |
| 159 | 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") |
156 | 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") |
| 160 | 157 | ||
| 161 | SET(CMAKE_LINKER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ld.bfd") |
158 | SET(CMAKE_LINKER "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ld.bfd") |
| 162 | SET(CMAKE_SHARED_LINKER_FLAGS "-lsocket") |
159 | SET(CMAKE_SHARED_LINKER_FLAGS "-lsocket") |
| 163 | SET(CMAKE_EXE_LINKER_FLAGS "-lsocket") |
160 | SET(CMAKE_EXE_LINKER_FLAGS "-lsocket") |
| 164 | 161 | ||
| 165 | SET(CMAKE_RANLIB "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ranlib") |
162 | SET(CMAKE_RANLIB "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ranlib") |
| - | 163 | ||
| - | 164 | SET(CMAKE_NM "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-nm") |
|
| 166 | 165 | ||
| 167 | SET(CMAKE_AR "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ar") |
166 | SET(CMAKE_AR "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ar") |
| 168 | 167 | ||
| 169 | SET(CMAKE_FIND_ROOT_PATH "${QNX_TARGET}") |
168 | SET(CMAKE_FIND_ROOT_PATH "${QNX_TARGET}") |
| 170 | SET(CMAKE_FIND_ROOT_PATH_HOST_PROGRAM NEVER) |
169 | SET(CMAKE_FIND_ROOT_PATH_HOST_PROGRAM NEVER) |
| 171 | SET(CMAKE_FIND_ROOT_PATH_HOST_LIBRARY ONLY) |
170 | SET(CMAKE_FIND_ROOT_PATH_HOST_LIBRARY ONLY) |
| 172 | SET(CMAKE_FIND_ROOT_PATH_HOST_INCLUDE ONLY) |
171 | SET(CMAKE_FIND_ROOT_PATH_HOST_INCLUDE ONLY) |
| 173 | ' > "${TARGET_TRIPLE}.cmake" |
172 | ' > "${TARGET_TRIPLE}.cmake" |
| - | 173 | ||
| - | 174 | backup_and_patch_if_necessary() |
|
| - | 175 | { |
|
| - | 176 | # handy function that patches a file in LLVM_SOURCES_DIR with a given sed replacement regex if necessary, creating backups |
|
| - | 177 | # args: <file pathname> <grep_string_to_test_for_presence_of_patch> <sed regex> |
|
| - | 178 | # test if already patched |
|
| - | 179 | grep -q "${2}" "../${LLVM_SOURCES_DIR}/${1}" && return |
|
| - | 180 | # tell what we're about to do |
|
| - | 181 | echo "Patching ${1}..." |
|
| - | 182 | # have a backup first |
|
| - | 183 | test -f "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [BEFORE PATCH]" || cp "../${LLVM_SOURCES_DIR}/${1}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [BEFORE PATCH]" |
|
| - | 184 | # perform the patch |
|
| - | 185 | sed -E "${3}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [BEFORE PATCH]" > "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [AFTER PATCH]" |
|
| - | 186 | # verify that we did it successfully |
|
| - | 187 | if ! grep -q "${2}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [AFTER PATCH]"; then |
|
| - | 188 | echo "Error: the file ${1} could not be patched. Please investigate and fix manually." | fold -s -w 79; exit 1 |
|
| - | 189 | fi |
|
| - | 190 | # and put the patched file in place |
|
| - | 191 | cp -f "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [AFTER PATCH]" "../${LLVM_SOURCES_DIR}/${1}" || exit 1 |
|
| - | 192 | } |
|
| - | 193 | ||
| 174 | 194 | ||
| 175 | # patch llvm/Support/Unix/Path.inc if not done yet |
195 | # patch llvm/Support/Unix/Path.inc if not done yet |
| 176 |
|
196 | # replace "defined(__FreeBSD_kernel__)" with "(defined(__FreeBSD_kernel__) || defined(__QNXNTO__))" |
| - | 197 | # 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. |
|
| - | 198 | # 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, |
|
| - | 199 | # 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). |
|
| - | 200 | # 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 |
|
| - | 201 | # 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. |
|
| - | 202 | # 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. |
|
| - | 203 | # FIXME: these hacks should be moved elsewhere not to pollute the QNX8 platform SDK -- it *SHOULD* be possible to build without devs |
|
| 177 |
|
204 | backup_and_patch_if_necessary "llvm/lib/Support/Unix/Path.inc" __QNXNTO__ 's/defined\(__FreeBSD_kernel__\)/\(defined\(__FreeBSD_kernel__\) \|\| \defined\(__QNXNTO__\)\)/g' |
| 178 | 205 | ||
| 179 |
|
206 | # patch lldb/Source/Host/common/Host.cpp if not done yet |
| - | 207 | # replace "defined(SIGINFO)" with "(defined(SIGINFO) && !defined(__QNXNTO__))" |
|
| - | 208 | # RATIONALE: the QNX people defined SIGINFO to the value of SIGUSR1 for a mysterious reason, defeating the purpose of SIGUSR1 |
|
| - | 209 | # which should be a User-Definable signal as mandated by POSIX. Consequently, userland code that enumerates POSIX signals |
|
| - | 210 | # hits twice the same value and all is left to solve this problem is to filter either one out. Since SIGINFO, contrarily to SIGUSR1, |
|
| - | 211 | # is an optional signal, this is the value that will be left out - even if on QNX nobody can actually use SIGUSR1's value. |
|
| 180 |
|
212 | backup_and_patch_if_necessary "lldb/source/Host/common/Host.cpp" __QNXNTO__ 's/defined\(SIGINFO\)/\(defined\(SIGINFO\) \&\& \!defined\(__QNXNTO__\)\)/g' |
| 181 | 213 | ||
| 182 |
|
214 | # FIXME: another patch is needed for LLDB. Basically, the ptrace() POSIX system call doesn't exist on QNX. Instead |
| 183 |
|
215 | # QNX use their own debug utility: pdebug. Note the /proc filesystem can be used to access a debuggee's virtual memory space. |
| 184 | # 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, |
- | |
| 185 | # 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). |
- | |
| 186 | # 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 |
- | |
| 187 | # 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. |
- | |
| 188 |
|
216 | # in lldb/source/Host/posix/ProcessLauncherPosixFork.cpp line 196: |
| 189 |
|
217 | # if (ptrace(PT_TRACE_ME, 0, nullptr, 0) == -1) // <--- undefined: ptrace, PT_TRACE_ME |
| 190 | sed 's/defined(__FreeBSD_kernel__)/(defined(__FreeBSD_kernel__) || defined(__QNXNTO__))/g' "${CURRENT_DIR}/Path [BEFORE PATCH].inc" > "${CURRENT_DIR}/Path [AFTER PATCH].inc" |
- | |
| 191 | 218 | ||
| 192 | # verify that we did it successfully |
- | |
| 193 |
|
219 | # -D LLVM_ENABLE_PROJECTS="clang;lld;lldb" \ |
| 194 | echo "Error: the LLVM support library source file llvm/Support/Unix/Path.inc could not be patched to support QNX neutrino. Please investigate and fix manually." | fold -s -w 79 |
- | |
| 195 | exit 1 |
- | |
| 196 | fi |
- | |
| 197 | 220 | ||
| 198 |
|
221 | # patch compiler-rt/lib/builtins/enable_execute_stack.c if not done yet |
| 199 |
|
222 | # replace "#include "int_lib.h"" with "#ifdef __QNXNTO__\n#define _QNX_SOURCE 1\n#endif\n#include "int_lib.h"" |
| 200 | fi |
- | |
| - | 223 | # 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. |
|
| - | 224 | # 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. |
|
| - | 225 | # 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 |
|
| - | 226 | # when building compiler-rt specifically, the CMAKE_C_FLAGS directive is ignored. Patching the source file seems like the best option to fix that. |
|
| - | 227 | 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' |
|
| 201 | 228 | ||
| 202 | # now configure LLVM |
229 | # now configure LLVM |
| 203 | echo "Configuring LLVM build..." |
230 | echo "Configuring LLVM build..." |
| 204 | cmake \ |
231 | cmake \ |
| 205 | -D CMAKE_TOOLCHAIN_FILE="${TARGET_TRIPLE}.cmake" \ |
232 | -D CMAKE_TOOLCHAIN_FILE="${TARGET_TRIPLE}.cmake" \ |
| 206 | -D CMAKE_BUILD_TYPE="MinSizeRel" \ |
233 | -D CMAKE_BUILD_TYPE="MinSizeRel" \ |
| 207 | -D CMAKE_INSTALL_PREFIX="/tmp/qnxsdk/host/ |
234 | -D CMAKE_INSTALL_PREFIX="/tmp/qnxsdk/host/qnx$(echo "${QNXSDK_VERSION}"|awk -F. '{print $1}')/${BUILD_TARGET_ARCH}" \ |
| 208 | -D CMAKE_STAGING_PREFIX="/usr/bin" \ |
235 | -D CMAKE_STAGING_PREFIX="/usr/bin" \ |
| 209 | -D LLVM_HOST_TRIPLE="${TARGET_TRIPLE}" \ |
236 | -D LLVM_HOST_TRIPLE="${TARGET_TRIPLE}" \ |
| 210 | -D LLVM_ENABLE_PROJECTS="clang;lld |
237 | -D LLVM_ENABLE_PROJECTS="clang;lld" \ |
| 211 | -D LLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi" \ |
238 | -D LLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \ |
| 212 | -D LLVM_TARGETS_TO_BUILD="AArch64;X86" \ |
239 | -D LLVM_TARGETS_TO_BUILD="AArch64;X86" \ |
| 213 | -G Ninja \ |
240 | -G Ninja \ |
| 214 | "../${LLVM_SOURCES_DIR}/llvm" || exit 1 |
241 | "../${LLVM_SOURCES_DIR}/llvm" || exit 1 |
| 215 | 242 | ||
| 216 | # hijack the "bin" and "lib/clang" output directories and redirect them to the hypervisor's filesystem |
243 | # hijack the "bin" and "lib/clang" output directories and redirect them to the hypervisor's filesystem |