install.sh 3.4 KB

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