-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
142 lines (114 loc) · 4.95 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
PROGRAM := openvpn3-indicator
DESTDIR ?=
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
DATADIR ?= $(PREFIX)/share
AUTOSTART ?= /etc/xdg/autostart
VERSION ?= $(shell git log -n 1 --format=format:devel-%cd-%h --date=format-local:%Y%m%d%H%M%S)
PREPAREDIR ?= build/prepare
DESTDIR := $(DESTDIR:/=)
PREFIX := $(PREFIX:/=)
BINDIR := $(BINDIR:/=)
DATADIR := $(DATADIR:/=)
AUTOSTART := $(AUTOSTART:/=)
PREPAREDIR := $(PREPAREDIR:/=)
SOURCES := $(shell find src -iname tests -prune -o -iname __pycache__ -prune -o -iname about.py -o -type f -print)
ABOUT := $(shell find src -type f -iname about.py)
SHARES := $(shell find share -type f -not -iname "*.[1-8]" -not -iname "*.desktop" -not -iname "*.bak" -not -iname "*.swp")
SHARES := $(patsubst share/%,%,$(SHARES))
MANS := $(shell find share -type f -iname "*.[1-8]")
MANS := $(patsubst share/%,%,$(MANS))
APPLICATION := $(shell find share -type f -iname "*.desktop")
APPLICATION := $(patsubst share/%,%,$(APPLICATION))
PREPARE_SOURCES := $(patsubst src/%,$(PREPAREDIR)/%,$(SOURCES))
PREPARE_ABOUT := $(patsubst src/%,$(PREPAREDIR)/%,$(ABOUT))
INSTALL_SHARES := $(patsubst %,$(DESTDIR)$(DATADIR)/%,$(SHARES))
INSTALL_SHARES := $(patsubst %,$(DESTDIR)$(DATADIR)/%,$(SHARES))
INSTALL_MANS := $(patsubst %,$(DESTDIR)$(DATADIR)/%.gz,$(MANS))
INSTALL_APPLICATION := $(patsubst %,$(DESTDIR)$(DATADIR)/%,$(APPLICATION))
INSTALL_AUTOSTART := $(DESTDIR)$(AUTOSTART)/$(PROGRAM).desktop
DEVEL_SHARES := $(patsubst %,$(HOME)/.local/share/%,$(SHARES))
#DEVEL_MANS :=
DEVEL_APPLICATION := $(patsubst %,$(HOME)/.local/share/%,$(APPLICATION))
DEVEL_AUTOSTART := $(HOME)/.config/autostart/$(PROGRAM).desktop
.PHONY: default
default:
@echo "This is Makefile for $(PROGRAM). It does nothing by default."
@echo
@echo "Use *** sudo make install *** to install $(PROGRAM) in $(PREFIX) for all users."
@echo
@echo "Use *** make devel *** to install symlinks to $(PROGRAM) in the current folder for the current user only."
@echo "This is the way for developers."
@echo
@echo "Use *** sudo make uninstall *** or *** make indevel *** to uninstall $(PROGRAM)."
@echo
@echo "Program version is $(VERSION)"
@echo
.PHONY: all
all: $(PROGRAM)
$(PROGRAM): $(PREPARE_SOURCES) $(PREPARE_ABOUT) Makefile scripts/build_executable
scripts/build_executable --directory $(PREPAREDIR) --executable $@
$(PREPARE_SOURCES): $(PREPAREDIR)/% : src/%
@install --directory $(dir $@)
install --mode 0644 $< $@
$(PREPARE_ABOUT): $(PREPAREDIR)/% : src/%
@install --directory $(dir $@)
install --mode 0644 $< $@
sed -E -e "s|^( *APPLICATION_VERSION *= *)'[^']*'$$|\1'$(VERSION)'|" -i $@
.PHONY: package
package: $(DESTDIR)$(BINDIR)/$(PROGRAM) $(INSTALL_SHARES) $(INSTALL_MANS) $(INSTALL_AUTOSTART)
.PHONY: install
install: package
update-desktop-database $(DESTDIR)$(DATADIR)/applications
update-mime-database $(DESTDIR)$(DATADIR)/mime
gtk-update-icon-cache -f -t $(DESTDIR)$(DATADIR)/icons/*
$(DESTDIR)$(BINDIR)/$(PROGRAM) : $(PROGRAM)
@install --directory $(dir $@)
install --mode 0755 $< $@
$(INSTALL_SHARES): $(DESTDIR)$(DATADIR)/% : share/%
@install --directory $(dir $@)
install --mode 0644 $< $@
$(INSTALL_MANS): $(DESTDIR)$(DATADIR)/%.gz : share/%
@install --directory $(dir $@)
gzip --stdout $< > $@
@chmod 0644 $@
$(INSTALL_APPLICATION): share/$(APPLICATION)
@install --directory $(dir $@)
sed -E -e "s|/usr/bin/|$(BINDIR)/|g" $< > $@
@chmod 0644 $@
$(INSTALL_AUTOSTART) : $(INSTALL_APPLICATION)
@install --directory $(dir $@)
install --mode 0644 $< $@
.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)$(BINDIR)/$(PROGRAM) $(INSTALL_SHARES) $(INSTALL_MANS) $(INSTALL_APPLICATION) $(INSTALL_AUTOSTART)
update-desktop-database $(DESTDIR)$(DATADIR)/applications
update-mime-database $(DESTDIR)$(DATADIR)/mime
gtk-update-icon-cache -f -t $(DESTDIR)$(DATADIR)/icons/*
.PHONY: devel
devel: $(HOME)/.local/bin/$(PROGRAM) $(DEVEL_SHARES) $(DEVEL_APPLICATION) $(DEVEL_AUTOSTART)
update-desktop-database $(HOME)/.local/share/applications
update-mime-database $(HOME)/.local/share/mime
gtk-update-icon-cache -f -t $(HOME)/.local/share/icons/*
$(HOME)/.local/bin/$(PROGRAM) : src/__main__.py
@install --directory $(dir $@)
ln --force --symbolic $(abspath $<) $@
$(DEVEL_SHARES): $(HOME)/.local/share/% : share/%
@install --directory $(dir $@)
ln --force --symbolic $(abspath $<) $@
$(DEVEL_APPLICATION): share/$(APPLICATION)
@install --directory $(dir $@)
sed -E -e "s|/usr/|$(HOME)/.local/|g" $< > $@
@chmod 0644 $@
$(DEVEL_AUTOSTART) : $(DEVEL_APPLICATION)
@install --directory $(dir $@)
ln --force --symbolic $(abspath $<) $@
.PHONY: undevel
undevel:
rm -f $(HOME)/.local/bin/$(PROGRAM) $(DEVEL_SHARES) $(DEVEL_APPLICATION) $(DEVEL_AUTOSTART)
update-desktop-database $(HOME)/.local/share/applications
update-mime-database $(HOME)/.local/share/mime
gtk-update-icon-cache -f -t $(HOME)/.local/share/icons/*
.PHONY: spellcheck
spellcheck: README.md share/applications/*.desktop share/man/*/*.1
for file in $^; do aspell --home-dir=. --save-repl --lang=en_US.UTF-8 check $$file; done