check-erlang-lib 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh -e
  2. # Helper to bypass AC_ERLANG_CHECK_LIB
  3. #
  4. # Ejabberd releases do not download specific versions of its erlang
  5. # dependencies. Instead, it clones the master branch of a git
  6. # repository and asks erl to provide the library version. However,
  7. # the target erl program cannot be called from the host. So, this
  8. # script aims at finding the library version installed on the target,
  9. # without calling erlang.
  10. usage() {
  11. cat <<EOF
  12. Usage:
  13. $0 library
  14. Look for Erlang's library in TARGET_DIR/usr/lib/erlang/lib.
  15. If the library is found, it returns the path to the latest version,
  16. relative to TARGET_DIR. Otherwise, it returns "not found".
  17. If there are several versions, it returns an error because it does not
  18. know which one Erlang uses.
  19. EOF
  20. }
  21. die () {
  22. echo "$@" >&2
  23. exit 1
  24. }
  25. if [ $# -ne 1 ]; then
  26. usage
  27. exit 0
  28. else
  29. library="$1"
  30. fi
  31. target_dir="${TARGET_DIR:-output/target}"
  32. [ -d "$target_dir" ] || die "TARGET_DIR is not a directory. Please \
  33. specify the TARGET_DIR environment variable."
  34. case "$(ls -1d -- "$target_dir/usr/lib/erlang/lib/$library-"* | wc -l)" in
  35. 0)
  36. echo "not found"
  37. ;;
  38. 1)
  39. echo "$target_dir/usr/lib/erlang/lib/$library-"* \
  40. | sed -e "s,^$target_dir,,"
  41. ;;
  42. *)
  43. die "Several versions of $library have been found. Please \
  44. remove the unused ones."
  45. ;;
  46. esac