summaryrefslogtreecommitdiff
path: root/build-aux/Makefile.each.tail/10-std.mk
blob: d32ec9b26e7bc780f5942f81d7f7dc326cf54af9 (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
# Copyright (C) 2015-2016  Luke Shumaker
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# Add some more defaults to the *_files variables
std.clean_files += $(std.gen_files) $(std.cfg_files) $(std.out_files)

# Fix each variable at its current value to avoid any weirdness
$(foreach c,src gen cfg out sys clean slow,$(eval std.$c_files := $$(std.$c_files)))

# Make each of the standard variables relative to the correct directory
std.src_files   := $(addprefix $(srcdir)/,$(std.src_files))
std.gen_files   := $(addprefix $(srcdir)/,$(std.gen_files))
std.cfg_files   := $(addprefix $(outdir)/,$(std.cfg_files))
std.out_files   := $(addprefix $(outdir)/,$(std.out_files))
std.sys_files   := $(addprefix $(DESTDIR),$(std.sys_files))
std.clean_files := $(addprefix $(outdir)/,$(std.clean_files))
std.slow_files  := $(addprefix $(outdir)/,$(std.slow_files))

# Creative targets
$(outdir)/build      :        $(std.out_files)
$(outdir)/install    :        $(std.sys_files)
$(outdir)/installdirs: $(sort $(dir $(std.sys_files)))

# Destructive targets
_std.uninstall/$(outdir)        := $(std.sys_files)
_std.mostlyclean/$(outdir)      := $(filter-out $(std.slow_files) $(std.cfg_files) $(std.gen_files) $(std.src_files),$(std.clean_files))
_std.clean/$(outdir)            := $(filter-out                   $(std.cfg_files) $(std.gen_files) $(std.src_files),$(std.clean_files))
_std.distclean/$(outdir)        := $(filter-out                                    $(std.gen_files) $(std.src_files),$(std.clean_files))
_std.maintainer-clean/$(outdir) := $(filter-out                                                     $(std.src_files),$(std.clean_files))
$(addprefix $(outdir)/,uninstall mostlyclean clean distclean maintainer-clean): %: %-hook
	$(RM)    -- $(sort $(filter-out %/,$(_std.$(@F)/$(@D))))
	$(RM) -r -- $(sort $(filter     %/,$(_std.$(@F)/$(@D))))
	$(RMDIR_P) $(sort $(dir $(_std.$(@F)/$(@D)))) 2>/dev/null || $(TRUE)
$(foreach t,uninstall mostlyclean clean distclean maintainer-clean, $(outdir)/$t-hook)::
.PHONY: $(foreach t,uninstall mostlyclean clean distclean maintainer-clean, $(outdir)/$t-hook)