|
| 1 | +#!/bin/sh |
| 2 | +# Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
| 3 | +# file at the top-level directory of this distribution and at |
| 4 | +# http://rust-lang.org/COPYRIGHT. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 8 | +# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 9 | +# option. This file may not be copied, modified, or distributed |
| 10 | +# except according to those terms. |
| 11 | + |
| 12 | +msg() { |
| 13 | + echo "install: $1" |
| 14 | +} |
| 15 | + |
| 16 | +step_msg() { |
| 17 | + msg |
| 18 | + msg "$1" |
| 19 | + msg |
| 20 | +} |
| 21 | + |
| 22 | +warn() { |
| 23 | + echo "install: WARNING: $1" |
| 24 | +} |
| 25 | + |
| 26 | +err() { |
| 27 | + echo "install: error: $1" |
| 28 | + exit 1 |
| 29 | +} |
| 30 | + |
| 31 | +need_ok() { |
| 32 | + if [ $? -ne 0 ] |
| 33 | + then |
| 34 | + err "$1" |
| 35 | + fi |
| 36 | +} |
| 37 | + |
| 38 | +putvar() { |
| 39 | + local T |
| 40 | + eval T=\$$1 |
| 41 | + eval TLEN=\${#$1} |
| 42 | + if [ $TLEN -gt 35 ] |
| 43 | + then |
| 44 | + printf "install: %-20s := %.35s ...\n" $1 "$T" |
| 45 | + else |
| 46 | + printf "install: %-20s := %s %s\n" $1 "$T" "$2" |
| 47 | + fi |
| 48 | + printf "%-20s := %s\n" $1 "$T" >>config.tmp |
| 49 | +} |
| 50 | + |
| 51 | +valopt() { |
| 52 | + VAL_OPTIONS="$VAL_OPTIONS $1" |
| 53 | + |
| 54 | + local OP=$1 |
| 55 | + local DEFAULT=$2 |
| 56 | + shift |
| 57 | + shift |
| 58 | + local DOC="$*" |
| 59 | + if [ $HELP -eq 0 ] |
| 60 | + then |
| 61 | + local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_') |
| 62 | + local V="CFG_${UOP}" |
| 63 | + eval $V="$DEFAULT" |
| 64 | + for arg in $CFG_ARGS |
| 65 | + do |
| 66 | + if echo "$arg" | grep -q -- "--$OP=" |
| 67 | + then |
| 68 | + val=$(echo "$arg" | cut -f2 -d=) |
| 69 | + eval $V=$val |
| 70 | + fi |
| 71 | + done |
| 72 | + putvar $V |
| 73 | + else |
| 74 | + if [ -z "$DEFAULT" ] |
| 75 | + then |
| 76 | + DEFAULT="<none>" |
| 77 | + fi |
| 78 | + OP="${OP}=[${DEFAULT}]" |
| 79 | + printf " --%-30s %s\n" "$OP" "$DOC" |
| 80 | + fi |
| 81 | +} |
| 82 | + |
| 83 | +opt() { |
| 84 | + BOOL_OPTIONS="$BOOL_OPTIONS $1" |
| 85 | + |
| 86 | + local OP=$1 |
| 87 | + local DEFAULT=$2 |
| 88 | + shift |
| 89 | + shift |
| 90 | + local DOC="$*" |
| 91 | + local FLAG="" |
| 92 | + |
| 93 | + if [ $DEFAULT -eq 0 ] |
| 94 | + then |
| 95 | + FLAG="enable" |
| 96 | + else |
| 97 | + FLAG="disable" |
| 98 | + DOC="don't $DOC" |
| 99 | + fi |
| 100 | + |
| 101 | + if [ $HELP -eq 0 ] |
| 102 | + then |
| 103 | + for arg in $CFG_ARGS |
| 104 | + do |
| 105 | + if [ "$arg" = "--${FLAG}-${OP}" ] |
| 106 | + then |
| 107 | + OP=$(echo $OP | tr 'a-z-' 'A-Z_') |
| 108 | + FLAG=$(echo $FLAG | tr 'a-z' 'A-Z') |
| 109 | + local V="CFG_${FLAG}_${OP}" |
| 110 | + eval $V=1 |
| 111 | + putvar $V |
| 112 | + fi |
| 113 | + done |
| 114 | + else |
| 115 | + if [ ! -z "$META" ] |
| 116 | + then |
| 117 | + OP="$OP=<$META>" |
| 118 | + fi |
| 119 | + printf " --%-30s %s\n" "$FLAG-$OP" "$DOC" |
| 120 | + fi |
| 121 | +} |
| 122 | + |
| 123 | +flag() { |
| 124 | + BOOL_OPTIONS="$BOOL_OPTIONS $1" |
| 125 | + |
| 126 | + local OP=$1 |
| 127 | + shift |
| 128 | + local DOC="$*" |
| 129 | + |
| 130 | + if [ $HELP -eq 0 ] |
| 131 | + then |
| 132 | + for arg in $CFG_ARGS |
| 133 | + do |
| 134 | + if [ "$arg" = "--${OP}" ] |
| 135 | + then |
| 136 | + OP=$(echo $OP | tr 'a-z-' 'A-Z_') |
| 137 | + local V="CFG_${OP}" |
| 138 | + eval $V=1 |
| 139 | + putvar $V |
| 140 | + fi |
| 141 | + done |
| 142 | + else |
| 143 | + if [ ! -z "$META" ] |
| 144 | + then |
| 145 | + OP="$OP=<$META>" |
| 146 | + fi |
| 147 | + printf " --%-30s %s\n" "$OP" "$DOC" |
| 148 | + fi |
| 149 | +} |
| 150 | + |
| 151 | +validate_opt () { |
| 152 | + for arg in $CFG_ARGS |
| 153 | + do |
| 154 | + isArgValid=0 |
| 155 | + for option in $BOOL_OPTIONS |
| 156 | + do |
| 157 | + if test --disable-$option = $arg |
| 158 | + then |
| 159 | + isArgValid=1 |
| 160 | + fi |
| 161 | + if test --enable-$option = $arg |
| 162 | + then |
| 163 | + isArgValid=1 |
| 164 | + fi |
| 165 | + if test --$option = $arg |
| 166 | + then |
| 167 | + isArgValid=1 |
| 168 | + fi |
| 169 | + done |
| 170 | + for option in $VAL_OPTIONS |
| 171 | + do |
| 172 | + if echo "$arg" | grep -q -- "--$option=" |
| 173 | + then |
| 174 | + isArgValid=1 |
| 175 | + fi |
| 176 | + done |
| 177 | + if [ "$arg" = "--help" ] |
| 178 | + then |
| 179 | + echo |
| 180 | + echo "No more help available for Configure options," |
| 181 | + echo "check the Wiki or join our IRC channel" |
| 182 | + break |
| 183 | + else |
| 184 | + if test $isArgValid -eq 0 |
| 185 | + then |
| 186 | + err "Option '$arg' is not recognized" |
| 187 | + fi |
| 188 | + fi |
| 189 | + done |
| 190 | +} |
| 191 | + |
| 192 | +CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/" |
| 193 | +CFG_SELF="$0" |
| 194 | +CFG_ARGS="$@" |
| 195 | + |
| 196 | +HELP=0 |
| 197 | +if [ "$1" = "--help" ] |
| 198 | +then |
| 199 | + HELP=1 |
| 200 | + shift |
| 201 | + echo |
| 202 | + echo "Usage: $CFG_SELF [options]" |
| 203 | + echo |
| 204 | + echo "Options:" |
| 205 | + echo |
| 206 | +else |
| 207 | + step_msg "processing $CFG_SELF args" |
| 208 | +fi |
| 209 | + |
| 210 | +OPTIONS="" |
| 211 | +BOOL_OPTIONS="" |
| 212 | +VAL_OPTIONS="" |
| 213 | + |
| 214 | +flag uninstall "only uninstall from the installation prefix" |
| 215 | +valopt prefix "/usr/local" "set installation prefix" |
| 216 | + |
| 217 | +if [ $HELP -eq 1 ] |
| 218 | +then |
| 219 | + echo |
| 220 | + exit 0 |
| 221 | +fi |
| 222 | + |
| 223 | +step_msg "validating $CFG_SELF args" |
| 224 | +validate_opt |
| 225 | + |
| 226 | +# First, uninstall from the installation prefix |
| 227 | +# FIXME: Hardcoded 'rustlib' ignores CFG_RUSTLIBDIR |
| 228 | +if [ -f "${CFG_PREFIX}/lib/rustlib/manifest" ] |
| 229 | +then |
| 230 | + while read p; do |
| 231 | + msg "uninstall ${CFG_PREFIX}/$p" |
| 232 | + rm "${CFG_PREFIX}/$p" |
| 233 | + need_ok "failed to remove file" |
| 234 | + done < "${CFG_PREFIX}/lib/rustlib/manifest" |
| 235 | + |
| 236 | + # Remove 'rustlib' directory |
| 237 | + msg "uninstall ${CFG_PREFIX}/lib/rustlib" |
| 238 | + rm -r "${CFG_PREFIX}/lib/rustlib" |
| 239 | + need_ok "failed to remove rustlib" |
| 240 | +fi |
| 241 | + |
| 242 | +# If we're only uninstalling then exit |
| 243 | +if [ -n "${CFG_UNINSTALL}" ] |
| 244 | +then |
| 245 | + exit 0 |
| 246 | +fi |
| 247 | + |
| 248 | +# Iterate through the new manifest and install files |
| 249 | +while read p; do |
| 250 | + |
| 251 | + umask 022 && mkdir -p "${CFG_PREFIX}/$(dirname $p)" |
| 252 | + need_ok "directory creation failed" |
| 253 | + |
| 254 | + msg "${CFG_PREFIX}/$p" |
| 255 | + if echo "$p" | grep "/bin/" > /dev/null |
| 256 | + then |
| 257 | + install -m755 "${CFG_SRC_DIR}/$p" "${CFG_PREFIX}/$p" |
| 258 | + else |
| 259 | + install -m644 "${CFG_SRC_DIR}/$p" "${CFG_PREFIX}/$p" |
| 260 | + fi |
| 261 | + need_ok "file creation failed" |
| 262 | + |
| 263 | +# The manifest lists all files to install |
| 264 | +done < "${CFG_SRC_DIR}/lib/rustlib/manifest" |
0 commit comments