📄 types.m4
字号:
# This file is part of Autoconf. -*- Autoconf -*-# Type related macros: existence, sizeof, and structure members.## Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006 Free Software# Foundation, Inc.## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2, or (at your option)# any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA# 02110-1301, USA.## As a special exception, the Free Software Foundation gives unlimited# permission to copy, distribute and modify the configure scripts that# are the output of Autoconf. You need not follow the terms of the GNU# General Public License when using or distributing such scripts, even# though portions of the text of Autoconf appear in them. The GNU# General Public License (GPL) does govern all other use of the material# that constitutes the Autoconf program.## Certain portions of the Autoconf source text are designed to be copied# (in certain cases, depending on the input) into the output of# Autoconf. We call these the "data" portions. The rest of the Autoconf# source text consists of comments plus executable code that decides which# of the data portions to output in any given case. We call these# comments and executable code the "non-data" portions. Autoconf never# copies any of the non-data portions into its output.## This special exception to the GPL applies to versions of Autoconf# released by the Free Software Foundation. When you make and# distribute a modified version of Autoconf, you may extend this special# exception to the GPL to apply to your modified version as well, *unless*# your modified version has the potential to copy into its output some# of the text that was the non-data portion of the version that you started# with. (In other words, unless your change moves or copies text from# the non-data portions to the data portions.) If your modification has# such potential, you must delete any notice of this special exception# to the GPL from your modified version.## Written by David MacKenzie, with help from# Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,# Roland McGrath, Noah Friedman, david d zuhn, and many others.## ---------------- #### Type existence. #### ---------------- ### ---------------- ## General checks. ## ---------------- ## Up to 2.13 included, Autoconf used to provide the macro## AC_CHECK_TYPE(TYPE, DEFAULT)## Since, it provides another version which fits better with the other# AC_CHECK_ families:## AC_CHECK_TYPE(TYPE,# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],# [INCLUDES = DEFAULT-INCLUDES])## In order to provide backward compatibility, the new scheme is# implemented as _AC_CHECK_TYPE_NEW, the old scheme as _AC_CHECK_TYPE_OLD,# and AC_CHECK_TYPE branches to one or the other, depending upon its# arguments.# _AC_CHECK_TYPE_NEW(TYPE,# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],# [INCLUDES = DEFAULT-INCLUDES])# ------------------------------------------------------------# Check whether the type TYPE is supported by the system, maybe via the# the provided includes. This macro implements the former task of# AC_CHECK_TYPE, with one big difference though: AC_CHECK_TYPE was# grepping in the headers, which, BTW, led to many problems until the# extended regular expression was correct and did not given false positives.# It turned out there are even portability issues with egrep...## The most obvious way to check for a TYPE is just to compile a variable# definition:## TYPE my_var;## Unfortunately this does not work for const qualified types in C++,# where you need an initializer. So you think of## TYPE my_var = (TYPE) 0;## Unfortunately, again, this is not valid for some C++ classes.## Then you look for another scheme. For instance you think of declaring# a function which uses a parameter of type TYPE:## int foo (TYPE param);## but of course you soon realize this does not make it with K&R# compilers. And by no ways you want to## int foo (param)# TYPE param# { ; }## since this time it's C++ who is not happy.## Don't even think of the return type of a function, since K&R cries# there too. So you start thinking of declaring a *pointer* to this TYPE:## TYPE *p;## but you know fairly well that this is legal in C for aggregates which# are unknown (TYPE = struct does-not-exist).## Then you think of using sizeof to make sure the TYPE is really# defined:## sizeof (TYPE);## But this succeeds if TYPE is a variable: you get the size of the# variable's type!!!## This time you tell yourself the last two options *together* will make# it. And indeed this is the solution invented by Alexandre Oliva.## Also note that we use## if (sizeof (TYPE))## to `read' sizeof (to avoid warnings), while not depending on its type# (not necessarily size_t etc.). Equally, instead of defining an unused# variable, we just use a cast to avoid warnings from the compiler.# Suggested by Paul Eggert.## Now, the next issue is that C++ disallows defining types inside casts# and inside `sizeof()', but we would like to allow unnamed structs, for# use inside AC_CHECK_SIZEOF, for example. So we create a typedef of the# new type. Note that this does not obviate the need for the other# constructs in general.m4_define([_AC_CHECK_TYPE_NEW],[AS_VAR_PUSHDEF([ac_Type], [ac_cv_type_$1])dnlAC_CACHE_CHECK([for $1], ac_Type,[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])typedef $1 ac__type_new_;],[if ((ac__type_new_ *) 0) return 0;if (sizeof (ac__type_new_)) return 0;])], [AS_VAR_SET(ac_Type, yes)], [AS_VAR_SET(ac_Type, no)])])AS_IF([test AS_VAR_GET(ac_Type) = yes], [$2], [$3])[]dnlAS_VAR_POPDEF([ac_Type])dnl])# _AC_CHECK_TYPE_NEW# AC_CHECK_TYPES(TYPES,# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],# [INCLUDES = DEFAULT-INCLUDES])# --------------------------------------------------------# TYPES is an m4 list. There are no ambiguities here, we mean the newer# AC_CHECK_TYPE.AC_DEFUN([AC_CHECK_TYPES],[m4_foreach([AC_Type], [$1], [_AC_CHECK_TYPE_NEW(AC_Type, [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]AC_Type), 1, [Define to 1 if the system has the type `]AC_Type['.])$2], [$3], [$4])])])# _AC_CHECK_TYPE_OLD(TYPE, DEFAULT)# ---------------------------------# FIXME: This is an extremely badly chosen name, since this# macro actually performs an AC_REPLACE_TYPE. Some day we# have to clean this up.m4_define([_AC_CHECK_TYPE_OLD],[_AC_CHECK_TYPE_NEW([$1],, [AC_DEFINE_UNQUOTED([$1], [$2], [Define to `$2' if <sys/types.h> does not define.])])dnl])# _AC_CHECK_TYPE_OLD# _AC_CHECK_TYPE_REPLACEMENT_TYPE_P(STRING)# -----------------------------------------# Return `1' if STRING seems to be a builtin C/C++ type, i.e., if it# starts with `_Bool', `bool', `char', `double', `float', `int',# `long', `short', `signed', or `unsigned' followed by characters# that are defining types.# Because many people have used `off_t' and `size_t' too, they are added# for better common-useward backward compatibility.m4_define([_AC_CHECK_TYPE_REPLACEMENT_TYPE_P],[m4_bmatch([$1], [^\(_Bool\|bool\|char\|double\|float\|int\|long\|short\|\(un\)?signed\|[_a-zA-Z][_a-zA-Z0-9]*_t\)[][_a-zA-Z0-9() *]*$], 1, 0)dnl])# _AC_CHECK_TYPE_REPLACEMENT_TYPE_P# _AC_CHECK_TYPE_MAYBE_TYPE_P(STRING)# -----------------------------------# Return `1' if STRING looks like a C/C++ type.m4_define([_AC_CHECK_TYPE_MAYBE_TYPE_P],[m4_bmatch([$1], [^[_a-zA-Z0-9 ]+\([_a-zA-Z0-9() *]\|\[\|\]\)*$], 1, 0)dnl])# _AC_CHECK_TYPE_MAYBE_TYPE_P# AC_CHECK_TYPE(TYPE, DEFAULT)# or# AC_CHECK_TYPE(TYPE,# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],# [INCLUDES = DEFAULT-INCLUDES])# -------------------------------------------------------## Dispatch respectively to _AC_CHECK_TYPE_OLD or _AC_CHECK_TYPE_NEW.# 1. More than two arguments => NEW# 2. $2 seems to be replacement type => OLD# See _AC_CHECK_TYPE_REPLACEMENT_TYPE_P for `replacement type'.# 3. $2 seems to be a type => NEW plus a warning# 4. default => NEWAC_DEFUN([AC_CHECK_TYPE],[m4_if($#, 3, [_AC_CHECK_TYPE_NEW($@)], $#, 4, [_AC_CHECK_TYPE_NEW($@)], _AC_CHECK_TYPE_REPLACEMENT_TYPE_P([$2]), 1, [_AC_CHECK_TYPE_OLD($@)], _AC_CHECK_TYPE_MAYBE_TYPE_P([$2]), 1, [AC_DIAGNOSE([syntax], [$0: assuming `$2' is not a type])_AC_CHECK_TYPE_NEW($@)], [_AC_CHECK_TYPE_NEW($@)])[]dnl])# AC_CHECK_TYPE# ---------------------------- ## Types that must be checked. ## ---------------------------- #AN_IDENTIFIER([ptrdiff_t], [AC_CHECK_TYPES])# ----------------- ## Specific checks. ## ----------------- ## AC_TYPE_GETGROUPS# -----------------AC_DEFUN([AC_TYPE_GETGROUPS],[AC_REQUIRE([AC_TYPE_UID_T])dnlAC_CACHE_CHECK(type of array argument to getgroups, ac_cv_type_getgroups,[AC_RUN_IFELSE([AC_LANG_SOURCE([[/* Thanks to Mike Rendell for this test. */]AC_INCLUDES_DEFAULT[#define NGID 256#undef MAX#define MAX(x, y) ((x) > (y) ? (x) : (y))intmain (){ gid_t gidset[NGID]; int i, n; union { gid_t gval; long int lval; } val; val.lval = -1; for (i = 0; i < NGID; i++) gidset[i] = val.gval; n = getgroups (sizeof (gidset) / MAX (sizeof (int), sizeof (gid_t)) - 1, gidset); /* Exit non-zero if getgroups seems to require an array of ints. This happens when gid_t is short int but getgroups modifies an array of ints. */ return n > 0 && gidset[n] != val.gval;}]])], [ac_cv_type_getgroups=gid_t], [ac_cv_type_getgroups=int], [ac_cv_type_getgroups=cross])if test $ac_cv_type_getgroups = cross; then dnl When we can't run the test program (we are cross compiling), presume dnl that <unistd.h> has either an accurate prototype for getgroups or none. dnl Old systems without prototypes probably use int. AC_EGREP_HEADER([getgroups.*int.*gid_t], unistd.h, ac_cv_type_getgroups=gid_t, ac_cv_type_getgroups=int)fi])AC_DEFINE_UNQUOTED(GETGROUPS_T, $ac_cv_type_getgroups, [Define to the type of elements in the array set by `getgroups'. Usually this is either `int' or `gid_t'.])])# AC_TYPE_GETGROUPS# AU::AM_TYPE_PTRDIFF_T# ---------------------AU_DEFUN([AM_TYPE_PTRDIFF_T],[AC_CHECK_TYPES(ptrdiff_t)])# AC_TYPE_INTMAX_T# -----------------AC_DEFUN([AC_TYPE_INTMAX_T],[ AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) AC_CHECK_TYPE([intmax_t], [AC_DEFINE([HAVE_INTMAX_T], 1, [Define to 1 if the system has the type `intmax_t'.])], [test $ac_cv_type_long_long_int = yes \ && ac_type='long long int' \ || ac_type='long int'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -