1 # $NetBSD: check-interpreter.mk,v 1.26 2011/04/19 14:28:28 roy Exp $
3 # This file checks that after installation, all files of the package
4 # that start with a "#!" line will find their interpreter. Files that
5 # have a "#!" line with a non-existent interpreter will generate an
6 # error message if they are executable, and a warning message otherwise.
8 # Files are not allowed to use /bin/env or /usr/bin/env as an interpreter
9 # due the use dynamic paths and package developers not checking that they work.
10 # A classic example is: #!/usr/bin/env python
12 # User-settable variables:
15 # Whether this check should be enabled or not.
17 # Default value: "yes" for PKG_DEVELOPER, "no" otherwise.
19 # Package-settable variables:
21 # CHECK_INTERPRETER_SKIP
22 # The list of file patterns that are skipped by the check.
23 # All files in share/examples and share/doc are skipped as well.
25 # Default value: (empty)
27 # Example: share/package1/* share/package2/somefile
30 .if defined
(PKG_DEVELOPER
) && ${PKG_DEVELOPER} != "no"
31 CHECK_INTERPRETER?
= yes
33 CHECK_INTERPRETER?
= no
35 CHECK_INTERPRETER_SKIP?
= # empty
37 _CHECK_INTERP_SKIP
= share
/doc
/*
38 _CHECK_INTERP_SKIP
+= share
/examples
/*
39 _CHECK_INTERP_SKIP
+= ${CHECK_INTERPRETER_SKIP}
41 _CHECK_INTERP_FILELIST_CMD?
= ${SED} -e
'/^@/d' ${PLIST}
43 .if
!empty
(CHECK_INTERPRETER
:M
[Yy
][Ee
][Ss
])
44 privileged-install-hook
: _check-interpreter
47 _check-interpreter
: error-check .PHONY
48 @
${STEP_MSG} "Checking for non-existent script interpreters in ${PKGNAME}"
49 ${RUN} cd
${DESTDIR}${PREFIX}; \
50 ${_CHECK_INTERP_FILELIST_CMD} |
${SORT} |
${SED} 's,\\,\\\\,g' |\
53 ${_CHECK_INTERP_SKIP
:@p@
${p}) continue
;;@
} \
56 if
[ ! -f
"$$file" ]; then \
59 if
[ ! -r
"$$file" ]; then \
60 ${DELAYED_WARNING_MSG} "[check-interpreter.mk] File \"${DESTDIR}${PREFIX}/$$file\" cannot be read."; \
63 ${SHCOMMENT} "[$$file]"; \
64 interp
=`${SED} -n -e '1s/^#![[:space:]]*\([^[:space:]]*\).*/\1/p' -e '1q' < "$$file"` \
65 ||
{ ${DELAYED_WARNING_MSG} "[check-interpreter.mk] sed(1) failed for \"${DESTDIR}${PREFIX}/$$file\"."; \
70 /bin
/env|
/usr
/bin
/env
) if
[ -x
"$$file" ]; then \
71 ${DELAYED_ERROR_MSG} "[check-interpreter.mk] The interpreter \"$$interp\" of \"${DESTDIR}${PREFIX}/$$file\" is not allowed."; \
73 ${DELAYED_WARNING_MSG} "[check-interpreter.mk] The interpreter \"$$interp\" of \"${DESTDIR}${PREFIX}/$$file\" is not allowed."; \
78 if
{ [ ! -f
${DESTDIR
:Q
}"$$interp" ] && \
79 [ ! -f
"$$interp" ]; }; then \
81 if
[ -x
"$$file" ]; then \
82 ${DELAYED_ERROR_MSG} "[check-interpreter.mk] The interpreter \"$$interp\" of \"${DESTDIR}${PREFIX}/$$file\" does not exist."; \
85 ${DELAYED_WARNING_MSG} "[check-interpreter.mk] The interpreter \"$$interp\" of \"${DESTDIR}${PREFIX}/$$file\" does not exist."; \