How to enable makefile dynamically

Now I have two makefiles: A.mk and B.mk.

A.mk will include B.mk But B.mk is dynamically generated by some command that runs in A.mk

Here is the A.mk pseudo code

command to generate B.mk 
include B.mk
compile and link

The question is that the include command is something like #include macro in the CAmk file, it will try to load the B.mk file before executing the command.

Can anyone give me some advice?

Many thanks jerry

+4
source share
1 answer

You can make it work as follows:

a.mk ( b.mkdoes not exist at the moment )

-include b.mk

all:
    @echo foo : $(FOO)

b.mk:
    @echo "FOO=2" > b.mk

With make -f a.mk allwe get the following:

foo: 2

The sign -before the include directive allows you to not generate a warning if it b.mkdoes not exist.

MadScientist , b.mk . make , , , .

+1

Source: https://habr.com/ru/post/1689609/


All Articles