pullup 3232
[pkgsrcv2.git] / mk / alternatives.mk
1 # $NetBSD: alternatives.mk,v 1.10 2007/09/29 15:56:04 rillig Exp $
2 #
3 # This Makefile fragment handles the alternatives system, registering a
4 # package in the database.
5 #
6 # User-settable variables:
7 #
8 # (none)
9 #
10 # Package-settable variables:
11 #
12 # ALTERNATIVES_SRC
13 #       A _single_ file that contains the alternatives provided by the
14 #       package.
15 #
16 #       Default value: The name of the ALTERNATIVES file in the package
17 #       directory, if it exists. Otherwise, nothing.
18 #
19 #       Each line of the alternatives file contains two filenames, first
20 #       the wrapper and then the alternative provided by the package.
21 #       Both paths are relative to PREFIX.
22 #
23 # Variables defined by this file:
24 #
25 # PKG_ALTERNATIVES
26 #       The path to the pkg_alternatives command.
27 #
28
29 .if !defined(ALTERNATIVES_MK)
30 ALTERNATIVES_MK=        # defined
31
32 _VARGROUPS+=            alternatives
33 _PKG_VARS.alternatives= ALTERNATIVES_SRC
34 _SYS_VARS.alternatives= PKG_ALTERNATIVES
35
36 .if exists(${.CURDIR}/ALTERNATIVES)
37 ALTERNATIVES_SRC?=      ${.CURDIR}/ALTERNATIVES
38 .endif
39 ALTERNATIVES_SRC?=      # none
40
41 .if !empty(ALTERNATIVES_SRC)
42
43 ${WRKDIR}/.altinstall: ${ALTERNATIVES_SRC}
44         @{ ${ECHO} 'if ${TEST} $${STAGE} = "POST-INSTALL"; then'; \
45         ${ECHO} '${CAT} >./+ALTERNATIVES <<EOF'; \
46         ${SED} ${FILES_SUBST_SED} <${ALTERNATIVES_SRC}; \
47         ${ECHO} 'EOF'; \
48         ${ECHO} 'if ${TEST} -x ${PKG_ALTERNATIVES}; then'; \
49         ${ECHO} '${PKG_ALTERNATIVES} -gs register ./+ALTERNATIVES'; \
50         ${ECHO} 'fi'; \
51         ${ECHO} 'fi'; \
52         } >${WRKDIR}/.altinstall
53
54 ${WRKDIR}/.altdeinstall: ${ALTERNATIVES_SRC}
55         @{ ${ECHO} 'if ${TEST} $${STAGE} = "DEINSTALL"; then'; \
56         ${ECHO} 'if ${TEST} -x ${PKG_ALTERNATIVES}; then'; \
57         ${ECHO} '${PKG_ALTERNATIVES} -gs unregister ./+ALTERNATIVES'; \
58         ${ECHO} 'fi'; \
59         ${ECHO} '${RM} -f ./+ALTERNATIVES'; \
60         ${ECHO} 'fi'; \
61         } >${WRKDIR}/.altdeinstall
62
63 PRINT_PLIST_AWK+=       /^libdata\/alternatives\// { next; }
64
65 EVAL_PREFIX+=                   PREFIX.pkg_alternatives=pkg_alternatives
66 PREFIX.alternatives_DEFAULT=    ${LOCALBASE}
67 PKG_ALTERNATIVES=               ${PREFIX.pkg_alternatives}/sbin/pkg_alternatives
68
69 INSTALL_TEMPLATES+=     ${WRKDIR}/.altinstall
70 DEINSTALL_TEMPLATES+=   ${WRKDIR}/.altdeinstall
71
72 .endif
73
74 .endif  # ALTERNATIVES_MK