Reputation: 3024
I need to know the best way of dealing with this. Also you could answer this -- after reading the sample below --: Look at the makelib
target in package.make
and tell me if there is a way to force this be treated as not updated if the recipe (make -C ../lib/ -f lib.make) reports as nothing to be made (not using ordered prequisites)?
I need to explain this point using an example. I have inherited this and I need the best way to make this right.
A target which other targets will be depending on:
File lib.make
--------------
.DEFAULT_GOAL = thelib.dll
%.dll: file1.obj file2.obj
makelib file1.obj file2.obj -o thelib.dll
This by itself is pretty solid. You run it once (make -f lib.make
) and it creates the lib. If you run it subsequently, having no modified files, then it will tell you it has nothing to do.
Now we're going to use this in a special way somewhere else:
File: package.make
------------------
.DEFAULT_GOAL: all
all: package
makelib:
@make -C ../lib/ -f lib.make
package: makelib file3 file4
@package_files file3 file4 ../lib/out/*.dll -o package
This is how lib.make
is referenced inside package.make
.
The issue is even though the package gets created when you call make -f package.make all
make assumes that package
target needs to be rebuilt every time since one of its dependencies -- makelib
-- had to be remade
Make considers makelib
out of date despite what happens after entering lib.make
.
To correct this I thought of a few choices:
moving makelib
to the ordered prerequisites ( after the |
) but that's not quite right because in case of a newly built library my package wont' be updated
adding the dll (thelib.dll
) as the dependency to the makelib
target a second time but this would almost duplicate the logic and break the encapsulation.
removing makelib
target and moving the line @make -C ../lib/ -f lib.make
to inside the package
recipe. There is a problem with this and that is that I have removed the dependency between the package and lib. If lib requires update, the package won't know about it and won't get updated.
using include lib.make
and then rewriting package
rule to something like: package: thelib.dll file3 file4
. There are problems with this also and the least of them is for a make file to be included, it must be written as such. Otherwise a lot of overwriting/conflicting targets and definitions will be introduced.
Are there any suggestions other than and directly listing the dll as the dependency?
Upvotes: 0
Views: 261
Reputation: 101041
There are two main ways this works:
First, if you use recursive make (please remember to always invoke a sub-make using $(MAKE)
, never make
directly) then you should make the target in the parent makefile be the actual file generated by the sub-make:
package: lib/thelib.dll ...
...
lib/thelib.dll: FORCE
$(MAKE) -f lib
FORCE:
Second, you can use non-recursive make which means you include the sub-makefile into the parent make and write it so that it expects that. You can play tricks with variables etc. to make this more generic, so it can be invoked from either the parent or subdirectory, if you want.
Upvotes: 2