3 # Replace #! interpreters in scripts by what we actually have.
5 # Standard templates for bash, perl, python,... are included out of
6 # the box, others can easily be added per port.
9 # Usage: USES=shebangfix
11 # To specify that ${WRKSRC}/path1/file and all .pl files in ${WRKSRC}/path2
12 # should be processed:
14 # SHEBANG_FILES= path1/file path2/*.pl
16 # To define custom shebangs to replace, use the following (note that
17 # shebangs with spaces should be quoted):
19 # perl_OLD_CMD= /usr/bin/perl5.005 "/usr/bin/setenv perl5.005"
21 # To define a new shebang scheme add the following to the port Makefile:
24 # lua_OLD_CMD= /usr/bin/lua
25 # lua_CMD= ${LOCALBASE}/bin/lua
27 # To override a definition, for example replacing /usr/bin/perl by
28 # /usr/bin/env perl, add the following:
30 # perl_CMD= ${SETENV} perl
32 # MAINTAINER: portmgr@FreeBSD.org
34 .if !defined(_INCLUDE_USES_SHEBANGFIX_MK)
35 _INCLUDE_USES_SHEBANGFIX_MK= yes
37 SHEBANG_LANG+= bash java ksh perl php python ruby tcl tk
41 lua_CMD?= ${LOCALBASE}/bin/${LUA_CMD}
44 tcl_OLD_CMD+= /usr/bin/tclsh
47 tk_OLD_CMD+= /usr/bin/wish
51 python_CMD?= ${PYTHON_CMD}
54 # Replace the same patterns for all langs and setup a default, that may have
55 # been set already above with ?=.
56 .for lang in ${SHEBANG_LANG}
57 ${lang}_CMD?= ${LOCALBASE}/bin/${lang}
58 ${lang}_OLD_CMD+= "/usr/bin/env ${lang}"
59 ${lang}_OLD_CMD+= /bin/${lang}
60 ${lang}_OLD_CMD+= /usr/bin/${lang}
63 .for lang in ${SHEBANG_LANG}
64 . if !defined(${lang}_CMD)
65 IGNORE+= missing definition for ${lang}_CMD
67 . if !defined(${lang}_OLD_CMD)
68 IGNORE+= missing definition for ${lang}_OLD_CMD
70 . for old_cmd in ${${lang}_OLD_CMD}
71 _SHEBANG_REINPLACE_ARGS+= -e "1s|^\#![[:space:]]*${old_cmd:C/\"//g}\([[:space:]]\)|\#!${${lang}_CMD}\1|"
72 _SHEBANG_REINPLACE_ARGS+= -e "1s|^\#![[:space:]]*${old_cmd:C/\"//g}$$|\#!${${lang}_CMD}|"
76 _USES_patch+= 210:fix-shebang
79 ${ECHO_CMD} ${SHEBANG_FILES} | ${XARGS} ${SED} -i '' ${_SHEBANG_REINPLACE_ARGS}