initial commit
[otp-base.git] / build / beamver
blobfe448b96650e96226f467360d1315e1370960d08
1 #!/bin/sh
3 # erlwareSys: otp/build/beamver,v 1.1 2002/02/14 11:45:20 hal Exp $
5 # usage: beamver <beam_file>
7 # if there's a usable -vsn() attribute, print it and exit with status 0
8 # otherwise, print nothing and exit with status 1
10 # From the Erlang shell:
12 # 5> code:which(acca_inets).
13 # "/home/martin/work/otp/releases/<app>/../../acca/ebin/<app>.beam"
15 # 8> beam_lib:version(code:which(<app>)).
16 # {ok,{<app>,['$Id: beamver,v 1.1.1.1 2003/06/13 21:43:21 mlogan Exp $ ']}}
18 # TMPFILE looks like this:
20 # io:format("hello ~p~n",
21 # beam_lib:version("/home/hal/work/otp/acca/ebin/acca_inets.beam")]).
23 TMPFILE=/tmp/beamver.$$
25 # exit with failure if we can't read the file
26 test -f "$1" || exit 1
27 BEAMFILE=\"$1\"
29 cat > $TMPFILE <<_EOF
30 io:format("~p~n",
31 [beam_lib:version($BEAMFILE)]).
32 _EOF
34 # beam_result is {ok,{Module_name, Beam_version} or {error,beam_lib,{Reason}}
35 beam_result=`erl -noshell \
36 -s file eval $TMPFILE \
37 -s erlang halt`
39 rm -f $TMPFILE
41 # sed regexes:
42 # remove brackets and anything outside them
43 # remove quotes and anything outside them
44 # remove apostrophes and anything outside them
45 # remove leading and trailing spaces
47 case $beam_result in
48 \{ok*)
49 echo $beam_result | sed -e 's/.*\[\(.*\)].*/\1/' \
50 -e 's/.*\"\(.*\)\".*/\1/' \
51 -e "s/.*\'\(.*\)\'.*/\1/" \
52 -e 's/ *$//' -e 's/^ *//'
53 exit 0
56 exit 1
58 esac