Commits

Anonymous committed 6f41c94

GNUmakefile: optimization & new interface

usage:
$(call accum_setup,TARGETS PROGS JUNKS)
$(call accum_clear_all_vars)
$(call import,$Pliba/Makefile)

Comments (0)

Files changed (1)

 __debug__ := y
 default: all
 
-# import will accumulate these variables into their ALL_* counterparts
-ACCUM_VARS := TARGETS PROGS JUNKS JUNKDIRS CLEANDIRS PHONYS TESTS
 # internal definitions, don't touch :) {{{
 # internal _get_dir: set the current directory to $P {{{
 define __get_dir
 _get_dir = $(eval $(__get_dir))
 # }}}
 $(_get_dir) # should be the first (before any include statement)
-ifeq ($(strip $(__debug__)),y)
- $(info we are at $P)
-endif
 
 # _is_main_makefile: save the flag whether we are the main Makefile {{{
 _is_main_makefile := $(if $(subst $(firstword $(MAKEFILE_LIST)),,$(_last_makefile)),n,y)
 endef
 # }}}
 
-accum_clear_all_vars = $(foreach v,$(ACCUM_VARS),$(eval $v :=))
+# Accumulation Utilities: accum_{setup,clear_all_vars} and import {{{
+# This is the core part of the sub-dir build mechanism.
+# accum_setup, setting up all the necessities for accumulation.
+# Usage: $(call accum_setup,$(ACCUM_VARS))
+define _accum_setup #{{{
+# Define ALL_* vars {{{
+# ALL_* must be recursive variable to handle the case when we have been included
+# by a sub-Makefile, but in ordinary conditions, we must be careful to update the
+# ALL_* immediately.
+$(foreach v,$(1),$$(eval ALL_$v = $$$$($v)))
+# }}}
+# Define accum_clear_all_vars
+accum_clear_all_vars = $(foreach v,$(1),$$(eval $v :=))
+$$(call accum_clear_all_vars) # immediately clear all $$v's
 # internal import helper function {{{
 #                                |   1    |
-# usage: $(eval $(call __import__,filename))
+# usage: $$(eval $$(call __import__,filename))
 define __import__
-__incfile := $(subst //,/,$(1))
-P:=$$(dir $$(__incfile))
-$$(call debuginfo,including $$(__incfile))
-$$(call accum_clear_all_vars)
-__indent__:=$$(empty)$(__indent__)$$(space)$$(empty)
-include $$(__incfile)
-__indent__:=$$(empty)$(__indent__)$$(empty)
-P:=$P
-ifeq ($$(_accum_progs_),y)
- $$(eval $(foreach v,$(ACCUM_VARS),$$$$(eval ALL_$v += $$($v))))
+__incfile := $$(subst //,/,$$(1))
+P:=$$$$(dir $$$$(__incfile))
+$$$$(call debuginfo,including $$$$(__incfile))
+$$$$(call accum_clear_all_vars)
+__indent__:=$$$$(empty)$$(__indent__)$$$$(space)$$$$(empty)
+include $$$$(__incfile)
+__indent__:=$$$$(empty)$$(__indent__)$$$$(empty)
+P:=$$P
+ifeq ($$$$(_accum_progs_),y)
+ $$$$(eval $(foreach v,$(1),$$$$$$$$(eval ALL_$v+=$$$$($v))))
 endif
 # Extra empty line here, to avoid make joining the lines here
 
 endef # }}}
-# import the sub-sub-Makefiles
+# import: import the sub-Makefiles {{{
 #                     |    1    |
-# Usage: $(call import,makefiles))
-import = $(eval $(foreach f,$(1),$(call __import__,$f)))
+# Usage: $$(call import,makefiles))
+import = $$(eval $$(foreach f,$$(1),$$(call __import__,$$f)))
+# }}}
+endef # }}}
+accum_setup = $(eval $(call _accum_setup,$(1)))
+# }}}
 
 # show-XXXX target {{{
 ifeq ($(findstring show-,$(MAKECMDGOALS)),show-)
 	@echo \$$\($(_show_var)\) = '$(value $(_show_var))'
 endif
 # }}}
-
-# ALL_* must be recursive variable to handle the case when we have been included
-# by a sub-Makefile, but in ordinary conditions, we must be careful to update the
-# ALL_* immediately.
-$(foreach v,$(ACCUM_VARS),$(eval ALL_$v = $$($v)))
-$(call accum_clear_all_vars) # set flavor of all vars to simple, not recursive
 # }}}
+ifeq ($(strip $(__debug__)),y)
+ $(info we are at $P)
+endif
+
+# import will accumulate these variables into their ALL_* counterparts
+$(call accum_setup,TARGETS PROGS JUNKS JUNKDIRS CLEANDIRS PHONYS TESTS)
 
 # if we aren't the first Makefile read in, it means that we are read in by 
 # some sub-Makefiles, so don't accumulate further progs in other sub-Makefiles
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.