I'm calling make from a bash script. Part of the rest of the script only needs to be executed if make actually did something (i.e. it doesn't say nothing to be done for...).

How would I check on that in bash? The return code is the same as when something does happen (and doesn't fail), so I can't use that. Is there a better way than comparing make's output and see if it contains nothing to be done for?

I'm using GNU Make 4.0.

  • Are you sure the return code is the same? It should be 0 if the make is unsuccessful, 2 if there are no rules to generate the target ... you've tried to run echo $? after the make that ends with nothing to be done for? – LilloX Dec 11 '15 at 9:45
  • @LilloX yes, I have tried echo $?. Both nothing to be done for and an actual make are successful, so they return 0. – user37050 Dec 11 '15 at 11:09

If your workflow can accomodate it, you can send make on a trial run before you run it to update files:

-q, --question

‘‘Question mode’’. Do not run any commands, or print anything; just return an exit status that is zero if the specified targets are already up to date, nonzero otherwise.

(I am somewhat surprised this is not part of --recon's behaviour.)

  • make does not implement --dry-run did you mean -n? – schily Dec 11 '15 at 10:27
  • @schily: you're right, I just always think it should be --dry-run where it's --recon. – Ulrich Schwarz Dec 11 '15 at 10:44
  • The options you mention are part of gmake but not supported by make. – schily Dec 11 '15 at 10:59
  • 1
    @schily Please stop trolling. The question explicitly states that the make implementation is GNU make. – Gilles 'SO- stop being evil' Dec 11 '15 at 23:17
  • If people write gmake when they are talking about gmake, nobody needs to correct them. So please stop trolling. – schily Dec 12 '15 at 0:04

I believe this will do what you want. Tested with GNU grep.

mk_output=$(make)   # add whatever make options you use
if printf '%s\n' "$mk_output" | grep -qF 'Nothing to be done for'
    echo '"Nothing to be done for" was present in output'
    echo '"Nothing to be done for" was NOT present in output'

We capture the output from make, then grep (options quiet and fixed string) for the string you're seeking. If found, the exit status of grep is 0; if not found, 1.


make often generates a lot of output, so it might be best to change the first line to:

mk_output=$(make (make options) | grep -qF 'Nothing to be done for')

That way, mk_output won't be so huge.

If you want to see the output from make as it's running, as well as capture it, use tee to capture to a file instead:

make | tee make_output
if grep -qF 'Nothing to be done for' make_output
then etc.
  • 1
    @schily Please stop pretending you're confused when people refer to a GNU tool by its name. There's no need to call it gwhatever when the context is clear, and it can't be clearer in a question that's tagged [gnu-make] and says "I'm using GNU Make 4.0.". Whatever personal vendetta you have going on is your business, but you're confusing people for no reason – Michael Mrozek Dec 12 '15 at 3:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy