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

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

CVSweb <webmaster@jp.NetBSD.org>