Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Rev 12 | Rev 14 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12 Rev 13
Line 9... Line 9...
9
export QNXSDK_TARGETPATH="target/qnx" # relative location in QNXSDK_PATH of the tree containing the QNX8 system header files
9
export QNXSDK_TARGETPATH="target/qnx" # relative location in QNXSDK_PATH of the tree containing the QNX8 system header files
10
 
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
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"
12
export BUILD_TARGET_ARCH="x86_64" # CPU architecture to build LLVM for, either "x86_64" or "aarch64"
13
 
13
 
14
export LLVM_VERSION="17.0.6" # version of LLVM that will be built
14
export LLVM_VERSION="16.0.6" # version of LLVM that will be built (ideally the same version as the libc++ supplied by QNX in their platform SDK)
15
export LLVM_SOURCES_FILE="llvmorg-${LLVM_VERSION}.tar.gz" # name of the 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
16
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
17
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
-
 
18
 
-
 
19
export LLVM_PROJECTS_TO_BUILD="clang;polly;lld" # semicolon-separated list of LLVM projects to build (full list: "clang;clang-tools-extra;cross-project-tests;libc;libclc;lld;lldb;openmp;polly;pstl")
-
 
20
export LLVM_RUNTIMES_TO_BUILD="compiler-rt;libunwind" # semicolon-separated list of LLVM runtimes to build (full list: "compiler-rt;libc;libcxx;libcxxabi;libunwind;openmp")
-
 
21
export LLVM_BUILD_CONFIGURATION_TYPE="MinSizeRel" # build configuration, one of "Debug", "Release", "RelWithDebugInfo" or "MinSizeRel"
-
 
22
 
-
 
23
export REQUIRED_TOOLS="wget python3 cmake gcc g++ ninja ccache" # list of build tools required to build all this on the build host
18
 
24
 
19
# see where we are
25
# see where we are
20
export CURRENT_DIR="$(pwd)"
26
export CURRENT_DIR="$(pwd)"
21
 
27
 
22
# verify we're a x86_64 Linux host
28
print_error_and_die()
-
 
29
{
23
if [ ! "$(uname)" = "Linux" ] || [ ! "$(uname -m)" = "x86_64" ]; then
30
        # a handy function that does what it says. Args: error strings to print, one line per argument
-
 
31
        test -z "${COLUMNS}" && COLUMNS=80
24
        echo ""
32
        echo ""
-
 
33
        while [ -n "${1}" ]; do
25
        echo "Error: this script requires a x86_64 Linux machine (possibly a virtual machine) as the build host." | fold -s -w 79
34
                echo "${1}"|fold -s -w "${COLUMNS}"
-
 
35
                shift
-
 
36
        done
26
        echo ""
37
        echo ""
27
        exit 1
38
        exit 1
-
 
39
}
-
 
40
 
-
 
41
# verify we're a x86_64 Linux host
-
 
42
if [ ! "$(uname)" = "Linux" ] || [ ! "$(uname -m)" = "x86_64" ]; then
-
 
43
        print_error_and_die "Error: this script requires a x86_64 Linux machine (possibly a virtual machine) as the build host."
28
fi
44
fi
29
 
45
 
30
# verify that we have the QNX platform SDK
46
# verify that we have the QNX platform SDK
31
if [ ! -d "${QNXSDK_PATH}/${QNXSDK_HOSTPATH}" ] || [ ! -d "${QNXSDK_PATH}/${QNXSDK_TARGETPATH}" ]; then
47
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
48
        print_error_and_die "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."
34
        echo ""
-
 
35
        exit 1
-
 
36
fi
49
fi
37
 
50
 
38
# verify that we have wget, python3, cmake, gcc, g++ and ninja
51
# verify that we have the required tools
39
if    ! wget    --version > /dev/null 2>&1 \
52
for REQUIRED_TOOL in ${REQUIRED_TOOLS}; do
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
53
        "${REQUIRED_TOOL}" --version > /dev/null 2>&1 || print_error_and_die \
45
        echo ""
-
 
46
        echo "Error: this script requires at the very least the following tools installed:"
54
                "Error: this script requires at the very least the following tools installed:" \
47
        echo "  wget"
55
                "       $(echo "${REQUIRED_TOOLS}"|sed 's/ /\n  /g')" \
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."
56
                "Please install them (possibly as binary packages with apt-get) and try again." \
54
        echo ""
57
                "More specifically, the following tool was not found: '${REQUIRED_TOOL}'"
55
        exit 1
-
 
56
fi
58
done
57
 
59
 
58
# verify that the symlinks are deployed in the SDK -- just test one of them
60
# 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
61
if [ ! -e "${QNXSDK_PATH}/${QNXSDK_TARGETPATH}/usr/include/readline.h" ]; then
60
        echo ""
62
        print_error_and_die \
61
        echo "Error: the toolchain platform-specific symbolic links have not been deployed in this QNX SDK. Please run" | fold -s -w 79
63
                "Error: the toolchain platform-specific symbolic links have not been deployed in this QNX SDK. Please run" \
62
        echo "(on a POSIX machine:)"
64
                "(on a POSIX machine:)" \
63
        echo "  cd ${QNXSDK_PATH}" | fold -s -w 79
65
                "       cd ${QNXSDK_PATH}" \
64
        echo "  find . -name symlinks.lst -exec ./symlinks.sh {} create \\; && printf 'present' > .symlinks-state" | fold -s -w 79
66
                "       find . -name symlinks.lst -exec ./symlinks.sh {} create \\; && printf 'present' > .symlinks-state" \
65
        echo "(else on a Windows machine:)"
67
                "(else on a Windows machine:)" \
66
        echo "  cd ${QNXSDK_PATH}" | fold -s -w 79
68
                "       cd ${QNXSDK_PATH}" \
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
                "       host\\win64\\x86_64\\usr\\bin\\busybox.exe sh -c \"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
70
                "Note that this step WILL take time on a Win32 machine, but is only done once."
71
        echo ""
-
 
72
        exit 1
-
 
73
fi
71
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 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
 
