summaryrefslogtreecommitdiff
path: root/mk/check/check-wrkref.mk
blob: 6baa150e5b18cabe81c5e99c4c6cd2272e1c361a (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
78
79
80
# $NetBSD: check-wrkref.mk,v 1.3 2006/06/07 17:05:25 jlam Exp $

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

###########################################################################
# CHECK_WRKREF_SKIP is a list of shell globs.  Installed files that
# match these globs are skipped when running the check-wrkref target.
#
.if !defined(_CHECK_WRKREF_SKIP_FILTER)
_CHECK_WRKREF_SKIP_FILTER=	${TRUE}
.  if defined(CHECK_WRKREF_SKIP) && !empty(CHECK_WRKREF_SKIP)
_CHECK_WRKREF_SKIP_FILTER=	case "$$file" in
_CHECK_WRKREF_SKIP_FILTER+=	${_CHECK_WRKREF_SKIP_FILTER_BODY}
_CHECK_WRKREF_SKIP_FILTER+=	*) ;;
_CHECK_WRKREF_SKIP_FILTER+=	esac
.  endif
.endif
.if !defined(_CHECK_WRKREF_SKIP_FILTER_BODY)
.  for _pattern_ in ${CHECK_WRKREF_SKIP}
_CHECK_WRKREF_SKIP_FILTER_BODY+=	${_pattern_}) continue ;;
.  endfor
.endif
MAKEVARS+=	_CHECK_WRKREF_SKIP_FILTER_BODY

_CHECK_WRKREF:=		${CHECK_WRKREF}
.if !empty(_CHECK_WRKREF:Mwork)
_CHECK_WRKREF:=		work		# "work" is the "max" option
.endif

###########################################################################
# check-wrkref target
#
_CHECK_WRKREF_FOUND=	${WRKDIR}/.check_wrkref_found

.PHONY: check-wrkref
check-wrkref: check-wrkref-message check-wrkref-clean ${_CHECK_WRKREF_FOUND}
	${_PKG_SILENT}${_PKG_DEBUG}					\
	if ${_ZERO_FILESIZE_P} ${_CHECK_WRKREF_FOUND}; then		\
		${DO_NADA};						\
	else								\
		${ERROR_MSG} "The following files still have references to the build directory."; \
		${ERROR_MSG} "This is possibly an error that should be fixed by unwrapping"; \
		${ERROR_MSG} "the files or adding missing tools to the package makefile!"; \
		${ERROR_MSG} "";					\
		${CAT} ${_CHECK_WRKREF_FOUND} | ${ERROR_CAT};		\
		exit 1;							\
	fi

.PHONY: check-wrkref-message
check-wrkref-message:
	@${STEP_MSG} "Checking for work-directory references in ${PKGNAME}"

check-clean: check-wrkref-clean
.PHONY: check-wrkref-clean
check-wrkref-clean:
	${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${_CHECK_WRKREF_FOUND}

${_CHECK_WRKREF_FOUND}:
	${_PKG_SILENT}${_PKG_DEBUG}					\
	${PKG_FILELIST_CMD} | ${SORT} |					\
	while read file; do						\
		${_CHECK_WRKREF_SKIP_FILTER};				\
		${SHCOMMENT} [$$file];					\
		case ${_CHECK_WRKREF:Mwork:Q}"" in			\
		work)							\
			${GREP} ${WRKDIR} "$$file" 2>/dev/null |	\
			${SED} -e "s|^|$$file:	|";			\
			;;						\
		esac;							\
		case ${_CHECK_WRKREF:Mtools:Q}"" in			\
		tools)							\
			${GREP} ${TOOLS_DIR} "$$file" 2>/dev/null |	\
			${SED} -e "s|^|$$file:	|";			\
			;;						\
		esac;							\
	done > ${.TARGET}.tmp
	${_PKG_SILENT}${_PKG_DEBUG}${MV} -f ${.TARGET}.tmp ${.TARGET}