Annotation of pkgsrc/mk/patch/patch.mk, revision 1.6

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

CVSweb <webmaster@jp.NetBSD.org>