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