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 $(srcdir)/configure: $(srcdir)/configure.ac
96 $(call v-tag,AUTOCONF)cd $(srcdir) && autoconf
98 config.status: $(srcdir)/configure
99 $(call v-tag,CONFIG)./config.status --recheck
101 Makefile: config.status $(srcdir)/Makefile.in \
102 $(foreach d,$(ALL_SUBDIRS), $d/Makefile)
103 $(call v-tag,SUBST)./config.status Makefile
104 $(foreach d,$(ALL_SUBDIRS), \
105 $(eval $d/Makefile: config.status $$(srcdir)/$d/Makefile.in; \
106 $$(call v-tag,SUBST)./config.status $$@))
108 ###--------------------------------------------------------------------------
111 all_dirtargets = $(foreach d,$(ALL_SUBDIRS), \
112 $(foreach t,$(dirtargets), $d/$t))
116 ifeq ($(origin SUBDIR),undefined)
117 $(foreach t,$(dirtargets), \
118 $(eval $t:: $(foreach d,$(ALL_SUBDIRS),$d/$t)))
120 $(foreach t,$(dirtargets), \
121 $(eval $t:: $(SUBDIR)/$t))
123 $(foreach d,$(SUBDIRS), \
124 $(foreach t,$(dirtargets), \
126 .PHONY: $(foreach t,$(dirtargets),$t $(foreach d,$(ALL_SUBDIRS),$d/$t))
128 $(foreach d,$(ALL_SUBDIRS), $d/clean):: %/clean:
129 rm -f $*/*.o $*/*.d $($*_CLEANFILES)
132 rm -f config.status config.log
133 rm -f Makefile $(foreach d,$(ALL_SUBDIRS), $d/Makefile)
135 -include $(ALL_DEPFILES)
137 ###----- That's all, folks --------------------------------------------------