chiark / gitweb /
Makefile: Better `install' targets, with hostnames only.
[exim-config] / Makefile
1 ### -*-makefile-*-
2 ###
3 ### Build script for Exim configuration
4 ###
5 ### (c) 2012 Mark Wooding
6 ###
7
8 ###----- Licensing notice ---------------------------------------------------
9 ###
10 ### This program is free software; you can redistribute it and/or modify
11 ### it under the terms of the GNU General Public License as published by
12 ### the Free Software Foundation; either version 2 of the License, or
13 ### (at your option) any later version.
14 ###
15 ### This program is distributed in the hope that it will be useful,
16 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ### GNU General Public License for more details.
19 ###
20 ### You should have received a copy of the GNU General Public License
21 ### along with this program; if not, write to the Free Software Foundation,
22 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 V = 0
25 v_tag = $(call v_tag_$V,$1)
26 v_tag_0 = @printf "  %-6s %s\n" $1 $@;
27
28 V_GEN = $(call v_tag,GEN)
29 V_AT = $(V_AT_$V)
30 V_AT_0 = @
31
32 dir-nosl = $(patsubst %/,%,$(dir $1))
33
34 all:
35 .SECONDEXPANSION: # sorry
36
37 CLEANFILES              += $(TARGETS)
38
39 EARLY                    = defs.m4 divmap.m4 config.m4
40 MAIN                     = lists.m4 base.m4
41
42 MODES                    =
43
44 MODES                   += satellite
45 OPTIONS_satellite        = satellite.m4
46
47 MODES                   += hub
48 OPTIONS_hub              = auth.m4 exchange.m4 local.m4 spam.m4 vhost.m4
49
50 MODES                   += usersat
51 OPTIONS_usersat          = auth.m4 local.m4 satellite.m4
52
53 -include local.mk
54
55 HOST_MODES              += $(foreach m, $(MODES), \
56                                 $(foreach h, $(HOSTS_$m), $h/$m))
57
58 CONFIGS                  = $(foreach m, $(MODES), exim4-$m.conf)
59 TARGETS                 += $(CONFIGS)
60 $(CONFIGS): exim4-%.conf: $(EARLY) $$(HOOKS_$$*) $(MAIN) $$(OPTIONS_$$*)
61         $(V_GEN)m4 -P -DMODE=$* $^ >$@.new
62         $(V_AT)$(CHECK_$*)exim4 -C$@.new -bV >/dev/null
63         $(V_AT)mv $@.new $@
64
65 all: $(TARGETS)
66
67 host-mode                = $(notdir $(filter $1/%, $(HOST_MODES)))
68
69 HOSTS                    = $(sort $(call dir-nosl, $(HOST_MODES)))
70 THISHOST                 = $(shell hostname)
71 OTHERHOSTS               = $(filter-out $(THISHOST), $(HOSTS))
72
73 ROOT                     = sudo
74
75 install/$(THISHOST): exim4-$(call host-mode,$(THISHOST)).conf
76         $(ROOT) install -m644 $< /etc/exim4/exim4.conf
77         $(ROOT) service exim4 reload
78
79 show:
80         : $(addprefix install/, $(OTHERHOSTS))
81
82 $(addprefix install/, $(OTHERHOSTS)): \
83 install/%: exim4-$$(call host-mode,$$*).conf
84         $(ROOT) scp $< root@$*:/etc/exim4/exim4.conf
85         $(ROOT) ssh root@$* service exim4 reload
86
87 install: $(addprefix install/, $(HOSTS))
88
89 clean:; rm -f $(CLEANFILES)
90 .PHONY: clean