I have a medium-size project which consists of many *.c
unit files.
In a "normal" compilation exercise, the program is built from its *.o
object files, which are passed as pre-requisite of the main program in the Makefile
recipe. This works well for parallel builds : with make -j
, all these object files are compiled in parallel, then linked together at the end. It makes the whole build experience a lot faster.
However, in other cases, the list of prerequisites is passed as a list of *.c
unit files, not *.o
object files. The original intention is to not build these object files, as they could pollute the cache.
Now, this could probably be done differently, but for this specific project, the Makefile
is an immutable object, so it can't be updated, and we have to live with it.
In this case, using make -j
is not effective, as gcc
will effectively receive the full list of units directly on a single command line. Which means, make
is no longer able to organize parallelism.
The only opportunity I've got left is to pass flags and parameters to make
. I was trying to find one which would make gcc
compile a list of units in parallel, internally. I couldn't find any. Searching around on Internet, I found conjectures stating that "since make
can do parallel build, gcc
doesn't need to replicate this functionality". But no solution.
So the question is : how to deal with it ?
Assuming a compilation line like gcc *.c -o final_exe
, which can be altered through standard flags (CC
, CFLAGS
, CPPFLAGS
, LDFLAGS
), is there any option available to make it build these units in parallel ?