Merge from vendor branch TNF:
[pkgsrcv2.git] / mk / bsd.pkg.update.mk
1 # $NetBSD: bsd.pkg.update.mk,v 1.21 2010/06/15 04:14:26 dholland Exp $
2 #
3 # This Makefile fragment is included by bsd.pkg.mk and contains the targets
4 # and variables for "make update".
5 #
6 # There is no documentation on what "update" actually does.  This is merely
7 # an attempt to separate the magic into a separate module that can be
8 # reimplemented later.
9 #
10
11 NOCLEAN?=       NO      # don't clean up after update
12 REINSTALL?=     NO      # reinstall upon update
13
14 # UPDATE_TARGET is the target that is invoked when updating packages during
15 # a "make update".  This variable is user-settable within /etc/mk.conf.
16 #
17 .if !defined(UPDATE_TARGET)
18 .  if defined(DEPENDS_TARGET) && (${DEPENDS_TARGET} == "update")
19 .    if ${_USE_DESTDIR} != "no" || make(package)
20 UPDATE_TARGET=  package-install
21 .    else
22 UPDATE_TARGET=  install
23 .    endif
24 .  else
25 UPDATE_TARGET=  ${DEPENDS_TARGET}
26 .  endif
27 .endif
28
29 # The 'update' target can be used to update a package and all
30 # currently installed packages that depend upon this package.
31
32 _DDIR=  ${WRKDIR}/.DDIR
33 _DLIST= ${WRKDIR}/.DLIST
34
35 .PHONY: update-create-ddir
36 update-create-ddir: ${_DDIR}
37
38 .PHONY: update
39 .if !target(update)
40 .if exists(${_DDIR})
41 RESUMEUPDATE?=  YES
42 CLEAR_DIRLIST?= NO
43
44 update:
45         @${PHASE_MSG} "Resuming update for ${PKGNAME}"
46 .  if ${REINSTALL} != "NO" && ${UPDATE_TARGET} != "replace"
47         ${RUN} ${RECURSIVE_MAKE} ${MAKEFLAGS} deinstall _UPDATE_RUNNING=YES DEINSTALLDEPENDS=ALL
48 .  endif
49 .else
50 RESUMEUPDATE?=  NO
51 CLEAR_DIRLIST?= YES
52
53 update:
54         ${RUN} ${RECURSIVE_MAKE} ${MAKEFLAGS} check-vulnerable
55         ${RUN} ${RECURSIVE_MAKE} ${MAKEFLAGS} update-create-ddir
56 .  if ${UPDATE_TARGET} != "replace"
57         ${RUN} if ${PKG_INFO} -qe ${PKGBASE}; then                      \
58                 ${RECURSIVE_MAKE} ${MAKEFLAGS} deinstall _UPDATE_RUNNING=YES DEINSTALLDEPENDS=ALL \
59                 || (${RM} ${_DDIR} && ${FALSE});                        \
60         fi
61 .  endif
62 .endif
63         ${RUN} ${RECURSIVE_MAKE} ${MAKEFLAGS} ${UPDATE_TARGET} KEEP_WRKDIR=YES DEPENDS_TARGET=${DEPENDS_TARGET:Q}
64         ${RUN}                                  \
65         [ ! -s ${_DDIR} ] || for dep in `${CAT} ${_DDIR}` ; do          \
66                 (if cd ../.. && cd "$${dep}" ; then                     \
67                         ${PHASE_MSG} "Installing in $${dep}" &&         \
68                         if [ "(" "${RESUMEUPDATE}" = "NO" -o            \
69                              "${REINSTALL}" != "NO" ")" -a              \
70                              "${UPDATE_TARGET}" != "replace" ] ; then   \
71                                 ${RECURSIVE_MAKE} ${MAKEFLAGS} deinstall _UPDATE_RUNNING=YES; \
72                         fi &&                                           \
73                         ${RECURSIVE_MAKE} ${MAKEFLAGS} ${UPDATE_TARGET} \
74                                 _PKGSRC_UPDATE_CHECK=yes                \
75                                 DEPENDS_TARGET=${DEPENDS_TARGET:Q} ;    \
76                 else                                                    \
77                         ${PHASE_MSG} "Skipping removed directory $${dep}"; \
78                 fi) ;                                                   \
79         done
80 .if ${NOCLEAN} == "NO"
81         ${RUN} ${RECURSIVE_MAKE} ${MAKEFLAGS} clean-update CLEAR_DIRLIST=YES
82 .endif
83
84
85 .PHONY: clean-update
86 clean-update:
87         ${RUN} ${RECURSIVE_MAKE} ${MAKEFLAGS} update-create-ddir
88         ${RUN}                                  \
89         if [ -s ${_DDIR} ] ; then                                       \
90                 for dep in `${CAT} ${_DDIR}` ; do                       \
91                         (if cd ../.. && cd "$${dep}" ; then             \
92                                 ${RECURSIVE_MAKE} ${MAKEFLAGS} clean ;  \
93                         else                                            \
94                                 ${PHASE_MSG} "Skipping removed directory $${dep}";\
95                         fi) ;                                           \
96                 done ;                                                  \
97         fi
98 .if ${CLEAR_DIRLIST} != "NO"
99         ${RUN} ${RECURSIVE_MAKE} ${MAKEFLAGS} clean
100 .else
101         ${RUN} ${RECURSIVE_MAKE} ${MAKEFLAGS} clean update-dirlist DIRLIST="`${CAT} ${_DDIR}`" PKGLIST="`${CAT} ${_DLIST}`"
102         @${WARNING_MSG} "preserved leftover directory list.  Your next"
103         @${WARNING_MSG} "\`\`${MAKE} update'' may fail.  It is advised to use"
104         @${WARNING_MSG} "\`\`${MAKE} update REINSTALL=YES'' instead!"
105 .endif
106
107 .endif  # !target(update)
108
109
110 .PHONY: update-dirlist
111 update-dirlist:
112         ${RUN} ${MKDIR} ${WRKDIR}
113 .if defined(PKGLIST)
114 .  for __tmp__ in ${PKGLIST}
115         ${RUN} ${ECHO} >>${_DLIST} "${__tmp__}"
116 .  endfor
117 .endif
118 .if defined(DIRLIST)
119 .  for __tmp__ in ${DIRLIST}
120         ${RUN} ${ECHO} >>${_DDIR} "${__tmp__}"
121 .  endfor
122 .endif
123
124
125 ${_DDIR}: ${_DLIST}
126         ${RUN} pkgs=`${CAT} ${_DLIST}`;                                 \
127         if [ "$$pkgs" ]; then ${PKG_INFO} -Q PKGPATH $$pkgs; fi > ${_DDIR}
128
129 ${_DLIST}: ${WRKDIR}
130         if ${PKG_INFO} -qe "${PKGWILDCARD}"; then \
131                 ${PKG_INFO} -qr "${PKGWILDCARD}" > ${_DLIST}; \
132         else \
133                 ${TOUCH} ${_DLIST}; \
134         fi