summaryrefslogtreecommitdiff
path: root/Makefile
blob: f3e2a11e990c84ade71c95f1d06530e83e844872 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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)')