72
 
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
73
# 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)
74
# (this is totally prohibitive with the official QNX toolchain)
89
if [ ! -L /tmp/qnxsdk ] || [ ! "$(readlink /tmp/qnxsdk)" = "$(realpath "${CURRENT_DIR}/${QNXSDK_PATH}")" ]; then
75
if [ ! -L /tmp/qnxsdk ] || [ ! "$(readlink /tmp/qnxsdk)" = "$(realpath "${CURRENT_DIR}/${QNXSDK_PATH}")" ]; then
90
        echo "Creating symlink to QNX toolchain in /tmp/qnxsdk..."
76
        echo "Creating symlink to QNX toolchain in /tmp/qnxsdk..."
Line 95... Line 81...
95
# setup the environment
81
# setup the environment
96
export QNX_HOST="/tmp/qnxsdk/${QNXSDK_HOSTPATH}"
82
export QNX_HOST="/tmp/qnxsdk/${QNXSDK_HOSTPATH}"
97
export QNX_TARGET="/tmp/qnxsdk/${QNXSDK_TARGETPATH}"
83
export QNX_TARGET="/tmp/qnxsdk/${QNXSDK_TARGETPATH}"
98
export MAKEFLAGS="-I${QNX_TARGET}/usr/include"
84
export MAKEFLAGS="-I${QNX_TARGET}/usr/include"
99
export PATH="${QNX_HOST}/usr/bin:${PATH}"
85
export PATH="${QNX_HOST}/usr/bin:${PATH}"
-
 
86
 
-
 
87
# print the build environment
-
 
88
echo "QNX_HOST=${QNX_HOST}"
-
 
89
echo "QNX_TARGET=${QNX_TARGET}"
-
 
90
echo "MAKEFLAGS=${MAKEFLAGS}"
-
 
91
 
-
 
92
# construct the target triple (actually a quadruple)
-
 
93
export TARGET_ARCH="${BUILD_TARGET_ARCH}"
-
 
94
test "${BUILD_TARGET_ARCH}" = "x86_64" && export TARGET_VENDOR="pc" || export TARGET_VENDOR="unknown"
-
 
95
export TARGET_KERNEL="nto"
-
 
96
export TARGET_SYSTEM="qnx${QNXSDK_VERSION}"
-
 
97
export TARGET_TRIPLE="${TARGET_ARCH}-${TARGET_VENDOR}-${TARGET_KERNEL}-${TARGET_SYSTEM}"
-
 
98
echo "Will build for ${TARGET_TRIPLE}"
-
 
99
 
-
 
100
# change to an immediately visible path, i.e. the user's desktop (failsafe to $HOME if xdg-user-dir is unavailable)
-
 
101
STAGING_PATH="$(xdg-user-dir DESKTOP 2>/dev/null || echo "${HOME}")"
-
 
102
cd "${STAGING_PATH}"
100
 
103
 
101
# download the involved source packages and unpack them if not done yet
104
# download the involved source packages and unpack them if not done yet
102
download_and_unpack_if_necessary()
105
download_and_unpack_if_necessary()
103
{
106
{
104
        # helper function that downloads a sources tarball, extracts it and patches it if necessary
107
        # helper function that downloads a sources tarball, extracts it and patches it if necessary
Line 122... Line 125...
122
                tar xJf "${CURRENT_DIR}/${2}" || exit 1
125
                tar xJf "${CURRENT_DIR}/${2}" || exit 1
123
        elif echo "${2}"|grep -q "\.tar\.gz$"; then
126
        elif echo "${2}"|grep -q "\.tar\.gz$"; then
124
                # GZipped tarball
127
                # GZipped tarball
125
                tar xzf "${CURRENT_DIR}/${2}" || exit 1
128
                tar xzf "${CURRENT_DIR}/${2}" || exit 1
126
        else
129
        else
127
                echo "Error: unsupported file extension. Please improve the download_and_unpack_if_necessary() shell function to support it."
130
                print_error_and_die "Error: unsupported file extension. Please improve the download_and_unpack_if_necessary() shell function to support it."
128
                exit 1
-
 
129
        fi
131
        fi
130
        # make sure the expected directory is here after extraction
132
        # make sure the expected directory is here after extraction
131
        if [ ! -d "${1}" ]; then
133
        if [ ! -d "${1}" ]; then
132
                echo "Error: couldn't find ${1} in extracted sources."
134
                print_error_and_die "Error: couldn't find ${1} in extracted sources."
133
                exit 1
-
 
134
        fi
135
        fi
135
        # do we have a patchset to apply ?
136
        # do we have a patchset to apply ?
136
        if [ -n "${4}" ]; then
137
        if [ -n "${4}" ]; then
137
                echo "Downloading ${1} patchset from ${4}..."
138
                echo "Downloading ${1} patchset from ${4}..."
138
                wget -O "${CURRENT_DIR}/${2}.patchset" "${4}" || exit 1
139
                wget -O "${CURRENT_DIR}/${2}.patchset" "${4}" || exit 1
Line 144... Line 145...
144
                unset OLDDIR
145
                unset OLDDIR
145
        fi
146
        fi
146
        return 0
147
        return 0
147
}
148
}
148
download_and_unpack_if_necessary "${LLVM_SOURCES_DIR}" "${LLVM_SOURCES_FILE}" "${LLVM_SOURCES_URL}" || exit 1
149
download_and_unpack_if_necessary "${LLVM_SOURCES_DIR}" "${LLVM_SOURCES_FILE}" "${LLVM_SOURCES_URL}" || exit 1
149
 
-
 
150
# download the LLVM source package and unpack it if not done yet
-
 
151
if [ ! -d "${LLVM_SOURCES_DIR}" ]; then
-
 
152
        if [ ! -f "${CURRENT_DIR}/${LLVM_SOURCES_FILE}" ]; then
-
 
153
                echo "Downloading LLVM ${LLVM_VERSION} sources from LLVM GitHub..."
-
 
154
                wget "${LLVM_SOURCES_URL}" || exit 1
-
 
155
        fi
-
 
156
        echo "Extracting LLVM ${LLVM_VERSION} sources..."
-
 
157
        cd "$(dirname "${LLVM_SOURCES_DIR}")"
-
 
158
        tar xzf "${CURRENT_DIR}/${LLVM_SOURCES_FILE}" || exit 1
-
 
159
        if [ ! -d "${LLVM_SOURCES_DIR}" ]; then
