First, let me briefly go into the rationale behind all this.

Non-recursive make (as per http://aegis.sourceforge.net/auug97.pdf) promotes the 
inclusion of makefiles to transfer information regarding dependencies within a module. 
 Since module dependencies form a DAG, caching the contents of the makefiles can save
many file open and close operations thereby speeding up the build.

The solution:
# sets __FILE__ macro to file to be included, then includes the file.
# allows included file to know where it is in relation to includer.
# included file is cached in memory in case it's included again.
# $(1) is the file to be included
# $(2) is the current value of $(__FILE__)
define _include-makefile
  __FILE__ := $(1)

  ifndef $(1).contents
    -include $(1).contents
  endif

  $$(eval $$($(1).contents))

  __FILE__ := $(2)
endef

# include makefile passing in its name as __FILE__
# $(1) is the file to be included
include-makefile = $(eval $(call _include-makefile,$(1),$(__FILE__)))

%.contents: %
        @( \
                echo define $@; \
                cat $^; \
                echo endef; \
                echo; \
                echo '$@ := $$(value $@)'; \
        ) >$@


The drawbacks I see with this solution is the extra initial cost due to the %.contents 
file creation and inclusion and, as it is, it needs tweaking in order to work if the 
included file is on a read-only partition.  The second drawback isn't too difficult
to overcome.  Can anyone see a way around the first?

Thanks,
Noel


_______________________________________________
Help-make mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/help-make

Reply via email to