Annotation of pkgsrc/mk/patch/patch.mk, revision 1.5
1.5 ! jlam 1: # $NetBSD: patch.mk,v 1.4 2006/06/09 13:59:08 jlam Exp $
1.1 jlam 2: #
3: # The following variables may be set in a package Makefile and control
4: # how pkgsrc patches are applied.
5: #
6: # PATCH_STRIP is a patch(1) argument that sets the pathname strip
7: # count to help find the correct files to patch. See the patch(1)
8: # man page for more details. Defaults to "-p0".
9: #
10: # PATCH_ARGS is the base set of arguments passed to patch(1).
11: # The default set of arguments will apply the patches to the
12: # files in ${WRKSRC} with any ${PATCH_STRIP} arguments set.
13: #
14: # The following variables may be set in a package Makefile and control
15: # how "distribution" patches are applied.
16: #
17: # PATCH_DIST_STRIP is a patch(1) argument that sets the pathname
18: # strip count to help find the correct files to patch. See the
19: # patch(1) man page for more details. Defaults to "-p0".
20: #
21: # PATCH_DIST_ARGS is the base set of arguments passed to patch(1).
22: # The default set of arguments will apply the patches to the
23: # files in ${WRKSRC} with any ${PATCH_DIST_STRIP} arguments set.
24: #
25: # PATCH_DIST_CAT is the command that outputs the contents of the
26: # "$patchfile" to stdout. The default value is a command that
27: # can output gzipped, bzipped, or plain patches to stdout.
28: #
29: # PATCH_DIST_STRIP.<patchfile>
30: # PATCH_DIST_ARGS.<patchfile>
31: # PATCH_DIST_CAT.<patchfile>
32: # These are versions of the previous three variables which allow
33: # for customization of their values for specific patchfiles.
34: #
35: # The following variables may be set by the user and affect how patching
36: # occurs:
37: #
38: # PATCH_DEBUG, if defined, causes the the patch process to be more
39: # verbose.
40: #
41: # PATCH_FUZZ_FACTOR is a patch(1) argument that specifies how much
42: # fuzz to accept when applying pkgsrc patches. See the patch(1)
43: # man page for more details. Defaults to "-F0" for zero fuzz.
44: #
45:
46: _PATCH_APPLIED_FILE= ${WRKDIR}/.patch
47: _PATCH_COOKIE= ${WRKDIR}/.patch_done
48:
49: ######################################################################
50: ### patch (PUBLIC)
51: ######################################################################
52: ### patch is a public target to apply the distribution and pkgsrc
53: ### patches to the extracted sources for the package.
54: ###
1.5 ! jlam 55: _PATCH_TARGETS+= check-vulnerable
1.1 jlam 56: _PATCH_TARGETS+= extract
57: _PATCH_TARGETS+= acquire-patch-lock
58: _PATCH_TARGETS+= ${_PATCH_COOKIE}
59: _PATCH_TARGETS+= release-patch-lock
60:
61: .PHONY: patch
1.5 ! jlam 62: .if !target(patch)
! 63: . if !exists(${_PATCH_COOKIE})
1.1 jlam 64: patch: ${_PATCH_TARGETS}
1.5 ! jlam 65: . else
! 66: patch:
! 67: @${DO_NADA}
! 68: . endif
! 69: .endif
1.1 jlam 70:
71: .PHONY: acquire-patch-lock release-patch-lock
72: acquire-patch-lock: acquire-lock
73: release-patch-lock: release-lock
74:
75: ${_PATCH_COOKIE}: real-patch
76:
77: ######################################################################
78: ### real-patch (PRIVATE)
79: ######################################################################
80: ### real-patch is a helper target onto which one can hook all of the
81: ### targets that do the actual patching work.
82: ###
83: _REAL_PATCH_TARGETS+= patch-message
84: _REAL_PATCH_TARGETS+= patch-vars
85: _REAL_PATCH_TARGETS+= pre-patch
86: _REAL_PATCH_TARGETS+= do-patch
87: _REAL_PATCH_TARGETS+= post-patch
88: _REAL_PATCH_TARGETS+= patch-cookie
1.4 jlam 89: _REAL_PATCH_TARGETS+= error-check
1.1 jlam 90:
91: .PHONY: real-patch
92: real-patch: ${_REAL_PATCH_TARGETS}
93:
94: .PHONY: patch-message
95: patch-message:
96: @${PHASE_MSG} "Patching for ${PKGNAME}"
97:
98: ######################################################################
99: ### patch-cookie (PRIVATE)
100: ######################################################################
101: ### patch-cookie creates the "patch" cookie file. The contents are
102: ### the paths to the patches that were applied (if any).
103: ###
104: .PHONY: patch-cookie
105: patch-cookie:
106: ${_PKG_SILENT}${_PKG_DEBUG} \
107: if ${TEST} -f ${_PATCH_APPLIED_FILE:Q}; then \
108: ${MV} -f ${_PATCH_APPLIED_FILE:Q} ${_PATCH_COOKIE:Q}; \
109: else \
110: ${TOUCH} ${TOUCH_FLAGS} ${_PATCH_COOKIE:Q}; \
111: fi
112:
113: ######################################################################
114: ### pre-patch, do-patch, post-patch (PUBLIC, override)
115: ######################################################################
116: ### {pre,do,post}-patch are the heart of the package-customizable
117: ### patch targets, and may be overridden within a package Makefile.
118: ###
119: .PHONY: pre-patch do-patch post-patch
120:
121: _PKGSRC_PATCH_TARGETS+= uptodate-digest
122: .if defined(PATCHFILES)
123: _PKGSRC_PATCH_TARGETS+= distribution-patch-message
124: _PKGSRC_PATCH_TARGETS+= do-distribution-patch
125: .endif
126: .if (defined(PATCHDIR) && exists(${PATCHDIR})) || \
127: (defined(LOCALPATCHES) && exists(${LOCALPATCHES}/${PKGPATH}))
128: _PKGSRC_PATCH_TARGETS+= pkgsrc-patch-message
129: _PKGSRC_PATCH_TARGETS+= do-pkgsrc-patch
130: .endif
131:
132: .PHONY: do-patch
133: .if !target(do-patch)
134: do-patch: ${_PKGSRC_PATCH_TARGETS}
135: .endif
136:
137: .if !target(pre-patch)
138: pre-patch:
139: @${DO_NADA}
140: .endif
141: .if !target(post-patch)
142: post-patch:
143: @${DO_NADA}
144: .endif
145:
146: ######################################################################
147:
148: .if defined(PATCH_DEBUG) || defined(PKG_VERBOSE)
149: _PATCH_DEBUG= yes
150: ECHO_PATCH_MSG?= ${STEP_MSG}
151: .else
152: _PATCH_DEBUG= no
153: ECHO_PATCH_MSG?= ${SHCOMMENT}
154: .endif
155:
156: PATCH_STRIP?= -p0
157: .if !empty(_PATCH_DEBUG:M[yY][eE][sS])
158: PATCH_ARGS?= -d ${WRKSRC} -E ${PATCH_STRIP}
159: .else
160: PATCH_ARGS?= -d ${WRKSRC} --forward --quiet -E ${PATCH_STRIP}
161: .endif
162: .if defined(BATCH)
163: PATCH_ARGS+= --batch
164: .endif
165: .if defined(_PATCH_CAN_BACKUP) && (${_PATCH_CAN_BACKUP} == "yes")
166: PATCH_ARGS+= ${_PATCH_BACKUP_ARG} .orig
167: .endif
168: PATCH_FUZZ_FACTOR?= -F0 # Default to zero fuzz
169:
170: _PKGSRC_PATCH_FAIL= \
171: if ${TEST} -n ${PKG_OPTIONS:Q}"" || \
172: ${TEST} -n ${LOCALPATCHES:Q}"" -a -d ${LOCALPATCHES:Q}/${PKGPATH:Q}; then \
173: ${ERROR_MSG} "=========================================================================="; \
174: ${ERROR_MSG}; \
175: ${ERROR_MSG} "Some of the selected build options and/or local patches may be incompatible."; \
176: ${ERROR_MSG} "Please try building with fewer options or patches."; \
177: ${ERROR_MSG}; \
178: ${ERROR_MSG} "=========================================================================="; \
179: fi; exit 1
180:
181: ######################################################################
182: ### do-distribution-patch (PRIVATE)
183: ######################################################################
184: ### do-distribution-patch applies the distribution patches (specified
185: ### in PATCHFILES) to the extracted sources.
186: ###
187: .PHONY: distribution-patch-message do-distribution-patch
188:
189: # PATCH_DIST_STRIP is a patch option that sets the pathname strip count.
190: # PATCH_DIST_ARGS is the list of arguments to pass to the patch command.
191: # PATCH_DIST_CAT is the command that outputs the patch to stdout.
192: #
193: # For each of these variables, there is a patch-specific variant that
194: # may be set, i.e. PATCH_DIST_STRIP.<patch>, PATCH_DIST_ARGS.<patch>,
195: # PATCH_DIST_CAT.<patch>.
196: #
197: PATCH_DIST_STRIP?= -p0
198: .for i in ${PATCHFILES}
199: PATCH_DIST_STRIP.${i:S/=/--/}?= ${PATCH_DIST_STRIP}
200: . if defined(PATCH_DIST_ARGS)
201: PATCH_DIST_ARGS.${i:S/=/--/}?= ${PATCH_DIST_ARGS}
202: . elif !empty(_PATCH_DEBUG:M[yY][eE][sS])
203: PATCH_DIST_ARGS.${i:S/=/--/}?= -d ${WRKSRC} -E ${PATCH_DIST_STRIP.${i:S/=/--/}}
204: . else
205: PATCH_DIST_ARGS.${i:S/=/--/}?= -d ${WRKSRC} --forward --quiet -E ${PATCH_DIST_STRIP.${i:S/=/--/}}
206: . endif
207: .endfor
208: .if defined(BATCH)
209: PATCH_DIST_ARGS+= --batch
210: . for i in ${PATCHFILES}
211: PATCH_DIST_ARGS.${i:S/=/--/}+= --batch
212: . endfor
213: .endif
214: .if defined(_PATCH_CAN_BACKUP) && (${_PATCH_CAN_BACKUP} == "yes")
215: PATCH_DIST_ARGS+= ${_PATCH_BACKUP_ARG} .orig_dist
216: . for i in ${PATCHFILES}
217: PATCH_DIST_ARGS.${i:S/=/--/}+= ${_PATCH_BACKUP_ARG} .orig_dist
218: . endfor
219: .endif
220: PATCH_DIST_CAT?= { case $$patchfile in \
221: *.Z|*.gz) ${GZCAT} $$patchfile ;; \
222: *.bz2) ${BZCAT} $$patchfile ;; \
223: *) ${CAT} $$patchfile ;; \
224: esac; }
225: .for i in ${PATCHFILES}
226: PATCH_DIST_CAT.${i:S/=/--/}?= { patchfile=${i}; ${PATCH_DIST_CAT}; }
227: .endfor
228:
229: distribution-patch-message:
1.3 rillig 230: @${STEP_MSG} "Applying distribution patches for ${PKGNAME}"
1.1 jlam 231:
232: do-distribution-patch:
233: .for i in ${PATCHFILES}
234: @${ECHO_PATCH_MSG} "Applying distribution patch ${i}"
235: ${_PKG_SILENT}${_PKG_DEBUG}cd ${_DISTDIR}; \
236: ${PATCH_DIST_CAT.${i:S/=/--/}} | \
237: ${PATCH} ${PATCH_DIST_ARGS.${i:S/=/--/}} || \
238: { ${ERROR_MSG} "Patch ${i} failed"; ${_PKGSRC_PATCH_FAIL}; }
239: ${_PKG_SILENT}${_PKG_DEBUG}${ECHO} ${_DISTDIR:Q}/${i:Q} >> ${_PATCH_APPLIED_FILE:Q}
240: .endfor
241:
242: ######################################################################
243: ### do-pkgsrc-patch (PRIVATE)
244: ######################################################################
245: ### do-pkgsrc-patch applies the pkgsrc patches to the extracted
246: ### sources.
247: ###
248: .PHONY: pkgsrc-patch-message do-pkgsrc-patch
249:
250: .if defined(PATCHDIR) && exists(${PATCHDIR})
251: _PKGSRC_PATCHES+= ${PATCHDIR}/patch-*
252: .endif
253: .if defined(LOCALPATCHES) && exists(${LOCALPATCHES}/${PKGPATH})
254: _PKGSRC_PATCHES+= ${LOCALPATCHES}/${PKGPATH}/*
255: .endif
256:
257: pkgsrc-patch-message:
1.2 rillig 258: @${STEP_MSG} "Applying pkgsrc patches for ${PKGNAME}"
1.1 jlam 259:
260: do-pkgsrc-patch:
261: ${_PKG_SILENT}${_PKG_DEBUG} \
262: fail=; \
263: patches=${_PKGSRC_PATCHES:Q}; \
264: patch_warning() { \
265: ${ECHO_MSG} "**************************************"; \
266: ${ECHO_MSG} "$$1"; \
267: ${ECHO_MSG} "**************************************"; \
268: }; \
269: for i in $$patches; do \
270: ${TEST} -f "$$i" || continue; \
271: case "$$i" in \
272: *.orig|*.rej|*~) \
273: ${STEP_MSG} "Ignoring patchfile $$i"; \
274: continue; \
275: ;; \
276: ${PATCHDIR}/patch-local-*) \
277: ;; \
278: ${PATCHDIR}/patch-*) \
279: if ${TEST} ! -f ${DISTINFO_FILE:Q}; then \
280: patch_warning "Ignoring patch file $$i: distinfo not found"; \
281: continue; \
282: fi; \
283: filename=`${BASENAME} $$i`; \
284: algsum=`${AWK} '(NF == 4) && ($$2 == "('$$filename')") && ($$3 == "=") {print $$1 " " $$4}' ${DISTINFO_FILE} || ${TRUE}`; \
285: if ${TEST} -z "$$algsum"; then \
286: patch_warning "Ignoring patch file $$i: no checksum found"; \
287: continue; \
288: fi; \
289: set -- $$algsum; \
290: alg="$$1"; \
291: recorded="$$2"; \
292: calcsum=`${SED} -e '/\$$NetBSD.*/d' $$i | ${DIGEST} $$alg`; \
293: ${ECHO_PATCH_MSG} "Verifying $$filename (using digest algorithm $$alg)"; \
294: if ${TEST} "$$calcsum" != "$$recorded"; then \
295: patch_warning "Ignoring patch file $$i: invalid checksum"; \
296: fail="$$fail $$i"; \
297: continue; \
298: fi; \
299: ;; \
300: esac; \
301: ${ECHO_PATCH_MSG} "Applying pkgsrc patch $$i"; \
302: fuzz_flags=; \
303: if ${PATCH} -v >/dev/null 2>&1; then \
304: fuzz_flags=${PATCH_FUZZ_FACTOR:Q}; \
305: fi; \
306: if ${PATCH} $$fuzz_flags ${PATCH_ARGS} < $$i; then \
307: ${ECHO} "$$i" >> ${_PATCH_APPLIED_FILE:Q}; \
308: else \
309: ${ECHO_MSG} "Patch $$i failed"; \
310: fail="$$fail $$i"; \
311: fi; \
312: done; \
313: if ${TEST} -n "$$fail"; then \
314: ${ERROR_MSG} "Patching failed due to modified or broken patch file(s):"; \
315: for i in $$fail; do \
316: ${ERROR_MSG} " $$i"; \
317: done; \
318: ${_PKGSRC_PATCH_FAIL}; \
319: fi
CVSweb <webmaster@jp.NetBSD.org>