2007-04-16 06:45:25 +08:00
|
|
|
dnl --------------------------------------------------------------------------
|
2017-11-02 01:45:50 +08:00
|
|
|
dnl PA_SYM(prefix, string)
|
2007-04-16 06:45:25 +08:00
|
|
|
dnl
|
2017-11-02 01:45:50 +08:00
|
|
|
dnl Convert a (semi-) arbitrary string to a CPP symbol
|
|
|
|
dnl --------------------------------------------------------------------------
|
|
|
|
AC_DEFUN(PA_SYM,
|
|
|
|
[[$1]m4_bpatsubsts(m4_toupper([$2]),[[^ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]+],[_],[^._?\(.*\)_.$],[[\1]])])
|
|
|
|
|
|
|
|
dnl --------------------------------------------------------------------------
|
|
|
|
dnl PA_ADD_CFLAGS(flag [,actual_flag])
|
|
|
|
dnl
|
|
|
|
dnl Attempt to add the given option to CFLAGS, if it doesn't break
|
|
|
|
dnl compilation. If the option to be tested is different than the
|
|
|
|
dnl option that should actually be added, add the option to be
|
|
|
|
dnl actually added as a second argument.
|
2007-04-16 06:45:25 +08:00
|
|
|
dnl --------------------------------------------------------------------------
|
|
|
|
AC_DEFUN(PA_ADD_CFLAGS,
|
|
|
|
[AC_MSG_CHECKING([if $CC accepts $1])
|
|
|
|
pa_add_cflags__old_cflags="$CFLAGS"
|
|
|
|
CFLAGS="$CFLAGS $1"
|
2017-04-19 06:48:31 +08:00
|
|
|
AC_TRY_LINK(AC_INCLUDES_DEFAULT,
|
2007-04-16 06:45:25 +08:00
|
|
|
[printf("Hello, World!\n");],
|
2017-04-24 12:42:08 +08:00
|
|
|
[AC_MSG_RESULT([yes])
|
2017-11-02 01:45:50 +08:00
|
|
|
CFLAGS="$pa_add_cflags__old_cflags ifelse([$2],[],[$1],[$2])"
|
|
|
|
AC_DEFINE(PA_SYM([CFLAG_],[$1]), 1,
|
|
|
|
[Define to 1 if compiled with the `$1' compiler flag])],
|
2017-04-24 12:42:08 +08:00
|
|
|
[AC_MSG_RESULT([no])
|
|
|
|
CFLAGS="$pa_add_cflags__old_cflags"])])
|
2007-04-16 06:45:25 +08:00
|
|
|
|
2017-03-01 10:48:01 +08:00
|
|
|
dnl --------------------------------------------------------------------------
|
2017-11-02 01:45:50 +08:00
|
|
|
dnl PA_ADD_CLDFLAGS(flag [,actual_flag])
|
2017-03-01 10:48:01 +08:00
|
|
|
dnl
|
|
|
|
dnl Attempt to add the given option to CFLAGS and LDFLAGS,
|
|
|
|
dnl if it doesn't break compilation
|
|
|
|
dnl --------------------------------------------------------------------------
|
|
|
|
AC_DEFUN(PA_ADD_CLDFLAGS,
|
|
|
|
[AC_MSG_CHECKING([if $CC accepts $1])
|
|
|
|
pa_add_cldflags__old_cflags="$CFLAGS"
|
|
|
|
CFLAGS="$CFLAGS $1"
|
|
|
|
pa_add_cldflags__old_ldflags="$LDFLAGS"
|
|
|
|
LDFLAGS="$LDFLAGS $1"
|
2017-04-19 06:48:31 +08:00
|
|
|
AC_TRY_LINK(AC_INCLUDES_DEFAULT,
|
2017-03-01 10:48:01 +08:00
|
|
|
[printf("Hello, World!\n");],
|
2017-04-24 12:42:08 +08:00
|
|
|
[AC_MSG_RESULT([yes])
|
|
|
|
CFLAGS="$pa_add_cldflags__old_cflags ifelse([$2],[],[$1],[$2])"
|
2017-11-02 01:45:50 +08:00
|
|
|
LDFLAGS="$pa_add_cldflags__old_ldflags ifelse([$2],[],[$1],[$2])"
|
|
|
|
AC_DEFINE(PA_SYM([CFLAG_],[$1]), 1,
|
|
|
|
[Define to 1 if compiled with the `$1' compiler flag])],
|
2017-04-24 12:42:08 +08:00
|
|
|
[AC_MSG_RESULT([no])
|
|
|
|
CFLAGS="$pa_add_cldflags__old_cflags"
|
|
|
|
LDFLAGS="$pa_add_cldflags__old_ldflags"])])
|
2017-03-01 10:48:01 +08:00
|
|
|
|
2017-04-19 06:48:31 +08:00
|
|
|
dnl --------------------------------------------------------------------------
|
2017-11-02 01:45:50 +08:00
|
|
|
dnl PA_HAVE_FUNC(func_name)
|
2009-03-02 05:57:40 +08:00
|
|
|
dnl
|
2016-02-18 16:54:30 +08:00
|
|
|
dnl Look for a function with the specified arguments which could be
|
|
|
|
dnl a builtin/intrinsic function.
|
2009-03-02 05:57:40 +08:00
|
|
|
dnl --------------------------------------------------------------------------
|
2016-02-18 16:54:30 +08:00
|
|
|
AC_DEFUN(PA_HAVE_FUNC,
|
|
|
|
[AC_MSG_CHECKING([for $1])
|
2017-11-02 01:45:50 +08:00
|
|
|
AC_TRY_LINK([], [(void)$1$2;],
|
2016-02-18 16:54:30 +08:00
|
|
|
AC_MSG_RESULT([yes])
|
2017-11-02 01:45:50 +08:00
|
|
|
AC_DEFINE(AS_TR_CPP([HAVE_$1]), 1,
|
2016-02-18 16:54:30 +08:00
|
|
|
[Define to 1 if you have the `$1' intrinsic function.]),
|
|
|
|
AC_MSG_RESULT([no]))])
|
2016-03-10 06:11:40 +08:00
|
|
|
|
|
|
|
dnl --------------------------------------------------------------------------
|
|
|
|
dnl PA_LIBEXT
|
|
|
|
dnl
|
|
|
|
dnl Guess the library extension based on the object extension
|
|
|
|
dnl --------------------------------------------------------------------------
|
|
|
|
AC_DEFUN(PA_LIBEXT,
|
|
|
|
[AC_MSG_CHECKING([for suffix of library files])
|
|
|
|
if test x"$LIBEXT" = x; then
|
|
|
|
case "$OBJEXT" in
|
|
|
|
obj )
|
|
|
|
LIBEXT=lib
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
LIBEXT=a
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
AC_MSG_RESULT([$LIBEXT])
|
|
|
|
AC_SUBST([LIBEXT])])
|
2016-11-16 06:01:37 +08:00
|
|
|
|
|
|
|
dnl --------------------------------------------------------------------------
|
2017-11-02 01:45:50 +08:00
|
|
|
dnl PA_FUNC_ATTRIBUTE(attribute_name)
|
2016-11-16 06:01:37 +08:00
|
|
|
dnl
|
|
|
|
dnl See if this compiler supports the equivalent of a specific gcc
|
|
|
|
dnl attribute on a function, using the __attribute__(()) syntax.
|
|
|
|
dnl All arguments except the attribute name are optional.
|
|
|
|
dnl PA_FUNC_ATTRIBUTE(attribute, attribute_opts, return_type,
|
|
|
|
dnl prototype_args, call_args)
|
|
|
|
dnl --------------------------------------------------------------------------
|
|
|
|
AC_DEFUN(PA_FUNC_ATTRIBUTE,
|
|
|
|
[AC_MSG_CHECKING([if $CC supports the $1 function attribute])
|
|
|
|
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
2017-04-19 06:48:31 +08:00
|
|
|
AC_INCLUDES_DEFAULT
|
2016-11-16 06:01:37 +08:00
|
|
|
extern ifelse([$3],[],[void *],[$3]) __attribute__(($1$2))
|
|
|
|
bar(ifelse([$4],[],[int],[$4]));
|
2017-02-24 11:22:27 +08:00
|
|
|
void *foo(void);
|
2016-11-16 06:01:37 +08:00
|
|
|
void *foo(void)
|
|
|
|
{
|
|
|
|
return bar(ifelse([$5],[],[1],[$5]));
|
|
|
|
}
|
|
|
|
])],
|
|
|
|
[AC_MSG_RESULT([yes])
|
2017-11-02 01:45:50 +08:00
|
|
|
AC_DEFINE(PA_SYM([HAVE_FUNC_ATTRIBUTE_],[$1]), 1,
|
2016-11-16 06:01:37 +08:00
|
|
|
[Define to 1 if your compiler supports __attribute__(($1)) on functions])],
|
|
|
|
[AC_MSG_RESULT([no])])
|
|
|
|
])
|
2016-12-20 18:29:58 +08:00
|
|
|
|
|
|
|
dnl --------------------------------------------------------------------------
|
|
|
|
dnl PA_FUNC_ATTRIBUTE_ERROR
|
|
|
|
dnl
|
|
|
|
dnl See if this compiler supports __attribute__((error("foo")))
|
|
|
|
dnl The generic version of this doesn't work as it makes the compiler
|
|
|
|
dnl throw an error by design.
|
|
|
|
dnl --------------------------------------------------------------------------
|
|
|
|
AC_DEFUN(PA_FUNC_ATTRIBUTE_ERROR,
|
|
|
|
[AC_MSG_CHECKING([if $CC supports the error function attribute])
|
|
|
|
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
2017-04-19 06:48:31 +08:00
|
|
|
AC_INCLUDES_DEFAULT
|
2016-12-20 18:29:58 +08:00
|
|
|
extern void __attribute__((error("message"))) barf(void);
|
2017-02-24 11:22:27 +08:00
|
|
|
void foo(void);
|
2016-12-20 18:29:58 +08:00
|
|
|
void foo(void)
|
|
|
|
{
|
|
|
|
if (0)
|
|
|
|
barf();
|
|
|
|
}
|
|
|
|
])],
|
|
|
|
[AC_MSG_RESULT([yes])
|
2017-11-02 01:45:50 +08:00
|
|
|
AC_DEFINE([HAVE_FUNC_ATTRIBUTE_ERROR], 1,
|
2016-12-20 18:29:58 +08:00
|
|
|
[Define to 1 if your compiler supports __attribute__((error)) on functions])],
|
|
|
|
[AC_MSG_RESULT([no])])
|
|
|
|
])
|
2017-04-19 06:48:31 +08:00
|
|
|
|
2017-04-07 06:24:58 +08:00
|
|
|
dnl --------------------------------------------------------------------------
|
2017-11-02 01:45:50 +08:00
|
|
|
dnl PA_ARG_ENABLED(option, helptext [,enabled_action [,disabled_action]])
|
|
|
|
dnl PA_ARG_DISABLED(option, helptext [,disabled_action [,enabled_action]])
|
2017-04-07 06:24:58 +08:00
|
|
|
dnl
|
|
|
|
dnl Simpler-to-use versions of AC_ARG_ENABLED, that include the
|
|
|
|
dnl test for $enableval and the AS_HELP_STRING definition
|
|
|
|
dnl --------------------------------------------------------------------------
|
|
|
|
AC_DEFUN(PA_ARG_ENABLED,
|
2017-04-24 12:42:08 +08:00
|
|
|
[AC_ARG_ENABLE([$1], [AS_HELP_STRING([--enable-$1],[$2])], [], [enableval=no])
|
|
|
|
AS_IF([test x"$enableval" != xno], [$3], [$4])
|
2017-04-07 06:24:58 +08:00
|
|
|
])
|
|
|
|
|
|
|
|
AC_DEFUN(PA_ARG_DISABLED,
|
2017-04-24 12:42:08 +08:00
|
|
|
[AC_ARG_ENABLE([$1],[AS_HELP_STRING([--disable-$1],[$2])], [], [enableval=yes])
|
|
|
|
AS_IF([test x"$enableval" = xno], [$3], [$4])
|
2017-04-07 06:24:58 +08:00
|
|
|
])
|
2017-04-19 07:07:18 +08:00
|
|
|
|
2017-04-19 06:48:31 +08:00
|
|
|
dnl --------------------------------------------------------------------------
|
2017-11-02 01:45:50 +08:00
|
|
|
dnl PA_ADD_HEADERS(headers...)
|
2017-04-19 06:48:31 +08:00
|
|
|
dnl
|
|
|
|
dnl Call AC_CHECK_HEADERS(), and add to ac_includes_default if found
|
|
|
|
dnl --------------------------------------------------------------------------
|
|
|
|
AC_DEFUN(_PA_ADD_HEADER,
|
|
|
|
[AC_CHECK_HEADERS([$1],[ac_includes_default="$ac_includes_default
|
2017-11-02 04:31:22 +08:00
|
|
|
#include <$1>"
|
2017-11-02 01:45:50 +08:00
|
|
|
])])
|
2017-04-19 06:48:31 +08:00
|
|
|
|
|
|
|
AC_DEFUN(PA_ADD_HEADERS,
|
|
|
|
[m4_map_args_w([$1],[_PA_ADD_HEADER(],[)])])
|