In my project, I want to build a shared library libfoo.so
first, then build some test programs that use this shared library. For the test programs, if I use need
need libfoo.so
then they will be rebuilt every time libfoo.so
is updated. Instead, I want to build the test programs after libfoo.so
exists and the header files change (or build the test programs for the first).
The dependency on the header files can be done through gcc -MMD -MF
and needMakefileDependencies
.
How do I express the dependency on the existence of libfoo.so
without forcing rebuild every time?
Thanks!
If I understand properly, you build a library
libfoo.so
which also produces some header files in order to build itself. You want to compile some programs which make use of those header files, but depending onlibfoo.so
itself causes your programs to rebuild if it changes, which is excessive.Assuming that, the answer is
orderOnly ["libfoo.so"]
. This construct ensures thatlibfoo.so
is built before continuing (and thus that the header file is correct), but does not actually depend on it. The main use oforderOnly
is when you want "a lot of stuff" to be built, and then you scan it (e.g. withgcc -MMD -MF
) to figure out exactly which pieces to depend on.