-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-llvm.sh
executable file
·165 lines (150 loc) · 4.15 KB
/
build-llvm.sh
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
#!/bin/sh
#
# COPYRIGHT (c) 2023 The Fellowship of SML/NJ (http://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)
# -ninja -- generate build.ninja files (instead of Unix makefiles)
#
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 targets"
echo " 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 " -ninja generate build.ninja files (instead of Unix makefiles)"
exit $1
}
LLVM_BUILD_TYPE=Release
USE_GOLD_LD=no
NPROCS=2
GENERATOR="Unix Makefiles"
# the install location should be specified as the environment variable RUNTIMEDIR
#
if [ x"$SMLNJ_ROOT" != x ] ; then
INSTALL_PREFIX="$SMLNJ_ROOT/runtime"
else
INSTALL_PREFIX=..
fi
# 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" ;;
*) 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
;;
-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 llvm --list-presets > /dev/null 2>&1
if [ $? != 0 ] ; then
echo "Installation of SML/NJ requires CMake version 3.19 or later"
exit 1
fi
# most of the definitions are specified in the CMakePresets.json file
#
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
# 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
echo "build-llvm.sh: configuring build"
echo " cmake --preset=$PRESET -G \"$GENERATOR\" $CMAKE_DEFS ../src"
cmake --preset=$PRESET -G "$GENERATOR" $CMAKE_DEFS ../llvm || exit 1
echo "build-llvm.sh: building on $NPROCS cores"
echo " cmake --build . -j $NPROCS -t install"
time cmake --build . -j $NPROCS -t install
# if requested, build the CFG compiler
#
if [ x"$BUILD_CFGC" = xYES ] ; then
cd ../cfgc/src
make install
fi