• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
34NOBUILD=1 scripts/make.sh
35$DEBUG $HOSTCC -I . scripts/install.c -o "$UNSTRIPPED"/instlist || exit 1
36COMMANDS="$("$UNSTRIPPED"/instlist $LONG_PATH)"
37
38echo "${UNINSTALL:-Install} commands..."
39
40# Copy toybox itself
41
42if [ -z "$UNINSTALL" ]
43then
44  mkdir -p "${PREFIX}/${LONG_PATH}" &&
45  rm -f "${PREFIX}/${LONG_PATH}/toybox" &&
46  cp toybox"${TARGET:+-$TARGET}" ${PREFIX}/${LONG_PATH} || exit 1
47else
48  rm -f "${PREFIX}/${LONG_PATH}/toybox" 2>/dev/null
49fi
50cd "$PREFIX" || exit 1
51
52# Make links to toybox
53
54EXIT=0
55
56for i in $COMMANDS
57do
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${TARGET:+-$TARGET}" $i || EXIT=1
90  else
91    rm -f $i || EXIT=1
92  fi
93done
94
95[ -z "$AIRLOCK" ] && exit $EXIT
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
109PENDING="dd diff expr git tr vi wget bash sh xzcat bc ar gzip   ftpd less awk unxz bison flex make nm"
110
111# "gcc" can go away if the kernel guys merge my patch:
112# http://lkml.iu.edu/hypermail/linux/kernel/2202.0/01505.html
113TOOLCHAIN="as cc ld gcc objdump"
114
115# Tools needed to build packages
116for i in $TOOLCHAIN $PENDING $HOST_EXTRA
117do
118  if [ ! -f "$i" ]
119  then
120    # Loop through each instance, populating fallback directories (used by
121    # things like distcc, which require multiple instances of the same binary
122    # in a known order in the $PATH).
123
124    X=0
125    FALLBACK="$PREFIX"
126    which -a "$i" | while read j
127    do
128      if [ ! -e "$FALLBACK/$i" ]
129      then
130        mkdir -p "$FALLBACK" &&
131        ln -sf "$j" "$FALLBACK/$i" || exit 1
132      fi
133
134      X=$[$X+1]
135      FALLBACK="$PREFIX/fallback-$X"
136    done
137
138    if [ ! -f "$PREFIX/$i" ]
139    then
140      echo "Toolchain component missing: $i" >&2
141      [ -z "$PEDANTIC" ] || EXIT=1
142    fi
143  fi
144done
145
146exit $EXIT
147