ci_shellify_cmake.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env bash
  2. set -o errexit -o pipefail -o posix
  3. # Copyright (c) 2019-2025 Cosmin Truta.
  4. #
  5. # Use, modification and distribution are subject to the MIT License.
  6. # Please see the accompanying file LICENSE_MIT.txt
  7. #
  8. # SPDX-License-Identifier: MIT
  9. # shellcheck source=ci/lib/ci.lib.sh
  10. source "$(dirname "$0")/../lib/ci.lib.sh"
  11. function ci_shellify_cmake {
  12. # Convert CMake lists text, specifically originating
  13. # from CMakeLists.txt, to shell scripting text.
  14. # Select only the easy-to-parse definitions of PNGLIB_*.
  15. sed -n -e '/^ *set *(PNGLIB_[^ ]* * [$"0-9A-Za-z_].*)/ p' |
  16. sed -e 's/^ *set *(PNG\([^ ]*\) * \([^() ]*\)).*$/PNG\1=\2/' \
  17. -e 's/^\([^ ]*=[^ ]*\).*$/export \1;/'
  18. }
  19. function usage {
  20. echo "usage: $CI_SCRIPT_NAME [<options>] CMakeLists.txt"
  21. echo "options: -?|-h|--help"
  22. exit "${@:-0}"
  23. }
  24. function main {
  25. local opt
  26. while getopts ":" opt
  27. do
  28. # This ain't a while-loop. It only pretends to be.
  29. [[ $1 == -[?h]* || $1 == --help || $1 == --help=* ]] && usage 0
  30. ci_err "unknown option: '$1'"
  31. done
  32. shift $((OPTIND - 1))
  33. [[ $# -eq 0 ]] && usage 2
  34. [[ $# -eq 1 ]] || ci_err "too many operands"
  35. # And... go!
  36. test -e "$1" || ci_err "no such file: '$1'"
  37. filename="$(basename -- "$1")"
  38. [[ $filename == [Cc][Mm]ake[Ll]ists.txt ]] || {
  39. ci_err "incorrect operand: '$1' (expecting: 'CMakeLists.txt')"
  40. }
  41. ci_shellify_cmake <"$1"
  42. }
  43. main "$@"