forked from qbit/rust-cross-openbsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstage1-openbsd.sh
executable file
·159 lines (131 loc) · 4.21 KB
/
stage1-openbsd.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
#!/bin/sh
if [ `uname -s` != "OpenBSD" ]; then
echo "You have to run this on OpenBSD!"
exit 1
fi
mkdir -p stage1-openbsd
cd stage1-openbsd
TOP=`pwd`
AUTOMAKE_VERSION=1.14
BINUTILS_VERSION=2.23.2
TARGET_SUB=libs
TARGET=${TOP}/${TARGET_SUB}
ARCH=`machine -a`
RUSTARCH=${ARCH}
if [ "${ARCH}" -eq "amd64" ]; then
RUSTARCH="x86_64"
fi
export AS="/usr/local/bin/egcc-as"
#export AS="/usr/local/bin/nasm"
#export LD="/usr/local/bin/egcc-ld"
export CC="/usr/local/bin/egcc"
export CXX="/usr/local/bin/eg++"
export LDFLAGS="-L/usr/local/lib"
export CFLAGS="-I/usr/local/include"
export CXXFLAGS="-I/usr/local/include/c++/4.8.3/"
#export AR="/usr/local/bin/egcc-ar"
#export NM="/usr/local/bin/egcc-nm"
#export RANLIB="/usr/local/bin/egcc-ranlib"
LLVM_TARGET="/usr/local"
mkdir -p ${TARGET}
echo "-- TOP: ${TOP}"
echo "-- TARGET: ${TARGET}"
echo "-- LLVM_TARGET: ${LLVM_TARGET}"
echo "-- ARCH: ${ARCH}"
echo "-- RUSTARCH: ${RUSTARCH}"
if [ ! -e binutils-${BINUTILS_VERSION} ]; then
curl ftp://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.bz2 | tar -jxvf -
fi
cd binutils-${BINUTILS_VERSION}
./configure --enable-ld=no --prefix=${LLVM_TARGET} --program-prefix=egcc-
gmake VERBOSE=1
gmake VERBOSE=1 install
cd ${TOP}
if [ ! -e rust ]; then
git clone https://github.com/rust-lang/rust.git
fi
cd rust
git submodule init
git submodule update
if [ ! -e .patched ]; then
patch -p1 < ${TOP}/../patch-rust
date > .patched
else
echo "Rust already patched on:" `cat .patched`
fi
cd src/jemalloc
if [ ! -e .patched ]; then
patch -p1 < ${TOP}/../patch-jemalloc
date > .patched
else
echo "jemalloc already patched on:" `cat .patched`
fi
cd ../llvm
if [ ! -e .patched ]; then
patch -p1 < ${TOP}/../patch-llvm
date > .patched
else
echo "LLVM already patched on:" `cat .patched`
fi
cd ..
mkdir -p llvm-build
cd llvm-build
../llvm/configure --prefix=${LLVM_TARGET} #--disable-compiler-version-checks
gmake VERBOSE=1 ENABLE_OPTIMIZED=1
gmake VERBOSE=1 ENABLE_OPTIMIZED=1 install
mkdir -p ${TARGET}/llvm
cp `${LLVM_TARGET}/bin/llvm-config --libfiles` ${TARGET}/llvm
cd ${TOP}/rust/src/rustllvm
${CXX} -c `${LLVM_TARGET}/bin/llvm-config --cxxflags` PassWrapper.cpp
${CXX} -c `${LLVM_TARGET}/bin/llvm-config --cxxflags` RustWrapper.cpp
ar rcs librustllvm.a PassWrapper.o RustWrapper.o
cp librustllvm.a ${TARGET}
# build libcompiler-rt.a
cd ${TOP}/rust/src/compiler-rt
cmake -DLLVM_CONFIG_PATH=${LLVM_TARGET}/bin/llvm-config
gmake VERBOSE=1
cp ./lib/openbsd/libclang_rt.${ARCH}.a ${TARGET}/libcompiler-rt.a
cd ${TOP}/rust/src
ln -s libbacktrace include
cd libbacktrace
./configure
gmake VERBOSE=1
cp .libs/libbacktrace.a ${TARGET}
cd ..
rm -rf include
set -x
cd ${TOP}/rust/src/rt
${LLVM_TARGET}/bin/llc rust_try.ll
#${CC} -c -o rust_try.o rust_try.s
#${CC} -c -o record_sp.o arch/${RUSTARCH}/record_sp.S
${AS} -o rust_try.o rust_try.s
${AS} -o record_sp.o arch/${RUSTARCH}/record_sp.S
ar rcs ${TARGET}/librustrt_native.a rust_try.o record_sp.o
cd ${TOP}/rust/src/rt
${CC} -c -o context.o arch/${RUSTARCH}/_context.S
#${AS} -o context.o arch/${RUSTARCH}/_context.S
ar rcs ${TARGET}/libcontext_switch.a context.o
cd ${TOP}/rust/src/rt
${CC} -c -o rust_builtin.o rust_builtin.c
ar rcs ${TARGET}/librust_builtin.a rust_builtin.o
cd ${TOP}/rust/src/rt
${CC} -c -o morestack.o arch/${RUSTARCH}/morestack.S
#${AS} -o morestack.o arch/${RUSTARCH}/morestack.S
ar rcs ${TARGET}/libmorestack.a morestack.o
cd ${TOP}/rust/src/rt
${CC} -c -o miniz.o miniz.c
ar rcs ${TARGET}/libminiz.a miniz.o
set +x
cd ${TOP}/rust/src/rt/hoedown
gmake VERBOSE=1 libhoedown.a
cp libhoedown.a ${TARGET}
# Copy Openbsd system libraries
mkdir -p ${TARGET}/usr/lib
cp -r /usr/lib ${TARGET}/usr/lib
#
cd ${TOP}/..
#python ${TOP}/rust/src/etc/mklldeps.py stage1-openbsd/llvmdeps.rs "x86 arm mips ipo bitreader bitwriter linker asmparser jit mcjit interpreter instrumentation" true "${LLVM_TARGET}/bin/llvm-config"
python ${TOP}/rust/src/etc/mklldeps.py stage1-openbsd/llvmdeps.rs "x86 arm mips ipo bitreader bitwriter linker asmparser mcjit interpreter instrumentation" true "${LLVM_TARGET}/bin/llvm-config"
cd ${TOP}/..
tar cvzf stage1-openbsd.tgz stage1-openbsd/${TARGET_SUB} stage1-openbsd/llvmdeps.rs
echo "Please copy stage1-openbsd.tgz onto your Linux machine and extract it"