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