Greetings,

I was wondering if someone has solved the following recursive ascend
problem.

Lets say, we have a list of environment variables to export.. Obviously we
can put these in a file and either include them or source them. Obviously,
if one begins from the top of a src tree, this operation (or inclusion) will
be placed in the top level Makefile, aka $SRC_ROOT/Makefile

However, what if we are at some arbiterary place in the src tree, say
$SRC_ROOT/a/b/c and we want to build. In this situation, most solutions I
have seen consists of a hard coded (or static) solution where for example
$SRC_ROOT/a/b/c/Makefile would say something like

include ../../../env.mk

Note how the path is static. This is not a clean design, as if you change
the shape of the source tree, then all these static references need to be
updated. A cleaner design is a recursive ascend, just like OO languages and
how then find appropriate implementations of a code. More specifically, each
Makefile at a given node (or level) only knows about its parent, something
like. For example, lets say the top level Makefile has a target call "init",
then each non top level Makefile can say

$(MAKE) -C ../ init

I hope this has provided a sufficient background....now my attempt to solve
this...which is not working

first I'll set up a test environment consisting of a few dirs and sub-dirs

prompt > find d2 -print
d2
d2/Makefile
d2/a
d2/a/Makefile
d2/a/b
d2/a/b/c
d2/a/b/c/Makefile
d2/a/b/Makefile
d2/env.mk

----------------------
prmpt >  cat env.mk
$(info in env.mk)
export X = $(shell date)

.PHONY:
------------------------
prompt > cat
 cat Makefile
# this is root

default: test

.PHONY: init

init:
include env.mk


test:
        @pwd
        @echo "value of X=[$X]"

this:
        @echo "in target...@]"
-----------------------------------------
cat a/Makefile

default: test

.PHONY: init
init:
        $(MAKE) -C ../ init


test:
        @pwd
        @echo "value of X=[$X]"

------------------------------

So the idea I was trying is to have a target called "init" in every
makefile. I want to this target to be executed every time. In top level
makefile, this target will include or source some env vars. In non top level
makefiles, it calls the parent. Hence a recursive ascend.

Thanks
Medi
_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to