1 # $NetBSD: replace.mk,v 1.31 2010/09/14 22:30:42 gdt Exp $
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).
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.
21 replace-preserve-installed-info \
22 replace-preserve-required-by \
26 replace-fixup-required-by \
27 replace-fixup-installed-info \
30 _pkgformat-destdir-replace
: \
36 # _pkgformat-undo-replace:
37 # Undoes the actions from a previous _pkgformat-replace.
42 _pkgformat-undo-replace
: \
44 replace-preserve-installed-info \
45 replace-preserve-required-by \
47 undo-replace-install \
48 replace-fixup-required-by \
52 _pkgformat-destdir-undo-replace
: \
54 undo-destdir-replace-install \
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.
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
}; \
114 wildcard="${OLDNAME}-[0-9]*"; \
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
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} | \
155 /*) pkgdir
="$$pkg" ;; \
156 *) pkgdir
="${_PKG_DBDIR}/$$pkg" ;; \
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 } \
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; \
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; \
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} \
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
215 ${PKG_ADD} -U
-D
${PKGFILE}
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"; \
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
}