install.sh 3.5 KB

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