]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
macros: Move patch script into macros
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 8 Nov 2022 18:00:19 +0000 (18:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 8 Nov 2022 18:00:19 +0000 (18:00 +0000)
We no longer have a way to copy any scripts into the build environment,
but we can simply embed them.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
macros/build.macro
src/scripts/patch [deleted file]

index f5de8ec5db1b440bcf978cc0fff932858e689051..da8ac0e85f867a02d4cc3d7810f6f7bf0ecd579d 100644 (file)
@@ -707,7 +707,6 @@ dist_scripts_SCRIPTS = \
        src/scripts/find-prerequires \
        src/scripts/find-provides \
        src/scripts/find-requires \
-       src/scripts/patch \
        src/scripts/perl.prov \
        src/scripts/perl.req \
        src/scripts/py-compile \
index 2251074d6d519dfd98dbd4a622c0472d15b3dec3..dc79cc9ade303361d6cdbd5988dedb3b252dcab7 100644 (file)
@@ -71,7 +71,89 @@ def MACRO_FIX_AUTOTOOLS
        fi
 end
 
-MACRO_PATCHES = /usr/lib/pakfire/patch --search-path=%{DIR_PATCHES} "%{patches}"
+def MACRO_PATCHES
+       __patch() {
+               local paths=()
+               local path
+               local patches=()
+               local patch
+
+               while [ $# -gt 0 ]; do
+                       case "${1}" in
+                               --search-path=*)
+                                       paths+=( "${1#--search-path=}" )
+                                       ;;
+                               *)
+                                       patches+=( "${1}" )
+                                       ;;
+                       esac
+                       shift
+               done
+
+               # Apply all patches given on command line.
+               for patch in ${patches[@]}; do
+                       case "${patch}" in
+                               /*)
+                                       ;;
+                               *)
+                                       for path in ${paths[@]}; do
+                                               if [ -e "${path}/${patch}" ]; then
+                                                       patch="${path}/${patch}"
+                                                       break
+                                               fi
+                                       done
+                                       ;;
+                       esac
+
+                       # Check if patch file does exist.
+                       if ! [ -e "${patch}" ]; then
+                               echo >&2 "  ERROR: Patch file does not exist: ${patch}"
+                               return 1
+                       fi
+
+                       # Options applied to patch command.
+                       options="-N"
+
+                       # Get right -p1 option.
+                       case "${patch}" in
+                               *.patch[0-9]|*.patch[0-9]R)
+                                       _patch="${patch}"
+                                       # Get patch level from file name.
+                                       while [ ${#_patch} -gt 0 ]; do
+                                               last_pos=$(( ${#_patch} - 1 ))
+                                               last_char=${_patch:${last_pos}}
+                                               _patch=${_patch:0:${last_pos}}
+
+                                               case "${last_char}" in
+                                                       [0-9])
+                                                               options="${options} -p${last_char}"
+                                                               break
+                                                               ;;
+                                                       R)
+                                                               options="${options} -R"
+                                                               ;;
+                                               esac
+                                       done
+                                       ;;
+                               *.patch|*.diff)
+                                       # Default is -p1.
+                                       options="${options} -p1"
+                                       ;;
+                               *)
+                                       echo >&2 "   WARNING: Ignoring unknown file: ${patch}"
+                                       continue
+                                       ;;
+                       esac
+
+                       echo "  Applying ${patch} (${options})..."
+                       patch ${options} -i ${patch} || return $?
+               done
+
+               return 0
+       }
+
+       __patch --search-path=%{DIR_PATCHES} "%{patches}"
+end
 
 # Pre-defined build scripts.
 build
diff --git a/src/scripts/patch b/src/scripts/patch
deleted file mode 100644 (file)
index 4d4c2ae..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/bin/bash
-# Script that automatically applies patches.
-
-paths=
-patches=
-
-while [ $# -gt 0 ]; do
-       case "${1}" in
-               --search-path=*)
-                       paths="${paths} ${1#--search-path=}"
-                       ;;
-               *)
-                       patches="${patches} ${1}"
-                       ;;
-       esac
-       shift
-done
-
-if [ -n "${patches}" ]; then
-       echo "Applying patches..."
-fi
-
-# Apply all patches given on command line.
-for patch in ${patches}; do
-       case "${patch}" in
-               /*)
-                       ;;
-               *)
-                       for path in ${paths}; do
-                               if [ -e "${path}/${patch}" ]; then
-                                       patch="${path}/${patch}"
-                                       break
-                               fi
-                       done
-                       ;;
-       esac
-
-       # 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]|*.patch[0-9]R)
-                       _patch="${patch}"
-                       # Get patch level from file name.
-                       while [ ${#_patch} -gt 0 ]; do
-                               last_pos=$(( ${#_patch} - 1 ))
-                               last_char=${_patch:${last_pos}}
-                               _patch=${_patch:0:${last_pos}}
-
-                               case "${last_char}" in
-                                       [0-9])
-                                               options="${options} -p${last_char}"
-                                               break
-                                               ;;
-                                       R)
-                                               options="${options} -R"
-                                               ;;
-                               esac
-                       done
-                       ;;
-               *.patch|*.diff)
-                       # Default is -p1.
-                       options="${options} -p1"
-                       ;;
-               *)
-                       echo >&2 "   WARNING: Ignoring unknown file: ${patch}"
-                       continue
-                       ;;
-       esac
-
-       echo "  Applying ${patch} (${options})..."
-       patch ${options} -i ${patch} || exit $?
-done
-
-exit 0