From: Michael Tremer Date: Sat, 3 Dec 2011 12:08:35 +0000 (+0100) Subject: Add more comfortable patch function. X-Git-Tag: 0.9.18~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=49e0e07336dfe9d0fec52064c353ae2ec847d5a5;p=pakfire.git Add more comfortable patch function. --- diff --git a/macros/build.macro b/macros/build.macro index b42207f84..f822adb38 100644 --- a/macros/build.macro +++ b/macros/build.macro @@ -58,6 +58,8 @@ MACRO_PERL_CLEANUP xargs --no-run-if-empty rm -f end +MACRO_PATCHES = /usr/lib/pakfire/patch %{patches} + # Pre-defined build scripts. build # These variables are used if you have to add some targets diff --git a/macros/constants.macro b/macros/constants.macro index 87e42114e..bda9bfb0a 100644 --- a/macros/constants.macro +++ b/macros/constants.macro @@ -14,7 +14,9 @@ configure_options = \ --build=%{DISTRO_MACHINE} \ --prefix=/usr -patches = +# By default, take all patches from the patches directory +# in alphabetical order. +patches = $(find %{DIR_PATCHES} -not -type d 2>/dev/null | sort) sources = %{thisapp}.tar.gz # Macro definitions @@ -23,38 +25,6 @@ sources = %{thisapp}.tar.gz # Guesses the compression type automatically. MACRO_EXTRACT = tar xvaf -MACRO_PATCHES - patches="%{patches}" - - if [ -n "${patches}" ]; then - _patches="" - for patch in ${patches}; do - _patches="${_patches} %{DIR_PATCHES}/${patch}" - done - patches="${_patches}" - unset _patches - else - for patch in %{DIR_PATCHES}/*.{diff,patch{,0}}; do - [ -e "${patch}" ] || continue - patches="${patches} ${patch}" - done - fi - - for patch in ${patches}; do - case "${patch}" in - *.patch0) - cmd="patch -Np0" - ;; - *.patch|*.diff) - cmd="patch -Np1" - ;; - esac - - ${cmd} -i ${patch} - done - unset cmd patch patches -end - # Remove rpath from libtool. MACRO_FIX_LIBTOOL if [ -e "%{DIR_APP}/libtool" ]; then diff --git a/scripts/Makefile b/scripts/Makefile index 4a4d79fd8..e3922fd33 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -9,6 +9,7 @@ SCRIPTS_SHELL = \ compress-man-pages \ dependency-tracker \ pakfire-multicall.py \ + patch \ py-compile \ quality-agent \ remove-static-libs \ diff --git a/scripts/patch b/scripts/patch new file mode 100755 index 000000000..6c4e9aa3d --- /dev/null +++ b/scripts/patch @@ -0,0 +1,44 @@ +#!/bin/bash +# Script that automatically applies patches. + +if [ -n "$@" ]; then + echo "Applying patches..." +fi + +# Apply all patches given on command line. +for patch in $@; do + # Check if patch file does exist. + if ! [ -e "${patch}" ]; then + echo >&2 " ERROR: Patch file does not exist: ${patch}" + exit 1 + fi + + # Options applied to patch command. + options="-N" + + # Get right -p1 option. + case "${patch}" in + *.patch[0-9]) + # Get patch level from file name. + level=${patch:$(( ${#patch} - 1))} + options="${options} -p${level}" + ;; + *.patch|*.diff) + # Default is -p1. + options="${options} -p1" + ;; + *.off) + # Ignore disabled patches. + continue + ;; + *) + echo >&2 " ERROR: Unknown filetype: ${patch}" + exit 1 + ;; + esac + + echo " Applying ${patch} (${options})..." + patch ${options} -i ${patch} || exit $? +done + +exit 0