summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-08-23 20:07:28 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2018-08-23 20:07:28 -0400
commitd31a16c435e497f320ccfa880122dff963f151a7 (patch)
tree35d5c3423f3f77743f2e89dee17cff88a9511d2b /Makefile
parent799e0edc196c4273b728b9f832d90dc79bbf8bbe (diff)
Organize in to an installable packagev20180714
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile73
1 files changed, 73 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..f3e2a11
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,73 @@
+# Copyright (C) 2016-2018 Luke Shumaker
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+# GNU standard settings
+prefix = /usr/local
+exec_prefix = $(prefix)
+bindir = $(exec_prefix)/bin
+localstatedir = $(prefix)/var
+runstatedir = $(or $(shell systemd-path system-runtime 2>/dev/null),$(localstatedir)/run)
+sysconfdir = $(prefix)/etc
+
+# systemd settings
+rootprefix = $(prefix)
+systemunitdir = $(or $(shell pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null),$(rootprefix)/lib/systemd/system)
+
+# other
+pkgconfdir = $(sysconfdir)/conf.d/qemu.d
+BINPROG = $(bindir)/qemu
+SOCAT = /bin/socat
+
+outdir = .
+srcdir = .
+
+####
+
+files.out.all += qemu qemu@.service
+
+files.sys.all += $(BINPROG)
+files.sys.all += $(systemunitdir)/qemu@.service
+files.sys.all += $(pkgconfdir)
+
+var = $(patsubst ./%,%,$(outdir)/.var.)
+
+all: $(addprefix $(outdir)/,$(files.out.all))
+clean:
+ rm -f -- $(addprefix $(outdir)/,$(files.out.all))
+install: $(addprefix $(DESTDIR),$(files.sys.all))
+.PHONY: all clean install
+.SECONDARY:
+.DELETE_ON_ERROR:
+
+$(outdir)/qemu: $(var)runstatedir $(var)pkgconfdir
+$(outdir)/qemu@.service: $(var)runstatedir $(var)BINPROG $(var)SOCAT
+$(outdir)/%: $(srcdir)/%.in
+ sed $(foreach v,$(patsubst $(var)%,%,$(filter $(var)%,$^)),-e 's|@$v@|$($v)|g') < $< > $@
+
+$(DESTDIR)$(BINPROG): $(outdir)/qemu
+ install -DTm755 $< $@
+$(DESTDIR)$(systemunitdir)/%: $(outdir)/%
+ install -DTm644 $< $@
+$(DESTDIR)$(pkgconfdir): $(wildcard $(srcdir)/examples/*)
+ install -Dm644 -t $@ -- $^
+ test -d $@
+ touch $@
+
+####
+
+# Magic to depend on the value of variables
+
+.PHONY: FORCE
+$(var)%: FORCE
+ @printf '%s' $(call quote.shell,$($*)) | sed 's/^/#/' | ./write-ifchanged $@
+-include $(wildcard $(var)*)
+
+define at.nl
+
+
+endef
+
+# I put this as the last line in the file because it confuses Emacs
+# syntax highlighting and makes the remainder of the file difficult to
+# edit.
+quote.shell = $(subst $(at.nl),'$$'\n'','$(subst ','\'',$1)')