-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild-llvm.sh
More file actions
executable file
·216 lines (195 loc) · 5.67 KB
/
build-llvm.sh
File metadata and controls
executable file
·216 lines (195 loc) · 5.67 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/sh
#
# COPYRIGHT (c) 2024 The Fellowship of SML/NJ (https://www.smlnj.org)
# All rights reserved.
#
# This script handles building the LLVM code generator library as part
# of the SML/NJ installation process. It will use available parallelism
# and normally builds a code generator that supports just a single target.
#
# usage: build-llvm.sh [options]
#
# options:
# -h | -help -- print help message
# -all-targets -- build a version of LLVM that supports all hardware targets
# that are known to SML/NJ
# -build-cfgc -- build the cfgc (CFG compiler) tool
# -debug -- build a debug release of LLVM (WARNING: debug releases take
# much longer to build and are signficantly slower than the
# default release builds)
# -sanitize-address
# -- sanitize addresses to check for memory bugs
# -docs -- build LLVM API documentation
# -config -- configure, but do not compile
# -install <dir> -- specify installation directory; default is this directory
# -ninja -- generate build.ninja files (instead of Unix makefiles)
#
# get location of this script as an absolute path
#
CMDDIR=`dirname "$0"`
LLVMDIR=$(cd $CMDDIR; pwd)
usage() {
echo "usage: build-llvm.sh [ options ]"
echo "options:"
echo " -h, -help print this message and exit"
echo " -all-targets build a version of LLVM that supports all hardware"
echo " targets that are known to SML/NJ"
echo " -build-cfgc build the cfgc (CFG compiler) tool."
echo " -debug build a debug version of the LLVM libraries"
echo " -sanitize-address sanitize addresses to check for memory bugs"
echo " -docs build LLVM API documentation"
echo " -config configure, but do not compile"
echo " -install <dir> specify installation directory (default: $CMDDIR)"
echo " -ninja generate build.ninja files (instead of Unix makefiles)"
exit $1
}
CONFIG_ONLY=no
LLVM_BUILD_TYPE=Release
USE_GOLD_LD=no
SANITIZE_ADDRESS=no
NPROCS=2
GENERATOR="make"
# default place to put the headers, libraries, and tools.
# we expect this to be overridden when building LLVM as part
# of the SML/NJ system
#
INSTALL_PREFIX="$LLVMDIR"
# system specific defaults
#
case `uname -s` in
Darwin)
case `uname -p` in
arm) # on arm processors, we only use the performance cores
NPROCS=$(sysctl -n hw.perflevel0.physicalcpu)
;;
*) # otherwise use the physical core count
NPROCS=$(sysctl -n hw.physicalcpu)
;;
esac
;;
Linux)
USE_GOLD_LD=yes
if [ -x /bin/nproc ] ; then
# NPROCS reports the number of hardware threads, which is usually twice the
# number of actual cores, so we will divide by two.
NPROCS=$(/bin/nproc --all)
if [ $NPROCS -gt 4 ] ; then
NPROCS=$(($NPROCS / 2))
fi
fi
;;
*)
echo "build-llvm.sh: unsupported system"
exit 1
;;
esac
ALL_TARGETS="AArch64;X86"
case $(uname -m) in
x86_64) TARGETS="X86" ;;
arm64) TARGETS="AArch64" ;;
aarch64) TARGETS="AArch64" ;;
*) echo "unknown hardware platform"
exit 1
;;
esac
# process command-line arguments
#
BUILD_CFGC=no
while [ "$#" != "0" ] ; do
arg=$1; shift
case $arg in
-h|-help)
usage 0
;;
-all-targets)
TARGETS=$ALL_TARGETS
;;
-build-cfgc)
BUILD_CFGC=yes
;;
-debug)
LLVM_BUILD_TYPE=Debug
;;
-sanitize-address)
SANITIZE_ADDRESS=yes
;;
-docs)
BUILD_DOCS=yes
;;
-config)
CONFIG_ONLY=yes
;;
-install)
if [ "$#" != "0" ] ; then
INSTALL_PREFIX=$1; shift
else
echo "build-llvm.sh: missing installation path"
usage 1
fi
;;
-ninja)
GENERATOR="ninja"
;;
*)
echo "build-llvm.sh: invalid option '$arg'"
usage 1
;;
esac
done
if [ $LLVM_BUILD_TYPE = "Debug" ] ; then
PRESET=smlnj-llvm-debug
else
PRESET=smlnj-llvm-release
fi
# check that we have a version of CMake that understands presets
#
cmake --list-presets > /dev/null 2>&1
if [ $? != 0 ] ; then
echo "Installation of SML/NJ requires CMake version 3.23 or later"
exit 1
fi
# most of the definitions are specified in the CMakePresets.json file,
# but we define a few here based on the command-line options
#
CMAKE_DEFS="\
-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
-DLLVM_TARGETS_TO_BUILD=$TARGETS \
-DLLVM_ENABLE_DUMP=ON \
"
if [ x"$USE_GOLD_LD" = xyes ] ; then
CMAKE_DEFS="$CMAKE_DEFS -DLLVM_USE_LINKER=gold"
fi
if [ x"$SANITIZE_ADDRESS" = xyes ] ; then
CMAKE_DEFS="$CMAKE_DEFS -DLLVM_USE_SANITIZER=Address"
fi
if [ x"$BUILD_DOCS" = xyes ] ; then
CMAKE_DEFS="$CMAKE_DEFS -DLLVM_BUILD_DOCS=ON -DLLVM_INCLUDE_DOCS=ON -DLLVM_ENABLE_DOXYGEN=ON"
fi
if [ x"$BUILD_CFGC" = xyes ] ; then
CMAKE_DEFS="$CMAKE_DEFS -DSMLNJ_CFGC_BUILD=ON"
fi
# remove the build directory if it exists
#
if [ -d build ] ; then
echo "$0: removing existing build etc. directories"
rm -rf build bin lib include
fi
echo "build-llvm.sh: mkdir build"
mkdir build
cd build
if [ x"$GENERATOR" = xmake ] ; then
CMAKE_GENERATOR="Unix Makefiles"
elif [ x"$GENERATOR" = xninja ] ; then
CMAKE_GENERATOR="Ninja"
else
# default
CMAKE_GENERATOR="Unix Makefiles"
fi
echo "build-llvm.sh: configuring build"
echo " cmake --preset=$PRESET -G \"$CMAKE_GENERATOR\" $CMAKE_DEFS .."
cmake --preset=$PRESET -G "$CMAKE_GENERATOR" $CMAKE_DEFS .. || exit 1
if [ x"$CONFIG_ONLY" = xno ] ; then
echo "build-llvm.sh: building LLVM on $NPROCS cores"
echo " $GENERATOR -j $NPROCS install"
$GENERATOR -j $NPROCS install
fi