-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathbuild_flang-classic.sh
More file actions
executable file
·164 lines (142 loc) · 5.42 KB
/
Copy pathbuild_flang-classic.sh
File metadata and controls
executable file
·164 lines (142 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
#
#Copyright © Advanced Micro Devices, Inc., or its affiliates.
#
#SPDX-License-Identifier: MIT
#
# build_flang-classic.sh: Script to build the flang-classic binary driver
# This driver will never call flang -fc1, it only calls binaries
# clang, flang1, flang2, build elsewhere
# Instead of downloading the ROCm 5.5 llvm package we have to
# compile the 11vm/clang libs from source to support various
# operating systems and spack. This will be the llvm-classic build step.
# These libs/headers are not installed and will picked up from the build
# tree for flang-classic.
#
BUILD_TYPE=${BUILD_TYPE:-Release}
# --- Start standard header to set AOMP environment variables ----
realpath=$(realpath "$0")
thisdir=$(dirname "$realpath")
. "$thisdir/aomp_common_vars"
# --- end standard header ----
if [ "$AOMP_BUILD_FLANG_CLASSIC" == 0 ] ; then
if [ "$1" != "install" ] ; then
echo "WARNING: ROCM install for $AOMP_FLANG_CLASSIC_REL/llvm-classic not found."
echo " This build will skip build of flang-classic."
echo " The flang will link to the clang driver."
fi
exit
fi
if [ "$AOMP_USE_NINJA" == 0 ] ; then
AOMP_SET_NINJA_GEN=()
else
AOMP_SET_NINJA_GEN=(-G Ninja)
fi
osversion=$(grep -e ^VERSION_ID < /etc/os-release)
if [[ $osversion =~ \"7\. ]] || [[ $osversion =~ \"8\. ]]; then
_cxx_flag=(-DCMAKE_CXX_FLAGS='-D_GLIBCXX_USE_CXX11_ABI=0')
else
_cxx_flag=()
fi
# We need a version of ROCM llvm that supports flang-classic
# via the link from flang to clang. rocm 5.5 would be best.
# This will enable removal of flang-classic driver support
# from clang to make way for flang
# Do not change the AOMP_LFL_DIR default because it is the subdirectory
# from where we build the flang-classic driver binary. This is the
# Last Frozen LLVM (LFL) for which there is amd-only clang driver support
# for flang. Originally there was no subdirectory for LFL so setting
# AOMP_LFL_DIR to "/" would build flang-classic with the original
# ROCm 5.6 sources.
AOMP_LFL_DIR=${AOMP_LFL_DIR:-"17.0-4"}
# comment out above line and uncomment next line for new LFL
#AOMP_LFL_DIR=${AOMP_LFL_DIR:-17.0-4}
declare -a MYCMAKEOPTS
MYCMAKEOPTS=(-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
-DCMAKE_C_COMPILER="$LLVM_INSTALL_LOC/bin/clang"
-DCMAKE_CXX_COMPILER="$LLVM_INSTALL_LOC/bin/clang++"
"${_cxx_flag[@]}"
-DCMAKE_CXX_STANDARD=17
-DCMAKE_INSTALL_PREFIX="$LLVM_INSTALL_LOC"
"${AOMP_SET_NINJA_GEN[@]}")
if [ "$AOMP_STANDALONE_BUILD" == 1 ] ; then
MYCMAKEOPTS=("${MYCMAKEOPTS[@]}" -DBUILD_SHARED_LIBS=ON
"${AOMP_ORIGIN_RPATH[@]}")
else
MYCMAKEOPTS=("${MYCMAKEOPTS[@]}" -DBUILD_SHARED_LIBS=OFF
"${OPENMP_EXTRAS_ORIGIN_RPATH[@]}")
fi
if [ "$1" == "-h" ] || [ "$1" == "help" ] || [ "$1" == "-help" ] ; then
help_build_aomp
fi
if [ "$AOMP_STANDALONE_BUILD" == 1 ] ; then
if [ ! -L "$AOMP" ] && [ -d "$AOMP" ] ; then
echo "ERROR: Directory $AOMP is a physical directory."
echo " It must be a symbolic link or not exist"
exit 1
fi
fi
check_writable_installdir "$1" "$AOMP_INSTALL_DIR"
# Allow extglobs -- seems like this must be set before bash starts parsing
# the 'if' block below.
shopt -s extglob
if [ "$1" != "nocmake" ] && [ "$1" != "install" ] ; then
echo
echo "This is a FRESH START. ERASING any previous builds in $BUILD_DIR/build/flang-classic/$AOMP_LFL_DIR"
echo "Use ""$0 nocmake"" or ""$0 install"" to avoid FRESH START."
if [ -d "$BUILD_DIR/build/flang-classic/$AOMP_LFL_DIR" ]; then
# This needs extglob enabled, as set above.
rm -rf "$BUILD_DIR/build/flang-classic/$AOMP_LFL_DIR"/!("llvm-classic")
else
echo "ERROR: Build llvm-classic before flang-classic."
exit 1
fi
else
if [ ! -d "$BUILD_DIR/build/flang-classic/$AOMP_LFL_DIR" ] ; then
echo "ERROR: The build directory $BUILD_DIR/build/flang-classic/$AOMP_LFL_DIR does not exist"
echo " run $0 without nocmake or install options. "
exit 1
fi
fi
echo
# Cmake flang-classic.
if [ "$1" != "nocmake" ] && [ "$1" != "install" ] ; then
cd "$BUILD_DIR/build/flang-classic/$AOMP_LFL_DIR" || exit
echo " -----Running cmake ---- "
echo "${AOMP_CMAKE}" "$(shquot "${MYCMAKEOPTS[@]}")" "$AOMP_REPOS/$AOMP_FLANG_REPO_NAME/flang-classic/$AOMP_LFL_DIR"
if ! ${AOMP_CMAKE} "${MYCMAKEOPTS[@]}" "$AOMP_REPOS/$AOMP_FLANG_REPO_NAME/flang-classic/$AOMP_LFL_DIR" 2>&1; then
echo "ERROR cmake failed. Cmake flags"
echo " $(shquot "${MYCMAKEOPTS[@]}")"
exit 1
fi
fi
if [ "$1" = "cmake" ]; then
exit 0
fi
echo
# Build flang-classic.
echo " --- Running $AOMP_NINJA_BIN for $BUILD_DIR/build/flang-classic/$AOMP_LFL_DIR ---- "
cd "$BUILD_DIR/build/flang-classic/$AOMP_LFL_DIR" || exit
if ! $AOMP_NINJA_BIN -j "$AOMP_JOB_THREADS"; then
echo " "
echo "ERROR: $AOMP_NINJA_BIN -j $AOMP_JOB_THREADS FAILED"
echo "To restart:"
echo " cd $BUILD_DIR/build/flang-classic/$AOMP_LFL_DIR"
echo " $AOMP_NINJA_BIN"
exit 1
fi
if [ "$1" == "install" ] ; then
echo " -----Installing to $AOMP_INSTALL_DIR ---- "
if ! $SUDO "${AOMP_CMAKE}" --build . -j "$AOMP_JOB_THREADS" --target install; then
echo "ERROR make install failed "
exit 1
fi
echo
echo "SUCCESSFUL INSTALL to $AOMP_INSTALL_DIR"
echo
else
echo
echo "SUCCESSFUL BUILD, please run: $0 install"
echo " to install into $AOMP"
echo
fi