ci_shellify_shell.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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_shell {
  12. # Convert shell scripting text to shell scripting text.
  13. # Select only the easy-to-parse version definitions.
  14. sed -n -e '/^ *[A-Za-z_][0-9A-Za-z_]*=[0-9][^ #]* *$/ p' |
  15. sed -e 's/^ *\([^ ]*=[^ ]*\) *$/export \1;/'
  16. }
  17. function usage {
  18. echo "usage: $CI_SCRIPT_NAME [<options>] libpng-config-head.in"
  19. echo "options: -?|-h|--help"
  20. exit "${@:-0}"
  21. }
  22. function main {
  23. local opt
  24. while getopts ":" opt
  25. do
  26. # This ain't a while-loop. It only pretends to be.
  27. [[ $1 == -[?h]* || $1 == --help || $1 == --help=* ]] && usage 0
  28. ci_err "unknown option: '$1'"
  29. done
  30. shift $((OPTIND - 1))
  31. [[ $# -eq 0 ]] && usage 2
  32. [[ $# -eq 1 ]] || ci_err "too many operands"
  33. # And... go!
  34. test -e "$1" || ci_err "no such file: '$1'"
  35. [[ $(basename -- "$1") == libpng-config-head.in ]] || {
  36. ci_err "incorrect operand: '$1' (expecting: 'libpng-config-head.in')"
  37. }
  38. ci_shellify_shell <"$1"
  39. }
  40. main "$@"