-
 
160
                echo "Error: couldn't find ${LLVM_SOURCES_DIR} in extracted LLVM sources."
-
 
161
                exit 1
-
 
162
        fi
-
 
163
fi
-
 
164
 
150
 
165
# create the build directory
151
# create the build directory
166
echo "Wiping out build directory..."
152
echo "Wiping out build directory..."
167
test -e "${BUILD_DIR_NAME}" && rm -rf "${BUILD_DIR_NAME}"
153
test -e "${BUILD_DIR_NAME}" && rm -rf "${BUILD_DIR_NAME}"
168
mkdir "${BUILD_DIR_NAME}" || exit 1
154
mkdir "${BUILD_DIR_NAME}" || exit 1
169
cd "${BUILD_DIR_NAME}" || exit 1
155
cd "${BUILD_DIR_NAME}" || exit 1
170
 
-
 
171
# print the build environment
-
 
172
echo "QNX_HOST=${QNX_HOST}"
-
 
173
echo "QNX_TARGET=${QNX_TARGET}"
-
 
174
echo "MAKEFLAGS=${MAKEFLAGS}"
-
 
175
 
156
 
176
# create the QNX CMake toolchain file
157
# create the QNX CMake toolchain file
177
test -e "${TARGET_TRIPLE}.cmake" || echo '# '${TARGET_TRIPLE}' CMake toolchain file by Pierre-Marie Baty <pm@pmbaty.com>
158
test -e "${TARGET_TRIPLE}.cmake" || echo '# '${TARGET_TRIPLE}' CMake toolchain file by Pierre-Marie Baty <pm@pmbaty.com>
178
 
159
 
179
SET(CMAKE_SYSTEM_NAME "QNX")
160
SET(CMAKE_SYSTEM_NAME "QNX")
Line 239... Line 220...
239
                sed -E -i "${3}" "${CURRENT_DIR}/${_DOTTED_NAME} [PATCHED]"
220
                sed -E -i "${3}" "${CURRENT_DIR}/${_DOTTED_NAME} [PATCHED]"
240
                shift
221
                shift
241
        done
222
        done
242
        # verify that we did it successfully
223
        # verify that we did it successfully
243
        if ! grep -q "${_PATCHED_PATTERN}" "${CURRENT_DIR}/${_DOTTED_NAME} [PATCHED]"; then
224
        if ! grep -q "${_PATCHED_PATTERN}" "${CURRENT_DIR}/${_DOTTED_NAME} [PATCHED]"; then
244
                echo "Error: the file ${_PATCHEE_PATHNAME} could not be patched. Please investigate and fix manually." | fold -s -w 79; exit 1
225
                print_error_and_die "Error: the file ${_PATCHEE_PATHNAME} could not be patched. Please investigate and fix manually."
245
        fi
226
        fi
246
        # and put the patched file in place
227
        # and put the patched file in place
247
        cp -f "${CURRENT_DIR}/${_DOTTED_NAME} [PATCHED]" "../${LLVM_SOURCES_DIR}/${_PATCHEE_PATHNAME}" || exit 1
228
        cp -f "${CURRENT_DIR}/${_DOTTED_NAME} [PATCHED]" "../${LLVM_SOURCES_DIR}/${_PATCHEE_PATHNAME}" || exit 1
248
}
229
}
249
 
230
 
250
# patch llvm/Support/Unix/Path.inc if not done yet
231
# patch llvm/lib/Support/Unix/Path.inc if not done yet
-
 
232
# replace:
-
 
233
#       defined(__FreeBSD_kernel__)
-
 
234
# with:
251
# replace [defined(__FreeBSD_kernel__)] with [(defined(__FreeBSD_kernel__) || defined(__QNXNTO__))]
235
#       (defined(__FreeBSD_kernel__) || defined(__QNXNTO__))
252
# 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.
236
# 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.
253
# 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,
237
# 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,
254
# 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).
238
# 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).
255
# 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
239
# 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
256
# 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.
240
# 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.
257
# 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.
241
# 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.
258
# FIXME: these hacks should be moved elsewhere not to pollute the QNX8 platform SDK -- it *SHOULD* be possible to build without devs
242
# FIXME: these hacks should be moved elsewhere not to pollute the QNX8 platform SDK -- it *SHOULD* be possible to build without devs
259
backup_and_patch_if_necessary "llvm/lib/Support/Unix/Path.inc" __QNXNTO__ \
243
backup_and_patch_if_necessary "llvm/lib/Support/Unix/Path.inc" __QNXNTO__ \
260
        's/defined\(__FreeBSD_kernel__\)/\(defined\(__FreeBSD_kernel__\) \|\| \defined\(__QNXNTO__\)\)/g'
244
        's@defined\(__FreeBSD_kernel__\)@\(defined\(__FreeBSD_kernel__\) \|\| \defined\(__QNXNTO__\)\)@g'
261
 
245
 
262
# patch lldb/Source/Host/common/Host.cpp if not done yet
246
# LLVM 16: patch llvm/lib/Support/Path.cpp if not done yet
-
 
247
# replace:
-
 
248
#       std::string getMainExecutable
-
 
249
# with:
-
 
250
#       #if 0
-
 
251
#       std::string getMainExecutable
-
 
252
# and:
-
 
253
#       TempFile::TempFile(StringRef Name, int FD)
-
 
254
# with:
-
 
255
#       #endif
263
# replace [defined(SIGINFO)] with [(defined(SIGINFO) && !defined(__QNXNTO__))]
256
#       TempFile::TempFile(StringRef Name, int FD)
264
# RATIONALE: the QNX people defined SIGINFO to the value of SIGUSR1 for a mysterious reason, defeating the purpose of SIGUSR1
257
# RATIONALE: std::string getMainExecutable(const char *Argv0, void *MainAddr) is already defined in llvm/lib/Support/Unix/Path.inc, this looks like a LLVM bug?
265
# which should be a User-Definable signal as mandated by POSIX. Consequently, userland code that enumerates POSIX signals
258
# Specifically read the following patch list: https://reviews.llvm.org/D109977 -- it looks like the implementation of this diff in LLVM 16.0.6 is incomplete.
266
# hits twice the same value and all is left to solve this problem is to filter either one out. Since SIGINFO, contrarily to SIGUSR1,
259
# This patch restores a working state (ante D109977).
267
# is an optional signal, this is the value that will be left out - even if on QNX nobody can actually use SIGUSR1's value.
260
test "$(echo "${LLVM_VERSION}"|cut -d . -f 1)" -lt 17 && backup_and_patch_if_necessary "llvm/lib/Support/Path.cpp" "#if 0" \
268
backup_and_patch_if_necessary "lldb/source/Host/common/Host.cpp" __QNXNTO__ \
261
        's@std::string getMainExecutable@#if 0\nstd::string getMainExecutable@' \
269
        's/defined\(SIGINFO\)/\(defined\(SIGINFO\) \&\& \!defined\(__QNXNTO__\)\)/g'
262
        's@TempFile::TempFile\(StringRef Name, int FD\)@#endif\nTempFile::TempFile\(StringRef Name, int FD\)@'
270
 
263
 
271
# FIXME: another patch is needed for LLDB. Basically, the ptrace() POSIX system call doesn't exist on QNX. Instead
-
 
272
# QNX use their own debug utility: pdebug. Note the /proc filesystem can be used to access a debuggee's virtual memory space.
-
 
273
# in lldb/source/Host/posix/ProcessLauncherPosixFork.cpp line 196:
264
# LLDB patches
274
#   if (ptrace(PT_TRACE_ME, 0, nullptr, 0) == -1) // <--- undefined: ptrace, PT_TRACE_ME
265
if echo "${LLVM_PROJECTS_TO_BUILD}"|tr ';' '\n'|grep -q "lldb"; then
275
 
266
 
-
 
267
        # patch lldb/Source/Host/common/Host.cpp if not done yet
-
 
268
        # replace:
-
 
269
        #       defined(SIGINFO)
-
 
270
        # with:
276
#    -D LLVM_ENABLE_PROJECTS="clang;lld;lldb" \
271
        #       (defined(SIGINFO) && !defined(__QNXNTO__))
-
 
272
        # RATIONALE: once upon a time (probably in the early steps of the design of their OS), the QNX people defined SIGINFO to the value of SIGUSR1 for a mysterious reason,
-
 
273
        # defeating the purpose of SIGUSR1 completely, which should be a User-Definable signal as mandated by POSIX. Consequently, any userland code that enumerates POSIX signals
-
 
274
        # hits the same value twice, and all is left to solve this problem is to filter either one out. Since SIGINFO, contrarily to SIGUSR1, is an optional signal,
-
 
275
        # this is the value that will be left out. It is not possible to correct this in the platform SDK since all the precompiled userland programs supplied by QNX
-
 
276
        # expect the value of SIGUSR1 for SIGINFO.
-
 
277
        backup_and_patch_if_necessary "lldb/source/Host/common/Host.cpp" __QNXNTO__ \
-
 
278
                's@defined\(SIGINFO\)@\(defined\(SIGINFO\) \&\& \!defined\(__QNXNTO__\)\)@g'
-
 
279
       
-
 
280
        # FIXME: another patch is needed for LLDB. Basically, the ptrace() POSIX system call doesn't exist on QNX. Instead
-
 
281
        # QNX use their own debug utility: pdebug. Note the /proc filesystem can be used to access a debuggee's virtual memory space.
-
 
282
        # in lldb/source/Host/posix/ProcessLauncherPosixFork.cpp line 196:
-
 
283
        #   if (ptrace(PT_TRACE_ME, 0, nullptr, 0) == -1) // <--- undefined: ptrace, PT_TRACE_ME
-
 
284
fi
277
 
285
 
278
# patch compiler-rt/lib/builtins/enable_execute_stack.c if not done yet
286
# compiler-rt patches
279
# replace [#include "int_lib.h"] with [#ifdef __QNXNTO__\n#define _QNX_SOURCE 1\n#endif\n#include "int_lib.h"]
-
 
280
# 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.
-
 
281
# 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.
-
 
282
# 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
-
 
283
# when building compiler-rt specifically, the CMAKE_C_FLAGS directive is ignored. Patching the source file seems like the best option to fix that.
-
 
284
backup_and_patch_if_necessary "compiler-rt/lib/builtins/enable_execute_stack.c" __QNXNTO__ \
-
 
285
        's/#include "int_lib.h"/#ifdef __QNXNTO__\n#define _QNX_SOURCE 1\n#endif\n#include "int_lib.h"/g'
287
if echo "${LLVM_RUNTIMES_TO_BUILD}"|tr ';' '\n'|grep -q "compiler-rt"; then
286
 
288
 
-
 
289
        # patch compiler-rt/lib/builtins/enable_execute_stack.c if not done yet
-
 
290
        # replace:
287
# patch libunwind/src/RWMutex.hpp
291
        #       #include "int_lib.h"
-
 
292
        # with:
-
 
293
        #       #ifdef __QNXNTO__
288
# replace [#include <pthread.h>] with [#ifdef __QNXNTO__\n#define __EXT_QNX\n#define __EXT_POSIX1_200112\n#endif\n#include <pthread.h>]
294
        #       #define _QNX_SOURCE 1
-
 
295
        #       #endif
-
 
296
        #       #include "int_lib.h"
289
# RATIONALE: the pthreads implementation in QNX 'steals' things from the POSIX.1 standard and hides them behind the __EXT_QNX macro,
297
        # 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.
290
# which is defined when either _QNX_SOURCE or __EXT without anything else is defined. This is not correct and low-level libraries
298
        # 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.
291
# 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
299
        # 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
292
# platform SDK: /usr/include/link.h, which defines Elf types as Elf64/Elf32 types depending on the architecture and adds some glue.
300
        # when building compiler-rt specifically, the CMAKE_C_FLAGS directive is ignored. Patching the source file seems like the best option to fix that.
293
backup_and_patch_if_necessary "libunwind/src/RWMutex.hpp" __QNXNTO__ \
301
        backup_and_patch_if_necessary "compiler-rt/lib/builtins/enable_execute_stack.c" __QNXNTO__ \
294
        's/#include <pthread.h>/#ifdef __QNXNTO__\n#define __EXT_QNX\n#define __EXT_POSIX1_200112\n#endif\n#include <pthread.h>/g'
