summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
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)')