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

1.12    ! rillig      1: # $NetBSD: patch.mk,v 1.11 2006/07/22 16:31: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
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-*
                    259: .endif
                    260: .if defined(LOCALPATCHES) && exists(${LOCALPATCHES}/${PKGPATH})
                    261: _PKGSRC_PATCHES+=      ${LOCALPATCHES}/${PKGPATH}/*
                    262: .endif
                    263: 
                    264: pkgsrc-patch-message:
1.2       rillig    265:        @${STEP_MSG} "Applying pkgsrc patches for ${PKGNAME}"
1.1       jlam      266: 
                    267: do-pkgsrc-patch:
                    268:        ${_PKG_SILENT}${_PKG_DEBUG}                                     \
                    269:        fail=;                                                          \
                    270:        patches=${_PKGSRC_PATCHES:Q};                                   \
                    271:        patch_warning() {                                               \
                    272:                ${ECHO_MSG} "**************************************";   \
                    273:                ${ECHO_MSG} "$$1";                                      \
                    274:                ${ECHO_MSG} "**************************************";   \
                    275:        };                                                              \
                    276:        for i in $$patches; do                                          \
                    277:                ${TEST} -f "$$i" || continue;                           \
                    278:                case "$$i" in                                           \
                    279:                *.orig|*.rej|*~)                                        \
                    280:                        ${STEP_MSG} "Ignoring patchfile $$i";           \
                    281:                        continue;                                       \
                    282:                        ;;                                              \
                    283:                ${PATCHDIR}/patch-local-*)                              \
                    284:                        ;;                                              \
                    285:                ${PATCHDIR}/patch-*)                                    \
                    286:                        if ${TEST} ! -f ${DISTINFO_FILE:Q}; then        \
                    287:                                patch_warning "Ignoring patch file $$i: distinfo not found"; \
                    288:                                continue;                               \
                    289:                        fi;                                             \
                    290:                        filename=`${BASENAME} $$i`;                     \
                    291:                        algsum=`${AWK} '(NF == 4) && ($$2 == "('$$filename')") && ($$3 == "=") {print $$1 " " $$4}' ${DISTINFO_FILE} || ${TRUE}`; \
                    292:                        if ${TEST} -z "$$algsum"; then                  \
                    293:                                patch_warning "Ignoring patch file $$i: no checksum found"; \
                    294:                                continue;                               \
                    295:                        fi;                                             \
                    296:                        set -- $$algsum;                                \
                    297:                        alg="$$1";                                      \
                    298:                        recorded="$$2";                                 \
1.9       jlam      299:                        calcsum=`${SED} -e '/\$$NetBSD.*/d' $$i | ${TOOLS_DIGEST} $$alg`; \
1.1       jlam      300:                        ${ECHO_PATCH_MSG} "Verifying $$filename (using digest algorithm $$alg)"; \
                    301:                        if ${TEST} "$$calcsum" != "$$recorded"; then    \
                    302:                                patch_warning "Ignoring patch file $$i: invalid checksum"; \
                    303:                                fail="$$fail $$i";                      \
                    304:                                continue;                               \
                    305:                        fi;                                             \
                    306:                        ;;                                              \
                    307:                esac;                                                   \
                    308:                ${ECHO_PATCH_MSG} "Applying pkgsrc patch $$i";          \
                    309:                fuzz_flags=;                                            \
                    310:                if ${PATCH} -v >/dev/null 2>&1; then                    \
                    311:                        fuzz_flags=${PATCH_FUZZ_FACTOR:Q};              \
                    312:                fi;                                                     \
                    313:                if ${PATCH} $$fuzz_flags ${PATCH_ARGS} < $$i; then      \
                    314:                        ${ECHO} "$$i" >> ${_PATCH_APPLIED_FILE:Q};      \
                    315:                else                                                    \
                    316:                        ${ECHO_MSG} "Patch $$i failed";                 \
                    317:                        fail="$$fail $$i";                              \
                    318:                fi;                                                     \
                    319:        done;                                                           \
                    320:        if ${TEST} -n "$$fail"; then                                    \
                    321:                ${ERROR_MSG} "Patching failed due to modified or broken patch file(s):"; \
                    322:                for i in $$fail; do                                     \
                    323:                        ${ERROR_MSG} "  $$i";                           \
                    324:                done;                                                   \
                    325:                ${_PKGSRC_PATCH_FAIL};                                  \
                    326:        fi

CVSweb <webmaster@jp.NetBSD.org>