forked from flang-compiler/flang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-flang.sh
executable file
·88 lines (78 loc) · 2.3 KB
/
build-flang.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
#!/bin/bash
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize our own variables:
TARGET="X86"
INSTALL_PREFIX="/usr/local"
NPROC=1
USE_CCACHE="0"
USE_SUDO="0"
set -e # Exit the script on first error.
function print_usage {
echo "Usage: ./build-flang.sh [options]";
echo "";
echo "Build and install libpgmath and flang.";
echo "Run this script in a directory with flang sources.";
echo "Example:";
echo " $ git clone https://github.com/flang-compiler/flang";
echo " $ cd flang";
echo " $ .github/workflows/build-flang.sh -t X86 -p /install/prefix/ -n 2 -s";
echo "";
echo "Options:";
echo " -t Target to build for (X86, AArch64, PowerPC). Default: X86";
echo " -p Install prefix. Default: /usr/local";
echo " -n Number of parallel jobs. Default: 1";
echo " -c Use ccache. Default: 0 - do not use ccache";
echo " -s Use sudo to install. Default: 0 - do not use sudo";
}
while getopts "t:p:n:c?s?" opt; do
case "$opt" in
t) TARGET=$OPTARG;;
p) INSTALL_PREFIX=$OPTARG;;
n) NPROC=$OPTARG;;
c) USE_CCACHE="1";;
s) USE_SUDO="1";;
?) print_usage; exit 0;;
esac
done
CMAKE_OPTIONS="-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER=$INSTALL_PREFIX/bin/clang++ \
-DCMAKE_C_COMPILER=$INSTALL_PREFIX/bin/clang \
-DLLVM_TARGETS_TO_BUILD=$TARGET"
if [ $USE_CCACHE == "1" ]; then
echo "Build using ccache"
CMAKE_OPTIONS="$CMAKE_OPTIONS \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
fi
# Build and install libpgmath
cd runtime/libpgmath
mkdir -p build && cd build
cmake $CMAKE_OPTIONS ..
make -j$NPROC
if [ $USE_SUDO == "1" ]; then
echo "Install with sudo"
sudo make install
else
echo "Install without sudo"
make install
fi
cd ../../..
# Build and install flang
mkdir -p build && cd build
cmake $CMAKE_OPTIONS \
-DCMAKE_Fortran_COMPILER=$INSTALL_PREFIX/bin/flang \
-DCMAKE_Fortran_COMPILER_ID=Flang \
-DFLANG_INCLUDE_DOCS=ON \
-DFLANG_LLVM_EXTENSIONS=ON \
-DWITH_WERROR=ON \
..
make -j$NPROC
if [ $USE_SUDO == "1" ]; then
echo "Install with sudo"
sudo make install
else
echo "Install without sudo"
make install
fi