toybox/scripts/install.sh
<<
>>
Prefs
   1#!/bin/bash
   2
   3# Grab default values for $CFLAGS and such.
   4
   5source ./configure
   6
   7[ -z "$PREFIX" ] && PREFIX="/usr/toybox"
   8
   9# Parse command line arguments.
  10
  11LONG_PATH=""
  12while [ ! -z "$1" ]
  13do
  14  # Create symlinks instead of hardlinks?
  15  [ "$1" == "--symlink" ] && LINK_TYPE="-s"
  16
  17  # Uninstall?
  18  [ "$1" == "--uninstall" ] && UNINSTALL=Uninstall
  19
  20  # Delete destination command if it exists?
  21  [ "$1" == "--force" ] && DO_FORCE="-f"
  22
  23  # Use {,usr}/{bin,sbin} paths instead of all files in one directory?
  24  [ "$1" == "--long" ] && LONG_PATH="bin/"
  25
  26  # Symlink host toolchain binaries to destination to create cross compile $PATH
  27  [ "$1" == "--airlock" ] && AIRLOCK=1
  28
  29  shift
  30done
  31
  32echo "Compile instlist..."
  33
  34NOBUILD=1 scripts/make.sh
  35$DEBUG $HOSTCC -I . scripts/install.c -o generated/instlist || exit 1
  36COMMANDS="$(generated/instlist $LONG_PATH)"
  37
  38echo "${UNINSTALL:-Install} commands..."
  39
  40# Copy toybox itself
  41
  42if [ -z "$UNINSTALL" ]
  43then
  44  mkdir -p "${PREFIX}/${LONG_PATH}" &&
  45  rm -f "${PREFIX}/${LONG_PATH}/toybox" &&
  46  cp toybox"${TARGET:+-$TARGET}" ${PREFIX}/${LONG_PATH} || exit 1
  47else
  48  rm -f "${PREFIX}/${LONG_PATH}/toybox" 2>/dev/null
  49fi
  50cd "$PREFIX" || exit 1
  51
  52# Make links to toybox
  53
  54EXIT=0
  55
  56for i in $COMMANDS
  57do
  58  # Figure out target of link
  59
  60  if [ -z "$LONG_PATH" ]
  61  then
  62    DOTPATH=""
  63  else
  64    # Create subdirectory for command to go in (if necessary)
  65
  66    DOTPATH="$(dirname "$i")"/
  67    if [ -z "$UNINSTALL" ]
  68    then
  69      mkdir -p "$DOTPATH" || exit 1
  70    fi
  71
  72    if [ -z "$LINK_TYPE" ]
  73    then
  74      DOTPATH="bin/"
  75    else
  76      if [ "$DOTPATH" != "$LONG_PATH" ]
  77      then
  78        # For symlinks we need ../../bin style relative paths
  79        DOTPATH="$(echo $DOTPATH | sed -e 's@[^/]*/@../@g')"$LONG_PATH
  80      else
  81        DOTPATH=""
  82      fi
  83    fi
  84  fi
  85
  86  # Create link
  87  if [ -z "$UNINSTALL" ]
  88  then
  89    ln $DO_FORCE $LINK_TYPE ${DOTPATH}"toybox${TARGET:+-$TARGET}" $i || EXIT=1
  90  else
  91    rm -f $i || EXIT=1
  92  fi
  93done
  94
  95[ -z "$AIRLOCK" ] && exit $EXIT
  96
  97# --airlock creates a single directory you can point the $PATH to for cross
  98# compiling, which contains just toybox and symlinks to toolchain binaries.
  99
 100# This not only means you're building with a known set of tools (insulated from
 101# variations in the host distro), but that everything else is NOT in your PATH
 102# and thus various configure stages won't find things on thie host that won't
 103# be there on the target (such as the distcc build noticing the host has
 104# python and deciding to #include Python.h).
 105
 106# The following are commands toybox should provide, but doesn't yet.
 107# For now symlink the host version. This list must go away by 1.0.
 108
 109PENDING="dd diff expr ftpd less tr vi wget awk sh unxz xzcat bc bison flex make nm ar gzip"
 110
 111# "gcc" should go away for llvm, but some things still hardwire it
 112TOOLCHAIN="as cc ld gcc objdump"
 113
 114# Tools needed to build packages
 115for i in $TOOLCHAIN $PENDING $HOST_EXTRA
 116do
 117  if [ ! -f "$i" ]
 118  then
 119    # Loop through each instance, populating fallback directories (used by
 120    # things like distcc, which require multiple instances of the same binary
 121    # in a known order in the $PATH).
 122
 123    X=0
 124    FALLBACK="$PREFIX"
 125    which -a "$i" | while read j
 126    do
 127      if [ ! -e "$FALLBACK/$i" ]
 128      then
 129        mkdir -p "$FALLBACK" &&
 130        ln -sf "$j" "$FALLBACK/$i" || exit 1
 131      fi
 132
 133      X=$[$X+1]
 134      FALLBACK="$PREFIX/fallback-$X"
 135    done
 136
 137    if [ ! -f "$PREFIX/$i" ]
 138    then
 139      echo "Toolchain component missing: $i" >&2
 140      [ -z "$PEDANTIC" ] || EXIT=1
 141    fi
 142  fi
 143done
 144
 145exit $EXIT
 146