Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / mk / find-prefix.mk
blobf4cf1c3dafc5f19cc67f536754fec2519e9e9c7c
1 # $NetBSD: find-prefix.mk,v 1.6 2008/02/10 10:12:13 rillig Exp $
3 # This is a "subroutine" that can be included to find the installation
4 # prefix of an installed package.
6 # Parameters:
8 # FIND_PREFIX
9 # A list of <VARNAME>=<pattern> pairs, where
11 # * <pattern> is a package wildcard pattern (see pkg_info(8)),
12 # * <VARNAME> is the variable that will be set to the
13 # installation prefix for the package.
15 # Returns:
17 # <VARNAME>
18 # The prefix of the corresponding package, or ${LOCALBASE}
19 # if the package is not installed.
21 # Example:
23 # FIND_PREFIX:= M4DIR=gm4
24 # .include "../../mk/find-prefix.mk"
25 # # ${M4DIR} now contains the installation prefix for the "gm4" package.
28 .for i in ${FIND_PREFIX}
29 . for varname in ${i:C/=.*$//}
30 . for pattern in ${i:C/^[^=]*=//}
31 . if !defined(${varname})
33 # XXX: Is this *_DEFAULT variable really necessary? The default value
34 # can be easily embedded in the shell code. What if VARNAME is set to
35 # PKG_APACHE, for example?
37 ${varname}_DEFAULT?= ${LOCALBASE}
38 _${varname}_cmd= \
39 ${PKG_INFO} -qp ${pattern:Q} 2>/dev/null | \
40 { read cmd arg; \
41 case "$$arg" in \
42 "") ${ECHO} ${${varname}_DEFAULT:Q} ;; \
43 *) ${ECHO} "$$arg" ;; \
44 esac; }
45 ${varname}= ${_${varname}_cmd:sh}
46 . endif
47 MAKEVARS+= ${varname}
48 . endfor
49 . endfor
50 .endfor