summaryrefslogtreecommitdiff
path: root/mk/plist/shlib-type
blob: a657d4e05f0b3694c20f66a6a110262467ad26df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# /bin/sh
#
# $NetBSD: shlib-type,v 1.2 2006/01/19 17:24:44 jlam Exp $
#
# This code is derived from software contributed to The NetBSD Foundation
# by Alistair Crooks.
#
# This script returns the the library format for the platform.  If the
# library format is "ELF/a.out", then a small program is compiled to
# determine the correct object format (either ELF or a.out).
#

: ${CC=cc}
: ${ECHO=echo}
: ${FILE_CMD=file}
: ${RM=rm}
: ${MKDIR=mkdir}
: ${TEST=test}
: ${TMPDIR=/tmp}

self="${0##*/}"

usage() {
	${ECHO} 1>&2 "usage: $self libformat"
}

${TEST} $# -gt 0 || { usage; exit 1; }

sotype=none
case "$1" in
ELF/a.out)
	tmpdir="${TMPDIR}/shlib-type.$$"
	umask 077 && ${MKDIR} "$tmpdir"
	if ${TEST} -d "$tmpdir"; then
		cd $tmpdir
		${ECHO} "int main() { return(0); }" > a.c
		${CC} ${CFLAGS} a.c -o a.out >/dev/null 2>&1
		if ${TEST} -f "a.out"; then
			case `${FILE_CMD} a.out` in
			*ELF*dynamically*)	sotype="ELF" ;;
			*shared*library*)	sotype="a.out" ;;
			*dynamically*)		sotype="a.out" ;;
			esac
		fi
		${RM} -fr "$tmpdir"
	fi
	;;
*)
	sotype="$1"
	;;
esac
${ECHO} $sotype

exit 0