]> git.ipfire.org Git - pakfire.git/commitdiff
Add more comfortable patch function.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 3 Dec 2011 12:08:35 +0000 (13:08 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 4 Dec 2011 00:30:46 +0000 (01:30 +0100)
macros/build.macro
macros/constants.macro
scripts/Makefile
scripts/patch [new file with mode: 0755]

index b42207f84edb32ed546c688787b3a407a558f0a3..f822adb38036953320cfa84f31493a68b23e3aca 100644 (file)
@@ -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
index 87e42114e34806c0bd2ac7202893be333b234ef1..bda9bfb0ad1f219948daae626bb75fb31c3cf1de 100644 (file)
@@ -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
index 4a4d79fd83c24351230af6b44375081004152a68..e3922fd33206cfc3a464f1628d014bfff26afbb0 100644 (file)
@@ -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 (executable)
index 0000000..6c4e9aa
--- /dev/null
@@ -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