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
|
prefix = /usr/local
bindir = $(prefix)/bin
libdir = $(prefix)/lib
systemddir = $(libdir)/systemd
user = nshd
group = nshd
NET ?= NET
CFLAGS = -std=c99 -Wall -Wextra -Werror -pedantic
CGO_CFLAGS = $(CFLAGS) -Wno-unused-parameter
CGO_ENABLED = 1
export CGO_ENABLED
cgo_variables = CGO_ENABLED CGO_CFLAGS CGO_CPPFLAGS CGO_CXXFLAGS CGO_LDFLAGS CC CXX
GOPATH := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
vp = .Makefile.var.%
deps = gopkg.in/yaml.v2
subdirs = src/nslcd_proto
all: build
include $(addsuffix /Makefile,$(subdirs))
secondary +=
download += $(addprefix src/,$(deps))
generate +=
build += bin/nshd nshd.service nshd.socket
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) $(addprefix .Makefile.var.,$(cgo_variables))
@true $(foreach f,$(filter $(vp),$^), && test $@ -nt $f ) || rm -rf -- bin pkg
GOPATH='$(GOPATH)' CGO_CFLAGS='$(CGO_CFLAGS)' go install nshd
%: %.in
< $< sed $(foreach v,$(patsubst $(vp),%,$(filter $(vp),$^)), -e 's|@$v@|$($v)|g' ) > $@
nshd.service: .Makefile.var.bindir .Makefile.var.user .Makefile.var.group
nshd.socket: .Makefile.var.user .Makefile.var.group
$(DESTDIR)$(bindir)/%: bin/%
install -TDm755 $< $@
$(DESTDIR)$(systemddir)/system/%.socket: %.socket
install -TDm644 $< $@
$(DESTDIR)$(systemddir)/system/%.service: %.service
install -TDm644 $< $@
.Makefile.var.%: FORCE
@printf '%s' '$($*)' > .tmp$@ && { cmp -s .tmp$@ $@ && rm -f -- .tmp$@ || mv -Tf .tmp$@ $@; } || { rm -f -- .tmp$@; false; }
.PHONY: FORCE
.SECONDARY:
.DELETE_ON_ERROR:
|