0

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 ?

Cyan
  • 13,248
  • 8
  • 43
  • 78
  • 8
    "_for this specific project, the `Makefile` is an immutable object_" - Fork the project and create a proper makefile instead of trying to build something on a broken foundation. – Ted Lyngmo Aug 29 '21 at 21:15
  • 4
    You could maybe try writing a wrapper builder to name as `CC` which will split the work into `gcc -c` commands and a link step. But really, fixing the Makefile or moving to a different build system entirely is the better way. – aschepler Aug 29 '21 at 21:16
  • It would be *relatively* easy for gcc to allow a `-j` flag. But this is not Microsoft. The Unix-filosophy is: One program solves one problem. There is no Email-functionality in GCC, either. – wildplasser Aug 29 '21 at 21:36
  • The short answer to your question is, no, there is no way to do that. If you can't change the makefile then you'll have to live without parallel builds. – MadScientist Aug 30 '21 at 14:00

0 Answers0