Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / mk / check / check-interpreter.mk
blob268c7ef1bf1843652073c3102193a6dc2a7dee9d
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:
14 # CHECK_INTERPRETER
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
32 .else
33 CHECK_INTERPRETER?= no
34 .endif
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
45 .endif
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' |\
51 while read file; do \
52 case "$$file" in \
53 ${_CHECK_INTERP_SKIP:@p@${p}) continue ;;@} \
54 *) ;; \
55 esac; \
56 if [ ! -f "$$file" ]; then \
57 continue; \
58 fi; \
59 if [ ! -r "$$file" ]; then \
60 ${DELAYED_WARNING_MSG} "[check-interpreter.mk] File \"${DESTDIR}${PREFIX}/$$file\" cannot be read."; \
61 continue; \
62 fi; \
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\"."; \
66 continue; \
67 }; \
68 case "$$interp" in \
69 "") continue;; \
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."; \
72 else \
73 ${DELAYED_WARNING_MSG} "[check-interpreter.mk] The interpreter \"$$interp\" of \"${DESTDIR}${PREFIX}/$$file\" is not allowed."; \
74 fi; \
75 continue;; \
76 esac; \
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."; \
83 else \
85 ${DELAYED_WARNING_MSG} "[check-interpreter.mk] The interpreter \"$$interp\" of \"${DESTDIR}${PREFIX}/$$file\" does not exist."; \
86 fi; \
87 fi; \
88 done