Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

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

Rev 9 Rev 10
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="18.1.4" # version of LLVM that will be built
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
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
 
18
 
19
# see where we are
19
# see where we are
Line 95... Line 95...
95
# setup the environment
95
# setup the environment
96
export QNX_HOST="/tmp/qnxsdk/${QNXSDK_HOSTPATH}"
96
export QNX_HOST="/tmp/qnxsdk/${QNXSDK_HOSTPATH}"
97
export QNX_TARGET="/tmp/qnxsdk/${QNXSDK_TARGETPATH}"
97
export QNX_TARGET="/tmp/qnxsdk/${QNXSDK_TARGETPATH}"
98
export MAKEFLAGS="-I${QNX_TARGET}/usr/include"
98
export MAKEFLAGS="-I${QNX_TARGET}/usr/include"
99
export PATH="${QNX_HOST}/usr/bin:${PATH}"
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
100
 
141
 
101
# download the LLVM source package and unpack it if not done yet
142
# download the LLVM source package and unpack it if not done yet
102
if [ ! -d "${LLVM_SOURCES_DIR}" ]; then
143
if [ ! -d "${LLVM_SOURCES_DIR}" ]; then
103
        if [ ! -f "${CURRENT_DIR}/${LLVM_SOURCES_FILE}" ]; then
144
        if [ ! -f "${CURRENT_DIR}/${LLVM_SOURCES_FILE}" ]; then
104
                echo "Downloading LLVM ${LLVM_VERSION} sources from LLVM GitHub..."
145
                echo "Downloading LLVM ${LLVM_VERSION} sources from LLVM GitHub..."
Line 162... Line 203...
162
SET(CMAKE_RANLIB "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ranlib")
203
SET(CMAKE_RANLIB "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ranlib")
163
 
204
 
164
SET(CMAKE_NM "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-nm")
205
SET(CMAKE_NM "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-nm")
165
 
206
 
166
SET(CMAKE_AR "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ar")
207
SET(CMAKE_AR "${QNX_HOST}/usr/bin/'${TARGET_TRIPLE}'-ar")
167
 
208
 
168
SET(CMAKE_FIND_ROOT_PATH "${QNX_TARGET}")
209
SET(CMAKE_FIND_ROOT_PATH "${QNX_TARGET}")
169
SET(CMAKE_FIND_ROOT_PATH_HOST_PROGRAM NEVER)
210
SET(CMAKE_FIND_ROOT_PATH_HOST_PROGRAM NEVER)
170
SET(CMAKE_FIND_ROOT_PATH_HOST_LIBRARY ONLY)
211
SET(CMAKE_FIND_ROOT_PATH_HOST_LIBRARY ONLY)
171
SET(CMAKE_FIND_ROOT_PATH_HOST_INCLUDE ONLY)
212
SET(CMAKE_FIND_ROOT_PATH_HOST_INCLUDE ONLY)
172
' > "${TARGET_TRIPLE}.cmake"
213
' > "${TARGET_TRIPLE}.cmake"
Line 178... Line 219...
178
        # test if already patched
219
        # test if already patched
179
        grep -q "${2}" "../${LLVM_SOURCES_DIR}/${1}" && return
220
        grep -q "${2}" "../${LLVM_SOURCES_DIR}/${1}" && return
180
        # tell what we're about to do
221
        # tell what we're about to do
181
        echo "Patching ${1}..."
222
        echo "Patching ${1}..."
182
        # have a backup first
223
        # have a backup first
183
        test -f "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ORIGINAL]" || cp "../${LLVM_SOURCES_DIR}/${1}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ORIGINAL]"
224
        test -f "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ORIGINAL]" || cp "../${LLVM_SOURCES_DIR}/${1}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ORIGINAL]" || exit 1
184
        # perform the patch
225
        # perform the patch
185
        sed -E "${3}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ORIGINAL]" > "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [PATCHED]"
226
        sed -E "${3}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ORIGINAL]" > "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [PATCHED]"
186
        # verify that we did it successfully
227
        # verify that we did it successfully
187
        if ! grep -q "${2}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [PATCHED]"; then
228
        if ! grep -q "${2}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [PATCHED]"; then
188
                echo "Error: the file ${1} could not be patched. Please investigate and fix manually." | fold -s -w 79; exit 1
229
                echo "Error: the file ${1} could not be patched. Please investigate and fix manually." | fold -s -w 79; exit 1
Line 230... Line 271...
230
# RATIONALE: the pthreads implementation in QNX 'steals' things from the POSIX.1 standard and hides them behind the __EXT_QNX macro,
271
# RATIONALE: the pthreads implementation in QNX 'steals' things from the POSIX.1 standard and hides them behind the __EXT_QNX macro,
231
# which is defined when either _QNX_SOURCE or __EXT without anything else is defined. This is not correct and low-level libraries
272
# which is defined when either _QNX_SOURCE or __EXT without anything else is defined. This is not correct and low-level libraries
232
# 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
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
233
# platform SDK: /usr/include/link.h, which defines Elf types as Elf64/Elf32 types depending on the architecture and adds some glue.
274
# platform SDK: /usr/include/link.h, which defines Elf types as Elf64/Elf32 types depending on the architecture and adds some glue.
234
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'
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'
235
 
283
 
236
# now configure LLVM -- and use ccache
284
# now configure LLVM -- and use ccache
237
echo "Configuring LLVM build..."
285
echo "Configuring LLVM build..."
238
export CCACHE_DIR="$(realpath "../${LLVM_SOURCES_DIR}/.ccache")"
286
export CCACHE_DIR="$(realpath "../${LLVM_SOURCES_DIR}/.ccache")"
239
cmake \
287
cmake \