Annotation of pkgsrc/mk/patch/patch.mk, revision 1.7
1.7 ! jlam 1: # $NetBSD: patch.mk,v 1.6 2006/07/05 22:21:03 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)
1.6 jlam 63: . if exists(${_PATCH_COOKIE})
1.5 jlam 64: patch:
65: @${DO_NADA}
1.6 jlam 66: . else
67: patch: ${_PATCH_TARGETS}
1.5 jlam 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:
1.6 jlam 75: .if exists(${_PATCH_COOKIE})
76: ${_PATCH_COOKIE}:
77: @${DO_NADA}
78: .else
1.1 jlam 79: ${_PATCH_COOKIE}: real-patch
1.6 jlam 80: .endif
1.1 jlam 81:
82: ######################################################################
83: ### real-patch (PRIVATE)
84: ######################################################################
85: ### real-patch is a helper target onto which one can hook all of the
86: ### targets that do the actual patching work.
87: ###
88: _REAL_PATCH_TARGETS+= patch-message
89: _REAL_PATCH_TARGETS+= patch-vars
90: _REAL_PATCH_TARGETS+= pre-patch
91: _REAL_PATCH_TARGETS+= do-patch
92: _REAL_PATCH_TARGETS+= post-patch
93: _REAL_PATCH_TARGETS+= patch-cookie
1.4 jlam 94: _REAL_PATCH_TARGETS+= error-check
1.1 jlam 95:
96: .PHONY: real-patch
97: real-patch: ${_REAL_PATCH_TARGETS}
98:
99: .PHONY: patch-message
100: patch-message:
101: @${PHASE_MSG} "Patching for ${PKGNAME}"
102:
103: ######################################################################
104: ### patch-cookie (PRIVATE)
105: ######################################################################
106: ### patch-cookie creates the "patch" cookie file. The contents are
107: ### the paths to the patches that were applied (if any).
108: ###
109: .PHONY: patch-cookie
110: patch-cookie:
1.7 ! jlam 111: ${_PKG_SILENT}${_PKG_DEBUG}${TEST} ! -f ${_PATCH_COOKIE} || ${FALSE}
1.1 jlam 112: ${_PKG_SILENT}${_PKG_DEBUG} \
113: if ${TEST} -f ${_PATCH_APPLIED_FILE:Q}; then \
114: ${MV} -f ${_PATCH_APPLIED_FILE:Q} ${_PATCH_COOKIE:Q}; \
115: else \
116: ${TOUCH} ${TOUCH_FLAGS} ${_PATCH_COOKIE:Q}; \
117: fi
118:
119: ######################################################################
120: ### pre-patch, do-patch, post-patch (PUBLIC, override)
121: ######################################################################
122: ### {pre,do,post}-patch are the heart of the package-customizable
123: ### patch targets, and may be overridden within a package Makefile.
124: ###
125: .PHONY: pre-patch do-patch post-patch
126:
127: _PKGSRC_PATCH_TARGETS+= uptodate-digest
128: .if defined(PATCHFILES)
129: _PKGSRC_PATCH_TARGETS+= distribution-patch-message
130: _PKGSRC_PATCH_TARGETS+= do-distribution-patch
131: .endif
132: .if (defined(PATCHDIR) && exists(${PATCHDIR})) || \
133: (defined(LOCALPATCHES) && exists(${LOCALPATCHES}/${PKGPATH}))
134: _PKGSRC_PATCH_TARGETS+= pkgsrc-patch-message
135: _PKGSRC_PATCH_TARGETS+= do-pkgsrc-patch
136: .endif
137:
138: .PHONY: do-patch
139: .if !target(do-patch)
140: do-patch: ${_PKGSRC_PATCH_TARGETS}
141: .endif
142:
143: .if !target(pre-patch)
144: pre-patch:
145: @${DO_NADA}
146: .endif
147: .if !target(post-patch)
148: post-patch:
149: @${DO_NADA}
150: .endif
151:
152: ######################################################################
153:
154: .if defined(PATCH_DEBUG) || defined(PKG_VERBOSE)
155: _PATCH_DEBUG= yes
156: ECHO_PATCH_MSG?= ${STEP_MSG}
157: .else
158: _PATCH_DEBUG= no
159: ECHO_PATCH_MSG?= ${SHCOMMENT}
160: .endif
161:
162: PATCH_STRIP?= -p0
163: .if !empty(_PATCH_DEBUG:M[yY][eE][sS])
164: PATCH_ARGS?= -d ${WRKSRC} -E ${PATCH_STRIP}
165: .else
166: PATCH_ARGS?= -d ${WRKSRC} --forward --quiet -E ${PATCH_STRIP}
167: .endif
168: .if defined(BATCH)
169: PATCH_ARGS+= --batch
170: .endif
171: .if defined(_PATCH_CAN_BACKUP) && (${_PATCH_CAN_BACKUP} == "yes")
172: PATCH_ARGS+= ${_PATCH_BACKUP_ARG} .orig
173: .endif
174: PATCH_FUZZ_FACTOR?= -F0 # Default to zero fuzz
175:
176: _PKGSRC_PATCH_FAIL= \
177: if ${TEST} -n ${PKG_OPTIONS:Q}"" || \
178: ${TEST} -n ${LOCALPATCHES:Q}"" -a -d ${LOCALPATCHES:Q}/${PKGPATH:Q}; then \
179: ${ERROR_MSG} "=========================================================================="; \
180: ${ERROR_MSG}; \
181: ${ERROR_MSG} "Some of the selected build options and/or local patches may be incompatible."; \
182: ${ERROR_MSG} "Please try building with fewer options or patches."; \
183: ${ERROR_MSG}; \
184: ${ERROR_MSG} "=========================================================================="; \
185: fi; exit 1
186:
187: ######################################################################
188: ### do-distribution-patch (PRIVATE)
189: ######################################################################
190: ### do-distribution-patch applies the distribution patches (specified
191: ### in PATCHFILES) to the extracted sources.
192: ###
193: .PHONY: distribution-patch-message do-distribution-patch
194:
195: # PATCH_DIST_STRIP is a patch option that sets the pathname strip count.
196: # PATCH_DIST_ARGS is the list of arguments to pass to the patch command.
197: # PATCH_DIST_CAT is the command that outputs the patch to stdout.
198: #
199: # For each of these variables, there is a patch-specific variant that
200: # may be set, i.e. PATCH_DIST_STRIP.<patch>, PATCH_DIST_ARGS.<patch>,
201: # PATCH_DIST_CAT.<patch>.
202: #
203: PATCH_DIST_STRIP?= -p0
204: .for i in ${PATCHFILES}
205: PATCH_DIST_STRIP.${i:S/=/--/}?= ${PATCH_DIST_STRIP}
206: . if defined(PATCH_DIST_ARGS)
207: PATCH_DIST_ARGS.${i:S/=/--/}?= ${PATCH_DIST_ARGS}
208: . elif !empty(_PATCH_DEBUG:M[yY][eE][sS])
209: PATCH_DIST_ARGS.${i:S/=/--/}?= -d ${WRKSRC} -E ${PATCH_DIST_STRIP.${i:S/=/--/}}
210: . else
211: PATCH_DIST_ARGS.${i:S/=/--/}?= -d ${WRKSRC} --forward --quiet -E ${PATCH_DIST_STRIP.${i:S/=/--/}}
212: . endif
213: .endfor
214: .if defined(BATCH)
215: PATCH_DIST_ARGS+= --batch
216: . for i in ${PATCHFILES}
217: PATCH_DIST_ARGS.${i:S/=/--/}+= --batch
218: . endfor
219: .endif
220: .if defined(_PATCH_CAN_BACKUP) && (${_PATCH_CAN_BACKUP} == "yes")
221: PATCH_DIST_ARGS+= ${_PATCH_BACKUP_ARG} .orig_dist
222: . for i in ${PATCHFILES}
223: PATCH_DIST_ARGS.${i:S/=/--/}+= ${_PATCH_BACKUP_ARG} .orig_dist
224: . endfor
225: .endif
226: PATCH_DIST_CAT?= { case $$patchfile in \
227: *.Z|*.gz) ${GZCAT} $$patchfile ;; \
228: *.bz2) ${BZCAT} $$patchfile ;; \
229: *) ${CAT} $$patchfile ;; \
230: esac; }
231: .for i in ${PATCHFILES}
232: PATCH_DIST_CAT.${i:S/=/--/}?= { patchfile=${i}; ${PATCH_DIST_CAT}; }
233: .endfor
234:
235: distribution-patch-message:
1.3 rillig 236: @${STEP_MSG} "Applying distribution patches for ${PKGNAME}"
1.1 jlam 237:
238: do-distribution-patch:
239: .for i in ${PATCHFILES}
240: @${ECHO_PATCH_MSG} "Applying distribution patch ${i}"
241: ${_PKG_SILENT}${_PKG_DEBUG}cd ${_DISTDIR}; \
242: ${PATCH_DIST_CAT.${i:S/=/--/}} | \
243: ${PATCH} ${PATCH_DIST_ARGS.${i:S/=/--/}} || \
244: { ${ERROR_MSG} "Patch ${i} failed"; ${_PKGSRC_PATCH_FAIL}; }
245: ${_PKG_SILENT}${_PKG_DEBUG}${ECHO} ${_DISTDIR:Q}/${i:Q} >> ${_PATCH_APPLIED_FILE:Q}
246: .endfor
247:
248: ######################################################################
249: ### do-pkgsrc-patch (PRIVATE)
250: ######################################################################
251: ### do-pkgsrc-patch applies the pkgsrc patches to the extracted
252: ### sources.
253: ###
254: .PHONY: pkgsrc-patch-message do-pkgsrc-patch
255:
256: .if defined(PATCHDIR) && exists(${PATCHDIR})
257: _PKGSRC_PATCHES+= ${PATCHDIR}/patch-*
258: .endif
259: .if defined(LOCALPATCHES) && exists(${LOCALPATCHES}/${PKGPATH})
260: _PKGSRC_PATCHES+= ${LOCALPATCHES}/${PKGPATH}/*
261: .endif
262:
263: pkgsrc-patch-message:
1.2 rillig 264: @${STEP_MSG} "Applying pkgsrc patches for ${PKGNAME}"
1.1 jlam 265:
266: do-pkgsrc-patch:
267: ${_PKG_SILENT}${_PKG_DEBUG} \
268: fail=; \
269: patches=${_PKGSRC_PATCHES:Q}; \
270: patch_warning() { \
271: ${ECHO_MSG} "**************************************"; \
272: ${ECHO_MSG} "$$1"; \
273: ${ECHO_MSG} "**************************************"; \
274: }; \
275: for i in $$patches; do \
276: ${TEST} -f "$$i" || continue; \
277: case "$$i" in \
278: *.orig|*.rej|*~) \
279: ${STEP_MSG} "Ignoring patchfile $$i"; \
280: continue; \
281: ;; \
282: ${PATCHDIR}/patch-local-*) \
283: ;; \
284: ${PATCHDIR}/patch-*) \
285: if ${TEST} ! -f ${DISTINFO_FILE:Q}; then \
286: patch_warning "Ignoring patch file $$i: distinfo not found"; \
287: continue; \
288: fi; \
289: filename=`${BASENAME} $$i`; \
290: algsum=`${AWK} '(NF == 4) && ($$2 == "('$$filename')") && ($$3 == "=") {print $$1 " " $$4}' ${DISTINFO_FILE} || ${TRUE}`; \
291: if ${TEST} -z "$$algsum"; then \
292: patch_warning "Ignoring patch file $$i: no checksum found"; \
293: continue; \
294: fi; \
295: set -- $$algsum; \
296: alg="$$1"; \
297: recorded="$$2"; \
298: calcsum=`${SED} -e '/\$$NetBSD.*/d' $$i | ${DIGEST} $$alg`; \
299: ${ECHO_PATCH_MSG} "Verifying $$filename (using digest algorithm $$alg)"; \
300: if ${TEST} "$$calcsum" != "$$recorded"; then \
301: patch_warning "Ignoring patch file $$i: invalid checksum"; \
302: fail="$$fail $$i"; \
303: continue; \
304: fi; \
305: ;; \
306: esac; \
307: ${ECHO_PATCH_MSG} "Applying pkgsrc patch $$i"; \
308: fuzz_flags=; \
309: if ${PATCH} -v >/dev/null 2>&1; then \
310: fuzz_flags=${PATCH_FUZZ_FACTOR:Q}; \
311: fi; \
312: if ${PATCH} $$fuzz_flags ${PATCH_ARGS} < $$i; then \
313: ${ECHO} "$$i" >> ${_PATCH_APPLIED_FILE:Q}; \
314: else \
315: ${ECHO_MSG} "Patch $$i failed"; \
316: fail="$$fail $$i"; \
317: fi; \
318: done; \
319: if ${TEST} -n "$$fail"; then \
320: ${ERROR_MSG} "Patching failed due to modified or broken patch file(s):"; \
321: for i in $$fail; do \
322: ${ERROR_MSG} " $$i"; \
323: done; \
324: ${_PKGSRC_PATCH_FAIL}; \
325: fi
CVSweb <webmaster@jp.NetBSD.org>