# Copyright 2015 Luke Shumaker . # # This is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # # The GNU General Public License's references to "object code" and # "executables" are to be interpreted to also include the output of # any document formatting or typesetting system, including # intermediate and printed output. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this manual; if not, see # . MAKEFLAGS += --no-builtin-rules 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 goext = c s S cc cpp cxx h hh hpp hxx gosrc = $(shell find -L src -name '.*' -prune -o \( -type f \( $(foreach e,$(goext), -name '*.$e' ) \) -o -type d \) -print) 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 += test/*.o download += $(addprefix src/,$(deps)) generate += LICENSE.lgpl-2.1.txt LICENSE.gpl-2.txt LICENSE.apache-2.0.txt build += bin/nshd nshd.service nshd.socket test/runner 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 LICENSE.lgpl-2.1.txt: $(NET) curl https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt > $@ LICENSE.gpl-2.txt: $(NET) curl https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt > $@ LICENSE.apache-2.0.txt: $(NET) curl https://www.apache.org/licenses/LICENSE-2.0 > $@ $(foreach d,$(deps),$(eval src/$d: $(NET); GOPATH='$(GOPATH)' go get -d -u $d)) bin/nshd: $(download) $(generate) $(gosrc) $(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 $< $@ %.o: %.c .Makefile.var.CC .Makefile.var.CPPFLAGS .Makefile.var.CFLAGS $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(filter-out $(vp),$^) %: %.o .Makefile.var.CC .Makefile.var.LDFLAGS .Makefile.var.LOADLIBES .Makefile.var.LDLIBS $(CC) $(LDFLAGS) -o $@ $(filter-out $(vp),$^) $(LOADLIBES) $(LDLIBS) .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: .PHONY: NET