302
                's@#include "int_lib.h"@#ifdef __QNXNTO__\n#define _QNX_SOURCE 1\n#endif\n#include "int_lib.h"@'
295
 
303
 
296
# patch libunwind/src/libunwind.cpp
304
        # patch compiler-rt/lib/profile/InstrProfilingUtil.c
-
 
305
        # replace:
-
 
306
        #       #include <sys/mman.h>
-
 
307
        # with:
-
 
308
        #       #ifdef __QNXNTO__
297
# replace [#include <libunwind.h>] with [#ifdef __QNXNTO__\n#include <sys/link.h>\n#include <link.h>\n#endif\n#include <libunwind.h>]
309
        #       #include <devs/sys/mman.h>
-
 
310
        #       #endif
-
 
311
        #       #include <sys/mman.h>
298
# 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.
312
        # RATIONALE: QNX doesn't define MADV_DONTNEED (but does so for POSIX_MADV_DONTNEED), unfortunately compiler-rt needs the former. By luck, its value is defined in
299
# 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.
313
        # the extra platform headers they borrowed from FreeBSD, i.e. devs/sys/mman.h, and it has the same value, so include both to fix the problem.
300
# 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).
-
 
301
backup_and_patch_if_necessary "libunwind/src/libunwind.cpp" __QNXNTO__ \
314
        backup_and_patch_if_necessary "compiler-rt/lib/profile/InstrProfilingUtil.c" __QNXNTO__ \
302
        's,#include <libunwind.h>,#ifdef __QNXNTO__\n#include <sys/link.h>\n#include <link.h>\n#endif\n#include <libunwind.h>,g'
315
                's@#include <sys/mman.h>@#ifdef __QNXNTO__\n#include <devs/sys/mman.h>\n#endif\n#include <sys/mman.h>@'
303
 
316
 
304
# patch libcxx/include/__config
317
        # patch compiler-rt/lib/orc/endianness.h
-
 
318
        # replace:
-
 
319
        #       #elif defined(__MVS__)
-
 
320
        # with:
-
 
321
        #       #elif defined(__QNXNTO__)
-
 
322
        #       #define BYTE_ORDER __BYTE_ORDER__
-
 
323
        #       #elif defined(__MVS__)
305
# replace [define _LIBCPP_HAS_THREAD_API_WIN32] with [define _LIBCPP_HAS_THREAD_API_WIN32\n#    elif defined(__QNXNTO__)\n#      define _LIBCPP_HAS_THREAD_API_PTHREAD]
324
        # RATIONALE: QNX doesn't provide a <machine/endian.h> header directly: the user must specify the machine-specific include path (e.g. -isystem ${QNX_TARGET}/usr/include/devs/include_x86_64)
306
# RATIONALE: simply bring QNX among the list of systems known by libc++ to expose a pthreads API, and inform it that pthread_cond_clockwait() is available (pah!)
325
        # Instead of going through platform detection logic, we supply the only definition this file needs, which is opportunisticly the same one that GCC and Clang provide implicitly.
307
backup_and_patch_if_necessary "libcxx/include/__config" __QNXNTO__ \
326
        backup_and_patch_if_necessary "compiler-rt/lib/orc/endianness.h" __QNXNTO__ \
308
        's/define _LIBCPP_HAS_THREAD_API_WIN32/define _LIBCPP_HAS_THREAD_API_WIN32\n#    elif defined(__QNXNTO__)\n#      define _LIBCPP_HAS_THREAD_API_PTHREAD\n#      define _LIBCPP_HAS_COND_CLOCKWAIT/g'
327
                's@#elif defined\(__MVS__\)@#elif defined\(__QNXNTO__\)\n#define BYTE_ORDER __BYTE_ORDER__\n#elif defined\(__MVS__\)@'
-
 
328
fi
309
 
329
 
310
# patch libcxx/include/__locale, libcxx/include/CMakeLists.txt and add __support/qnx/xlocale.h to the libc++ source tree
-
 
311
# replace [# include <__support/openbsd/xlocale.h>] with [# include <__support/openbsd/xlocale.h>\n#elif defined(__QNXNTO__)\n# include <__support/qnx/xlocale.h>]
-
 
312
# RATIONALE: add QNX-specific locale C++ bindings and definitions
-
 
313
backup_and_patch_if_necessary "libcxx/include/__locale" __QNXNTO__ \
-
 
314
        's,# include <__support/openbsd/xlocale.h>,# include <__support/openbsd/xlocale.h>\n#elif defined\(__QNXNTO__\)\n# include <__support/qnx/xlocale.h>,g' \
-
 
315
        's/#elif defined\(__MVS__\)/#elif defined\(__QNXNTO__\)\n    typedef short mask;\n    static const mask space  = \(_CN\|_SP\|_XS\);\n    static const mask print  = \(_DI\|_LO\|_PU\|_SP\|_UP\|_XA\);\n    static const mask cntrl  = _BB;\n    static const mask upper  = _UP;\n    static const mask lower  = _LO;\n    static const mask alpha  = \(_LO\|_UP\|_XA\);\n    static const mask digit  = _DI;\n    static const mask punct  = _PU;\n    static const mask xdigit = _XD;\n    static const mask blank  = \(_SP\|_XB\);\n    static const mask __regex_word = 0x1000;\n#elif defined\(__MVS__\)/g'
330
# libunwind patches
316
backup_and_patch_if_necessary "libcxx/include/CMakeLists.txt" qnx/xlocale.h 's,  __support/openbsd/xlocale.h,  __support/openbsd/xlocale.h\n  __support/qnx/xlocale.h,g'
-
 
317
test -d "../${LLVM_SOURCES_DIR}/libcxx/include/__support/qnx" || mkdir "../${LLVM_SOURCES_DIR}/libcxx/include/__support/qnx" || exit 1
331
if echo "${LLVM_RUNTIMES_TO_BUILD}"|tr ';' '\n'|grep -q "libunwind"; then
318
test -f "../${LLVM_SOURCES_DIR}/libcxx/include/__support/qnx/xlocale.h" || cp "${QNX_TARGET}/usr/include/c++/v1/__support/qnx/xlocale.h" "../${LLVM_SOURCES_DIR}/libcxx/include/__support/qnx/xlocale.h" || exit 1
-
 
319
 
332
 
320
# patch libcxx/include/locale
333
        # patch libunwind/src/libunwind.cpp
-
 
334
        # replace:
-
 
335
        #       #include <libunwind.h>:
-
 
336
        # with:
-
 
337
        #       #ifdef __QNXNTO__
-
 
338
        #       #define _QNX_SOURCE 1
-
 
339
        #       #endif
-
 
340
        #       #include <libunwind.h>
-
 
341
        # RATIONALE: the pthreads implementation in QNX 'steals' things from the POSIX.1 standard and hides them behind the __EXT_QNX macro,
321
# replace [!defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__)] with [!defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__) && !defined(__QNX__)]
342
        # which is defined when either _QNX_SOURCE or __EXT without anything else is defined. This is not correct and low-level libraries
322
# RATIONALE: QNX doesn't have catopen() to open a "message catalog"
343
        # 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
-
 
344
        # platform SDK: /usr/include/link.h, which defines Elf types as Elf64/Elf32 types depending on the architecture and adds some glue.
323
backup_and_patch_if_necessary "libcxx/include/locale" __QNXNTO__ \
345
        backup_and_patch_if_necessary "libunwind/src/libunwind.cpp" __QNXNTO__ \
324
        's/\!defined\(__BIONIC__\) \&\& \!defined\(_NEWLIB_VERSION\) \&\& \!defined\(__EMSCRIPTEN__\)/!defined\(__BIONIC__\) \&\& !defined\(_NEWLIB_VERSION\) \&\& !defined\(__EMSCRIPTEN__\) \&\& !defined\(__QNXNTO__\)/g'
346
                's@#include <libunwind.h>@#ifdef __QNXNTO__\n#define _QNX_SOURCE 1\n#endif\n#include <libunwind.h>@'
-
 
347
fi
325
 
348
 
326
# patch libcxx/include/setjmp.h
349
# libc++ patches
327
# replace [#endif // __cplusplus] with [#ifdef __QNXNTO__\n#undef longjmp\n[[noreturn]] inline void longjmp(jmp_buf env, int val) { ::siglongjmp(env, val); }\n#endif\n\n#endif // __cplusplus]
-
 
328
# RATIONALE: QNX doesn't have longjmp() (or has it? it rather seems they don't *WANT* to expose it... check that) but instead siglongjmp()
-
 
329
backup_and_patch_if_necessary "libcxx/include/setjmp.h" __QNXNTO__ \
350
if echo "${LLVM_PROJECTS_TO_BUILD}"|tr ';' '\n'|grep -q "libcxx"; then
330
        's|#endif // __cplusplus|#ifdef __QNXNTO__\n#undef longjmp\n\[\[noreturn\]\] inline void longjmp\(jmp_buf env, int val\) { ::siglongjmp\(env, val\); }\n#endif\n\n#endif // __cplusplus|g'
-
 
331
 
351
 
332
# patch libcxx/include/__chrono/high_resolution_clock.h
352
        # patch libcxx/include/__config
-
 
353
        # replace:
-
 
354
        #       #      define _LIBCPP_HAS_THREAD_API_WIN32
-
 
355
        # with:
-
 
356
        #       #      define _LIBCPP_HAS_THREAD_API_WIN32
-
 
357
        #       #    elif defined(__QNXNTO__)
-
 
358
        #       #      define _LIBCPP_HAS_THREAD_API_PTHREAD
-
 
359
        #       #      define _LIBCPP_HAS_COND_CLOCKWAIT
-
 
360
        #       #      define _LIBCPP_HAS_CLOCK_GETTIME
-
 
361
        # RATIONALE: simply bring QNX among the list of systems known by libc++ to expose a pthreads API; while we're at it inform it that pthread_cond_clockwait() is available
-
 
362
        # and that the standard POSIX clock_gettime() is available to return a realtime wall clock value in nanoseconds (this might not be the optimal way of getting it though).
-
 
363
        backup_and_patch_if_necessary "libcxx/include/__config" __QNXNTO__ \
333
# replace [#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK] with [#if defined(__QNXNTO__)\nclass _LIBCPP_VISIBILITY("default") high_resolution_clock\n{\npublic:\n    typedef nanoseconds duration;\n    typedef duration::rep rep;\n    typedef duration::period period;\n    typedef chrono::time_point<high_resolution_clock, duration> time_point;\n    static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = true;\n    static time_point now() _NOEXCEPT;\n};\n#elif !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK)]
364
                's@#      define _LIBCPP_HAS_THREAD_API_WIN32@#      define _LIBCPP_HAS_THREAD_API_WIN32\n#    elif defined(__QNXNTO__)\n#      define _LIBCPP_HAS_THREAD_API_PTHREAD\n#      define _LIBCPP_HAS_COND_CLOCKWAIT\n#      define _LIBCPP_HAS_CLOCK_GETTIME@'
-
 
365
       
-
 
366
        # patch libcxx/include/__locale
-
 
367
        # replace:
-
 
368
        #       # include <__support/openbsd/xlocale.h>
-
 
369
        # with:
-
 
370
        #       # include <__support/openbsd/xlocale.h>
-
 
371
        #       #elif defined(__QNXNTO__)
-
 
372
        #       # include <__support/qnx/xlocale.h>
-
 
373
        # and:
-
 
374
        #       #elif defined(__MVS__)
-
 
375
        # with:
-
 
376
        #       #elif defined(__QNXNTO__)
-
 
377
        #           typedef short mask;
-
 
378
        #           static const mask space  = (_CN|_SP|_XS);
-
 
379
        #           static const mask print  = (_DI|_LO|_PU|_SP|_UP|_XA);
-
 
380
        #           static const mask cntrl  = _BB;
-
 
381
        #           static const mask upper  = _UP;
-
 
382
        #           static const mask lower  = _LO;
-
 
383
        #           static const mask alpha  = (_LO|_UP|_XA);
-
 
384
        #           static const mask digit  = _DI;
-
 
385
        #           static const mask punct  = _PU;
-
 
386
        #           static const mask xdigit = _XD;
-
 
387
        #           static const mask blank  = (_SP|_XB);
-
 
388
        #           static const mask __regex_word = 0x1000;
-
 
