1#!/bin/bash 2 3# Grab default values for $CFLAGS and such. 4 5source ./configure 6 7# Parse command line arguments. 8 9[ -z "$PREFIX" ] && PREFIX="." 10 11LONG_PATH="" 12while [ ! -z "$1" ] 13do 14 # Create symlinks instead of hardlinks? 15 16 [ "$1" == "--symlink" ] && LINK_TYPE="-s" 17 18 # Uninstall? 19 20 [ "$1" == "--uninstall" ] && UNINSTALL=1 21 22 # Delete destination command if it exists? 23 24 [ "$1" == "--force" ] && DO_FORCE="-f" 25 26 # Use {,usr}/{bin,sbin} paths instead of all files in one directory? 27 28 if [ "$1" == "--long" ] 29 then 30 LONG_PATH="bin/" 31 fi 32 33 shift 34done 35 36echo "Compile instlist..." 37 38$DEBUG $HOSTCC -I . scripts/install.c -o generated/instlist || exit 1 39COMMANDS="$(generated/instlist $LONG_PATH)" 40 41echo "Install commands..." 42 43# Copy toybox itself 44 45if [ -z "$UNINSTALL" ] 46then 47 mkdir -p ${PREFIX}/${LONG_PATH} || exit 1 48 cp toybox ${PREFIX}/${LONG_PATH} || exit 1 49else 50 rm "${PREFIX}/${LONG_PATH}/toybox" 2>/dev/null 51 rmdir "${PREFIX}/${LONG_PATH}" 2>/dev/null 52fi 53cd "${PREFIX}" 54 55# Make links to toybox 56 57for i in $COMMANDS 58do 59 # Figure out target of link 60 61 if [ -z "$LONG_PATH" ] 62 then 63 DOTPATH="" 64 else 65 # Create subdirectory for command to go in (if necessary) 66 67 DOTPATH="$(echo $i | sed 's@\(.*/\).*@\1@')" 68 if [ -z "$UNINSTALL" ] 69 then 70 mkdir -p "$DOTPATH" || exit 1 71 else 72 rmdir "$DOTPATH" 2>/dev/null 73 fi 74 75 if [ -z "$LINK_TYPE" ] 76 then 77 dotpath="bin/" 78 else 79 if [ "$DOTPATH" != "$LONG_PATH" ] 80 then 81 DOTPATH="$(echo $DOTPATH | sed -e 's@[^/]*/@../@g')"$LONG_PATH 82 else 83 DOTPATH="" 84 fi 85 fi 86 fi 87 88 # Create link 89 [ -z "$UNINSTALL" ] && 90 ln $DO_FORCE $LINK_TYPE ${DOTPATH}toybox $i || 91 rm $i 2>/dev/null 92done 93