summaryrefslogtreecommitdiff
path: root/scripts/mkc_check_funclib
diff options
context:
space:
mode:
authorAndrew Shadura <andrewsh@debian.org>2014-01-05 22:42:41 +0100
committerAndrew Shadura <andrew@shadura.me>2015-07-25 14:44:33 +0200
commitc8659b636be5e763c5dc028a5db7294b1af2648c (patch)
tree7dacf7580ff8c7d8c64682eaa28350bc47fbd56e /scripts/mkc_check_funclib
parent004c4cd3db1d9ad252eccbc1e9e6c54ec61a2927 (diff)
parentaba913436a8521abe405a04ed71388989e1d646f (diff)
Imported Debian patch 0.25.0-1
Diffstat (limited to 'scripts/mkc_check_funclib')
-rwxr-xr-xscripts/mkc_check_funclib119
1 files changed, 119 insertions, 0 deletions
diff --git a/scripts/mkc_check_funclib b/scripts/mkc_check_funclib
new file mode 100755
index 0000000..6b3ba4b
--- /dev/null
+++ b/scripts/mkc_check_funclib
@@ -0,0 +1,119 @@
+#!/bin/sh
+
+############################################################
+# Copyright (c) 2009-2010 by Aleksey Cheusov
+#
+# See LICENSE file in the distribution.
+############################################################
+
+set -e
+
+LC_ALL=C
+export LC_ALL
+
+##################################################
+# 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
+
+. 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
+ if test "$funcname" = main; then
+ fname=__fake__
+ else
+ fname="$funcname"
+ fi
+
+ cat > "$tmpc" <<EOF
+static void __fake__ () {}
+
+void $fname ();
+
+int main ()
+{
+ $fname ();
+ return 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 ${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