From 722db61ea2d1c465692c10bb68b7869150aaf61f Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 3 Nov 2010 15:56:37 +0100 Subject: [PATCH] xbps-src: improve how patches can be applied. 1) $patch_args can be used if all patches need special args other than "-Np0" (set by default). 2) If the $PATCHESDIR/series file exist, it will specify how the patches will be applied, in that order. --- xbps-src/shutils/patch_funcs.sh | 101 +++++++++++++++++------------- xbps-src/shutils/tmpl_funcs.sh.in | 2 +- 2 files changed, 57 insertions(+), 46 deletions(-) diff --git a/xbps-src/shutils/patch_funcs.sh b/xbps-src/shutils/patch_funcs.sh index 3f62774b11..afa8eb5012 100644 --- a/xbps-src/shutils/patch_funcs.sh +++ b/xbps-src/shutils/patch_funcs.sh @@ -27,56 +27,67 @@ # Applies to the build directory all patches found in PATCHESDIR # (templates/$pkgname/patches). # +_process_patch() +{ + local args _patch i=$1 + + args="-Np0" + _patch=$(basename $i) + if [ -f $PATCHESDIR/${_patch}.args ]; then + args=$(cat $PATCHESDIR/${_patch}.args) + elif [ -n "$patch_args" ]; then + args=$patch_args + fi + cp -f $i $wrksrc + + # Try to guess if its a compressed patch. + if $(echo $i|grep -q '.diff.gz'); then + gunzip $wrksrc/${_patch} + _patch=${_patch%%.gz} + elif $(echo $i|grep -q '.patch.gz'); then + gunzip $wrksrc/${_patch} + _patch=${_patch%%.gz} + elif $(echo $i|grep -q '.diff.bz2'); then + bunzip2 $wrksrc/${_patch} + _patch=${_patch%%.bz2} + elif $(echo $i|grep -q '.patch.bz2'); then + bunzip2 $wrksrc/${_patch} + _patch=${_patch%%.bz2} + elif $(echo $i|grep -q '.diff'); then + : + elif $(echo $i|grep -q '.patch'); then + : + else + msg_warn "unknown patch type: $i." + continue + fi + + cd $wrksrc && patch -s ${args} < ${_patch} 2>/dev/null + if [ $? -eq 0 ]; then + msg_normal "Patch applied: ${_patch}." + else + msg_error "couldn't apply patch: ${_patch}." + fi +} + apply_tmpl_patches() { - local patch_files args patch i + local f [ ! -d $PATCHESDIR ] && return 0 - for f in $(echo $PATCHESDIR/*); do - if $(echo $f|grep -q '.args'); then - continue - fi - patch_files="$patch_files $f" - done - - for i in ${patch_files}; do - args="-Np0" - patch=$(basename $i) - if [ -f $PATCHESDIR/$patch.args ]; then - args=$(cat $PATCHESDIR/$patch.args) - fi - cp -f $i $wrksrc - - # Try to guess if its a compressed patch. - if $(echo $i|grep -q '.diff.gz'); then - gunzip $wrksrc/$patch - patch=${patch%%.gz} - elif $(echo $i|grep -q '.patch.gz'); then - gunzip $wrksrc/$patch - patch=${patch%%.gz} - elif $(echo $i|grep -q '.diff.bz2'); then - bunzip2 $wrksrc/$patch - patch=${patch%%.bz2} - elif $(echo $i|grep -q '.patch.bz2'); then - bunzip2 $wrksrc/$patch - patch=${patch%%.bz2} - elif $(echo $i|grep -q '.diff'); then - : - elif $(echo $i|grep -q '.patch'); then - : - else - msg_warn "unknown patch type: $i." - continue - fi - - cd $wrksrc && patch -s ${args} < $patch 2>/dev/null - if [ $? -eq 0 ]; then - msg_normal "Patch applied: $patch." - else - msg_error "couldn't apply patch: $patch." - fi - done + if [ -r $PATCHESDIR/series ]; then + cat $PATCHESDIR/series | while read f; do + _process_patch "$PATCHESDIR/$f" + done + else + for f in $(echo $PATCHESDIR/*); do + if $(echo $f|grep -q '.args'); then + continue + fi + _process_patch $f + done + fi touch -f $XBPS_APPLYPATCHES_DONE } diff --git a/xbps-src/shutils/tmpl_funcs.sh.in b/xbps-src/shutils/tmpl_funcs.sh.in index f24f830fe0..d26ca16e92 100644 --- a/xbps-src/shutils/tmpl_funcs.sh.in +++ b/xbps-src/shutils/tmpl_funcs.sh.in @@ -68,7 +68,7 @@ reset_tmpl_vars() make_build_target configure_script noextract nofetch \ pre_configure pre_build pre_install build_depends \ post_configure post_build post_install nostrip \ - make_install_target version revision \ + make_install_target version revision patch_args \ sgml_catalogs xml_catalogs xml_entries sgml_entries \ disable_parallel_build run_depends font_dirs preserve \ only_for_archs conf_files keep_libtool_archives \