389
        #       #elif defined(__MVS__)
-
 
390
        # RATIONALE: add QNX-specific locale C++ bindings and definitions
-
 
391
        backup_and_patch_if_necessary "libcxx/include/__locale" __QNXNTO__ \
-
 
392
                's@# include <__support/openbsd/xlocale.h>@# include <__support/openbsd/xlocale.h>\n#elif defined\(__QNXNTO__\)\n# include <__support/qnx/xlocale.h>@' \
334
# RATIONALE: QNX provides its own implementation of a high resolution clock for libc++'s std::chrono, so better use it
393
                's@#elif defined\(__MVS__\)@#elif defined\(__QNXNTO__\)\n    typedef short mask;\n    static const mask space  = \(_CN\|_SP\|_XS\);\n    static const mask print  = \(_DI\|_LO\|_PU\|_SP\|_UP\|_XA\);\n    static const mask cntrl  = _BB;\n    static const mask upper  = _UP;\n    static const mask lower  = _LO;\n    static const mask alpha  = \(_LO\|_UP\|_XA\);\n    static const mask digit  = _DI;\n    static const mask punct  = _PU;\n    static const mask xdigit = _XD;\n    static const mask blank  = \(_SP\|_XB\);\n    static const mask __regex_word = 0x1000;\n#elif defined\(__MVS__\)@'
-
 
394
       
-
 
395
        # patch libcxx/include/CMakeLists.txt
-
 
396
        # replace:
-
 
397
        #         __support/openbsd/xlocale.h
-
 
398
        # with:
-
 
399
        #         __support/openbsd/xlocale.h
-
 
400
        #         __support/qnx/xlocale.h
-
 
401
        # RATIONALE: add QNX-specific locale C++ bindings and definitions
-
 
402
        backup_and_patch_if_necessary "libcxx/include/CMakeLists.txt" qnx/xlocale.h \
-
 
403
                's@  __support/openbsd/xlocale.h@  __support/openbsd/xlocale.h\n  __support/qnx/xlocale.h@'
-
 
404
       
-
 
405
        # add __support/qnx/xlocale.h to the libc++ source tree
-
 
406
        # RATIONALE: add QNX-specific locale C++ bindings and definitions
-
 
407
        test -d "../${LLVM_SOURCES_DIR}/libcxx/include/__support/qnx" || mkdir "../${LLVM_SOURCES_DIR}/libcxx/include/__support/qnx" || exit 1
-
 
408
        test -f "../${LLVM_SOURCES_DIR}/libcxx/include/__support/qnx/xlocale.h" || cp "${QNX_TARGET}/usr/include/c++/v1/__support/qnx/xlocale.h" "../${LLVM_SOURCES_DIR}/libcxx/include/__support/qnx/xlocale.h" || exit 1
-
 
409
       
-
 
410
        # patch libcxx/include/locale
-
 
411
        # replace:
-
 
412
        #       !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__)
-
 
413
        # with:
-
 
414
        #       !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__) && !defined(__QNXNTO__)
-
 
415
        # RATIONALE: QNX doesn't have catopen() to open a "message catalog"
-
 
416
        backup_and_patch_if_necessary "libcxx/include/locale" __QNXNTO__ \
-
 
417
                's@\!defined\(__BIONIC__\) \&\& \!defined\(_NEWLIB_VERSION\) \&\& \!defined\(__EMSCRIPTEN__\)@!defined\(__BIONIC__\) \&\& !defined\(_NEWLIB_VERSION\) \&\& !defined\(__EMSCRIPTEN__\) \&\& !defined\(__QNXNTO__\)@'
-
 
418
       
-
 
419
        # patch libcxx/include/setjmp.h
-
 
420
        # replace:
-
 
421
        #       #endif // __cplusplus
-
 
422
        # with:
-
 
423
        #       #ifdef __QNXNTO__
-
 
424
        #       #undef longjmp
-
 
425
        #       [[noreturn]] inline void longjmp(jmp_buf env, int val) { ::siglongjmp(env, val); }
-
 
426
        #       #endif // __QNXNTO__
-
 
427
        #       
-
 
428
        #       #endif // __cplusplus
-
 
429
        # RATIONALE: restore the thread signal mask when calling longjmp() by calling siglongjmp() instead (not sure why, but that's how they do it in the libc++ 16.0.6 they ship with their SDK)
-
 
430
        # FIXME: is this a good idea really? It looks like by calling siglongjmp() instead of longjmp() after setjmp() the QNX people did a broken implementation !?
335
backup_and_patch_if_necessary "libcxx/include/__chrono/high_resolution_clock.h" __QNXNTO__ \
431
        backup_and_patch_if_necessary "libcxx/include/setjmp.h" __QNXNTO__ \
-
 
432
                's@#endif // __cplusplus@#ifdef __QNXNTO__\n#undef longjmp\n\[\[noreturn\]\] inline void longjmp\(jmp_buf env, int val\) { ::siglongjmp\(env, val\); }\n#endif // __QNXNTO_\n\n#endif // __cplusplus@'
-
 
433
fi
-
 
434
 
-
 
435
# polly patches
-
 
436
if echo "${LLVM_PROJECTS_TO_BUILD}"|tr ';' '\n'|grep -q "polly"; then
-
 
437
 
-
 
438
        # patch polly/lib/External/isl/imath/imath.c
-
 
439
        # replace:
-
 
440
        #       /* Select min/max. */
-
 
441
        # with:
-
 
442
        #       #ifdef __QNXNTO__
-
 
443
        #       #undef MIN
-
 
444
        #       #undef MAX
-
 
445
        #       #endif // __QNXNTO__
-
 
446
        #       /* Select min/max. */
-
 
447
        # RATIONALE: QNX already defines MIN/MAX as macros, but polly intends to define them as inline functions. Perhaps this could be avoided by passing _POSIX_SOURCE instead of _QNX_SOURCE.
336
        's/#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK/#if defined\(__QNXNTO__\)\nclass _LIBCPP_VISIBILITY\("default"\) high_resolution_clock\n{\npublic:\n    typedef nanoseconds duration;\n    typedef duration::rep rep;\n    typedef duration::period period;\n    typedef chrono::time_point<high_resolution_clock, duration> time_point;\n    static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = true;\n    static time_point now\(\) _NOEXCEPT;\n};\n#elif !defined\(_LIBCPP_HAS_NO_MONOTONIC_CLOCK\)/g'
