This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-runtime.sh
executable file
·174 lines (145 loc) · 5.4 KB
/
make-runtime.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
166
167
168
169
170
171
172
173
174
#!/bin/bash
# Makes a new runtime
set -e
TOP=$(dirname "$0")
COLOR_RED="\e[91m"
COLOR_GREEN="\e[92m"
COLOR_DEFAULT="\e[39m"
function fatal-error
{
echo -e "$COLOR_RED$1$COLOR_DEFAULT"
exit 1
}
[ $EUID -ne 0 ] && fatal-error "Script must be run as root"
# Check for dpkg and debootstrap
[ -z $(which debootstrap) ] && fatal-error "Debootstrap not installed; please install it to continue"
[ -z $(which dpkg) ] && fatal-error "dpkg not installed, you can only run this script from a debian-based machine (Debian, Ubuntu, Linux Mint, etc.)"
[ -z $(which dpkg-deb) ] && fatal-error "dpkg-deb not installed; please install it to continue"
# cd to our directory
pushd $TOP
function make-runtime
{
for arg in "$@"; do
case $arg in
--arch=*)
ARCH=$(echo $arg | sed "s/--arch=//")
shift
;;
--packages=*)
PACKAGES_FILE=$(echo $arg | sed "s/--packages=//")
shift
;;
--gcc-version=*)
GCC_VER=$(echo $arg | sed "s/--gcc-version=//")
shift
;;
--clang-version=*)
CLANG_VER=$(echo $arg | sed "s/--clang-version=//")
shift
;;
*)
fatal-error "Unknown arg"
;;
esac
done
case $ARCH in
i386)
PLATLIB="i386-linux-gnu"
ARCHC="I386"
;;
amd64)
PLATLIB="x86_64-linux-gnu"
ARCHC="AMD64"
;;
arm64)
PLATLIB=""
ARCHC="AARCH64"
;;
*)
fatal-error "invalid arch, please choose from: i386,amd64,arm64"
;;
esac
# Delete old temp
[ -d "$TOP/temp" ] && rm -rf "$TOP/temp"
# Delete old runtime dir
[ -d "$TOP/quiver-runtime-$ARCH" ] && rm -rf "$TOP/quiver-runtime-$ARCH"
[ -z $PACKAGES_FILE ] && PACKAGES_FILE="packages.txt"
for package in $(cat "$PACKAGES_FILE" | tr '\n', ' '); do
PACKAGES="${PACKAGES},$package"
done
PACKAGES="${PACKAGES},gcc-$GCC_VER,g++-$GCC_VER,clang-$CLANG_VER,llvm-$CLANG_VER"
if [ -d "$TOP/quiver-runtime-$ARCH" ]; then
echo "quiver-runtime exists, deleting..."
rm -rf "$TOP/quiver-runtime-$ARCH"
fi
debootstrap --arch=$ARCH --download-only --include=$PACKAGES sid "$TOP/temp/"
for pkg in $(ls "$TOP/temp/var/cache/apt/archives/" -p | grep -v /); do
echo "unpacking $pkg"
dpkg-deb -x "$TOP/temp/var/cache/apt/archives/$pkg" "$TOP/quiver-runtime-$ARCH"
done
# Removed things we dont need
rm -rf "$TOP/quiver-runtime-$ARCH/sys"
rm -rf "$TOP/quiver-runtime-$ARCH/root"
rm -rf "$TOP/quiver-runtime-$ARCH/proc"
rm -rf "$TOP/quiver-runtime-$ARCH/home"
rm -rf "$TOP/quiver-runtime-$ARCH/dev"
rm -rf "$TOP/quiver-runtime-$ARCH/run"
rm -rf "$TOP/quiver-runtime-$ARCH/boot"
rm -rf "$TOP/quiver-runtime-$ARCH/tmp"
rm -rf "$TOP/quiver-runtime-$ARCH/bin"
rm -rf "$TOP/quiver-runtime-$ARCH/sbin"
mkdir -p "$TOP/quiver-runtime-$ARCH/bin"
# Symlinks to certain applications
ln -s "$TOP/quiver-runtime-$ARCH/usr/bin/gcc-$GCC_VER" "$TOP/quiver-runtime-$ARCH/usr/bin/gcc"
ln -s "$TOP/quiver-runtime-$ARCH/usr/bin/g++-$GCC_VER" "$TOP/quiver-runtime-$ARCH/usr/bin/g++"
ln -s "$TOP/quiver-runtime-$ARCH/usr/bin/clang-$CLANG_VER" "$TOP/quiver-runtime-$ARCH/usr/bin/clang"
ln -s "$TOP/quiver-runtime-$ARCH/usr/bin/clang++-$CLANG_VER" "$TOP/quiver-runtime-$ARCH/usr/bin/clang++"
# Copy in the template shell scripts for our toolchain
EXTRA_LIB_DIRS="-L\$QUIVER_RUNTIME_$ARCHC/lib/ -L\$QUIVER_RUNTIME_$ARCHC/lib/$PLAT_LIB -L\$QUIVER_RUNTIME_$ARCHC/lib/ -L\$QUIVER_RUNTIME_$ARCHC/lib/$PLAT_LIB"
EXTRA_INC_DIRS="-I\$QUIVER_RUNTIME_$ARCHC/usr/include"
echo -e "#!/bin/bash\nshift;\n\$QUIVER_RUNTIME_$ARCHC/usr/bin/gcc-$GCC_VER $EXTRA_LIB_DIRS $EXTRA_INC_DIRS \$@\n" > "$TOP/quiver-runtime-$ARCH/bin/gcc"
chmod +rwx "$TOP/quiver-runtime-$ARCH/bin/gcc"
echo -e "#!/bin/bash\nshift;\n\$QUIVER_RUNTIME_$ARCHC/usr/bin/g++-$GCC_VER $EXTRA_LIB_DIRS $EXTRA_INC_DIRS \$@\n" > "$TOP/quiver-runtime-$ARCH/bin/g++"
chmod +rwx "$TOP/quiver-runtime-$ARCH/bin/g++"
echo -e "#!/bin/bash\nshift;\n\$QUIVER_RUNTIME_$ARCHC/usr/bin/clang-$CLANG_VER $EXTRA_LIB_DIRS $EXTRA_INC_DIRS \$@\n" > "$TOP/quiver-runtime-$ARCH/bin/clang"
chmod +rwx "$TOP/quiver-runtime-$ARCH/bin/clang"
echo -e "#!/bin/bash\nshift;\n\$QUIVER_RUNTIME_$ARCHC/usr/bin/clang++-$CLANG_VER $EXTRA_LIB_DIRS $EXTRA_INC_DIRS \$@\n" > "$TOP/quiver-runtime-$ARCH/bin/clang++"
chmod +rwx "$TOP/quiver-runtime-$ARCH/bin/clang++"
# Assemblers
echo -e "#!/bin/bash\nshift;\n\$QUIVER_RUNTIME_$ARCHC/usr/bin/nasm $EXTRA_INC_DIRS \$@\n" > "$TOP/quiver-runtime-$ARCH/bin/nasm"
chmod +rwx "$TOP/quiver-runtime-$ARCH/bin/nasm"
make_app_link "cmake"
make_app_link "perl"
make_app_link "ar"
make_app_link "tar"
make_app_link "gzip"
make_app_link "gunzip"
make_app_link "strip"
make_app_link "objdump"
make_app_link "nm"
make_app_link "objcopy"
make_app_link "make"
make_app_link "gcov"
make_app_link "ranlib"
make_app_link "readelf"
make_app_link "llc-$CLANG_VER"
make_app_link "llvm-link-$CLANG_VER"
make_app_link "llvm-objcopy-$CLANG_VER"
make_app_link "llvm-objdump-$CLANG_VER"
make_app_link "llvm-nm-$CLANG_VER"
make_app_link "llvm-strip-$CLANG_VER"
make_app_link "llvm-ar-$CLANG_VER"
make_app_link "llvm-readelf-$CLANG_VER"
# Throw it into an archive
echo "Packing into quiver-runtime-$ARCH.tgz"
tar -czf "$TOP/quiver-runtime-$ARCH.tgz" "$TOP/quiver-runtime-$ARCH/"
rm -rf "$TOP/quiver-runtime-$ARCH"
}
function make_app_link
{
ln -s "$TOP/quiver-runtime-$ARCH/usr/bin/$1" "$TOP/quiver-runtime-$ARCH/bin/$1"
}
make-runtime --arch=i386 --packages=packages.txt --gcc-version=9 --clang-version=8
make-runtime --arch=amd64 --packages=packages.txt
#make-runtime --arch=arm64 --packages=packages-arm.txt
popd