OSDN Git Service

Merge remote-tracking branch \'toybox/master\' into HEAD
[android-x86/external-toybox.git] / scripts / install.sh
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   shift
27 done
28
29 echo "Compile instlist..."
30
31 $DEBUG $HOSTCC -I . scripts/install.c -o generated/instlist || exit 1
32 COMMANDS="$(generated/instlist $LONG_PATH)"
33
34 echo "${UNINSTALL:-Install} commands..."
35
36 # Copy toybox itself
37
38 if [ -z "$UNINSTALL" ]
39 then
40   mkdir -p "${PREFIX}/${LONG_PATH}" &&
41   rm -f "${PREFIX}/${LONG_PATH}/toybox" &&
42   cp toybox ${PREFIX}/${LONG_PATH} || exit 1
43 else
44   rm -f "${PREFIX}/${LONG_PATH}/toybox" 2>/dev/null
45 fi
46 cd "$PREFIX" || exit 1
47
48 # Make links to toybox
49
50 EXIT=0
51
52 for i in $COMMANDS
53 do
54   # Figure out target of link
55
56   if [ -z "$LONG_PATH" ]
57   then
58     DOTPATH=""
59   else
60     # Create subdirectory for command to go in (if necessary)
61
62     DOTPATH="$(dirname "$i")"/
63     if [ -z "$UNINSTALL" ]
64     then
65       mkdir -p "$DOTPATH" || exit 1
66     fi
67
68     if [ -z "$LINK_TYPE" ]
69     then
70       DOTPATH="bin/"
71     else
72       if [ "$DOTPATH" != "$LONG_PATH" ]
73       then
74         # For symlinks we need ../../bin style relative paths
75         DOTPATH="$(echo $DOTPATH | sed -e 's@[^/]*/@../@g')"$LONG_PATH
76       else
77         DOTPATH=""
78       fi
79     fi
80   fi
81
82   # Create link
83   if [ -z "$UNINSTALL" ]
84   then
85     ln $DO_FORCE $LINK_TYPE ${DOTPATH}toybox $i || EXIT=1
86   else
87     rm -f $i || EXIT=1
88   fi
89 done
90
91 exit $EXIT