1 ### -*-makefile-gmake-*-
3 ### Top-level build script for toy project.
5 ### (c) 2019 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This program is free software; you can redistribute it and/or modify
11 ### it under the terms of the GNU Library General Public License as
12 ### published by the Free Software Foundation; either version 2 of the
13 ### License, or (at your option) any later version.
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 Library General Public License for more details.
20 ### You should have received a copy of the GNU Library General Public
21 ### License along with this program; if not, write to the Free
22 ### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 ### MA 02111-1307, USA.
28 ###--------------------------------------------------------------------------
29 ### Configuration things.
31 ## (This is a toy. More stuff is needed in a proper project.)
33 ## Source and build directories.
35 abs_srcdir = @abs_srcdir@
36 abs_builddir = @abs_builddir@
38 ## Installation directories.
40 exec_prefix = @exec_prefix@
45 ###--------------------------------------------------------------------------
54 dirvars += TARGETS PROGRAMS LIBS CLEANFILES
55 dirtargets += all clean check install
57 define %descend-subdir
58 %dirstack := $$D $$(%dirstack)
59 D := $$(if $$D,$$D/)$1
61 include $$(srcdir)/$$D/Subdir.mk
62 D := $$(firstword $$(dirstack))
63 %dirstack := $$(wordlist 2,$$(words $$(%dirstack)),$$(%dirstack))
65 descend-subdirs = $(foreach d,$1, \
66 $(eval $(call %descend-subdir,$d)))
69 v-tag = $(call %v-tag.$V,$1)
70 %v-tag.0 = @printf " %-8s %s\n" "$1" "$@";
80 notice-objects = $(eval ALL_DEPFILES += $$(patsubst %.o,%.d,$1))
82 ###--------------------------------------------------------------------------
83 ### Descend into subdirectories.
90 $(call descend-subdirs, $(SUBDIRS))
92 ###--------------------------------------------------------------------------
93 ### Maintaining the build system.
95 ###--------------------------------------------------------------------------
98 all_dirtargets = $(foreach d,$(ALL_SUBDIRS), \
99 $(foreach t,$(dirtargets), $d/$t))
103 ifeq ($(origin SUBDIR),undefined)
104 $(foreach t,$(dirtargets), \
105 $(eval $t:: $(foreach d,$(ALL_SUBDIRS),$d/$t)))
107 $(foreach t,$(dirtargets), \
108 $(eval $t:: $(SUBDIR)/$t))
110 $(foreach d,$(SUBDIRS), \
111 $(foreach t,$(dirtargets), \
113 .PHONY: $(foreach t,$(dirtargets),$t $(foreach d,$(ALL_SUBDIRS),$d/$t))
115 $(foreach d,$(ALL_SUBDIRS), $d/clean):: %/clean:
116 rm -f $*/*.o $*/*.d $($*_CLEANFILES)
119 rm -f config.status config.log
120 rm -f Makefile $(foreach d,$(ALL_SUBDIRS), $d/Makefile)
122 -include $(ALL_DEPFILES)
124 ###----- That's all, folks --------------------------------------------------