File: mkc_check_funclib.in

package info (click to toggle)
mk-configure 0.36.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,996 kB
  • sloc: ansic: 4,974; makefile: 1,387; sh: 1,087; cpp: 177; perl: 101; yacc: 85; lex: 21
file content (118 lines) | stat: -rwxr-xr-x 2,223 bytes parent folder | download | duplicates (2)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh

############################################################
# Copyright (c) 2009-2010 by Aleksey Cheusov
#
# See LICENSE file in the distribution.
############################################################

set -e

LC_ALL=C
export LC_ALL

: ${CHECK_COMMON_SH_DIR:=@mkc_libexecdir@}

##################################################
# options
usage (){
    cat <<EOF
mkc_check_funclib detects presense of function in a library
by compiling and linking a test program.

Usage: mkc_check_funclib [OPTIONS] function [libraries...]

OPTIONS:
   -h             display this help
   -d             delete cache files

Examples:
   mkc_check_funclib dlopen dl
   mkc_check_funclib dlopen
   mkc_check_funclib strlcpy
   mkc_check_funclib select socket
EOF
}

if test $# -eq 0; then
    usage
    exit 1
fi
if test "_$1" = '_-h'; then
    usage
    exit 0
fi
if test "_$1" = '_-d'; then
    delcache=1
    shift
fi

##################################################
# initializing

pathpart=funclib_`echo $* | tr '/. ' ___`

funcname=$1
shift

. ${CHECK_COMMON_SH_DIR}/mkc_check_common.sh

for i in "$@"; do
    LDADD="$LDADD -l$i"
    libs_msg="$libs_msg -l$i"
done

if test -n "$libs_msg"; then
    libs_msg=" ($libs_msg )"
fi

##################################################
# test

check_itself (){
    # preparations
    fname="$funcname"

    cat > "$tmpc" <<EOF
void yylex ();
void yylex () {}

int $fname (int, char **);

int main(int argc, char **argv)
{
   if (argc && argv) return 0;
   return $fname(0, (char*)0);
}
EOF

    # test itself
    if $CC -o "$tmpexe" "$tmpc" $LDFLAGS $LDADD 2>"$tmperr"; then
	echo 1
    else
	# SunPro may leave object files in current directory.
	# We need not this garbage. Also we cannot use smart shell
	# expansions because of crappy Solaris' /bin/sh.
	tmpbase=`basename "$tmpc" | sed 's/[.][^.]*$//'`
	rm -f ${tmpbase}.o
	echo 0
    fi
}

check_and_cache "checking for function implementation ${funcname}${libs_msg}" "$cache" "$@"

##################################################
# clean-ups

cleanup

##################################################
# finishing

if test "$ret" -eq 1; then
    printme 'yes\n' 1>&2
else
    printme 'no\n' 1>&2
fi

echo $ret