2
0

cmp-pkg-config.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env bash
  2. # Copyright (C) Viktor Szakats
  3. #
  4. # SPDX-License-Identifier: curl
  5. # Sort list of libs, libpaths, cflags found in libcurl.pc and curl-config files,
  6. # then diff the autotools and cmake generated ones.
  7. sort_lists() {
  8. prevline=''
  9. section=''
  10. while IFS= read -r l; do
  11. if [[ "${prevline}" =~ (--cc|--configure) ]]; then # curl-config
  12. echo "<IGNORED>"
  13. else
  14. # libcurl.pc
  15. if [[ "${l}" =~ ^(Requires|Libs|Cflags)(\.private)?:\ (.+)$ ]]; then
  16. if [ "${BASH_REMATCH[1]}" = 'Requires' ]; then
  17. # Spec does not allow duplicates here:
  18. # https://manpages.debian.org/unstable/pkg-config/pkg-config.1.en.html#Requires:
  19. # "You may only mention the same package one time on the Requires: line"
  20. val="$(printf '%s' "${BASH_REMATCH[3]}" | tr ',' '\n' | sort | tr '\n' ' ')"
  21. else
  22. val="$(printf '%s' "${BASH_REMATCH[3]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')"
  23. fi
  24. l="${BASH_REMATCH[1]}${BASH_REMATCH[2]}: ${val}"
  25. # curl-config
  26. elif [[ "${section}" =~ (--libs|--static-libs) && "${l}" =~ ^( *echo\ \")(.+)(\")$ ]]; then
  27. val="$(printf '%s' "${BASH_REMATCH[2]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')"
  28. l="${BASH_REMATCH[1]}${val}${BASH_REMATCH[3]}"
  29. section=''
  30. fi
  31. echo "${l}"
  32. fi
  33. # curl-config
  34. prevline="${l}"
  35. if [[ "${l}" =~ --[a-z-]+\) ]]; then
  36. section="${BASH_REMATCH[0]}"
  37. fi
  38. done < "$1"
  39. }
  40. am=$(mktemp -t autotools.XXX); sort_lists "$1" > "${am}"
  41. cm=$(mktemp -t cmake.XXX) ; sort_lists "$2" > "${cm}"
  42. diff -u "${am}" "${cm}"
  43. res="$?"
  44. rm -r -f "${am}" "${cm}"
  45. exit "${res}"