Last Updated: December 30, 2020
·
2.295K
· pykler

GNU Make Tips & Tricks

I have 2 little unique tricks that I use in make files and would like to share, here they are ...

Ask for "yes" before proceeding

install: do-install production-deploy 

do-install: #... all deps
    gcc ...

production-deploy: production-ask
    rm -fr /

%-ask:
   @python -c 'raise SystemExit(not raw_input("All Done! Are you sure you want to install to $(subst -ask,,$@)? (yes/NO) ") == "yes")'

Wait a few seconds before restarting, allows for operator cancel via Ctrl-C

install: do-install production-restart

do-install: #... all deps
    gcc ...

production-restart: 5-rwait
    sudo reboot

%-rwait:
    @python -c 'import sys,time;n=$(subst -rwait,,$@);filter(lambda i: (sys.stdout.write("will restart system in %s\n" % (n-i)) or time.sleep(1)), range(n)) or sys.stdout.write("restarting ...\n")'

1 Response
Add your response

Nice, but you can use $* to get what the % matched, instead of your $(subst -ask,,$@) :)

over 1 year ago ·