AR = $(CROSS_COMPILE)ar
RANLIB = $(CROSS_COMPILE)ranlib
+INSTALL = ./tools/install.sh
ARCH_INCLUDES = $(wildcard arch/$(ARCH)/bits/*.h)
ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH) $(ARCH_INCLUDES:arch/$(ARCH)/%=include/%))
chmod +x $@
$(DESTDIR)$(bindir)/%: tools/%
- install -D $< $@
+ $(INSTALL) -D $< $@
$(DESTDIR)$(libdir)/%.so: lib/%.so
- install -D -m 755 $< $@
+ $(INSTALL) -D -m 755 $< $@
$(DESTDIR)$(libdir)/%: lib/%
- install -D -m 644 $< $@
+ $(INSTALL) -D -m 644 $< $@
$(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
- install -D -m 644 $< $@
+ $(INSTALL) -D -m 644 $< $@
$(DESTDIR)$(includedir)/%: include/%
- install -D -m 644 $< $@
+ $(INSTALL) -D -m 644 $< $@
$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so
- test -d $(DESTDIR)$(syslibdir) || install -d -m 755 $(DESTDIR)$(syslibdir) || true
- { ln -sf $(libdir)/libc.so $@.tmp.$$$$ && mv -f $@.tmp.$$$$ $@ ; } || true
+ $(INSTALL) -D -l $< $@
install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
--- /dev/null
+#!/bin/sh
+#
+# This is an actually-safe install command which installs the new
+# file atomically in the new location, rather than overwriting
+# existing files.
+#
+
+usage() {
+printf "usage: %s [-D] [-l] [-m mode] src dest\n" "$0" 1>&2
+exit 1
+}
+
+mkdirp=
+symlink=
+mode=755
+
+while getopts Dlm: name ; do
+case "$name" in
+D) mkdirp=yes ;;
+l) symlink=yes ;;
+m) mode=$OPTARG ;;
+?) usage ;;
+esac
+done
+shift $(($OPTIND - 1))
+
+test "$#" -eq 2 || usage
+src=$1
+dst=$2
+tmp="$dst.tmp.$$"
+
+case "$dst" in
+*/) printf "%s: %s ends in /\n", "$0" "$dst" 1>&2 ; exit 1 ;;
+esac
+
+set -C
+set -e
+
+if test "$mkdirp" ; then
+umask 022
+case "$2" in
+*/*) mkdir -p "${dst%/*}" ;;
+esac
+fi
+
+trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP
+
+umask 077
+
+if test "$symlink" ; then
+ln -s "$1" "$tmp"
+else
+cat < "$1" > "$tmp"
+fi
+
+mv "$tmp" "$2"
+test -d "$2" && {
+rm -f "$2/$tmp"
+printf "%s: %s is a directory\n" "$0" "$dst" 1>&2
+exit 1
+}
+
+test "$symlink" || chmod "$mode" "$2"
+
+exit 0