0

My rule for building my foo.a library is:

${LIB}: ${LIB_OBJ}
    ar ${LIB_ARGS} ${LIB} ${LIB_OBJ}
    ranlib ${LIB}

This becomes:

 ar -cvrU lib/libfoo.a ... (all the obj/foo.o files)

It works, but as I add more code, this takes longer and longer. It's necessary for a clean build, but what if libfoo.a lists, and I've only changed a single foo.cpp?

Note that I just did this manually:

ar -cvrU lib/libfoo.a obj/foo.o

And it took 10 or 15 seconds, which seems a little crazy.

So I guess my question: can I do this more efficiently?

Joseph Larson
  • 8,530
  • 1
  • 19
  • 36
  • I am thinking about incremental build. You could see this for example but I am not sure whether you already have incremental build since you haven't posted whole code: https://stackoverflow.com/questions/31082409/incremental-build-with-gcc-and-manual-makefile –  Jul 06 '21 at 15:54

1 Answers1

1

Yes. Make has built-in support for managing archive files. It can break open the archive and compare the timestamp on the object in the archive with the source file on disk to decide whether to remake the object, then replace just that one object file.

You can read about this in the GNU make manual.

MadScientist
  • 92,819
  • 9
  • 109
  • 136