Pullup ticket #2747 - requested by tez
[pkgsrc.git] / mk / scripts / shlib-type
1 # /bin/sh
2 #
3 # $NetBSD: shlib-type,v 1.2 2007/08/02 15:46:33 jlam Exp $
4 #
5 # This code is derived from software contributed to The NetBSD Foundation
6 # by Alistair Crooks.
7 #
8 # This script returns the the library format for the platform.  If
9 # the library format is "ELF/a.out", then we inspect the specified
10 # path to determine the correct object format (either ELF or a.out).
11 #
12
13 if [ -z "${FILE_CMD}" ]; then
14         FILE_CMD=file
15 fi
16
17 if [ $# -lt 2 ]; then
18         echo 1>&2 "usage: shlib-type libformat binpath"
19         exit 1
20 fi
21
22 libformat="$1"
23 binpath="$2"
24
25 sotype=none
26 case "$1" in
27 ELF/a.out)
28         if [ -f "$binpath" ]; then
29                 output=`${FILE_CMD} $binpath 2>/dev/null`
30         else
31                 output=
32         fi
33         case "$output" in
34         *ELF*dynamically*)      sotype="ELF" ;;
35         *shared*library*)       sotype="a.out" ;;
36         *dynamically*)          sotype="a.out" ;;
37         *)                      sotype="ELF" ;;         # guess "ELF"
38         esac
39         ;;
40 *)
41         sotype="$1"
42         ;;
43 esac
44 echo $sotype
45
46 exit 0