448
        backup_and_patch_if_necessary "polly/lib/External/isl/imath/imath.c" __QNXNTO__ \
-
 
449
                's@\/\* Select min\/max. \*\/@#ifdef __QNXNTO__\n#undef MIN\n#undef MAX\n#endif\n\/\* Select min\/max. \*\/@'
-
 
450
fi
337
 
451
 
338
# now configure LLVM -- and use ccache
452
# now configure LLVM...
339
# TAKE NOTE: THE VALUE OF LIBCXX*_ADDITIONAL_COMPILE_FLAGS CAN ONLY HAVE ONE FLAG! It is passed by CMake surrounded by quotes to the compiler, e.g. -Dflag "-Dflag1 -Dflag2" -Dflag which is WRONG.
-
 
340
echo "Configuring LLVM build..."
453
echo "Configuring LLVM build..."
341
export CCACHE_DIR="$(realpath "../${LLVM_SOURCES_DIR}/.ccache")"
454
export CCACHE_DIR="$(realpath "../${LLVM_SOURCES_DIR}/.ccache")"
342
cmake \
455
cmake \
343
    -D CMAKE_TOOLCHAIN_FILE="${TARGET_TRIPLE}.cmake" \
456
    -D CMAKE_TOOLCHAIN_FILE="${TARGET_TRIPLE}.cmake" \
344
    -D CMAKE_BUILD_TYPE="MinSizeRel" \
457
    -D CMAKE_BUILD_TYPE="${LLVM_BUILD_CONFIGURATION_TYPE}" \
345
    -D CMAKE_INSTALL_PREFIX="/tmp/qnxsdk/host/qnx$(echo "${QNXSDK_VERSION}"|awk -F. '{print $1}')/${BUILD_TARGET_ARCH}" \
458
    -D CMAKE_INSTALL_PREFIX="/usr/bin" \
346
    -D CMAKE_STAGING_PREFIX="/usr/bin" \
459
    -D CMAKE_STAGING_PREFIX="${CURRENT_DIR}/llvm-build/${BUILD_TARGET_ARCH}" \
347
    -D CMAKE_C_COMPILER_LAUNCHER="ccache" \
460
    -D CMAKE_C_COMPILER_LAUNCHER="ccache" \
348
    -D CMAKE_CXX_COMPILER_LAUNCHER="ccache" \
461
    -D CMAKE_CXX_COMPILER_LAUNCHER="ccache" \
349
    -D LLVM_HOST_TRIPLE="${TARGET_TRIPLE}" \
462
    -D LLVM_HOST_TRIPLE="${TARGET_TRIPLE}" \
350
    -D LLVM_ENABLE_PROJECTS="clang;lld" \
463
    -D LLVM_ENABLE_PROJECTS="${LLVM_PROJECTS_TO_BUILD}" \
351
    -D LLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
464
    -D LLVM_ENABLE_RUNTIMES="${LLVM_RUNTIMES_TO_BUILD}" \
352
    -D LLVM_TARGETS_TO_BUILD="AArch64;X86" \
465
    -D LLVM_TARGETS_TO_BUILD="AArch64;X86" \
353
    -D COMPILER_RT_BUILD_SANITIZERS="OFF" \
466
    -D COMPILER_RT_BUILD_SANITIZERS="OFF" \
354
    -D COMPILER_RT_BUILD_XRAY="OFF" \
467
    -D COMPILER_RT_BUILD_XRAY="OFF" \
355
    -D LIBCXX_ADDITIONAL_COMPILE_FLAGS="-D_QNX_SOURCE=1" \
468
    -D COMPILER_RT_BUILD_MEMPROF="OFF" \
-
 
469
    -D COMPILER_RT_BUILD_LIBFUZZER="OFF" \
356
    -D LIBCXXABI_ADDITIONAL_COMPILE_FLAGS="-D_QNX_SOURCE=1" \
470
    -D COMPILER_RT_BUILD_PROFILE="OFF" \
357
    -G Ninja \
471
    -G Ninja \
358
    "../${LLVM_SOURCES_DIR}/llvm" || exit 1
472
    "../${LLVM_SOURCES_DIR}/llvm" || exit 1
359
 
-
 
360
# hijack the "bin" and "lib/clang" output directories and redirect them to the hypervisor's filesystem
-
 
361
test -e "${CURRENT_DIR}/llvm-build" && rm -rf "${CURRENT_DIR}/llvm-build"
-
 
362
mkdir -p "${CURRENT_DIR}/llvm-build"
-
 
363
test -d bin && mv bin "${CURRENT_DIR}/llvm-build/bin" || mkdir "${CURRENT_DIR}/llvm-build/bin"
-
 
364
ln -s "${CURRENT_DIR}/llvm-build/bin" bin
-
 
365
mkdir -p "${CURRENT_DIR}/llvm-build/lib"
-
 
366
test -d lib/clang && mv lib/clang "${CURRENT_DIR}/llvm-build/lib/clang" || mkdir "${CURRENT_DIR}/llvm-build/lib/clang"
-
 
367
ln -s "${CURRENT_DIR}/llvm-build/lib/clang" lib/clang
-
 
368
 
473
 
369
# and do the Lord's work. https://youtu.be/jcyYmCnkbEE
474
# and do the Lord's work. https://youtu.be/jcyYmCnkbEE
370
echo "Building LLVM..."
475
echo "Building LLVM..."
371
cmake --build . || exit 1
476
cmake --build . --target install || exit 1
372
 
477
 
373
# TODO: port lldb bindings
-
 
374
# TODO: port compiler_rt sanitizer bindings
478
/bin/printf "\n\xF0\x9F\x8D\xBE\x20\x43\x68\x61\x6d\x70\x61\x67\x6e\x65\x2e\n"
375
echo "Champagne, James. Champagne."
-
 
376
exit 0
479
exit 0
-
 
480
 
-
 
481
# TODO optional: port compiler_rt sanitizer bindings and build sanitizers, xray, memprof, libfuzzer and profile
-
 
482
# TODO optional: port lldb bindings and build lldb