Merge from vendor branch TNF:
[pkgsrc.git] / mk / alternatives.mk
1 # $NetBSD: alternatives.mk,v 1.3 2005/01/25 16:29:16 jmmv Exp $
2 #
3 # This Makefile fragment handles the alternatives system, registering a
4 # package in the database.
5 #
6 # The ALTERNATIVES_SRC variable contains the path to a file listing the
7 # alternatives provided by the package.  It defaults to the ALTERNATIVES
8 # file in the current directory if found.  If this variable is empty, no
9 # actions are taken by this file.
10 #
11
12 .if !defined(ALTERNATIVES_MK)
13 ALTERNATIVES_MK=        # defined
14
15 .if !defined(ALTERNATIVES_SRC)
16 .  if exists(${.CURDIR}/ALTERNATIVES)
17 ALTERNATIVES_SRC?=      ${.CURDIR}/ALTERNATIVES
18 .  else
19 ALTERNATIVES_SRC?=
20 .  endif
21 .endif
22
23 .if !empty(ALTERNATIVES_SRC)
24
25 ${WRKDIR}/.altinstall: ${ALTERNATIVES_SRC}
26         @{ ${ECHO} 'if ${TEST} $${STAGE} = "POST-INSTALL"; then'; \
27         ${ECHO} '${CAT} >./+ALTERNATIVES <<EOF'; \
28         ${SED} ${FILES_SUBST_SED} <${ALTERNATIVES_SRC}; \
29         ${ECHO} 'EOF'; \
30         ${ECHO} 'if ${TEST} -x ${PKG_ALTERNATIVES}; then'; \
31         ${ECHO} '${PKG_ALTERNATIVES} -gs register ./+ALTERNATIVES'; \
32         ${ECHO} 'fi'; \
33         ${ECHO} 'fi'; \
34         } >${WRKDIR}/.altinstall
35
36 ${WRKDIR}/.altdeinstall: ${ALTERNATIVES_SRC}
37         @{ ${ECHO} 'if ${TEST} $${STAGE} = "DEINSTALL"; then'; \
38         ${ECHO} 'if ${TEST} -x ${PKG_ALTERNATIVES}; then'; \
39         ${ECHO} '${PKG_ALTERNATIVES} -gs unregister ./+ALTERNATIVES'; \
40         ${ECHO} 'fi'; \
41         ${ECHO} '${RM} -f ./+ALTERNATIVES'; \
42         ${ECHO} 'fi'; \
43         } >${WRKDIR}/.altdeinstall
44
45 PRINT_PLIST_AWK+=       /^libdata\/alternatives\// { next; }
46 PRINT_PLIST_AWK+=       /^@dirrm libdata\/alternatives/ { next; }
47
48 EVAL_PREFIX+=                   PREFIX.pkg_alternatives=pkg_alternatives
49 PREFIX.alternatives_DEFAULT=    ${LOCALBASE}
50 PKG_ALTERNATIVES=               ${PREFIX.pkg_alternatives}/sbin/pkg_alternatives
51
52 INSTALL_EXTRA_TMPL+=    ${WRKDIR}/.altinstall
53 DEINSTALL_EXTRA_TMPL+=  ${WRKDIR}/.altdeinstall
54 USE_PKGINSTALL=         YES
55
56 .endif
57
58 .endif  # ALTERNATIVES_MK