aboutsummaryrefslogtreecommitdiffstats
path: root/Mk
diff options
context:
space:
mode:
authorbapt <bapt@FreeBSD.org>2013-05-07 06:23:09 +0800
committerbapt <bapt@FreeBSD.org>2013-05-07 06:23:09 +0800
commit1b4432605a504ff9920a3108877b8e3120f2a5a0 (patch)
tree8c5366a2e80d516e7c08823a098603b5ab592673 /Mk
parent5a54d445d99030ca11a7ce7b7bc9cc99e2839a79 (diff)
downloadfreebsd-ports-gnome-1b4432605a504ff9920a3108877b8e3120f2a5a0.tar.gz
freebsd-ports-gnome-1b4432605a504ff9920a3108877b8e3120f2a5a0.tar.zst
freebsd-ports-gnome-1b4432605a504ff9920a3108877b8e3120f2a5a0.zip
Add new USES: shebangfix
use it to fix shebang on files specified by SHEBANG_FILES macro, by default it proposes default values for bash, perl, php, python, ruby, it can be customized and extended
Diffstat (limited to 'Mk')
-rw-r--r--Mk/Uses/shebangfix.mk53
1 files changed, 53 insertions, 0 deletions
diff --git a/Mk/Uses/shebangfix.mk b/Mk/Uses/shebangfix.mk
new file mode 100644
index 000000000000..1cc36d250dde
--- /dev/null
+++ b/Mk/Uses/shebangfix.mk
@@ -0,0 +1,53 @@
+# $FreeBSD$
+#
+# common templates for replacing #! interpreters in scripts file
+#
+# MAINTAINER: portmgr@FreeBSD.org
+#
+# Feature: shebangfix
+# Usage: USES=shebangfix
+#
+# To define new shebang scheme, in the port Makefile add:
+#
+# SHEBANG_LANG= lua
+# lua_OLD_CMD= /usr/bin/lua
+# lua_CMD= ${LOCALBASE}/bin/lua
+#
+# To override a definition for example replacing /usr/bin/perl by /usr/bin/env perl
+# add to the port Makefile:
+# perl_CMD= ${SENTENV} perl
+#
+
+.if !defined(_INCLUDE_USES_SHEBANGFIX_Mk)
+_INCLUDE_USES_SHEBANGFIX_MK= yes
+
+bash_OLD_CMD?= /bin/bash
+bash_CMD?= ${LOCALBASE}/bin/bash
+perl_OLD_CMD?= /usr/bin/perl
+perl_CMD?= ${LOCALBASE}/bin/perl
+python_OLD_CMD?= /usr/bin/python
+python_CMD?= ${LOCALBASE}/bin/python
+ruby_OLD_CMD?= /usr/bin/ruby
+ruby_CMD?= ${LOCALBASE}/bin/ruby
+php_OLD_CMD?= /usr/bin/php
+php_CMD?= ${LOCALBASE}/bin/php
+
+SHEBANG_LANG+= bash perl python ruby php
+
+.for lang in ${SHEBANG_LANG}
+.if !defined(${lang}_CMD)
+IGNORE+= missing definition for ${lang}_CMD
+.endif
+.if !defined(${lang}_OLD_CMD)
+IGNORE+= missing definition for ${lang}_OLD_CMD
+.endif
+_SHEBANG_REINPLACE_ARGS+= -e "1s|^\#![[:space:]]*${${lang}_OLD_CMD}|\#!${${lang}_CMD}|"
+.endfor
+
+pre-patch: fix-shebang
+
+fix-shebang:
+ @cd ${WRKSRC}; \
+ ${ECHO_CMD} ${SHEBANG_FILES} | ${XARGS} ${REINPLACE_CMD} ${_SHEBANG_REINPLACE_ARGS}
+
+.endif