I've been trying to understand how to get the support for archive files to work in conjunction with reading in files with auto dependencies for the .o files. The documentation for archive support does help as it is not a model of clarity. My experimentation has only led to further confusion regarding the internal rules of this function.
My goal is to be able to not save .o files "permanently", using archive files instead, but also be able to state the dependencies of member .o files so that the archive members are remade when the appropriate .h files change. I have not figured out to do this. Of course in order to do this, make must talk to ar to get the timestamps of members of the archive, but the documentation seems to imply this capability exists.
Does anyone have an example of this, or can explain a little better how the archive support works under the hood? As mentioned above the GNU manual is rather unclear in this section.
On Wed, 2016-07-20 at 11:36 -0700, jandyman wrote:
> Does anyone have an example of this, or can explain a little better
> how the archive support works under the hood? As mentioned above the
> GNU manual is rather unclear in this section.
I don't quite know what you're trying to do or what information you're
looking for: usually a very abstract question like this is hard to
answer. If you provide a specific, small, runnable example of what you
want to do and describe what fails and what you expected to happen,
it's easier to discuss it.
As far as the internal implementation, GNU make actually has the
ability to directly parse archive files and extract the timestamp
information from them: it doesn't invoke ar to get that information.
One thing to note is that as part of the reproducible build initiative
unfortunately ar is often built these days such that "deterministic
mode" is the default; this means that the timestamp information in the
archive is always zeroed. I filed a bug about this in Debian,
requesting that the default be restored to "non-deterministic" and the
deterministic build effort make use of some other method to enable
deterministic mode (maybe some kind of environment variable). However,
no response to that.
If you want to rely on timestamps always add the "U" option to your ar
commands, if you use GNU binutils that you didn't build yourself.
I realized after doing some more searching that I needed to come up with a more concrete example. When I retraced my steps, everything suddenly started working exactly as expected, even with built-in rules! (Note that the built-in rule for archive targets does not seem to be documented in the docs I've got. But it seems to be close to the example rule they show in the section on archive targets).
Interestingly, when I tried to get an example working that does keep .o files around (not what I really want), I couldn't get things to work. Not that it matters, just for anyone searching here. So for those searching here, what did work was:
trylib.a(hello.o): ork.h (this line brought in from include file to show that autodependencies will work)
When I do this, touching either hello.c or ork.h will properly update the archive.
Thanks for letting me know about the "deterministic mode", I did find that issue when searching. My system isn't set up that way (recent Linux Mint), which is good because it would really screw me up.