apply-all.sh (2299B)
1 #!/bin/bash 2 3 # 4 # This file applies optional libtool patches mainly for better MSys2 compatibility, 5 # especially for MSys2/Clang{64,32} toolchains. 6 # It's a pity that these patches haven't been sent upstream. 7 # 8 # Based on Debian SID baseline files as of April 2023. 9 # 10 11 patchesdir=$(dirname $BASH_SOURCE) || exit 2 12 test -n "$patchesdir" || exit 2 13 cd "$patchesdir" || exit 2 14 patchesdir=$(pwd) || exit 2 15 16 patches=( 17 0003-Pass-various-runtime-library-flags-to-GCC.mingw.mod.patch 18 0006-Fix-strict-ansi-vs-posix.patch 19 0009-libtool-2.4.2.418-msysize.patch 20 0010-libtool-2.4.2-include-process-h.patch 21 0011-Pick-up-clang_rt-static-archives-compiler-internal-l.patch 22 0012-Prefer-response-files-over-linker-scripts-for-mingw-.patch 23 0013-Allow-statically-linking-compiler-support-libraries-.patch 24 0014-Support-llvm-objdump-f-output.patch 25 ) 26 27 failed=( ) 28 29 cd "${patchesdir}/../.." || exit 1 30 31 patch_params="-Nf -p1 --no-backup-if-mismatch -r - --read-only=fail" 32 33 for patch in ${patches[@]}; do 34 patchfile="${patchesdir}/${patch}" 35 # Load patch into memory for simplicity 36 # Patches should not be very large 37 if grep -Eq -e '^--- .*\/ltmain\.in(\.orig)?([[:space:]]|$)' "$patchfile" && grep -Eq -e '^--- .*\/ltmain\.sh(\.orig)?([[:space:]]|$)' "$patchfile" 38 then 39 patch_data=$(awk '/^diff .*\/ltmain\.in(\.orig)?$/||(/^--- / && $2 ~ /\/ltmain\.in(\.orig)?$/){h=1;s=1;next}/^-- ?$/{h=0;s=0}/^[^-+@ ]/{h||s=0}/^\+\+\+ /{h=0}!s' "$patchfile") || exit 2 40 else 41 patch_data=$(cat "$patchfile") || exit 2 42 fi 43 patch_data=$(echo "$patch_data" | sed -E -e '/^(diff|---|\+\+\+) / s|/ltmain\.in|/ltmain.sh|g' -) || exit 2 44 patch_data=$(echo "$patch_data" | awk '(/^diff / && !/.*\/(ltmain\.sh|config\.guess|libtool\.m4|ltoptions\.m4)$/)||(/^--- / && $2 !~ /\/(ltmain\.sh|config\.guess|libtool\.m4|ltoptions\.m4)(\.orig)?$/){h=1;s=1;next}/^-- ?$/{h=0;s=0}/^[^-+@ ]/{h||s=0}/^\+\+\+ /{h=0}!s' -) || exit 2 45 echo "*** Applying $patch..." 46 if echo "$patch_data" | patch $patch_params -i - 47 then 48 echo "** $patch successfully applied." 49 else 50 echo "** $patch failed." 51 failed+=("$patch") 52 fi 53 unset patch_data 54 done 55 56 echo '' 57 58 if [[ -n "${failed[@]}" ]]; then 59 printf '* Failed patch: %s\n' "${failed[@]}" >&2 60 exit 2 61 else 62 echo "* All patches have been successfully applied." 63 fi 64 65 exit 0