-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
95 lines (77 loc) · 2.41 KB
/
Makefile
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
NAME=gut
VERSION=0.0.1
files=$(wildcard *.sh *.sed)
shell_files=$(wildcard *.sh)
programs=$(addprefix bin/, $(files))
shell_programs=$(addprefix bin/, $(shell_files))
INSTALL_DIR=${HOME}/bin
installed_programs=$(addprefix $(INSTALL_DIR)/, $(notdir $(programs)))
installed_links=$(basename $(installed_programs))
default: all
bin:; mkdir -p $@
bin/%.sh : %.sh | bin
cp $< $@
bin/%.sed : %.sed | bin
cp $< $@
$(INSTALL_DIR):; mkdir -p $(INSTALL_DIR)
.PHONY: help
## Display helpful information:
## - which gut programs are installed
## - the installation directory
## - the most relevant targets
## and other helpful information.
help:
$(info installed programs are: $(installed_programs))
$(info installed links are: $(installed_links))
$(info installation directory: $(INSTALL_DIR))
@printf "\n"
@printf "A (non-exhaustive and generated) list of available targets:\n\n"
@awk -f list-make-targets.awk \
$(MAKEFILE_LIST) | sort | sed 's/\r/\n\t\t/g'
@echo "for a full list, please consult the make file"
$(INSTALL_DIR)/%.sh : bin/%.sh | $(INSTALL_DIR)
cp $< $@
chmod +x $@
$(INSTALL_DIR)/%.sed : bin/%.sed | $(INSTALL_DIR)
cp $< $@
chmod +x $@
$(INSTALL_DIR)/% : $(INSTALL_DIR)/%.sh
ln -fs $< $@
$(INSTALL_DIR)/% : $(INSTALL_DIR)/%.sed
ln -fs $< $@
## Make all of gut
all: $(installed_programs) $(installed_links)
## Uninstall all of gut
uninstall:
find $(installed_programs) $(installed_links) -delete
clean:
rm bin/*
## Compile all bash scripts with flags to
## set -e fail on error
## set -u fail on unbound variable
## set -o pipefail erros in pipeilines
debug: $(shell_programs)
sed -i -e '1 { /^#!\/bin\/bash$$/!q; }' \
-e '2 { /^set -[eu]*xo\{0,1\} pipefail$$/{p;d;}' \
-e '/^\(set -eu\)\(o\)\{0,1\}/{ s@@\1x\2@;p;d }' \
-e 's@^@set -euxo pipefail\n@ }' $?
debug_all: debug all
.PHONY: lint
## Run linter on files in project
lint: \
lint-python \
lint-shell
.PHONY: lint-python
## Run autopep8 on python files and fix the following errors:
## E301 - Add missing blank line.
## E302 - Add missing 2 blank lines.
## E303 - Remove extra blank lines.
## E304 - Remove blank line following function decorator.
## E305 - Expected 2 blank lines after end of function or class.
## E306 - Expected 1 blank line before a nested definition.
lint-python: **/*.py
autopep8 -i --select=E301,E302,E303,E304,E305,E306 $^
.PHONY: lint-shell
## Run shellcheck on all shell scripts.
lint-shell: **/*.sh
shellcheck -f gcc $^