-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
42 lines (36 loc) · 1.42 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
PREFIX ?= /usr/local
BINPREFIX ?= "$(PREFIX)/bin"
BINS = $(wildcard bin/git-*)
COMMANDS = $(subst bin/, , $(BINS))
default: install
install: mkdir_prefix
@echo "... installing bins to $(DESTDIR)$(BINPREFIX)"
$(eval TEMPFILE := $(shell mktemp -q $${TMPDIR:-/tmp}/star-git-tools.XXXXXX 2>/dev/null || mktemp -q))
@# chmod from rw-------(default) to rwxrwxr-x, so that users can exec the scripts
@chmod 775 $(TEMPFILE)
$(eval EXISTED_ALIASES := $(shell \
git config --get-regexp 'alias.*' | awk '{print "git-" substr($$1, 7)}'))
@$(foreach COMMAND, $(COMMANDS), \
disable=''; \
if test ! -z "$(filter $(COMMAND), $(EXISTED_ALIASES))"; then \
read -p "$(COMMAND) conflicts with an alias, still install it and disable the alias? [y/n]" answer; \
test "$$answer" = 'n' -o "$$answer" = 'N' && disable="true"; \
fi; \
if test -z "$$disable"; then \
echo "... installing $(COMMAND)"; \
cat bin/$(COMMAND) > $(TEMPFILE); \
cp -f $(TEMPFILE) $(DESTDIR)$(BINPREFIX)/$(COMMAND); \
fi; \
)
$(eval BINPATH := $(shell cd $(DESTDIR)$(BINPREFIX) && pwd))
@echo
@echo "Make sure $(BINPATH) is in your PATH. E.g. add to your ~/.bashrc"
@echo "export PATH+=\":$(BINPATH)\""
mkdir_prefix:
@mkdir -p $(DESTDIR)$(BINPREFIX)
uninstall:
@$(foreach BIN, $(BINS), \
echo "... uninstalling $(DESTDIR)$(BINPREFIX)/$(notdir $(BIN))"; \
rm -f $(DESTDIR)$(BINPREFIX)/$(notdir $(BIN)); \
)
.PHONY: default install uninstall mkdir_prefix