author: kx <kx@radix-linux.su> 2024-12-20 16:11:07 +0300
committer: kx <kx@radix-linux.su> 2024-12-20 16:11:07 +0300
commit: 868b2b66b564b5c00e3a74d10be45db7151627ac
parent: cce2ae8d3312493b7653358bb4af201d3271377b
Commit Summary:
Diffstat:
1 file changed, 244 insertions, 0 deletions
diff --git a/libmpu.m4 b/libmpu.m4
new file mode 100644
index 0000000..b3e320e
--- /dev/null
+++ b/libmpu.m4
@@ -0,0 +1,252 @@
+dnl #
+dnl # /usr/share/aclocal/libmpu.m4
+dnl #
+dnl # Configure paths for libmpu
+dnl # Andrey V.Kosteltsev
+
+dnl ============================================================
+dnl
+dnl Synopsis:
+dnl AC_CHECK_LIBMPU([MIN-VERSION [, # minimum libmpu version, e.g. 1.0.14
+dnl DEFAULT-WITH-LIBMPU [, # default value for --with-libmpu option
+dnl ACTION-IF-FOUND [, # action to perform if libmpu was found
+dnl ACTION-IF-NOT-FOUND # action to perform if libmpu was not found
+dnl ]]]])
+dnl Examples:
+dnl AC_CHECK_LIBMPU(1.0.14)
+dnl AC_CHECK_LIBMPU(1.0.14,,,CFLAGS="$CFLAGS -DHAVE_LIBMPU $LIBMPU_CFLAGS")
+dnl AC_CHECK_LIBMPU(1.0.14,yes,CFLAGS="$CFLAGS -DHAVE_LIBMPU")
+dnl
+dnl
+dnl If you have to change prefix returned by mpu-config script or change
+dnl location of mpu-config, you may set environment variable LIBMPU_CONFIG,
+dnl for example:
+dnl
+dnl # export LIBMPU_CONFIG="/usr/bin/mpu-config"
+dnl
+dnl ============================================================
+dnl
+dnl ============================================================
+dnl auxilliary macros
+dnl ============================================================
+AC_DEFUN([_AC_LIBMPU_ERROR], [dnl
+AC_MSG_RESULT([*FAILED*])
+cat <<EOT | sed -e 's/^[[ ]]*/ | /' -e 's/>>/ /' 1>&2
+$1
+EOT
+exit 1
+])
+
+AC_DEFUN([_AC_LIBMPU_VERBOSE], [dnl
+if test "x$verbose" = "xyes"; then
+ AC_MSG_RESULT([ $1])
+fi
+])
+
+dnl ============================================================
+dnl the user macro
+dnl ============================================================
+AC_DEFUN([AC_CHECK_LIBMPU], [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 "$LIBMPU_CONFIG"; then
+ LIBMPU_CONFIG='mpu-config'
+fi
+dnl
+LIBMPU_CPPFLAGS=''
+LIBMPU_CFLAGS=''
+LIBMPU_LDFLAGS=''
+LIBMPU_LIBS=''
+LIBMPU_REAL_IO_DATA_LIMIT=''
+LIBMPU_MATH_FN_DATA_LIMIT=''
+LIBMPU_REAL_MAX_WIDTH=''
+AC_SUBST(LIBMPU_CPPFLAGS)
+AC_SUBST(LIBMPU_CFLAGS)
+AC_SUBST(LIBMPU_LDFLAGS)
+AC_SUBST(LIBMPU_LIBS)
+AC_SUBST(LIBMPU_REAL_IO_DATA_LIMIT)
+AC_SUBST(LIBMPU_MATH_FN_DATA_LIMIT)
+AC_SUBST(LIBMPU_REAL_MAX_WIDTH)
+dnl
+dnl ============================================================
+dnl command line options
+dnl ============================================================
+AC_MSG_CHECKING(for libmpu)
+_AC_LIBMPU_VERBOSE([])
+AC_ARG_WITH(libmpu,dnl
+[ --with-libmpu[=ARG] Build with libmpu Library (default=]ifelse([$2],,yes,$2)[)],dnl
+,dnl
+with_libmpu="ifelse([$2],,yes,$2)"
+)dnl
+_AC_LIBMPU_VERBOSE([+ Command Line Options:])
+_AC_LIBMPU_VERBOSE([ o --with-libmpu=$with_libmpu])
+dnl
+dnl ============================================================
+dnl configuration
+dnl ============================================================
+if test "x$with_libmpu" != "xno"; then
+ libmpu_version=""
+ libmpu_location=""
+ libmpu_type=""
+ libmpu_cppflags=""
+ libmpu_cflags=""
+ libmpu_ldflags=""
+ libmpu_libs=""
+ libmpu_real_io_data_limit=""
+ libmpu_math_fn_data_limit=""
+ libmpu_real_max_width=""
+ if test "x$with_libmpu" = "xyes"; then
+ # via config script in $PATH
+ changequote(, )dnl
+ libmpu_version=`($LIBMPU_CONFIG --version) 2>/dev/null |\
+ sed -e 's/^.*\([0-9]\.[0-9]*[ab.][0-9]*\).*$/\1/'`
+ changequote([, ])dnl
+ if test "x$libmpu_version" != "x"; then
+ libmpu_location=`$LIBMPU_CONFIG --prefix`
+ libmpu_type='installed'
+ libmpu_cppflags=`$LIBMPU_CONFIG --cppflags`
+ libmpu_cflags=`$LIBMPU_CONFIG --cflags`
+ libmpu_ldflags=`$LIBMPU_CONFIG --ldflags`
+ libmpu_libs=`$LIBMPU_CONFIG --libs`
+ libmpu_real_io_data_limit=`$LIBMPU_CONFIG --real-io-data-limit`
+ libmpu_math_fn_data_limit=`$LIBMPU_CONFIG --math-fn-data-limit`
+ libmpu_real_max_width=`$LIBMPU_CONFIG --real-max-width`
+ fi
+ fi
+ dnl ========================================================
+ dnl Check whether the found version is sufficiently new
+ dnl ========================================================
+ _req_version="ifelse([$1],,1.0.0,$1)"
+ for _var in libmpu_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_LIBMPU_VERBOSE([+ Determined Versions:])
+ _AC_LIBMPU_VERBOSE([ o existing: $libmpu_version -> 0x$libmpu_version_hex])
+ _AC_LIBMPU_VERBOSE([ o required: $_req_version -> 0x$_req_version_hex])
+ _ok=0
+ if test "x$libmpu_version_hex" != "x"; then
+ if test "x$_req_version_hex" != "x"; then
+ if test $libmpu_version_hex -ge $_req_version_hex; then
+ _ok=1
+ fi
+ fi
+ fi
+ if test "x$_ok" = "x0"; then
+ _AC_LIBMPU_ERROR([dnl
+ Found libmpu version $libmpu_version, but required at least version $_req_version.
+ Upgrade libmpu under $libmpu_location to $_req_version or higher first, please.])
+ fi
+ dnl ========================================================
+ dnl Perform libmpu Sanity Compile Check
+ dnl ========================================================
+ _ac_save_CPPFLAGS="$CPPFLAGS"
+ _ac_save_CFLAGS="$CFLAGS"
+ _ac_save_LDFLAGS="$LDFLAGS"
+ _ac_save_LIBS="$LIBS"
+ CPPFLAGS="$CPPFLAGS $libmpu_cppflags"
+ CFLAGS="$CFLAGS $libmpu_cflags"
+ LDFLAGS="$LDFLAGS $libmpu_ldflags"
+ LIBS="$LIBS $libmpu_libs"
+ _AC_LIBMPU_VERBOSE([+ Test Build Environment:])
+ _AC_LIBMPU_VERBOSE([ o CPPFLAGS="$CPPFLAGS"])
+ _AC_LIBMPU_VERBOSE([ o CFLAGS="$CFLAGS"])
+ _AC_LIBMPU_VERBOSE([ o LDFLAGS="$LDFLAGS"])
+ _AC_LIBMPU_VERBOSE([ o LIBS="$LIBS"])
+ cross_compile=no
+ _AC_LIBMPU_VERBOSE([+ Performing Sanity Checks:])
+ _AC_LIBMPU_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_LIBMPU_ERROR([dnl
+ Found libmpu $libmpu_version under $libmpu_location, but
+ was unable to perform a sanity pre-processor check. This means
+ the libmpu header libmpu.h was not found.
+ We used the following build environment:
+ >> CPP="$CPP"
+ >> CPPFLAGS="$CPPFLAGS"
+ See config.log for possibly more details.])
+ fi
+ _AC_LIBMPU_VERBOSE([ o link check])
+ AC_LINK_IFELSE([AC_LANG_SOURCE([[
+#include <libmpu.h>
+
+int main()
+{
+ __mpu_init();
+
+ __mpu_free_context();
+
+ return( 0 );
+}
+ ]])], _ok=yes, _ok=no)
+ if test "x$_ok" != "xyes"; then
+ _AC_LIBMPU_ERROR([dnl
+ Found libmpu $libmpu_version under $libmpu_location, but
+ was unable to perform a sanity linker check. This means
+ the libmpu library libmpu.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"
+
+ LIBMPU_CPPFLAGS="$libmpu_cppflags"
+ LIBMPU_CFLAGS="$libmpu_cflags"
+ LIBMPU_LDFLAGS="$libmpu_ldflags"
+ LIBMPU_LIBS="$libmpu_libs"
+ LIBMPU_REAL_IO_DATA_LIMIT="$libmpu_real_io_data_limit"
+ LIBMPU_MATH_FN_DATA_LIMIT="$libmpu_math_fn_data_limit"
+ LIBMPU_REAL_MAX_WIDTH="$libmpu_real_max_width"
+ AC_SUBST(LIBMPU_CPPFLAGS)
+ AC_SUBST(LIBMPU_CFLAGS)
+ AC_SUBST(LIBMPU_LDFLAGS)
+ AC_SUBST(LIBMPU_LIBS)
+ AC_SUBST(LIBMPU_REAL_IO_DATA_LIMIT)
+ AC_SUBST(LIBMPU_MATH_FN_DATA_LIMIT)
+ AC_SUBST(LIBMPU_REAL_MAX_WIDTH)
+ _AC_LIBMPU_VERBOSE([+ Final Results:])
+ _AC_LIBMPU_VERBOSE([ o LIBMPU_CPPFLAGS="$LIBMPU_CPPFLAGS"])
+ _AC_LIBMPU_VERBOSE([ o LIBMPU_CFLAGS="$LIBMPU_CFLAGS"])
+ _AC_LIBMPU_VERBOSE([ o LIBMPU_LDFLAGS="$LIBMPU_LDFLAGS"])
+ _AC_LIBMPU_VERBOSE([ o LIBMPU_LIBS="$LIBMPU_LIBS"])
+ _AC_LIBMPU_VERBOSE([ o LIBMPU_REAL_IO_DATA_LIMIT="$LIBMPU_REAL_IO_DATA_LIMIT"])
+ _AC_LIBMPU_VERBOSE([ o LIBMPU_MATH_FN_DATA_LIMIT="$LIBMPU_MATH_FN_DATA_LIMIT"])
+ _AC_LIBMPU_VERBOSE([ o LIBMPU_REAL_MAX_WIDTH="$LIBMPU_REAL_MAX_WIDTH"])
+fi
+if test "x$with_libmpu" != "xno"; then
+ AC_MSG_RESULT([version $libmpu_version, $libmpu_type under $libmpu_location])
+ ifelse([$3], , :, [$3])
+else
+ AC_MSG_RESULT([no])
+ ifelse([$4], , :, [$4])
+fi
+])
+