G
G
German2022-01-12 23:46:09
GNU Make
German, 2022-01-12 23:46:09

How to use one variable in multiple makefiles?

I have two makefiles, the first one calls the second one.
I would like to get some data from the second makefile.
For a better understanding of the issue, an example:
Makefile


SHAREDVAR =
all:
    cd test && $(MAKE)
    @echo main: $(SHAREDVAR) # Output expected: main: aaa

test/Makefile

SHAREDVAR = aaa
all:
    @echo test: $(SHAREDVAR) # Succeeds: aaa


And I also tried to use this scheme:

Makefile

include Makefile.variable

all:
    cd test && $(MAKE)
    @echo main: $(SHAREDVAR)


Makefile.variable

SHAREDVAR = temp


test/Makefile

.PHONY: all

include ../Makefile.variable

SHAREDVAR = aaa

all:
@echo test: $(SHAREDVAR)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2022-01-13
@mrjbom

I have two makefiles, the first one calls the second one.
I would like to get some data from the second makefile.

This is not provided for by the logic of make, except that it can be nailed through eval. Usually, when you need a tight connection between different Makefiles, one of them is included in the other (and you get a large logical Makefile divided into several files).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question