### -*-makefile-gmake-*- ### ### Top-level build script for toy project. ### ### (c) 2019 Mark Wooding ### ###----- Licensing notice --------------------------------------------------- ### ### This program is free software; you can redistribute it and/or modify ### it under the terms of the GNU Library General Public License as ### published by the Free Software Foundation; either version 2 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 Library General Public License for more details. ### ### You should have received a copy of the GNU Library General Public ### License along with this program; if not, write to the Free ### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ### MA 02111-1307, USA. ## Default target. all:: ###-------------------------------------------------------------------------- ### Configuration things. ## (This is a toy. More stuff is needed in a proper project.) ## Source and build directories. srcdir = @srcdir@ abs_srcdir = @abs_srcdir@ abs_builddir = @abs_builddir@ ## Installation directories. prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ ## Build options. ###-------------------------------------------------------------------------- ### Machinery. dirvars = dirtargets = ALL_SUBDIRS := D := %dirstack := dirvars += TARGETS PROGRAMS LIBS CLEANFILES dirtargets += all clean check install define %descend-subdir %dirstack := $$D $$(%dirstack) D := $$(if $$D,$$D/)$1 ALL_SUBDIRS += $$D include $$(srcdir)/$$D/Subdir.mk D := $$(firstword $$(dirstack)) %dirstack := $$(wordlist 2,$$(words $$(%dirstack)),$$(%dirstack)) endef descend-subdirs = $(foreach d,$1, \ $(eval $(call %descend-subdir,$d))) V = 0 v-tag = $(call %v-tag.$V,$1) %v-tag.0 = @printf " %-8s %s\n" "$1" "$@"; %v-tag.1 = V_AT = $(%V_AT.$V) %V_AT.0 = @ %V_AT.1 = ALL_DEPFILES := notice-objects = $(eval ALL_DEPFILES += $$(patsubst %.o,%.d,$1)) ###-------------------------------------------------------------------------- ### Descend into subdirectories. SUBDIRS = SUBDIRS += lib SUBDIRS += src $(call descend-subdirs, $(SUBDIRS)) ###-------------------------------------------------------------------------- ### Maintaining the build system. ###-------------------------------------------------------------------------- ### More machinery. all_dirtargets = $(foreach d,$(ALL_SUBDIRS), \ $(foreach t,$(dirtargets), $d/$t)) $(all_dirtargets):: ifeq ($(origin SUBDIR),undefined) $(foreach t,$(dirtargets), \ $(eval $t:: $(foreach d,$(ALL_SUBDIRS),$d/$t))) else $(foreach t,$(dirtargets), \ $(eval $t:: $(SUBDIR)/$t)) endif $(foreach d,$(SUBDIRS), \ $(foreach t,$(dirtargets), \ $(eval $d/$t::))) .PHONY: $(foreach t,$(dirtargets),$t $(foreach d,$(ALL_SUBDIRS),$d/$t)) $(foreach d,$(ALL_SUBDIRS), $d/clean):: %/clean: rm -f $*/*.o $*/*.d $($*_CLEANFILES) realclean:: clean rm -f config.status config.log rm -f Makefile $(foreach d,$(ALL_SUBDIRS), $d/Makefile) -include $(ALL_DEPFILES) ###----- That's all, folks --------------------------------------------------