summaryrefslogtreecommitdiff
path: root/libmpuio.m4
blob: e4332c241ba8cf14f66a67807b4668033d4effa7 (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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
dnl #
dnl # /usr/share/aclocal/libmpuio.m4
dnl #
dnl # Configure paths for libmpuio
dnl # Andrey V.Kosteltsev

dnl ============================================================
dnl
dnl  Synopsis:
dnl     AC_CHECK_LIBMPUIO([MIN-VERSION [,             # minimum libmpuio version, e.g. 1.0.3
dnl                        DEFAULT-WITH-LIBMPU [,     # default value for --with-libmpuop option
dnl                        ACTION-IF-FOUND [,         # action to perform if libmpuio was found
dnl                        ACTION-IF-NOT-FOUND        # action to perform if libmpuio was not found
dnl                       ]]]])
dnl  Examples:
dnl     AC_CHECK_LIBMPUIO(1.0.3)
dnl     AC_CHECK_LIBMPUIO(1.0.3,,,CFLAGS="$CFLAGS -DHAVE_LIBMPUIO $LIBMPUIO_CFLAGS")
dnl     AC_CHECK_LIBMPUIO(1.0.3,yes,CFLAGS="$CFLAGS -DHAVE_LIBMPUIO")
dnl
dnl
dnl  If you have to change prefix returned by mpuio-config script or change
dnl  location of mpuio-config, you may set environment variable LIBMPUIO_CONFIG,
dnl  for example:
dnl
dnl  # export LIBMPUIO_CONFIG="/usr/bin/mpuio-config"
dnl
dnl ============================================================
dnl
dnl ============================================================
dnl  auxilliary macros
dnl ============================================================
AC_DEFUN([_AC_LIBMPUIO_ERROR], [dnl
AC_MSG_RESULT([*FAILED*])
cat <<EOT | sed -e 's/^[[ 	]]*/ | /' -e 's/>>/  /' 1>&2
$1
EOT
exit 1
])

AC_DEFUN([_AC_LIBMPUIO_VERBOSE], [dnl
if test "x$verbose" = "xyes"; then
    AC_MSG_RESULT([  $1])
fi
])

dnl ============================================================
dnl  the user macro
dnl ============================================================
AC_DEFUN([AC_CHECK_LIBMPUIO], [dnl
dnl
dnl ============================================================
dnl  prerequisites
dnl ============================================================
AC_REQUIRE([AC_PROG_CC])dnl
AC_REQUIRE([AC_PROG_CPP])dnl
dnl
dnl ============================================================
dnl  set LIBMPU_CONFIG variable
dnl ============================================================
if test -z "$LIBMPUIO_CONFIG"; then
  LIBMPUIO_CONFIG='mpuio-config'
fi
dnl
LIBMPUIO_CPPFLAGS=''
LIBMPUIO_CFLAGS=''
LIBMPUIO_LDFLAGS=''
LIBMPUIO_LIBS=''
AC_SUBST(LIBMPUIO_CPPFLAGS)
AC_SUBST(LIBMPUIO_CFLAGS)
AC_SUBST(LIBMPUIO_LDFLAGS)
AC_SUBST(LIBMPUIO_LIBS)
dnl
dnl ============================================================
dnl  command line options
dnl ============================================================
AC_MSG_CHECKING(for libmpuio)
_AC_LIBMPUIO_VERBOSE([])
AC_ARG_WITH(libmpuio,dnl
[  --with-libmpuio[=ARG]     Build with libmpuio Library  (default=]ifelse([$2],,yes,$2)[)],dnl
,dnl
with_libmpuio="ifelse([$2],,yes,$2)"
)dnl
_AC_LIBMPUIO_VERBOSE([+ Command Line Options:])
_AC_LIBMPUIO_VERBOSE([    o --with-libmpuio=$with_libmpu])
dnl
dnl ============================================================
dnl  configuration
dnl ============================================================
if test "x$with_libmpuio" != "xno"; then
    libmpuio_version=""
    libmpuio_location=""
    libmpuio_type=""
    libmpuio_cppflags=""
    libmpuio_cflags=""
    libmpuio_ldflags=""
    libmpuio_libs=""
    if test "x$with_libmpuio" = "xyes"; then
        #   via config script in $PATH
        changequote(, )dnl
        libmpuio_version=`($LIBMPUIO_CONFIG --version) 2>/dev/null |\
                        sed -e 's/^.*\([0-9]\.[0-9]*[ab.][0-9]*\).*$/\1/'`
        changequote([, ])dnl
        if test "x$libmpuio_version" != "x"; then
            libmpuio_location=`$LIBMPUIO_CONFIG --prefix`
            libmpuio_type='installed'
            libmpuio_cppflags=`$LIBMPUIO_CONFIG --cppflags`
            libmpuio_cflags=`$LIBMPUIO_CONFIG --cflags`
            libmpuio_ldflags=`$LIBMPUIO_CONFIG --ldflags`
            libmpuio_libs=`$LIBMPUIO_CONFIG --libs`
        fi
    fi
    dnl ========================================================
    dnl  Check whether the found version is sufficiently new
    dnl ========================================================
    _req_version="ifelse([$1],,1.0.0,$1)"
    for _var in libmpuio_version _req_version; do
        eval "_val=\"\$${_var}\""
        _major=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\1/'`
        _minor=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\2/'`
        _rtype=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\3/'`
        _micro=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\4/'`
        case $_rtype in
            "a" ) _rtype=0 ;;
            "b" ) _rtype=1 ;;
            "." ) _rtype=2 ;;
        esac
        _hex=`echo dummy | awk '{ printf("%d%02d%1d%02d", major, minor, rtype, micro); }' \
              "major=$_major" "minor=$_minor" "rtype=$_rtype" "micro=$_micro"`
        eval "${_var}_hex=\"\$_hex\""
    done
    _AC_LIBMPUIO_VERBOSE([+ Determined Versions:])
    _AC_LIBMPUIO_VERBOSE([    o existing: $libmpu_version -> 0x$libmpu_version_hex])
    _AC_LIBMPUIO_VERBOSE([    o required: $_req_version -> 0x$_req_version_hex])
    _ok=0
    if test "x$libmpuio_version_hex" != "x"; then
        if test "x$_req_version_hex" != "x"; then
            if test $libmpuio_version_hex -ge $_req_version_hex; then
                _ok=1
            fi
        fi
    fi
    if test "x$_ok" = "x0"; then
        _AC_LIBMPUIO_ERROR([dnl
        Found libmpuio version $libmpuio_version, but required at least version $_req_version.
        Upgrade libmpuio under $libmpuio_location to $_req_version or higher first, please.])
    fi
    dnl ========================================================
    dnl  Perform libmpuio Sanity Compile Check
    dnl ========================================================
    _ac_save_CPPFLAGS="$CPPFLAGS"
    _ac_save_CFLAGS="$CFLAGS"
    _ac_save_LDFLAGS="$LDFLAGS"
    _ac_save_LIBS="$LIBS"
    CPPFLAGS="$CPPFLAGS $libmpuio_cppflags"
    CFLAGS="$CFLAGS $libmpuio_cflags"
    LDFLAGS="$LDFLAGS $libmpuio_ldflags"
    LIBS="$LIBS $libmpu_libs"
    _AC_LIBMPUIO_VERBOSE([+ Test Build Environment:])
    _AC_LIBMPUIO_VERBOSE([    o CPPFLAGS="$CPPFLAGS"])
    _AC_LIBMPUIO_VERBOSE([    o CFLAGS="$CFLAGS"])
    _AC_LIBMPUIO_VERBOSE([    o LDFLAGS="$LDFLAGS"])
    _AC_LIBMPUIO_VERBOSE([    o LIBS="$LIBS"])
    cross_compile=no
    _AC_LIBMPUIO_VERBOSE([+ Performing Sanity Checks:])
    _AC_LIBMPUIO_VERBOSE([    o pre-processor test])
    AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
