summaryrefslogtreecommitdiff
path: root/Makefile
blob: a745ecfc04c13f967df58ce600f4c33e0c502ad4 (plain)
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
# Copyright 2016 Luke Shumaker
# License: WTFPLv2

prefix = /usr/local
bindir = $(prefix)/bin
systemddir = $(prefix)/lib/systemd/system
sysconfdir = $(prefix)/etc
pkgconfdir = $(sysconfdir)/httpconnectd
DESTDIR = 
Q = @

########################################################################

MAKEFLAGS += -r
vars = $(patsubst .var.%,%,$(filter .var.%,$^))
build_targets += httpconnectd httpconnectd@.service httpconnectd.socket
build_targets += httpsconnectd httpsconnectd.service
build_targets += basicauth.conf-sample
install_targets += $(DESTDIR)$(bindir)/httpconnectd $(DESTDIR)$(systemddir)/httpconnectd@.service $(DESTDIR)$(systemddir)/httpconnectd.socket
install_targets += $(DESTDIR)$(bindir)/httpsconnectd $(DESTDIR)$(systemddir)/httpsconnectd.service $(DESTDIR)$(pkgconfdir)/https.conf
install_targets += $(DESTDIR)$(pkgconfdir)/basicauth.conf-sample

all: $(build_targets)
install: $(install_targets)
clean:
	rm -f -- httpconnectd httpconnectd.sh httpconnectd@.service
	rm -f -- httpsconnectd httpsconnectd.sh httpsconnectd.service
uninstall:
	rm -f -- $(install_targets)
	rmdir -p -- $(dir $(install_targets))
.PHONY: all install clean uninstall

httpconnectd@.service: .var.bindir
httpconnectd.sh: .var.pkgconfdir

httpsconnectd.service: .var.bindir
httpsconnectd.sh: .var.pkgconfdir

########################################################################

%: %.sh
	install -m755 $< $@

%: %.in
	$(if $(Q),$(Q)echo 'EDIT < $< > $@';)$(if $(vars),sed $(foreach v,$(vars), -e 's|@$(v)@|$($(v))|g' ),cat) < $< > $@

$(DESTDIR)$(bindir)/%: %
	install -Dm755 $< $@
$(DESTDIR)$(systemddir)/%: %
	install -Dm644 $< $@
$(DESTDIR)$(pkgconfdir)/%: %
	install -Dm644 $< $@

.var.%: FORCE
	$(Q)printf '%s' '$($*)' > .tmp$@ && { cmp -s .tmp$@ $@ && rm -f -- .tmp$@ || mv -Tf .tmp$@ $@; } || { rm -f -- .tmp$@; false; }

.DELETE_ON_ERROR:
.SECONDARY:
.PHONY: FORCE