[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Macros to check for variables, next try
From: |
Peter Eisentraut |
Subject: |
Macros to check for variables, next try |
Date: |
Fri, 12 Apr 2002 12:38:03 -0400 (EDT) |
Following up to the suggestions, I have revised the macros to include the
type of the variable. The interface is
AC_CHECK_VAR(type, varname, yes, no, includes)
The order of type and varname is debatable.
For the plural version I have come up with
AC_CHECK_VAR([[type1, var1], [type2, var2], ...], yes, no, includes)
For consistency it might make some sense to make the singular
AC_CHECK_VAR([type, varname], yes, no, includes)
This partially depends on how the future interface for function checks is
envisioned.
Comments?
# should go into m4sugar
m4_define([m4_length], [$#])
# AC_LANG_VAR_LINK_TRY(C)(TYPE, VARIABLE, [INCLUDES])
# ---------------------------------------------------
m4_define([AC_LANG_VAR_LINK_TRY(C)],
[AC_LANG_PROGRAM(
[AC_INCLUDES_DEFAULT([$3])
extern $1 $2;
$1 i;
],
[i = $2;])])
# AC_LANG_VAR_LINK_TRY(C++)(TYPE, VARIABLE, [INCLUDES])
# -----------------------------------------------------
m4_copy([AC_LANG_VAR_LINK_TRY(C)], [AC_LANG_VAR_LINK_TRY(C++)])
# AC_LANG_VAR_LINK_TRY(TYPE, VARIABLE, [INCLUDES])
# ------------------------------------------------
# Produce a source which links correctly iff the VARIABLE exists.
AC_DEFUN([AC_LANG_VAR_LINK_TRY],
[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
# AC_CHECK_VAR(TYPE, VARIABLE,
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
# [INCLUDES = DEFAULT-INCLUDES])
# ------------------------------------------------------
AC_DEFUN([AC_CHECK_VAR],
[AS_VAR_PUSHDEF([ac_var], [ac_cv_var_$1_$2])dnl
AC_CACHE_CHECK([for $1 $2], ac_var,
[AC_LINK_IFELSE([AC_LANG_VAR_LINK_TRY([$1], [$2], [$5])],
[AS_VAR_SET(ac_var, yes)],
[AS_VAR_SET(ac_var, no)])])
AS_IF([test AS_VAR_GET(ac_var) = yes], [$3], [$4])dnl
AS_VAR_POPDEF([ac_var])dnl
])# AC_CHECK_VAR
# AC_CHECK_VARS([[TYPE, VARIABLE] ,...],
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
# [INCLUDES = DEFAULT-INCLUDES])
# -------------------------------------------------------
AC_DEFUN([AC_CHECK_VARS],
[m4_foreach([AC_Item], [$1],
[m4_if(m4_length(AC_Item), 2, [], [m4_fatal([$0: sublist does not have two
elements])])dnl
m4_pushdef([AC_Type], [m4_car(AC_Item)])dnl
m4_pushdef([AC_Var], [m4_car(m4_shift(AC_Item))])dnl
AC_CHECK_VAR(AC_Type, AC_Var,
[AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]AC_Type[]_[]AC_Var), 1,
[Define to 1 if you have the `]AC_Type
AC_Var[' global variable.]) $2],
[$3],
[$4])
m4_popdef([AC_Var])dnl
m4_popdef([AC_Type])dnl
])])
--
Peter Eisentraut address@hidden
- Macros to check for variables, next try,
Peter Eisentraut <=