News for hackers. Stuff that matters.
Re:GNU make insanity: finding the value of the -j parameter by JoshTriplett on Saturday March 28, 2015 @03:37PM (#9282495)
It's an amusing exercise, but for actual practical use, the right solution is to share make's jobserver. If you have a build rule that wants to run multiple things in parallel, put + in front of the command, and then your command will receive the file descriptors for the jobserver pipe on the command line. Then, when you want to start a parallel job, do a blocking read of a byte from the read fd, and when you're done with that job, write a byte to the write fd.
Re:GNU make insanity: finding the value of the -j parameter by chaosfactor on Saturday March 28, 2015 @03:40PM (#9282511)
This does not generalize to arbitrary purposes. If you just want to detect that the user has run more jobs than your build system can possibly benefit from and print a warning, there is no reason to start messing with the jobserver. This is not the Ockham solution :)
Re:GNU make insanity: finding the value of the -j parameter by JoshTriplett on Saturday March 28, 2015 @03:44PM (#9282525)
Why print such a warning? For most projects, make -j65536 will be effectively equivalent to make -j, both of which are perfectly fine. Suppose you're on a system with more CPUs than you have build rules in your build system; you shouldn't print a warning just because someone does make -j$(nproc).
Re:GNU make insanity: finding the value of the -j parameter by oso2k on Saturday March 28, 2015 @05:54PM (#9282876)
I get what you're saying but not seeing how to do that in make syntax. Mind giving an example?
Re:GNU make insanity: finding the value of the -j parameter by JoshTriplett on Saturday March 28, 2015 @06:43PM (#9283050)

        $ cat Makefile
        test:
        	+env | grep MAKEFLAGS
        $ make -j4 test
        env | grep MAKEFLAGS
        MAKEFLAGS= -j --jobserver-fds=3,4
If you want to act like a sub-make, then parse MAKEFLAGS from your environment, and if you see -j and --jobserver-fds=R,W , then parse R and W as file descriptor numbers, block waiting for a byte from R before starting an additional parallel job, and write a byte to W when done with a parallel job.