summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile100
1 files changed, 39 insertions, 61 deletions
diff --git a/Makefile b/Makefile
index 8630cd8..5d1dbb4 100644
--- a/Makefile
+++ b/Makefile
@@ -20,95 +20,73 @@
# <http://www.gnu.org/licenses/>.
MAKEFLAGS += --no-builtin-rules
+
prefix = /usr/local
bindir = $(prefix)/bin
libdir = $(prefix)/lib
systemddir = $(libdir)/systemd
+Q ?= @
+#NET ?= FORCE
+
user = nshd
group = nshd
-NET ?= FORCE
-
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 = go c s S cc cpp cxx h hh hpp hxx
-gosrc_cmd = find -L src -name '.*' -prune -o \( -type f \( -false $(foreach e,$(goext),-o -name '*.$e') \) -o -type d \) -print
-gosrc = $(shell $(gosrc_cmd))
-GOPATH := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
-
-vp = .Makefile.var.%
-
-deps = gopkg.in/yaml.v2
-subdirs = src/nslcd/proto
+deps += gopkg.in/yaml.v2
+deps += lukeshu.com/git/go/libgnulinux.git/dl
+deps += lukeshu.com/git/go/libgnulinux.git/getgr
+deps += lukeshu.com/git/go/libgnulinux.git/inotify
+deps += lukeshu.com/git/go/libnslcd.git/proto
+deps += lukeshu.com/git/go/libnslcd.git/systemd
+deps += lukeshu.com/git/go/libsystemd.git/sd_daemon
-all: build
+srcdir := $(abspath $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))))
+topdir := $(srcdir)
-include $(addsuffix /Makefile,$(subdirs))
+subdirs = src/lukeshu.com/git/go/libnslcd.git/proto
-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
+generate += $(addprefix $(topdir)/src/,$(deps))
+generate += $(topdir)/LICENSE.lgpl-2.1.txt $(topdir)/LICENSE.gpl-2.txt $(topdir)/LICENSE.apache-2.0.txt
+generate_secondary += $(topdir)/src/*.*/
+build += $(topdir)/bin/nshd $(topdir)/nshd.service $(topdir)/nshd.socket $(topdir)/test/runner
+build_secondary += $(topdir)/test/*.o
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 -- $(build) $(secondary)
-.PHONY: clean
-maintainer-clean: clean
- rm -f -- $(generate)
-.PHONY: maintainer-clean
-uninstall:
- rm -f -- $(install)
- rmdir -p -- $(sort $(dir $(install))) 2>/dev/null || true
-.PHONY: uninstall
+ifeq (1,$(words $(MAKEFILE_LIST)))
+ include $(topdir)/common.mk
+endif
-LICENSE.lgpl-2.1.txt: $(NET)
+$(topdir)/LICENSE.lgpl-2.1.txt: $(NET)
curl https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt > $@
-LICENSE.gpl-2.txt: $(NET)
+$(topdir)/LICENSE.gpl-2.txt: $(NET)
curl https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt > $@
-LICENSE.apache-2.0.txt: $(NET)
+$(topdir)/LICENSE.apache-2.0.txt: $(NET)
curl https://www.apache.org/licenses/LICENSE-2.0 > $@
+
+include $(topdir)/golang.mk
-$(foreach d,$(deps),$(eval src/$d: $(NET); GOPATH='$(GOPATH)' go get -d -u $d))
+$(call goget,$(topdir),$(deps))
-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
+$(topdir)/bin/nshd: $(generate) $(configure) $(call gosrc,$(topdir))
+ $(call goinstall,$(topdir),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
+%.o: %.c .var.CC .var.CPPFLAGS .var.CFLAGS
+ $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(filter-out .var.%,$^)
+%: %.o .var.CC .var.LDFLAGS .var.LOADLIBES .var.LDLIBS
+ $(CC) $(LDFLAGS) -o $@ $(filter-out .var.%,$^) $(LOADLIBES) $(LDLIBS)
+%: %.in
+ < $< sed $(foreach v,$(patsubst .var.%,%,$(filter .var.%,$^)), -e 's|@$v@|$($v)|g' ) > $@
+$(topdir)/nshd.service: .var.bindir .var.user .var.group
+$(topdir)/nshd.socket: .var.user .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: