Merge from vendor branch TNF:
[pkgsrc.git] / mk / find-prefix.mk
1 # $NetBSD: find-prefix.mk,v 1.2 2005/05/12 21:56:11 jlam Exp $
2 #
3 # This is a "subroutine" that can be included to find the installation
4 # prefix of a package.
5 #
6 # The input variable is FIND_PREFIX, which is a list of VARNAME=<package>
7 # pairs, where "VARNAME" is the variable that will be set to the
8 # installation prefix for the package, and <package> is the ${PKGNAME}
9 # for the package.
10 #
11 # An example use is:
12 #
13 # FIND_PREFIX:= M4DIR=gm4
14 # .include "../../mk/find-prefix.mk"
15 # # ${M4DIR} now contains the installation prefix for the "gm4" package
16 #
17
18 .for _def_ in ${FIND_PREFIX}
19 .  if !defined(${_def_:C/=.*$//})
20 ${_def_:C/=.*$//}_DEFAULT?=     ${LOCALBASE}
21 _${_def_:C/=.*$//}_cmd=         \
22         ${PKG_INFO} -qp ${_def_:C/^.*=//} 2>/dev/null |                 \
23         { read cmd arg;                                                 \
24           case "$$arg" in                                               \
25           "")   ${ECHO} ${${_def_:C/=.*$//}_DEFAULT:Q} ;;               \
26           *)    ${ECHO} "$$arg" ;;                                      \
27           esac; }
28 ${_def_:C/=.*$//}=              ${_${_def_:C/=.*$//}_cmd:sh}
29 .  endif
30 MAKEVARS+=      ${_def_:C/=.*$//}
31 .endfor
32 .undef _def_