Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / mk / pkgformat / pkg / replace.mk
blob55af4d01d17725abeb39ff38f3e8a0fb488da6a9
1 # $NetBSD: replace.mk,v 1.31 2010/09/14 22:30:42 gdt Exp $
4 # _pkgformat-replace:
5 # Updates a package in-place on the system (USE_DESTDIR=no).
7 # _pkgformat-destdir-replace:
8 # Updates a package in-place on the system (USE_DESTDIR=yes).
10 # See also:
11 # replace
13 # XXX: The whole replacement, from deinstalling the old package up
14 # to installing the new package, should be one transaction. It
15 # currently isn't, and the check-files target for other packages
16 # can be confused when a +REQUIRED_BY files suddenly disappears.
18 _pkgformat-replace: \
19 replace-names \
20 replace-tarup \
21 replace-preserve-installed-info \
22 replace-preserve-required-by \
23 deinstall \
24 install-clean \
25 install \
26 replace-fixup-required-by \
27 replace-fixup-installed-info \
28 .PHONY
30 _pkgformat-destdir-replace: \
31 replace-names \
32 replace-tarup \
33 replace-destdir \
34 .PHONY
36 # _pkgformat-undo-replace:
37 # Undoes the actions from a previous _pkgformat-replace.
39 # See also:
40 # undo-replace
42 _pkgformat-undo-replace: \
43 undo-replace-check \
44 replace-preserve-installed-info \
45 replace-preserve-required-by \
46 deinstall \
47 undo-replace-install \
48 replace-fixup-required-by \
49 replace-clean \
50 .PHONY
52 _pkgformat-destdir-undo-replace: \
53 undo-replace-check \
54 undo-destdir-replace-install \
55 replace-clean \
56 .PHONY
58 _INSTALLED_INFO_FILE= ${WRKDIR}/.replace-+INSTALLED_INFO
59 _REQUIRED_BY_FILE= ${WRKDIR}/.replace-+REQUIRED_BY
61 _COOKIE.replace= ${WRKDIR}/.replace_done
62 _REPLACE_OLDNAME_FILE= ${WRKDIR}/.replace_oldname
63 _REPLACE_NEWNAME_FILE= ${WRKDIR}/.replace_newname
65 _REPLACE_OLDNAME_CMD= \
66 [ -f ${_REPLACE_OLDNAME_FILE} ] \
67 || ${FAIL_MSG} "[${.TARGET}] ${_REPLACE_OLDNAME_FILE}: File not found"; \
68 oldname=`${CAT} ${_REPLACE_OLDNAME_FILE}`
70 _REPLACE_NEWNAME_CMD= \
71 [ -f ${_REPLACE_NEWNAME_FILE} ] \
72 || ${FAIL_MSG} "[${.TARGET}] ${_REPLACE_NEWNAME_FILE}: File not found"; \
73 newname=`${CAT} ${_REPLACE_NEWNAME_FILE}`
75 # Verifies that there was a previous "replace" action performed that can be undone.
77 undo-replace-check: .PHONY
78 ${RUN} [ -f ${_COOKIE.replace} ] \
79 || ${FAIL_MSG} "No replacement to undo!"
81 # Generates a binary package for the (older) installed package using pkg_tarup.
83 replace-tarup: .PHONY
84 ${RUN} [ -x ${_PKG_TARUP_CMD:Q} ] \
85 || ${FAIL_MSG} ${_PKG_TARUP_CMD:Q}" was not found."; \
86 ${_REPLACE_OLDNAME_CMD}; \
87 ${PKGSRC_SETENV} PKG_DBDIR=${_PKG_DBDIR} PKG_SUFX=${PKG_SUFX} \
88 PKGREPOSITORY=${WRKDIR} \
89 ${_PKG_TARUP_CMD} $${oldname} || \
90 ${FAIL_MSG} "Could not pkg_tarup $${oldname}".
92 # Re-installs the old package that has been saved by replace-tarup.
94 undo-replace-install: .PHONY
95 @${PHASE_MSG} "Re-adding ${PKGNAME} from saved tar-up package."
96 ${RUN} ${_REPLACE_OLDNAME_CMD}; \
97 ${ECHO} "Installing saved package ${WRKDIR}/$${oldname}${PKG_SUFX}"; \
98 ${PKG_ADD} ${WRKDIR}/$${oldname}${PKG_SUFX}
100 undo-destdir-replace-install: .PHONY
101 @${PHASE_MSG} "Re-adding ${PKGNAME} from saved tar-up package."
102 ${RUN} ${_REPLACE_OLDNAME_CMD}; \
103 ${ECHO} "Installing saved package ${WRKDIR}/$${oldname}${PKG_SUFX}"; \
104 ${PKG_ADD} -U -D ${WRKDIR}/$${oldname}${PKG_SUFX}
106 # Computes and saves the full names of the installed package to be replaced
107 # (oldname) and the package that will be installed (newname), so that these
108 # names are available later.
110 replace-names: .PHONY
111 ${RUN} if [ x"${OLDNAME}" = x ]; then \
112 wildcard=${PKGWILDCARD:Q}; \
113 else \
114 wildcard="${OLDNAME}-[0-9]*"; \
115 fi; \
116 ${_PKG_BEST_EXISTS} "$${wildcard}" > ${_REPLACE_OLDNAME_FILE}
117 ${RUN} ${ECHO} ${PKGNAME} > ${_REPLACE_NEWNAME_FILE}
118 ${RUN} ${CP} -f ${_REPLACE_NEWNAME_FILE} ${_COOKIE.replace}
120 # Saves and removes the +INSTALLED_INFO file from the installed package.
122 replace-preserve-installed-info: .PHONY
123 @${STEP_MSG} "Preserving existing +INSTALLED_INFO file."
124 ${RUN} ${_REPLACE_OLDNAME_CMD}; \
125 installed_info="${_PKG_DBDIR}/$$oldname/+INSTALLED_INFO"; \
126 ${TEST} ! -f "$$installed_info" || \
127 ${MV} $$installed_info ${_INSTALLED_INFO_FILE}
129 # Saves and removes the +REQUIRED_BY file from the installed package.
131 replace-preserve-required-by: .PHONY
132 @${STEP_MSG} "Preserving existing +REQUIRED_BY file."
133 ${RUN} ${_REPLACE_OLDNAME_CMD}; \
134 required_by="${_PKG_DBDIR}/$$oldname/+REQUIRED_BY"; \
135 ${TEST} ! -f "$$required_by" || \
136 ${MV} $$required_by ${_REQUIRED_BY_FILE}
138 # Fixes the +CONTENTS files of dependent packages to refer to the
139 # replacement package, and puts the +REQUIRED_BY file back into place.
140 # It also sets the unsafe_depends_strict tag on each dependent package,
141 # and sets the unsafe_depends tag if the replaced package has a different
142 # version.
144 # XXX Only set unsafe_depends if there is an ABI change.
146 replace-fixup-required-by: .PHONY
147 @${STEP_MSG} "Fixing @pkgdep entries in dependent packages."
148 ${RUN} ${_REPLACE_OLDNAME_CMD}; \
149 ${_REPLACE_NEWNAME_CMD}; \
150 ${TEST} -f ${_REQUIRED_BY_FILE} || exit 0; \
151 ${CAT} ${_REQUIRED_BY_FILE} | \
152 while read pkg; do \
153 case $$pkg in \
154 "") continue ;; \
155 /*) pkgdir="$$pkg" ;; \
156 *) pkgdir="${_PKG_DBDIR}/$$pkg" ;; \
157 esac; \
158 contents="$$pkgdir/+CONTENTS"; \
159 newcontents="$$contents.$$$$"; \
160 ${PKGSRC_SETENV} OLDNAME="$$oldname" NEWNAME="$$newname" \
161 ${AWK} '($$0 ~ "^@pkgdep " ENVIRON["OLDNAME"]) \
162 { print "@pkgdep " ENVIRON["NEWNAME"]; next } \
163 { print }' \
164 $$contents > $$newcontents; \
165 ${MV} -f $$newcontents $$contents; \
166 ${PKG_ADMIN} set unsafe_depends_strict=YES $$pkg; \
167 if ${TEST} "$$oldname" != "$$newname"; then \
168 ${PKG_ADMIN} set unsafe_depends=YES $$pkg; \
169 fi; \
170 done; \
171 ${MV} ${_REQUIRED_BY_FILE} ${_PKG_DBDIR}/$$newname/+REQUIRED_BY
173 # Removes unsafe_depends* and rebuild tags from this package.
175 # XXX: pkg_admin should not complain on unset with no +INSTALLED_INFO.
177 replace-fixup-installed-info: .PHONY
178 @${STEP_MSG} "Removing unsafe_depends and rebuild tags."
179 ${RUN} ${_REPLACE_NEWNAME_CMD}; \
180 [ ! -f ${_INSTALLED_INFO_FILE} ] || \
181 ${MV} ${_INSTALLED_INFO_FILE} ${_PKG_DBDIR}/$$newname/+INSTALLED_INFO; \
182 for var in unsafe_depends unsafe_depends_strict rebuild; do \
183 ${TEST} ! -f ${_PKG_DBDIR}/$$newname/+INSTALLED_INFO || \
184 ${PKG_ADMIN} unset $$var $$newname; \
185 done
187 # Removes the state files for the "replace" target, so that it may be re-invoked.
189 replace-clean: .PHONY
190 ${RUN} ${_REPLACE_OLDNAME_CMD}; \
191 ${_REPLACE_NEWNAME_CMD}; \
192 ${RM} -f ${WRKDIR}/$$oldname${PKG_SUFX}; \
193 ${RM} -f ${WRKDIR}/$$newname${PKG_SUFX}; \
194 ${RM} -f ${_REPLACE_OLDNAME_FILE} ${_REPLACE_NEWNAME_FILE} \
195 ${_COOKIE.replace}
197 # Logically we would like to do a "pkg_add -U". However, that fails
198 # if there is a depending package that exactly depends on the package
199 # being replaced, so we override that check with -D. Historically,
200 # 'make replace' would replace a package regardless of whether that
201 # broke depending packages (typically due to shlib ABI changes,
202 # especially major version bumps). Therefore, make replace in DESTDIR
203 # mode should behave the same way. unsafe_depends will be set on
204 # depending packages, and then those may be rebuilt via a manual
205 # process or by pkg_rolling-replace.
206 replace-destdir: .PHONY
207 @${PHASE_MSG} "Updating using binary package of "${PKGNAME:Q}
208 .if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
209 @${MKDIR} ${_CROSS_DESTDIR}${PREFIX}
210 ${PKG_ADD} -U -D -m ${MACHINE_ARCH} -I -p ${_CROSS_DESTDIR}${PREFIX} ${PKGFILE}
211 @${ECHO} "Fixing recorded cwd..."
212 @${SED} -e 's|@cwd ${_CROSS_DESTDIR}|@cwd |' ${_PKG_DBDIR}/${PKGNAME:Q}/+CONTENTS > ${_PKG_DBDIR}/${PKGNAME:Q}/+CONTENTS.tmp
213 @${MV} ${_PKG_DBDIR}/${PKGNAME:Q}/+CONTENTS.tmp ${_PKG_DBDIR}/${PKGNAME:Q}/+CONTENTS
214 .else
215 ${PKG_ADD} -U -D ${PKGFILE}
216 .endif
217 ${RUN}${_REPLACE_OLDNAME_CMD}; \
218 ${PKG_INFO} -qR ${PKGNAME:Q} | while read pkg; do \
219 [ -n "$$pkg" ] || continue; \
220 ${PKG_ADMIN} set unsafe_depends_strict=YES "$$pkg"; \
221 if [ "$$oldname" != ${PKGNAME:Q} ]; then \
222 ${PKG_ADMIN} set unsafe_depends=YES "$$pkg"; \
223 fi; \
224 done
225 ${RUN}${PKG_ADMIN} unset unsafe_depends ${PKGNAME:Q}
226 ${RUN}${PKG_ADMIN} unset unsafe_depends_strict ${PKGNAME:Q}
227 ${RUN}${PKG_ADMIN} unset rebuild ${PKGNAME:Q}