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