summaryrefslogtreecommitdiff
path: root/mk/check/check-wrkref.mk
blob: 3249f6779e63edec70420d8896779f0112c05e7a (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-wrkref.mk,v 1.10 2006/11/12 00:13:26 rillig Exp $
#
# This file checks that the installed files don't contain any strings
# that point to the directory where the package had been built, to make
# sure that the package still works after the source code has been
# cleaned up.
#
# User-settable variables:
#
# CHECK_WRKREF:
#	The kind of directory that must not appear in installed files.
#
#	* "no" to disable this check at all
#	* "tools" for the tool wrapper directory
#	* "work" for WRKDIR
#	* "wrkobjdir" for WRKOBJDIR
#
#	Default value: "tools" for PKG_DEVELOPERs, "no" otherwise.
#
# Package-settable variables:
#
# CHECK_WRKREF_SKIP:
#	The list of filename patterns that should be excluded from this
#	test.
#

.if defined(PKG_DEVELOPER)
CHECK_WRKREF?=		tools
.endif
CHECK_WRKREF?=		no
CHECK_WRKREF_SKIP?=	# none

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

_CHECK_WRKREF_DIR.no=		# none
_CHECK_WRKREF_DIR.work=		${WRKDIR}
_CHECK_WRKREF_DIR.tools=	${TOOLS_DIR}
_CHECK_WRKREF_DIR.wrkobjdir=	${WRKOBJDIR}

.if !defined(_CHECK_WRKREF_DIR.${CHECK_WRKREF})
PKG_FAIL_REASON+=	"[check-wrkref.mk] CHECK_WRKREF must be one of { no tools work objwrkdir }."
.endif
_CHECK_WRKREF_DIR=	${_CHECK_WRKREF_DIR.${CHECK_WRKREF}}

.if empty(CHECK_WRKREF:M[nN][oO])
privileged-install-hook: _check-wrkref
.endif

_check-wrkref: error-check .PHONY
	@${STEP_MSG} "Checking for work-directory references in ${PKGNAME}"
	${RUN} rm -f ${ERROR_DIR}/${.TARGET}
	${_PKG_SILENT}${_PKG_DEBUG}					\
	exec 1>${ERROR_DIR}/${.TARGET};					\
	cd ${DESTDIR}${PREFIX};						\
	${_CHECK_WRKREF_FILELIST_CMD} | ${SORT} |			\
	while read file; do						\
		case "$$file" in					\
		${CHECK_WRKREF_SKIP:@p@${p}) continue;; @}		\
		*) ;;							\
		esac;							\
		${SHCOMMENT} "[$$file]";				\
		case ${_CHECK_WRKREF_DIR:Q}"" in			\
		"")	${ERROR_MSG} "[check-wrkref.mk] The directory to check is empty."; \
			exit 1;						\
			;;						\
		*)	grep ${_CHECK_WRKREF_DIR:Q}"" "$$file" 2>/dev/null | \
			sed -e "s|^|$$file:	|";			\
			;;						\
		esac;							\
	done
	${_PKG_SILENT}${_PKG_DEBUG}					\
	exec 1>>${ERROR_DIR}/${.TARGET};				\
	if ${_NONZERO_FILESIZE_P} ${ERROR_DIR}/${.TARGET}; then		\
		${ECHO} "*** The above files still have references to the build directory."; \
		${ECHO} "    This is possibly an error that should be fixed by unwrapping"; \
		${ECHO} "    the files or adding missing tools to the package makefile!"; \
	fi