[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Macros to check for global variables
From: |
Peter Eisentraut |
Subject: |
Macros to check for global variables |
Date: |
Wed, 29 May 2002 18:37:18 +0200 (CEST) |
Following up to a thread last month, I have revised my set of macros that
check for global variables. You must supply the complete declaration of
the variable, e.g.,
AC_CHECK_VAR(int timezone)
and the code figures out the name of the variable with some regular
expressions. This handles arrays and function pointers as well, e.g.,
AC_CHECK_VAR([[char sys_siglist[]]])
AC_CHECK_VAR(char (*testptr)(int,int))
The exact REs could be debated, but this is a reasonable subset IMHO that
handles all correct arguments and catches some possibly common mistakes,
e.g., omitting the type.
Comments?
# AC_LANG_VAR_LINK_TRY(C)(VARIABLE-DECL, [INCLUDES])
# --------------------------------------------------
m4_define([AC_LANG_VAR_LINK_TRY(C)],
[m4_pushdef([AC_Varname],
[m4_bmatch([$1],
[^[^()]+(.+)],
[m4_bregexp([$1],
[^[^()]+([^_a-zA-Z0-9\$]*\([_a-zA-Z0-9\$]+\)], [\1])],
[[_a-zA-Z0-9\$]+[^_a-zA-Z0-9\$]+[_a-zA-Z0-9\$]+],
[m4_bregexp([$1],
[\([_a-zA-Z0-9\$]+\)[^_a-zA-Z0-9\$]*$], [\1])],
[m4_fatal([`$1' does not appear to be a valid C variable
declaration])])])dnl
AC_LANG_PROGRAM(
[AC_INCLUDES_DEFAULT([$3])
extern $1;
char *p;
],
[p = (char *) &AC_Varname;])
m4_popdef([AC_Varname])dnl
])
# AC_LANG_VAR_LINK_TRY(C++)(VARIABLE-DECL, [INCLUDES])
# ----------------------------------------------------
m4_copy([AC_LANG_VAR_LINK_TRY(C)], [AC_LANG_VAR_LINK_TRY(C++)])
# AC_LANG_VAR_LINK_TRY(VARIABLE-DECL, [INCLUDES])
# -----------------------------------------------
# Produce a source which links correctly iff the variable declared in
# VARIABLE-DECL exists.
AC_DEFUN([AC_LANG_VAR_LINK_TRY],
[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
# AC_CHECK_VAR(VARIABLE-DECL,
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
# [INCLUDES = DEFAULT-INCLUDES])
# ------------------------------------------------------
AC_DEFUN([AC_CHECK_VAR],
[AS_VAR_PUSHDEF([ac_var], [ac_cv_var_$1])dnl
AC_CACHE_CHECK([for $1], ac_var,
[AC_LINK_IFELSE([AC_LANG_VAR_LINK_TRY([$1], [$4])],
[AS_VAR_SET(ac_var, yes)],
[AS_VAR_SET(ac_var, no)])])
AS_IF([test AS_VAR_GET(ac_var) = yes], [$2], [$3])dnl
AS_VAR_POPDEF([ac_var])dnl
])# AC_CHECK_VAR
# AC_CHECK_VARS([VARIABLE-DECL, ...],
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
# [INCLUDES = DEFAULT-INCLUDES])
# -------------------------------------------------------
AC_DEFUN([AC_CHECK_VARS],
[m4_foreach([AC_Item], [$1],
[AC_CHECK_VAR(AC_Item,
[AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]AC_Item), 1,
[Define to 1 if you have the `]AC_Item['
global variable.]) $2],
[$3],
[$4])dnl
])])# AC_CHECK_VARS
--
Peter Eisentraut address@hidden
- Macros to check for global variables,
Peter Eisentraut <=