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: