chiark / gitweb /
Makefile: Support out-of-tree builds (badly).
[distorted-dkim] / Makefile
1 ### -*-makefile-*-
2
3 ###--------------------------------------------------------------------------
4 ### User-serviceable parts.
5
6 ## Source directory.
7 srcdir                  := $(dir $(lastword $(MAKEFILE_LIST)))
8
9 ## Installation directories.
10 prefix                   = /usr/local
11 exec_prefix              = ${prefix}
12 bindir                   = ${exec_prefix}/bin
13 datadir                  = ${prefix}/share
14 mandir                   = ${datadir}/man
15 man1dir                  = ${mandir}/man1
16
17 ## User configuration.
18 -include config.mk
19
20 ###--------------------------------------------------------------------------
21 ### Machinery.
22
23 ## Preliminaries.
24 all:
25 clean::
26 .PHONY: all clean
27 .SECONDEXPANSION:
28
29 force:
30 .PHONY: force
31
32 VPATH                    = $(srcdir)
33
34 ## Layout.
35 INSTDIRS                 =
36
37 INSTDIRS                += bin
38 bin_FILES                =
39 bin_INSTCMD              = install -t$(bindir) -m755
40
41 INSTDIRS                += man1
42 man1_FILES               =
43 man1_INSTCMD             = install -t$(man1dir) -m644
44
45 ## Version number.
46 VERSION                 := $(shell git describe --always --abbrev=4 --dirty=+)
47 -include version-stamp.mk
48 ifneq ($(VERSION),$(OLD_VERSION))
49   FORCE_VERSION          = force
50 else
51   FORCE_VERSION          =
52 endif
53 version-stamp.mk: $(FORCE_VERSION)
54         echo "OLD_VERSION = $(VERSION)" >$@.new && mv $@.new $@
55 clean::; rm version-stamp.mk
56
57 ## The main program.
58 bin_FILES               += dkim-keys
59 dkim-keys: dkim-keys.in version-stamp.mk
60         sed 's/@VERSION@/$(VERSION)/g' $< >$@.new && \
61                 chmod +x $@.new && mv $@.new $@
62
63 ## The manual.
64 man1_FILES              += dkim-keys.1
65 dkim-keys.1: dkim-keys.in version-stamp.mk
66         pod2man -s1 -dkim-keys -r"$(VERSION)" \
67                          -c"distorted.org.uk utilities" \
68                         $< >$@.new && \
69                 mv $@.new $@
70
71 ## Building.
72 TARGETS                  = $(foreach d,$(INSTDIRS), $($d_FILES))
73 all: $(TARGETS)
74 clean::; rm -f $(TARGETS)
75
76 ## Installation.
77 %/:; install -d $@
78
79 INSTALLS                 = $(addprefix install/, $(INSTDIRS))
80 install: $(INSTALLS)
81 $(INSTALLS): install/%: $$($$*_FILES) | $$($$*dir)/
82         $($*_INSTCMD) $+
83
84 UNINSTALLS               = $(addprefix uninstall/, $(INSTDIRS))
85 uninstall: $(UNINSTALLS)
86 $(UNINSTALLS): uninstall/%:
87         rm -f $(addprefix $($*dir)/,$($*_FILES))
88 .PHONY: install $(INSTALLS) uninstall $(UNINSTALLS)