[BMAKE (very similar to GNUMake)]
I have a project that depends on files generated by another project and I need make variables in this project that contains the names and locations of those files. So, from this project's Makefile, I'm initiating builds of the other projects.
I have setup my Makefile to have dependencies for each stage as follows:
prepareOther:
cd otherProject && make
prepareNames: prepareOther
build: prepareNames
make ${CPP_FLAGS} ${CPP_SRCS}
When the prepareNames
target is processed, I need to populate the Make variables CPP_FLAGS
(with -I statements) and CPP_SRCS
with filenames. However, I want to avoid having to do this using shell scripting within the target's recipe.
I'm using the following code to find and organise the names and locations of the necessary files into the Make variables:
# This example limits filetypes to CPP but using an if statement, C & H files can also be handled.
# In addition, this example only captures the file's name, not location.
PROJECTS=proj1 proj2
RAWNAMES=fileA.cpp fileB.cpp
.for proj in ${PROJECTS}
. for file in ${RAWNAMES}
THISFILENAME!= find ../${proj}/build/${proj} -maxdepth 1 -name '${proj}_${file}' -exec sh -c 'name="{}"; base=$$(basename $$name); echo "${proj}/$$base"' \;
${CPP_NAME_${proj}::+=${THISFILENAME}}= ## The assignment is performed by the '::+='
. endfor
.endfor
...
.for proj in ${PROJECTS}
CPP_SRCS+=${CPP_NAME_${proj}
.endfor
The problem is that this code gets run before the other projects are built, and therefore the files don't exist yet.
I've tried using a bmake construct .if target(prepareNames)
as a guard around the above code, but unless I invoke that target from the CLI, the code is never executed, even though the target is processed internally when I invoke bmake build
.
I also tried using the syntax:
prepareNames: Make statement1
prepareNames: Make statement2
But this produces duplicate script for target
warnings which causes those lines to be ignored.
Is there a way of doing this using Make code without resorting to convoluted, escaped shell code?