-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake
executable file
·63 lines (61 loc) · 1.9 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
#!/bin/sh
# shellcheck disable=SC2046,SC2086
DSM_SKIP_CLI_OPTIONS='' DSM_SKIP_CLI_VARIABLES='' . ./dot-slash-make.sh
param BUILD_DIR=./dist
param PREFIX="${HOME}/.local"
version=0.1.0-pre
app_name=template.sh
dist_bin=${BUILD_DIR}/${app_name}
shell_scripts=$(wildcard ./*.sh ./make ./test/*.sh)
selinux_flag=-Z
# Detect if the SELinux flag (-Z) is supported by the install command on the target platform
case $(install -Z 2>&1) in *'unrecognized option'*) selinux_flag= ;; esac
lint() {
run shellcheck "$@"
run shfmt -d "$@"
}
build() {
case $version in *[!.0-9]*) version_is_pre_release=1 ;; *) version_is_pre_release= ;; esac
git_status=$(git --no-optional-locks status --porcelain) || abort "Failed to read git status"
git_last_commit_info=$(git --no-optional-locks log -1 --pretty='format:(%h %cs)') || abort "Failed to read git log"
git_tree_is_dirty=${git_status:+1}
version_git="${version}${git_tree_is_dirty:+"+dirty"}${version_is_pre_release:+ $git_last_commit_info}"
./template.sh -e VERSION=${version_git} ${app_name} >${dist_bin} || abort "Failed to write file ${dist_bin}"
chmod +x ${dist_bin} || abort "Failed to chmod file ${dist_bin}"
}
test() { run ./test/test.sh; }
for __target in $(list_targets); do
case "${__target}" in
dist | -)
run mkdir -p ${BUILD_DIR}
lint ${shell_scripts}
run build
lint ${dist_bin}
test
;;
install)
run install -D ${selinux_flag} -m 755 -t "${PREFIX}/bin" ${dist_bin}
;;
uninstall)
run rm -f "${PREFIX}/bin/${app_name}"
;;
clean)
test_output_files=$(wildcard ./test/*.out)
[ ! "$test_output_files" ] || run_ rm -r ${test_output_files}
;;
test)
test
;;
lint)
lint ${shell_scripts} ${dist_bin}
;;
format)
run shfmt -w ${shell_scripts}
;;
dev-image)
run podman build -f Containerfile.dev -t template-sh-dev
;;
# dot-slash-make: This * case must be last and should not be changed
*) abort "No rule to make target '${__target}'" ;;
esac
done