#include <libmpu.h>
    ]])], _ok=yes, _ok=no)
    if test "x$_ok" != "xyes"; then
        _AC_LIBMPUIO_ERROR([dnl
        Found libmpuio $libmpuio_version under $libmpuio_location, but
        was unable to perform a sanity pre-processor check. This means
        the libmpuio header libmpuio.h was not found.
        We used the following build environment:
        >> CPP="$CPP"
        >> CPPFLAGS="$CPPFLAGS"
        See config.log for possibly more details.])
    fi
    _AC_LIBMPUIO_VERBOSE([    o link check])
    AC_LINK_IFELSE([AC_LANG_SOURCE([[
#include <libmpuio.h>

int main()
{
  __mpu_init();

  __mpu_free_context();

  return( 0 );
}
    ]])], _ok=yes, _ok=no)
    if test "x$_ok" != "xyes"; then
        _AC_LIBMPUIO_ERROR([dnl
        Found libmpuio $libmpuio_version under $libmpuio_location, but
        was unable to perform a sanity linker check. This means
        the libmpuio library libmpuio.a was not found.
        We used the following build environment:
        >> CC="$CC"
        >> CFLAGS="$CFLAGS"
        >> LDFLAGS="$LDFLAGS"
        >> LIBS="$LIBS"
        See config.log for possibly more details.])
    fi
    CPPFLAGS="$_ac_save_CPPFLAGS"
    CFLAGS="$_ac_save_CFLAGS"
    LDFLAGS="$_ac_save_LDFLAGS"
    LIBS="$_ac_save_LIBS"

    LIBMPUIO_CPPFLAGS="$libmpuio_cppflags"
    LIBMPUIO_CFLAGS="$libmpuio_cflags"
    LIBMPUIO_LDFLAGS="$libmpuio_ldflags"
    LIBMPUIO_LIBS="$libmpuio_libs"
    AC_SUBST(LIBMPUIO_CPPFLAGS)
    AC_SUBST(LIBMPUIO_CFLAGS)
    AC_SUBST(LIBMPUIO_LDFLAGS)
    AC_SUBST(LIBMPUIO_LIBS)
    _AC_LIBMPUIO_VERBOSE([+ Final Results:])
    _AC_LIBMPUIO_VERBOSE([    o LIBMPUIO_CPPFLAGS="$LIBMPUIO_CPPFLAGS"])
    _AC_LIBMPUIO_VERBOSE([    o LIBMPUIO_CFLAGS="$LIBMPUIO_CFLAGS"])
    _AC_LIBMPUIO_VERBOSE([    o LIBMPUIO_LDFLAGS="$LIBMPUIO_LDFLAGS"])
    _AC_LIBMPUIO_VERBOSE([    o LIBMPUIO_LIBS="$LIBMPUIO_LIBS"])
fi
if test "x$with_libmpuio" != "xno"; then
    AC_MSG_RESULT([version $libmpuio_version, $libmpuio_type under $libmpuio_location])
    ifelse([$3], , :, [$3])
else
    AC_MSG_RESULT([no])
    ifelse([$4], , :, [$4])
fi
])