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 11usage() { 12 cat <<EOF 13Usage: 14 $0 library 15Look for Erlang's library in TARGET_DIR/usr/lib/erlang/lib. 16 17If the library is found, it returns the path to the latest version, 18relative to TARGET_DIR. Otherwise, it returns "not found". 19 20If there are several versions, it returns an error because it does not 21know which one Erlang uses. 22 23EOF 24} 25 26die () { 27 echo "$@" >&2 28 exit 1 29} 30 31if [ $# -ne 1 ]; then 32 usage 33 exit 0 34else 35 library="$1" 36fi 37 38target_dir="${TARGET_DIR:-output/target}" 39 40[ -d "$target_dir" ] || die "TARGET_DIR is not a directory. Please \ 41specify the TARGET_DIR environment variable." 42 43case "$(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 ;; 55esac 56