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