apply-all.sh 2.2 KB

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