xepwda
Last Updated: February 25, 2016
·
1.631K
· pykler
88dcd9a1b56c02e905ac3a352e43ba81

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")'
Say Thanks
Respond

1 Response
Add your response

6802
6b9de42588e59ef84506f3e5e2a8c972

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

over 1 year ago ·
Filed Under