-
Notifications
You must be signed in to change notification settings - Fork 0
/
make
executable file
·75 lines (67 loc) · 1.82 KB
/
make
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env sh
# SPDX-License-Identifier: Unlicense
app_name=flatr
PREFIX=~/.local
is_debug=${BUILD_DEBUG:+1}
log_error() { printf '%s\n' "$*" >&2; }
log_info() { printf '%s\n' "$*"; }
log_debug() { [ "$is_debug" ] && printf 'DEBUG %s\n' "$*"; }
abort() {
log_error "$*"
exit 1
}
# Escape text for use in a shell script single-quoted string
escape_single_quotes() {
printf '%s' "$*" | sed -E "s/'/'\\\\''/g"
}
# Wrap all arguments in single-quotes and concatenate them
quote_eval_cmd() (
escaped_text=
for arg in "$@"; do
escaped_text="$escaped_text '$(escape_single_quotes "$arg")'"
done
printf '%s\n' "$escaped_text"
)
# Evaluate commands in a sub-shell, abort on error
run() {
log_info "$*"
__eval_cmd="$(quote_eval_cmd "$@")"
log_debug "__eval_cmd=$__eval_cmd"
(eval "$__eval_cmd") || abort 'Command failed, aborting'
}
# Evaluate commands in a sub-shell, ignore returned status code
run_() {
log_info "$*"
__eval_cmd="$(quote_eval_cmd "$@")"
log_debug "__eval_cmd=$__eval_cmd"
(eval "$__eval_cmd") || log_info 'Command failed, ignoring failure status'
}
read_arguments() {
target=
for arg in "$@"; do
case "$arg" in
PREFIX=*) PREFIX="${arg#'PREFIX='}" ;;
*) [ "$target" ] || target="$arg" ;;
esac
done
}
read_arguments "$@"
case "$target" in
install)
run install -DZ -m 755 -t "${PREFIX}/bin" "$app_name"
;;
uninstall)
run rm -f "${PREFIX}/bin/$app_name"
;;
lint)
run shellcheck "$app_name" make
run shfmt -p -i 4 -ci -d "$app_name" make
;;
format)
run shfmt -p -i 4 -ci -w make
;;
develop-image)
run podman build -f Containerfile.develop -t flatr-develop
;;
*) abort "No rule to make target '$target'" ;;
esac