> I don't know how many hours the author has spent/wasted
> on this topic
The author, John Graham-Cumming, has been extremely active on the GNU Make mailing list, is the author of the "GNU Make Standard Library" of supplemental functions for Make, has written at least 2 books on GNU Make, and has developed commercial products that integrate with GNU Make (namely, "Electric Make").That is to say: He is one of the world experts on GNU Make.
I'm confident that he did this more "for fun" than because he actually wanted to get the number of jobs.
Of course you can patch the software and in the long term that will of course be the best solution. But it can take a long time until that patch actually makes it into the main repo, and even longer until it will be in the default `make` on all major distributions. So if you want to use this feature right now then writing a patch is useless for you, unless you only ever use it on your own machine.
The big advantage of the workaround is that it actually works with current versions of make.
Anyway, it was my small contribution to the discussion :-)
It took me about 15 minutes to come up with the solution. I wrote it up for fun because it illustrates some of the functionality of GNU make that people might not be aware of (order-only prerequisites, $(eval)) and using $(call) in a recursive fashion.
I actually spent more time on the blog post.
Asking for -j value inside the Makefile was a tell-tale sign of this sort.
default: qualcosa.sh
JOBS=${#J} ./qualcosa.sh
Source for sample shell-script: #!/bin/bash
echo "According to \$JOBS environment variable, the argument of -j/--jobs is $JOBS"
Quite frankly, I find this whole "look i did a horrible hack and let's see who can make the best worst horrible hack" thing quite stupid and silly.
GNU Make is free software released under a free license, my opinion is that instead of doing that crazy thing, the author could have just written a patch for GNU Make in order to make it export a "JOBS" environment variable to all its child processes.
Oh but yes, "I felt this feature was missing so I added it" is way way way less cool than "geez the gnu make folks are insane lollerplex they have no way to know how many jobs they're running".
ALSO: http://www.catb.org/esr/faqs/hacker-howto.html#believe2
Here it is a patched version of GNU Make, providing a #J variable that holds the number of jobs as passed via -j/--jobs:
As can be seen in the screenshot, it can be passed as environment variable to programs called by makeSource: https://github.com/esantoro/make