summaryrefslogtreecommitdiff
path: root/mk/check/check-interpreter.mk
blob: 1aa35238930dd03b879ba8d9fe9154231195012e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# $NetBSD: check-interpreter.mk,v 1.21 2007/11/30 08:34:31 bjs Exp $
#
# This file checks that after installation, all files of the package
# that start with a "#!" line will find their interpreter. Files that
# have a "#!" line with a non-existent interpreter will generate an
# error message if they are executable, and a warning message otherwise.
#
# User-settable variables:
#
# CHECK_INTERPRETER
#	Whether this check should be enabled or not.
#
#	Default value: "no"
#
# Package-settable variables:
#
# CHECK_INTERPRETER_SKIP
#	The list of file patterns that are skipped by the check.
#	All files in share/examples and share/doc are skipped as well.
#
#	Default value: (empty)
#
#	Example: share/package1/* share/package2/somefile
#

.if defined(PKG_DEVELOPER)
CHECK_INTERPRETER?=		yes
.else
CHECK_INTERPRETER?=		no
.endif
CHECK_INTERPRETER_SKIP?=	# empty

_CHECK_INTERP_SKIP=		share/doc/*
_CHECK_INTERP_SKIP+=		share/examples/*
_CHECK_INTERP_SKIP+=		${CHECK_INTERPRETER_SKIP}

_CHECK_INTERP_FILELIST_CMD?=	${SED} -e '/^@/d' ${PLIST}

.if !empty(CHECK_INTERPRETER:M[Yy][Ee][Ss])
privileged-install-hook: _check-interpreter
.endif

_check-interpreter: error-check .PHONY
	@${STEP_MSG} "Checking for non-existent script interpreters in ${PKGNAME}"
	${_PKG_SILENT}${_PKG_DEBUG}					\
	set -e;								\
	cd ${DESTDIR}${PREFIX};						\
	${_CHECK_INTERP_FILELIST_CMD} | ${SORT} | ${SED} 's,\\,\\\\,g' |\
	while read file; do						\
		case "$$file" in					\
		${_CHECK_INTERP_SKIP:@p@${p}) continue ;;@}		\
		*) ;;							\
		esac;							\
		if [ ! -r "$$file" ]; then				\
			${DELAYED_WARNING_MSG} "[check-interpreter.mk] File \"${DESTDIR}${PREFIX}/$$file\" cannot be read."; \
			continue;					\
		fi;							\
		${SHCOMMENT} "[$$file]";				\
		interp=`${SED} -n -e '1s/^#![[:space:]]*\([^[:space:]]*\).*/\1/p' -e '1q' < "$$file"` \
		|| {	${DELAYED_WARNING_MSG} "[check-interpreter.mk] sed(1) failed for \"${DESTDIR}${PREFIX}/$$file\"."; \
			continue;					\
		};							\
		case "$$interp" in					\
		"") continue;						\
		esac;							\
									\
		if { [ ! -f ${DESTDIR:Q}"$$interp" ] &&			\
		     [ ! -f "$$interp" ]; }; then			\
									\
			if [ -x "$$file" ]; then			\
				${DELAYED_ERROR_MSG} "[check-interpreter.mk] The interpreter \"$$interp\" of \"${DESTDIR}${PREFIX}/$$file\" does not exist."; \
			else						\
									\
				${DELAYED_WARNING_MSG} "[check-interpreter.mk] The interpreter \"$$interp\" of \"${DESTDIR}${PREFIX}/$$file\" does not exist."; \
			fi;						\
		fi;							\
	done