Search code examples
makefilegnu-make

Is there a way to postpone execution of a target in GNU make?


I want to run several tests of my code, like so:

make test1 test2 test3 test4 ...

In total, this takes multiple hours, so I want to run this at night, so I can check the results in the morning.

It so happens that I need some licenses for those tests. At midnight, our license server is shortly rebooted (only takes about a minute). If it so happens that e.g. test3 starts executing while the license server is rebooting, it errors and doesn't execute the test. Which is annoying.

A possible solution I'm looking into is whether it's possible check the time before you start executing a test. If it's e.g. between 23:58 and 00:02, wait 5 minutes or whatever. I just want to avoid starting a test while rebooting. If the test is already running and then the server is rebooted, there is no issue.

I tried googling it, but I didn't really find anything related to that, so my hopes are quite low.


Solution

  • This is not something you need to do in Make itself. Just add a command at the beginning of each rule that needs the licence. If we need it a lot, use a variable to save writing it many times.

    avoid_midnight = if date +%H%M | grep -qE '235[89]|000[01]'; then sleep 5m; fi
    
    test1.results: test1
        $(avoid_midnight)
        ./< >&@