asc99c
asc99c

Reputation: 3905

Control output from makefile

I'm trying to write a makefile to replace one of the scripts used in building a fairly large application.

The current script compiles one file at a time, and the primary reason for using make is to parallelise the build process. Using make -j 16 I currently get a factor of 4 speedup on our office server.

But what I've lost is some readability of the output. The compilation program for a file bundles up a few bits and pieces of work, including running custom pre-compilers, and running the gcc command. Each of these steps outputs some information, and I would prefer it to buffer the output from the command, and then show the whole lot in one go.

Is it possible to make make do this?

Upvotes: 1

Views: 357

Answers (3)

Paul Evans
Paul Evans

Reputation: 27567

A simple way to accomplish this is to send all the log output a to log directory with each file named, say:

log_file_20131104_12013478_b.txt  // log_file_<date>_<time>_<sequence letter>.txt

and then simply cat them all together as your last make job in the dependency chain:

cat log_dir/log_file_20131104_12013478_*.txt > log_file_20131104_12013478.txt

Upvotes: 1

Daniel
Daniel

Reputation: 500

With makepp this is the default behaviour as soon as you use -j. All the individual outputs (and entering dir messages) get collected and are output together as soon as the command terminates.

Upvotes: 0

MadScientist
MadScientist

Reputation: 100781

If you upgrade to GNU make 4.0, then you can use the built-in output synchronization feature to get what you want.

If you don't want to upgrade, then you'll have to modify each of your recipes to be wrapped with a small program that manages the output. Or you can set the SHELL variable to something that does it for you. Searching the internet should give you some examples.

Upvotes: 3

Related Questions