63f8bf192648ba28e04a4602d25b49e74086c012
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / ejabberd / check-erlang-lib
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
11 usage() {
12     cat <<EOF
13 Usage:
14         $0 library
15 Look for Erlang's library in TARGET_DIR/usr/lib/erlang/lib.
16
17 If the library is found, it returns the path to the latest version,
18 relative to TARGET_DIR. Otherwise, it returns "not found".
19
20 If there are several versions, it returns an error because it does not
21 know which one Erlang uses.
22
23 EOF
24 }
25
26 die () {
27     echo "$@" >&2
28     exit 1
29 }
30
31 if [ $# -ne 1 ]; then
32     usage
33     exit 0
34 else
35     library="$1"
36 fi
37
38 target_dir="${TARGET_DIR:-output/target}"
39
40 [ -d "$target_dir" ] || die "TARGET_DIR is not a directory. Please \
41 specify the TARGET_DIR environment variable."
42
43 case "$(ls -1d -- "$target_dir/usr/lib/erlang/lib/$library-"* | wc -l)" in
44     0)
45         echo "not found"
46         ;;
47     1)
48         echo "$target_dir/usr/lib/erlang/lib/$library-"* \
49             | sed -e "s,^$target_dir,,"
50         ;;
51     *)
52         die "Several versions of $library have been found. Please \
53         remove the unused ones."
54         ;;
55 esac