Home | History | Annotate | Download | only in scripts
      1 #!/bin/bash
      2 
      3 # Grab default values for $CFLAGS and such.
      4 
      5 source ./configure
      6 
      7 [ -z "$PREFIX" ] && PREFIX="/usr/toybox"
      8 
      9 # Parse command line arguments.
     10 
     11 LONG_PATH=""
     12 while [ ! -z "$1" ]
     13 do
     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
     30 done
     31 
     32 echo "Compile instlist..."
     33 
     34 NOBUILD=1 scripts/make.sh
     35 $DEBUG $HOSTCC -I . scripts/install.c -o generated/instlist || exit 1
     36 COMMANDS="$(generated/instlist $LONG_PATH)"
     37 
     38 echo "${UNINSTALL:-Install} commands..."
     39 
     40 # Copy toybox itself
     41 
     42 if [ -z "$UNINSTALL" ]
     43 then
     44   mkdir -p "${PREFIX}/${LONG_PATH}" &&
     45   rm -f "${PREFIX}/${LONG_PATH}/toybox" &&
     46   cp toybox ${PREFIX}/${LONG_PATH} || exit 1
     47 else
     48   rm -f "${PREFIX}/${LONG_PATH}/toybox" 2>/dev/null
     49 fi
     50 cd "$PREFIX" || exit 1
     51 
     52 # Make links to toybox
     53 
     54 EXIT=0
     55 
     56 for i in $COMMANDS
     57 do
     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 $i || EXIT=1
     90   else
     91     rm -f $i || EXIT=1
     92   fi
     93 done
     94 
     95 [ -z "$AIRLOCK" ] && exit 0
     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 
    109 PENDING="bunzip2 bzcat dd diff expr ftpd ftpget ftpput gunzip less ping route tar test tr vi wget zcat awk bzip2 fdisk gzip sh sha512sum unxz xzcat bc"
    110 
    111 # "gcc" should go away for llvm, but some things still hardwire it
    112 TOOLCHAIN="ar as nm cc make ld gcc objdump"
    113 
    114 if [ ! -z "$AIRLOCK" ]
    115 then
    116 
    117   # Tools needed to build packages
    118   for i in $TOOLCHAIN $PENDING $HOST_EXTRA
    119   do
    120     if [ ! -f "$i" ]
    121   then
    122     # Loop through each instance, populating fallback directories (used by
    123     # things like distcc, which require multiple instances of the same binary
    124     # in a known order in the $PATH).
    125 
    126     X=0
    127     FALLBACK="$PREFIX"
    128     which -a "$i" | while read j
    129     do
    130       if [ ! -e "$FALLBACK/$i" ]
    131       then
    132         mkdir -p "$FALLBACK" &&
    133         ln -sf "$j" "$FALLBACK/$i" || exit 1
    134       fi
    135 
    136       X=$[$X+1]
    137       FALLBACK="$PREFIX/fallback-$X"
    138     done
    139 
    140     if [ ! -f "$PREFIX/$i" ]
    141     then
    142       echo "Toolchain component missing: $i" >&2
    143       [ -z "$PEDANTIC" ] || EXIT=1
    144     fi
    145   fi
    146 done
    147 
    148 
    149 
    150 fi
    151 
    152 exit $EXIT
    153