Add to git.
[makeplus.git] / check_funcs.sh
1 #!/bin/sh
2 #
3 # This is make+. Make+ is a set of scripts which enhance GNU make and
4 # let ou build RPMs, and other packages types with just one control
5 # file. Read more at http://www.annexia.org/freeware/makeplus/
6 #
7 # The original author is Richard W.M. Jones <rich@annexia.org>.
8 #
9 # This software has been explicitly placed in the PUBLIC DOMAIN.  You
10 # do not need any sort of license or agreement to use or copy this
11 # software. You may also copyright this software yourself, and/or
12 # relicense it under any terms you want, at any time and at no cost.
13 # This allows you (among other things) to include this software with
14 # other packages so that the user does not need to download and
15 # install make+ separately.
16
17 require=$1
18 shift
19
20 for func in "$@"; do
21     sym=`echo $func | tr -- '-.[a-z]' '__[A-Z]'`
22     have=
23
24     # Try to compile and link a short program which references this
25     # symbol. If the symbol exists in the library then this ought to
26     # succeed.
27     rm -f mp-check_func
28     echo "char $func(); char (*f) ();int main(){f = $func;return 0;}" \
29         > mp-check_func.c
30     echo "mp-check_func.c:" >>config.log
31     cat mp-check_func.c >>config.log
32     echo $CC $CFLAGS mp-check_func.c -o mp-check_func $LIBS >>config.log
33     $CC $CFLAGS mp-check_func.c -o mp-check_func $LIBS >>config.log 2>&1
34     if [ $? -eq 0 ]; then
35         if [ -f mp-check_func ]; then
36             have=y
37         fi
38     fi
39     rm -f mp-check_func*
40
41     if [ "x$have" = "xy" ]; then
42         echo "#define HAVE_$sym 1" >> config.h
43         echo "HAVE_$sym := 1" >> config.mk
44     else
45         if [ "x$require" = "xy" ]; then
46             echo "configure: function $func is required; not found"
47             exit 1
48         fi
49         echo "/* #define HAVE_$sym 1 */" >> config.h
50         echo "# HAVE_$sym := 1" >> config.mk
51     fi
52 done