|
| 1 | +#!/bin/bash |
| 2 | +#set -x |
| 3 | + |
| 4 | +# thanks to Giacomo Rizzi: some ideas have been taken from: https://github.com/gufoe/vuos-tutorial |
| 5 | + |
| 6 | +while getopts p: flag |
| 7 | +do |
| 8 | + case "${flag}" in |
| 9 | + p) prefix=${OPTARG};; |
| 10 | + esac |
| 11 | +done |
| 12 | + |
| 13 | +BASE=$(pwd) |
| 14 | +echo "BASE: $BASE" |
| 15 | + |
| 16 | +function check_env { |
| 17 | + if [ -z ${RISCV} ] |
| 18 | + then |
| 19 | + echo "RISCV environment variable NOT FOUND" |
| 20 | + exit 1 |
| 21 | + fi |
| 22 | + |
| 23 | + _=$(which apt) |
| 24 | + if [ $? -eq 0 ] |
| 25 | + then |
| 26 | + os="deb/ubuntu" |
| 27 | + else |
| 28 | + _=$(which yum) |
| 29 | + if [ $? -eq 0 ] |
| 30 | + then |
| 31 | + os="centos" |
| 32 | + else |
| 33 | + echo "yum/apt NOT FOUND" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + fi |
| 37 | + |
| 38 | +} |
| 39 | + |
| 40 | +function check_deps { |
| 41 | + _=$(which python3.8) |
| 42 | + if [ $? -ne 0 ] |
| 43 | + then |
| 44 | + echo "python3.8 not found" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + |
| 48 | + _=$(which unzip) |
| 49 | + if [ $? -ne 0 ] |
| 50 | + then |
| 51 | + echo "unzip not found" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + |
| 55 | + _=$(which wget) |
| 56 | + if [ $? -ne 0 ] |
| 57 | + then |
| 58 | + echo "wget not found" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + |
| 62 | +} |
| 63 | + |
| 64 | +check_env |
| 65 | + |
| 66 | +check_deps |
| 67 | + |
| 68 | +# User friendly messages on error |
| 69 | +set -E |
| 70 | +set -o functrace |
| 71 | +function handle_error { |
| 72 | + local retval=$? |
| 73 | + local line=${last_lineno:-$1} |
| 74 | + echo "Failed at $line: $BASH_COMMAND" |
| 75 | + echo "Trace: " "$@" |
| 76 | + exit $retval |
| 77 | +} |
| 78 | +if (( ${BASH_VERSION%%.*} <= 3 )) || [[ ${BASH_VERSION%.*} = 4.0 ]]; then |
| 79 | + trap '[[ $FUNCNAME = handle_error ]] || { last_lineno=$real_lineno; real_lineno=$LINENO; }' DEBUG |
| 80 | +fi |
| 81 | +trap 'handle_error $LINENO ${BASH_LINENO[@]}' ERR |
| 82 | + |
| 83 | +function install_repo { |
| 84 | + REPO=$1 |
| 85 | + NAME=$2 |
| 86 | + PREWD=$(pwd) |
| 87 | + echo installing $1 |
| 88 | + cd "$BASE"/dependencies |
| 89 | + mkdir $NAME |
| 90 | + wget $REPO -O $NAME.tar.gz |
| 91 | + tar -xvzf $NAME.tar.gz -C $NAME --strip-components=1 |
| 92 | + cd $NAME |
| 93 | + |
| 94 | + echo CMAKE |
| 95 | + mkdir -p build |
| 96 | + cd build |
| 97 | + if [ -z "$prefix" ] |
| 98 | + then |
| 99 | + cmake .. $2 |
| 100 | + make |
| 101 | + else |
| 102 | + if [ "$os" = "deb/ubuntu" ] |
| 103 | + then |
| 104 | + MARSHAL_PREFIX=$prefix CC=$BASE/gccwrap-ubuntu $prefix/bin/cmake .. -DCMAKE_PREFIX_PATH=$prefix -DCMAKE_INSTALL_PREFIX=$prefix |
| 105 | + C_INCLUDE_PATH="$prefix/include" LIBRARY_PATH="$prefix/lib" make |
| 106 | + else |
| 107 | + MARSHAL_PREFIX=$prefix CC=$BASE/gccwrap-centos $prefix/bin/cmake .. -DCMAKE_PREFIX_PATH=$prefix -DCMAKE_INSTALL_PREFIX=$prefix |
| 108 | + C_INCLUDE_PATH="$prefix/include" LIBRARY_PATH="$prefix/lib64" make |
| 109 | + fi |
| 110 | + fi |
| 111 | + make install |
| 112 | + |
| 113 | + |
| 114 | + cd $PREWD |
| 115 | +} |
| 116 | + |
| 117 | +function install_cmake { |
| 118 | + PREWD=$(pwd) |
| 119 | + version=3.23 |
| 120 | + build=0 |
| 121 | + echo installing cmake-$version.$build |
| 122 | + cd "$BASE"/dependencies |
| 123 | + wget https://github.com/Kitware/CMake/releases/download/v$version.$build/cmake-$version.$build-linux-x86_64.sh |
| 124 | + if [ -z "$prefix" ] |
| 125 | + then |
| 126 | + bash cmake-$version.$build-linux-x86_64.sh --prefix="/usr/local/bin" --exclude-subdir --skip-license |
| 127 | + else |
| 128 | + bash cmake-$version.$build-linux-x86_64.sh --prefix=$prefix --exclude-subdir --skip-license |
| 129 | + fi |
| 130 | + cd $PREWD |
| 131 | +} |
| 132 | + |
| 133 | +function install_meson { |
| 134 | + PREWD=$(pwd) |
| 135 | + release=0.61.4 |
| 136 | + echo installing meson-$release |
| 137 | + cd "$BASE"/dependencies |
| 138 | + mkdir meson |
| 139 | + wget https://github.com/mesonbuild/meson/releases/download/$release/meson-$release.tar.gz -O meson.tar.gz |
| 140 | + tar -xzvf meson.tar.gz -C meson --strip-components=1 |
| 141 | + cd $PREWD |
| 142 | +} |
| 143 | + |
| 144 | +function install_ninja { |
| 145 | + PREWD=$(pwd) |
| 146 | + release=1.10.2 |
| 147 | + echo installing ninja-$release |
| 148 | + cd "$BASE"/dependencies |
| 149 | + wget https://github.com/ninja-build/ninja/releases/download/v$release/ninja-linux.zip |
| 150 | + if [ -z "$prefix" ] |
| 151 | + then |
| 152 | + unzip -d /usr/local/bin/ ninja-linux.zip |
| 153 | + else |
| 154 | + unzip -d $prefix/bin/ ninja-linux.zip |
| 155 | + fi |
| 156 | + cd $PREWD |
| 157 | +} |
| 158 | + |
| 159 | +function install_libslirp { |
| 160 | + PREWD=$(pwd) |
| 161 | + release=4.6.1 |
| 162 | + echo installing libslirp |
| 163 | + cd "$BASE"/dependencies |
| 164 | + mkdir libslirp |
| 165 | + wget https://gitlab.freedesktop.org/slirp/libslirp/-/archive/v$release/libslirp-v$release.tar.gz -O libslirp.tar.gz |
| 166 | + tar -xvzf libslirp.tar.gz -C libslirp --strip-components=1 |
| 167 | + cd libslirp |
| 168 | + if [ -z "$prefix" ] |
| 169 | + then |
| 170 | + python3.8 ../meson/meson.py build |
| 171 | + ninja -C build install |
| 172 | + else |
| 173 | + NINJA=$prefix/bin/ninja python3.8 ../meson/meson.py build -Dprefix=$prefix |
| 174 | + $prefix/bin/ninja -C build install |
| 175 | + fi |
| 176 | + cd $PREWD |
| 177 | +} |
| 178 | + |
| 179 | +function install_qemu { |
| 180 | + PREWD=$(pwd) |
| 181 | + release=6.2.0 |
| 182 | + echo installing qemu-$release |
| 183 | + cd "$BASE"/dependencies |
| 184 | + mkdir qemu |
| 185 | + wget https://download.qemu.org/qemu-$release.tar.xz -O qemu.tar.xz |
| 186 | + tar -xvJf qemu.tar.xz -C qemu --strip-components=1 |
| 187 | + cd qemu |
| 188 | + |
| 189 | + mkdir -p build |
| 190 | + cd build |
| 191 | + if [ -z "$prefix" ] |
| 192 | + then |
| 193 | + ../configure --target-list=riscv64-softmu --enable-vde --disable-werror |
| 194 | + make |
| 195 | + else |
| 196 | + if [ "$os" = "deb/ubuntu" ] |
| 197 | + then |
| 198 | + MARSHAL_PREFIX=$prefix ../configure --prefix=$prefix --interp-prefix=$prefix --cc=$BASE/gccwrap-ubuntu --target-list=riscv64-softmmu --enable-vde --disable-werror |
| 199 | + C_INCLUDE_PATH="$prefix/include" LIBRARY_PATH="$prefix/lib" make |
| 200 | + else |
| 201 | + MARSHAL_PREFIX=$prefix ../configure --prefix=$prefix --interp-prefix=$prefix --cc=$BASE/gccwrap-centos --target-list=riscv64-softmmu --enable-vde --disable-werror |
| 202 | + C_INCLUDE_PATH="$prefix/include" LIBRARY_PATH="$prefix/lib64" make |
| 203 | + fi |
| 204 | + fi |
| 205 | + make install |
| 206 | + |
| 207 | + |
| 208 | + cd $PREWD |
| 209 | +} |
| 210 | + |
| 211 | +# Start installation |
| 212 | + |
| 213 | +rm -rf dependencies |
| 214 | +mkdir dependencies |
| 215 | + |
| 216 | +if [ -z "$prefix" ] |
| 217 | +then |
| 218 | + prefix=${RISCV} |
| 219 | +fi |
| 220 | + |
| 221 | +if [ -n "$prefix" ] |
| 222 | +then |
| 223 | + export PATH="$prefix:$prefix/bin:${PATH}" |
| 224 | +fi |
| 225 | + |
| 226 | +install_cmake |
| 227 | +install_ninja |
| 228 | +install_meson |
| 229 | +install_libslirp |
| 230 | + |
| 231 | +install_repo https://github.com/virtualsquare/s2argv-execs/archive/refs/tags/1.3.tar.gz s2argv-execs |
| 232 | +install_repo https://github.com/rd235/vdeplug4/archive/refs/tags/v4.0.1.tar.gz vdeplug4 |
| 233 | +install_repo https://github.com/virtualsquare/libvdeslirp/archive/refs/tags/0.1.1.tar.gz libvdeslirp |
| 234 | +install_repo https://github.com/virtualsquare/vdeplug_slirp/archive/refs/tags/0.1.0.tar.gz vdeplug_slirp |
| 235 | + |
| 236 | +install_qemu |
| 237 | + |
| 238 | +./init-submodules.sh |
| 239 | + |
| 240 | +echo 'Installation completed' |
0 commit comments