summaryrefslogtreecommitdiff
path: root/Makefile
blob: 32cf638e36fdd4a1f11724c9b3e8a9a157fd7b0b (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
prefix = /usr/local
bindir = $(prefix)/bin
libdir = $(prefix)/lib
systemddir = $(libdir)/systemd

GOPATH := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))

deps = gopkg.in/yaml.v2
subdirs = src/nslcd_proto

all: build

include $(addsuffix /Makefile,$(subdirs))

secondary += 
download += $(addprefix src/,$(deps))
generate +=
build += bin/nshd
install += $(addprefix $(DESTDIR),$(bindir)/nshd $(systemddir)/system/nshd.socket $(systemddir)/system/nshd.service)

download: $(download)
generate: $(generate)
build: $(build)
install: $(install)
.PHONY: download generate build install

clean:
	rm -rf -- pkg bin src/*.*/
	rm -f -- $(generate) $(build) $(secondary)
.PHONY: clean

uninstall:
	rm -f -- $(install)
	rmdir -p -- $(sort $(dir $(install))) 2>/dev/null || true
.PHONY: uninstall

$(foreach d,$(deps),$(eval src/$d: NET; GOPATH='$(GOPATH)' go get -d -u $d))
.PHONY: NET

bin/nshd: $(download) $(generate) $(shell find src -name .git -prune -o -print)
	GOPATH='$(GOPATH)' go install nshd

$(DESTDIR)$(bindir)/%: bin/%
	install -Dm755 $< $@
$(DESTDIR)$(systemddir)/system/%.socket: %.socket
	install -Dm644 $< $@
$(DESTDIR)$(systemddir)/system/%.service: %.service
	install -Dm644 $< $@

.SECONDARY:
.DELETE_ON_ERROR: