Makefile as an executable script with shebang?

[亡魂溺海] 提交于 2019-11-28 09:03:23
Flexo
#!/usr/bin/make -f

main:
        @echo Hello World!

Is normally all you need in a standard make file. The filename is implicitly passed as the last argument. /dev/stdin here is (usually) the tty. You can do the whole env thing if there's a reason to, but often there's no need.

ajw@rapunzel:~/code/videocc/tools > vi Makefile                       
ajw@rapunzel:~/code/videocc/tools > chmod a+x Makefile         
ajw@rapunzel:~/code/videocc/tools > ./Makefile                 
Hello World!

The following adds a level of indirection but it's the best solution I've come up with for self-executing makefiles not called "makefile":

#!/bin/sh
exec make -f- "$@" << 'eof'

.PHONY: all
all:
    @echo 'hello world!'

I'm trying to collect #! env hacks for each language / program here.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!