aboutsummaryrefslogtreecommitdiff
path: root/m4/otf.m4
blob: 42b0224dc650057d83b7700d8f1f03e94bb78d19 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# otf.m4 -- helper function to detect OTF libraries            -*- Autoconf -*-
# Copyright (C) 2013  Galois, Inc.
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this library.  If not, see <http://www.gnu.org/licenses/>.
#
# To contact Galois, complete the Web form at <http://corp.galois.com/contact/>
# or write to Galois, Inc., 421 Southwest 6th Avenue, Suite 300, Portland,
# Oregon, 97204-1622.

# GALOIS_PPAML_LIB_OPENTRACE(ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
# This macro expands the OTF_CFLAGS and OTF_LIBS variables, but it does not add
# them to CFLAGS or LIBS.
AC_DEFUN([GALOIS_PPAML_LIB_OPENTRACE], [
    AC_REQUIRE([AC_PROG_SED])
    otf_ok=whoKnows
    # Check for otfconfig.
    AC_PATH_PROG([OTFCONFIG], [otfconfig])
    AC_ARG_VAR([OTFCONFIG], [path to otfconfig binary])
    if test -z "$OTFCONFIG"; then
        otf_ok=no
    else
        OTF_CFLAGS="`"$OTFCONFIG" --includes`"
        OTF_LIBS="`"$OTFCONFIG" --libs`"
        # Save CFLAGS and LIBS, and reset CFLAGS and LIBS to the OTF
        # requirements.
        SAVECFLAGS="$CFLAGS"
        SAVELIBS="$LIBS"
        CFLAGS="$OTF_CFLAGS"
        LIBS="$OTF_LIBS"
        # Try to compile using the CFLAGS.
        AC_COMPILE_IFELSE(
            [AC_LANG_PROGRAM(
                [#include <otf.h>"],
                [int x = otf_errno;])],
            [otf_compile_headers=yes],
            [otf_compile_headers=no])
        # Try to compile using the libraries.
        AC_LINK_IFELSE(
            [AC_LANG_PROGRAM(
                [#include <otf.h>"],
                [int x = otf_errno;])],
            [otf_link=yes],
            [otf_link=no])
        # Did we pass?
        if test \( "$otf_compile_headers" = "yes" \) -a \
            \( "$otf_link" = "yes" \); then
            otf_ok=yes
        else
            otf_ok=no
        fi
        # Restore CFLAGS and LIBS.
        CFLAGS="$SAVECFLAGS"
        LIBS="$SAVELIBS"
    fi
    # Execute the users' blocks.
    if test "$otf_ok" = "yes"; then
        AC_SUBST([OTF_CFLAGS])
        AC_SUBST([OTF_LIBS])
        ifelse([$1], , :, [$1])
    else
        ifelse([$2], , :, [$2])
    fi
])