xref: /OK3568_Linux_fs/buildroot/package/ejabberd/check-erlang-lib (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/sh -e
2*4882a593Smuzhiyun# Helper to bypass AC_ERLANG_CHECK_LIB
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun# Ejabberd releases do not download specific versions of its erlang
5*4882a593Smuzhiyun# dependencies.  Instead, it clones the master branch of a git
6*4882a593Smuzhiyun# repository and asks erl to provide the library version.  However,
7*4882a593Smuzhiyun# the target erl program cannot be called from the host. So, this
8*4882a593Smuzhiyun# script aims at finding the library version installed on the target,
9*4882a593Smuzhiyun# without calling erlang.
10*4882a593Smuzhiyun
11*4882a593Smuzhiyunusage() {
12*4882a593Smuzhiyun    cat <<EOF
13*4882a593SmuzhiyunUsage:
14*4882a593Smuzhiyun        $0 library
15*4882a593SmuzhiyunLook for Erlang's library in TARGET_DIR/usr/lib/erlang/lib.
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunIf the library is found, it returns the path to the latest version,
18*4882a593Smuzhiyunrelative to TARGET_DIR. Otherwise, it returns "not found".
19*4882a593Smuzhiyun
20*4882a593SmuzhiyunIf there are several versions, it returns an error because it does not
21*4882a593Smuzhiyunknow which one Erlang uses.
22*4882a593Smuzhiyun
23*4882a593SmuzhiyunEOF
24*4882a593Smuzhiyun}
25*4882a593Smuzhiyun
26*4882a593Smuzhiyundie () {
27*4882a593Smuzhiyun    echo "$@" >&2
28*4882a593Smuzhiyun    exit 1
29*4882a593Smuzhiyun}
30*4882a593Smuzhiyun
31*4882a593Smuzhiyunif [ $# -ne 1 ]; then
32*4882a593Smuzhiyun    usage
33*4882a593Smuzhiyun    exit 0
34*4882a593Smuzhiyunelse
35*4882a593Smuzhiyun    library="$1"
36*4882a593Smuzhiyunfi
37*4882a593Smuzhiyun
38*4882a593Smuzhiyuntarget_dir="${TARGET_DIR:-output/target}"
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun[ -d "$target_dir" ] || die "TARGET_DIR is not a directory. Please \
41*4882a593Smuzhiyunspecify the TARGET_DIR environment variable."
42*4882a593Smuzhiyun
43*4882a593Smuzhiyuncase "$(ls -1d -- "$target_dir/usr/lib/erlang/lib/$library-"* | wc -l)" in
44*4882a593Smuzhiyun    0)
45*4882a593Smuzhiyun        echo "not found"
46*4882a593Smuzhiyun        ;;
47*4882a593Smuzhiyun    1)
48*4882a593Smuzhiyun        echo "$target_dir/usr/lib/erlang/lib/$library-"* \
49*4882a593Smuzhiyun            | sed -e "s,^$target_dir,,"
50*4882a593Smuzhiyun        ;;
51*4882a593Smuzhiyun    *)
52*4882a593Smuzhiyun        die "Several versions of $library have been found. Please \
53*4882a593Smuzhiyun        remove the unused ones."
54*4882a593Smuzhiyun        ;;
55*4882a593Smuzhiyunesac
56