chiark / gitweb /
WORKS
[subdirmk.git] / Makefile.in
1 ### -*-makefile-gmake-*-
2 ###
3 ### Top-level build script for toy project.
4 ###
5 ### (c) 2019 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 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.
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 Library General Public License for more details.
19 ###
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.
24
25 ## Default target.
26 all::
27
28 ###--------------------------------------------------------------------------
29 ### Configuration things.
30
31 ## (This is a toy.  More stuff is needed in a proper project.)
32
33 ## Source and build directories.
34 srcdir                   = @srcdir@
35 abs_srcdir               = @abs_srcdir@
36 abs_builddir             = @abs_builddir@
37
38 ## Installation directories.
39 prefix                   = @prefix@
40 exec_prefix              = @exec_prefix@
41 bindir                   = @bindir@
42
43 ## Build options.
44
45 ###--------------------------------------------------------------------------
46 ### Machinery.
47
48 dirvars                  =
49 dirtargets               =
50 ALL_SUBDIRS             :=
51 D                       :=
52 %dirstack               :=
53
54 dirvars                 += TARGETS PROGRAMS LIBS CLEANFILES
55 dirtargets              += all clean check install
56
57 define %descend-subdir
58   %dirstack             := $$D $$(%dirstack)
59   D                     := $$(if $$D,$$D/)$1
60   ALL_SUBDIRS           += $$D
61   include $$(srcdir)/$$D/Subdir.mk
62   D                     := $$(firstword $$(dirstack))
63   %dirstack             := $$(wordlist 2,$$(words $$(%dirstack)),$$(%dirstack))
64 endef
65 descend-subdirs          = $(foreach d,$1, \
66                                 $(eval $(call %descend-subdir,$d)))
67
68 V                        = 0
69 v-tag                    = $(call %v-tag.$V,$1)
70 %v-tag.0                 = @printf "  %-8s %s\n" "$1" "$@";
71 %v-tag.1                 =
72
73 V_AT                     = $(%V_AT.$V)
74 %V_AT.0                  = @
75 %V_AT.1                  =
76
77
78
79 ALL_DEPFILES            :=
80 notice-objects           = $(eval ALL_DEPFILES += $$(patsubst %.o,%.d,$1))
81
82 ###--------------------------------------------------------------------------
83 ### Descend into subdirectories.
84
85 SUBDIRS                  =
86
87 SUBDIRS                 += lib
88 SUBDIRS                 += src
89
90 $(call descend-subdirs, $(SUBDIRS))
91
92 ###--------------------------------------------------------------------------
93 ### Maintaining the build system.
94
95 ###--------------------------------------------------------------------------
96 ### More machinery.
97
98 all_dirtargets           = $(foreach d,$(ALL_SUBDIRS), \
99                                 $(foreach t,$(dirtargets), $d/$t))
100
101 $(all_dirtargets)::
102
103 ifeq ($(origin SUBDIR),undefined)
104 $(foreach t,$(dirtargets), \
105         $(eval $t:: $(foreach d,$(ALL_SUBDIRS),$d/$t)))
106 else
107 $(foreach t,$(dirtargets), \
108         $(eval $t:: $(SUBDIR)/$t))
109 endif
110 $(foreach d,$(SUBDIRS), \
111         $(foreach t,$(dirtargets), \
112                 $(eval $d/$t::)))
113 .PHONY: $(foreach t,$(dirtargets),$t $(foreach d,$(ALL_SUBDIRS),$d/$t))
114
115 $(foreach d,$(ALL_SUBDIRS), $d/clean):: %/clean:
116         rm -f $*/*.o $*/*.d $($*_CLEANFILES)
117
118 realclean:: clean
119         rm -f config.status config.log
120         rm -f Makefile $(foreach d,$(ALL_SUBDIRS), $d/Makefile)
121
122 -include $(ALL_DEPFILES)
123
124 ###----- That's all, folks --------------------------------------------------