]> git.sur5r.net Git - cc65/blob - make/install-sh
Makefile changes by Greg King
[cc65] / make / install-sh
1 #!/bin/sh
2 #
3 # install-sh -- install a program, script, or data-file.
4 #
5 # This isn't a full install-script; it does only what is needed by the cc65
6 # package.  It can install only one file at a time.
7
8 # Don't use ":-" because 4.3BSD and earlier shells don't like it.
9 # Put in absolute paths if you don't have these commands in your PATH;
10 # or, set these upper-case variables in your environment.
11 cpprog="${CPPROG-cp}"
12 mvprog="${MVPROG-mv}"
13 rmprog="${RMPROG-rm}"
14 stripprog="${STRIPPROG-strip}"
15 chmodprog="${CHMODPROG-chmod}"
16
17 instcmd="$cpprog"
18 stripcmd=""
19 chmodcmd=""
20 rmcmd="$rmprog -f"
21 mvcmd="$mvprog"
22 src=""
23 dst=""
24
25 while [ x"$1" != x ]; do
26     case $1 in
27         -c) ;;
28
29         -m) chmodcmd="$chmodprog $2"
30             shift
31             ;;
32
33         -s) stripcmd="$stripprog"
34             ;;
35
36         # The first name is the source; the last name is the destination.
37         *)  if [ x"$src" = x ]
38                 then src="$1"
39                 else dst="$1"
40                 fi
41         esac
42     shift
43     done
44
45 [ x"$src" != x ] || { echo "$0: no input file was named." >&2; exit 1;}
46 [ x"$dst" != x ] || { echo "$0: no destination was named." >&2; exit 1;}
47
48 [ -e "$src" ] || { echo "$0: \"$src\" doesn't exist." >&2; exit 1;}
49
50 # Make a temporary file-name in the proper directory.
51 dsttmp="$dst/#inst.$$#"
52
53 # Append the input filename to the destination directory.
54 dst="$dst"/`basename "$src"`
55
56 # Trap to remove the temporary file if it isn't renamed.
57 trap 'status=$?; $rmcmd "$dsttmp" && exit $status' 0
58 trap '(exit $?); exit' 1 2 3 13 15
59
60 # Copy the source file to the temporary name.
61 $instcmd "$src" "$dsttmp" &&
62
63 if [ x"$stripcmd" != x ]
64     then $stripcmd "$dsttmp"
65     fi &&
66 if [ x"$chmodcmd" != x ]
67     then $chmodcmd "$dsttmp"
68     fi &&
69
70 # Remove an old file (only if the temporary file was created successfully).
71 if [ -f "$dst" ]
72     then $rmcmd "$dst" 2>/dev/null ||
73     { echo "$0: can't remove \"$dst\"" >&2
74       (exit 1); exit
75       }
76     fi &&
77
78 # Rename the temporary file to the real name.
79 $mvcmd "$dsttmp" "$dst" &&
80
81 # The final little trick to pass "correctly" the exit status to exit traps.
82 { (exit 0); exit;}