llvm_installer.sh 3.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
#!/bin/bash

VERSION="9.0.0"

URL="http://releases.llvm.org"
 
WGET=wget

CURRENT_DIR=`pwd`
INSTALL_DIR=`pwd`/install
Akash Kothari's avatar
Akash Kothari committed
11
BUILD_DIR=$CURRENT_DIR/build
12
13
14
15
16
17
18
19
20
21

# Using 2 threads by default
NUM_THREADS=2

SUFFIX=".tar.xz"
CLANG_SRC="cfe-$VERSION.src"
LLVM_SRC="llvm-$VERSION.src"
LIBCXX_SRC="libcxx-$VERSION.src"
LIBCXXABI_SRC="libcxxabi-$VERSION.src"

22
HPVM_RT=hpvm-rt/hpvm-rt.bc
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

AUTOMATE="y"

read -p "Build and install HPVM automatically? (y or n): " AUTOMATE   

if [ ! $AUTOMATE == "y" ] && [ ! $AUTOMATE == "n" ]; then 
  echo invalid input!
  exit -1
fi

echo
read -p "Number of threads: " NUM_THREADS

if [ ! $NUM_THREADS -gt 0 ]; then
  NUM_THREADS = 2
  echo
  echo Using $NUM_THREADS threads by default.   
  echo
fi


if [ -d $LLVM_SRC ]; then
    echo Found $LLVM_SRC!
elif [ -d llvm ]; then
    echo Found llvm, not downloading $LLVM_SRC!
else
    echo $WGET $URL/$VERSION/$LLVM_SRC$SUFFIX
    $WGET $URL/$VERSION/$LLVM_SRC$SUFFIX
    tar xf $LLVM_SRC$SUFFIX
    rm $LLVM_SRC$SUFFIX
fi

if [ -d $LLVM_SRC ]; then
    echo Everything looks sane.
    mv $LLVM_SRC llvm
elif [ -d llvm ]; then
    echo Everything looks sane.
else
    echo Install had problems. Quitting.
    exit
fi

LLVM_SRC=llvm

if [ -d $CURRENT_DIR/$LLVM_SRC/tools ]; then
    cd $CURRENT_DIR/$LLVM_SRC/tools
    echo In tools.
else
    echo Fail! Something is wrong with your $LLVM_SRC checkout! 
    exit 1
fi

if [ -d clang ]; then
    echo Found clang! Not downloading clang again.
else
    $WGET $URL/$VERSION/$CLANG_SRC$SUFFIX
    tar xf $CLANG_SRC$SUFFIX
    rm $CLANG_SRC$SUFFIX
    mv $CLANG_SRC clang
    if [ -d clang ]; then
	echo Everything looks sane.
    else
	echo Install had problems. Quitting.
	exit
    fi
fi

cd $CURRENT_DIR

if [ -d $CURRENT_DIR/$LLVM_SRC/projects ]; then
    cd $CURRENT_DIR/$LLVM_SRC/projects
else
    echo Fail! Something is wrong wint $LLVM_SRC.
    exit 1
fi

if [ -d libcxx ]; then
    echo Found libcxx! Not downloading libcxx again.
else
    $WGET $URL/$VERSION/$LIBCXX_SRC$SUFFIX
    tar xf $LIBCXX_SRC$SUFFIX
    rm $LIBCXX_SRC$SUFFIX
    mv $LIBCXX_SRC libcxx
    if [ -d libcxx ]; then
	echo Everything looks sane.
    else
	echo Install had problems. Quitting.
	exit
    fi
fi

if [ $LIBCXXABI_SRC != "" ]; then
    if [ -d libcxxabi ]; then
	echo Found libcxxabi! Not downloading libcxx again.
    else
	$WGET $URL/$VERSION/$LIBCXXABI_SRC$SUFFIX
	tar xf $LIBCXXABI_SRC$SUFFIX
	rm $LIBCXXABI_SRC$SUFFIX
	mv $LIBCXXABI_SRC libcxxabi
	if [ -d libcxxabi ]; then
	    echo Everything looks sane.
	else
	    echo Install had problems. Quitting.
	    exit
	fi
    fi
fi

HPVM_DIR=$CURRENT_DIR/$LLVM_SRC/tools/hpvm

if [ ! -d $HPVM_DIR ]; then
  echo Adding HPVM sources to tree
  mkdir -p $HPVM_DIR
  ln -s $CURRENT_DIR/CMakeLists.txt $HPVM_DIR
  ln -s $CURRENT_DIR/include $HPVM_DIR/
  ln -s $CURRENT_DIR/lib $HPVM_DIR/
  ln -s $CURRENT_DIR/projects $HPVM_DIR/
  ln -s $CURRENT_DIR/test $HPVM_DIR/
else
  echo $CURRENT_DIR/$LLVM_SRC/tools/hpvm exists.
fi

export LLVM_SRC_ROOT=$CURRENT_DIR/$LLVM_SRC

echo Applying HPVM patches
cd $CURRENT_DIR/llvm_patches
/bin/bash ./construct_patch.sh
/bin/bash ./apply_patch.sh

echo Patches applied.

if [ ! $AUTOMATE == "y" ]; then
  echo
  echo HPVM not installed. Exiting. 
  exit  
fi

echo
echo Now building...

echo Using $NUM_THREADS threads to build HPVM.
echo

cd $CURRENT_DIR

if [ ! -d $BUILD_DIR ]; then
  mkdir -p $BUILD_DIR
fi

if [ ! -d $INSTALL_DIR ]; then
  mkdir -p $INSTALL_DIR
fi

cd $BUILD_DIR
echo cmake ../$LLVM_SRC -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DLLVM_TARGETS_TO_BUILD="X86"  -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR
cmake ../$LLVM_SRC -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DLLVM_TARGETS_TO_BUILD="X86"  -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR

echo make -j$NUM_THREADS
make -j$NUM_THREADS
#make install


185
if [ -f $BUILD_DIR/tools/hpvm/projects/$HPVM_RT ]; then
186
187
    true
else
188
    echo $BUILD_DIR/tools/hpvm/projects/$HPVM_RT
189
190
191
192
193
194
195
    echo HPVM not installed properly.
    exit 0
fi

cd $CURRENT_DIR