diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2015-09-12 12:23:07 -0500 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2015-09-15 22:43:33 -0500 |
commit | b6677f90864028e8faf8d531d801f5cd3d5ed487 (patch) | |
tree | f9a47471d3f8e238cc88d541290e0ad9a6908996 | |
parent | dee0ef6a7d9b765f3cbc2332c5205dc202fb52ea (diff) |
add make install rules
The install.sh script is taken from musl.
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | config.mak | 5 | ||||
-rwxr-xr-x | tools/install.sh | 64 |
3 files changed, 88 insertions, 1 deletions
@@ -1,3 +1,8 @@ +prefix = /usr/local +exec_prefix = $(prefix) +bindir = $(exec_prefix)/bin +sharedir = $(prefix)/share/saturn-tools + CFLAGS = -Os -pipe -std=c99 -D_POSIX_C_SOURCE=200809L LDFLAGS = SATURN_CROSS = saturn- @@ -6,6 +11,8 @@ SATURN_OBJCOPY = $(SATURN_CROSS)objcopy SATURN_CFLAGS = -Os -pipe -std=c99 -nostdlib SATURN_LDFLAGS = +INSTALL = ./tools/install.sh + -include config.mak BOOTSRCS = $(sort $(wildcard boot/*.c)) @@ -17,10 +24,12 @@ DATA = $(sort $(wildcard src/*.bin)) OBJS = $(SRCS:.c=.o) $(DATA:.bin=.o) BINS = bin/satmkboot bin/satmkiso -.PHONY: all clean +.PHONY: all clean install install-bins install-data all: $(BINS) $(BOOTBINS) +install: install-bins install-data + clean: rm -f $(BINS) $(OBJS) $(BOOTBINS) $(BOOTELFS) @@ -41,3 +50,12 @@ share/boot/%: boot/%.elf %.o: %.c $(CC) $(CFLAGS) -c $< -o $@ +$(DESTDIR)$(bindir)/%: bin/% + $(INSTALL) -D $< $@ + +$(DESTDIR)$(sharedir)/%: share/% + $(INSTALL) -D -m 644 $< $@ + +install-bins: $(BINS:bin/%=$(DESTDIR)$(bindir)/%) + +install-data: $(BOOTBINS:share/%=$(DESTDIR)$(sharedir)/%) @@ -2,6 +2,11 @@ # These values are the defaults used by the main makefile # if nothing is overridden here. +#prefix = /usr/local +#exec_prefix = $(prefix) +#bindir = $(exec_prefix)/bin +#sharedir = $(prefix)/share/saturn-tools + #CFLAGS = -Os -pipe -std=c99 -D_POSIX_C_SOURCE=200809L #LDFLAGS = #SATURN_CROSS = saturn- diff --git a/tools/install.sh b/tools/install.sh new file mode 100755 index 0000000..d913b60 --- /dev/null +++ b/tools/install.sh @@ -0,0 +1,64 @@ +#!/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" +chmod "$mode" "$tmp" +fi + +mv -f "$tmp" "$2" +test -d "$2" && { +rm -f "$2/$tmp" +printf "%s: %s is a directory\n" "$0" "$dst" 1>&2 +exit 1 +} + +exit 0 |