📄 acinclude.m4
字号:
dnl AC_C_RESTRICTdnl Do nothing if the compiler accepts the restrict keyword.dnl Otherwise define restrict to __restrict__ or __restrict if one ofdnl those work, otherwise define restrict to be empty.AC_DEFUN([AC_C_RESTRICT], [AC_MSG_CHECKING([for restrict]) ac_cv_c_restrict=no for ac_kw in restrict __restrict__ __restrict; do AC_TRY_COMPILE([],[char * $ac_kw p;],[ac_cv_c_restrict=$ac_kw; break]) done AC_MSG_RESULT([$ac_cv_c_restrict]) case $ac_cv_c_restrict in restrict) ;; no) AC_DEFINE([restrict],, [Define as `__restrict' if that's what the C compiler calls it, or to nothing if it is not supported.]) ;; *) AC_DEFINE_UNQUOTED([restrict],$ac_cv_c_restrict) ;; esac])dnl AC_C_BUILTIN_EXPECTdnl Check whether compiler understands __builtin_expect.AC_DEFUN([AC_C_BUILTIN_EXPECT], [AC_CACHE_CHECK([for __builtin_expect],[ac_cv_builtin_expect], [cat > conftest.c <<EOF#line __oline__ "configure"int foo (int a){ a = __builtin_expect (a, 10); return a == 10 ? 0 : 1;}EOF if AC_TRY_COMMAND([${CC-cc} $CFLAGS -nostdlib -nostartfiles -o conftest conftest.c -lgcc >&AC_FD_CC]); then ac_cv_builtin_expect=yes else ac_cv_builtin_expect=no fi rm -f conftest*]) if test x"$ac_cv_builtin_expect" = x"yes"; then AC_DEFINE(HAVE_BUILTIN_EXPECT,, [Define if you have the `__builtin_expect' function.]) fi])dnl AC_C_ALWAYS_INLINEdnl Define inline to something appropriate, including the new always_inlinednl attribute from gcc 3.1AC_DEFUN([AC_C_ALWAYS_INLINE], [AC_C_INLINE if test x"$GCC" = x"yes" -a x"$ac_cv_c_inline" = x"inline"; then AC_MSG_CHECKING([for always_inline]) SAVE_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -Wall -Werror" AC_TRY_COMPILE([], [__attribute__ ((__always_inline__)) void f (void); #ifdef __cplusplus 42 = 42; // obviously illegal - we want c++ to fail here #endif], [ac_cv_always_inline=yes],[ac_cv_always_inline=no]) CFLAGS="$SAVE_CFLAGS" AC_MSG_RESULT([$ac_cv_always_inline]) if test x"$ac_cv_always_inline" = x"yes"; then AC_DEFINE_UNQUOTED([inline],[__attribute__ ((__always_inline__))]) fi fi])dnl AC_C_ATTRIBUTE_ALIGNEDdnl define ATTRIBUTE_ALIGNED_MAX to the maximum alignment if this is supportedAC_DEFUN([AC_C_ATTRIBUTE_ALIGNED], [SAV_CFLAGS=$CFLAGS; if test x"$GCC" = xyes; then CFLAGS="$CFLAGS -Werror"; fi AC_CACHE_CHECK([__attribute__ ((aligned ())) support], [ac_cv_c_attribute_aligned], [ac_cv_c_attribute_aligned=0 for ac_cv_c_attr_align_try in 2 4 8 16 32 64; do AC_TRY_COMPILE([], [static struct s { char a; char b __attribute__ ((aligned($ac_cv_c_attr_align_try))); } S = {0, 0}; switch (1) { case 0: case (int)(&((struct s *)0)->b) == $ac_cv_c_attr_align_try: return 0; } return (long)&S;], [ac_cv_c_attribute_aligned=$ac_cv_c_attr_align_try]) done]) if test x"$ac_cv_c_attribute_aligned" != x"0"; then AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$ac_cv_c_attribute_aligned],[maximum supported data alignment]) fi CFLAGS=$SAV_CFLAGS])dnl AC_TRY_CFLAGS (CFLAGS, [ACTION-IF-WORKS], [ACTION-IF-FAILS])dnl check if $CC supports a given set of cflagsAC_DEFUN([AC_TRY_CFLAGS], [AC_MSG_CHECKING([if $CC supports $1 flags]) SAVE_CFLAGS="$CFLAGS" CFLAGS="$1" AC_TRY_COMPILE([],[],[ac_cv_try_cflags_ok=yes],[ac_cv_try_cflags_ok=no]) CFLAGS="$SAVE_CFLAGS" AC_MSG_RESULT([$ac_cv_try_cflags_ok]) if test x"$ac_cv_try_cflags_ok" = x"yes"; then ifelse([$2],[],[:],[$2]) else ifelse([$3],[],[:],[$3]) fi])dnl AC_LIBTOOL_NON_PIC ([ACTION-IF-WORKS], [ACTION-IF-FAILS])dnl check for nonbuggy libtool -prefer-non-picAC_DEFUN([AC_LIBTOOL_NON_PIC], [AC_MSG_CHECKING([if libtool supports -prefer-non-pic flag]) mkdir ac_test_libtool; cd ac_test_libtool; ac_cv_libtool_non_pic=no echo "int g (int i); static int h (int i) {return g (i);} int f (int i) {return h (i);}" >f.c echo "int (* hook) (int) = 0; int g (int i) {if (hook) i = hook (i); return i + 1;}" >g.c ../libtool --mode=compile $CC $CFLAGS -prefer-non-pic \ -c f.c >/dev/null 2>&1 && \ ../libtool --mode=compile $CC $CFLAGS -prefer-non-pic \ -c g.c >/dev/null 2>&1 && \ ../libtool --mode=link $CC $CFLAGS -prefer-non-pic -o libfoo.la \ -rpath / f.lo g.lo >/dev/null 2>&1 && ac_cv_libtool_non_pic=yes cd ..; rm -fr ac_test_libtool; AC_MSG_RESULT([$ac_cv_libtool_non_pic]) if test x"$ac_cv_libtool_non_pic" = x"yes"; then ifelse([$1],[],[:],[$1]) else ifelse([$2],[],[:],[$2]) fi])dnl AC_CHECK_GENERATE_INTTYPES_H (INCLUDE-DIRECTORY)dnl generate a default inttypes.h if the header file does not exist alreadyAC_DEFUN([AC_CHECK_GENERATE_INTTYPES], [rm -f $1/inttypes.h AC_CHECK_HEADER([inttypes.h],[],[AX_CREATE_STDINT_H([$1/inttypes.h])])])dnl from http://ac-archive.sourceforge.net/guidod/ax_create_stdint_h.htmldnl modified: s/AC_COMPILE_CHECK_SIZEOF/AC_CHECK_SIZEOF/gdnl @synopsis AX_CREATE_STDINT_H [( HEADER-TO-GENERATE [, HEDERS-TO-CHECK])]dnldnl the "ISO C9X: 7.18 Integer types <stdint.h>" section requires thednl existence of an include file <stdint.h> that defines a set of dnl typedefs, especially uint8_t,int32_t,uintptr_t.dnl Many older installations will not provide this file, but some willdnl have the very same definitions in <inttypes.h>. In other enviromentsdnl we can use the inet-types in <sys/types.h> which would define thednl typedefs int8_t and u_int8_t respectivly.dnldnl This macros will create a local "_stdint.h" or the headerfile given as dnl an argument. In many cases that file will just "#include <stdint.h>" dnl or "#include <inttypes.h>", while in other environments it will provide dnl the set of basic 'stdint's definitions/typedefs: dnl int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,intptr_t,uintptr_tdnl int_least32_t.. int_fast32_t.. intmax_tdnl which may or may not rely on the definitions of other files,dnl or using the AC_CHECK_SIZEOF macro to determine the actualdnl sizeof each type.dnldnl if your header files require the stdint-types you will want to create andnl installable file mylib-int.h that all your other installable headerdnl may include. So if you have a library package named "mylib", just usednl AX_CREATE_STDINT_H(mylib-int.h) dnl in configure.ac and go to install that very header file in Makefile.amdnl along with the other headers (mylib.h) - and the mylib-specific headersdnl can simply use "#include <mylib-int.h>" to obtain the stdint-types.dnldnl Remember, if the system already had a valid <stdint.h>, the generateddnl file will include it directly. No need for fuzzy HAVE_STDINT_H things...dnldnl @, (status: used on new platforms) (see http://ac-archive.sf.net/gstdint/)dnl @version $Id: acinclude.m4,v 1.16.2.1 2006/02/14 14:22:16 sammy Exp $dnl @author Guido Draheim <guidod@gmx.de> AC_DEFUN([AX_CREATE_STDINT_H],[# ------ AX CREATE STDINT H -------------------------------------AC_MSG_CHECKING([for stdint types])ac_stdint_h=`echo ifelse($1, , _stdint.h, $1)`# try to shortcircuit - if the default include path of the compiler# can find a "stdint.h" header then we assume that all compilers can.AC_CACHE_VAL([ac_cv_header_stdint_t],[old_CXXFLAGS="$CXXFLAGS" ; CXXFLAGS=""old_CPPFLAGS="$CPPFLAGS" ; CPPFLAGS=""old_CFLAGS="$CFLAGS" ; CFLAGS=""AC_TRY_COMPILE([#include <stdint.h>],[int_least32_t v = 0;],[ac_cv_stdint_result="(assuming C99 compatible system)" ac_cv_header_stdint_t="stdint.h"; ],[ac_cv_header_stdint_t=""])CXXFLAGS="$old_CXXFLAGS"CPPFLAGS="$old_CPPFLAGS"CFLAGS="$old_CFLAGS" ])v="... $ac_cv_header_stdint_h"if test "$ac_stdint_h" = "stdint.h" ; then AC_MSG_RESULT([(are you sure you want them in ./stdint.h?)])elif test "$ac_stdint_h" = "inttypes.h" ; then AC_MSG_RESULT([(are you sure you want them in ./inttypes.h?)])elif test "_$ac_cv_header_stdint_t" = "_" ; then AC_MSG_RESULT([(putting them into $ac_stdint_h)$v])else ac_cv_header_stdint="$ac_cv_header_stdint_t" AC_MSG_RESULT([$ac_cv_header_stdint (shortcircuit)])fiif test "_$ac_cv_header_stdint_t" = "_" ; then # can not shortcircuit..dnl .....intro message done, now do a few system checks.....dnl btw, all CHECK_TYPE macros do automatically "DEFINE" a type, thereforednl we use the autoconf implementation detail _AC CHECK_TYPE_NEW insteadinttype_headers=`echo $2 | sed -e 's/,/ /g'`ac_cv_stdint_result="(no helpful system typedefs seen)"AC_CACHE_CHECK([for stdint uintptr_t], [ac_cv_header_stdint_x],[ ac_cv_header_stdint_x="" # the 1997 typedefs (inttypes.h) AC_MSG_RESULT([(..)]) for i in stdint.h inttypes.h sys/inttypes.h $inttype_headers ; do unset ac_cv_type_uintptr_t unset ac_cv_type_uint64_t _AC_CHECK_TYPE_NEW(uintptr_t,[ac_cv_header_stdint_x=$i],dnl continue,[#include <$i>]) AC_CHECK_TYPE(uint64_t,[and64="/uint64_t"],[and64=""],[#include<$i>]) ac_cv_stdint_result="(seen uintptr_t$and64 in $i)" break; done AC_MSG_CHECKING([for stdint uintptr_t]) ])if test "_$ac_cv_header_stdint_x" = "_" ; thenAC_CACHE_CHECK([for stdint uint32_t], [ac_cv_header_stdint_o],[ ac_cv_header_stdint_o="" # the 1995 typedefs (sys/inttypes.h) AC_MSG_RESULT([(..)]) for i in inttypes.h sys/inttypes.h stdint.h $inttype_headers ; do unset ac_cv_type_uint32_t unset ac_cv_type_uint64_t AC_CHECK_TYPE(uint32_t,[ac_cv_header_stdint_o=$i],dnl continue,[#include <$i>]) AC_CHECK_TYPE(uint64_t,[and64="/uint64_t"],[and64=""],[#include<$i>]) ac_cv_stdint_result="(seen uint32_t$and64 in $i)" break; done AC_MSG_CHECKING([for stdint uint32_t]) ])fiif test "_$ac_cv_header_stdint_x" = "_" ; thenif test "_$ac_cv_header_stdint_o" = "_" ; thenAC_CACHE_CHECK([for stdint u_int32_t], [ac_cv_header_stdint_u],[ ac_cv_header_stdint_u="" # the BSD typedefs (sys/types.h) AC_MSG_RESULT([(..)]) for i in sys/types.h inttypes.h sys/inttypes.h $inttype_headers ; do unset ac_cv_type_u_int32_t unset ac_cv_type_u_int64_t AC_CHECK_TYPE(u_int32_t,[ac_cv_header_stdint_u=$i],dnl continue,[#include <$i>]) AC_CHECK_TYPE(u_int64_t,[and64="/u_int64_t"],[and64=""],[#include<$i>]) ac_cv_stdint_result="(seen u_int32_t$and64 in $i)" break; done AC_MSG_CHECKING([for stdint u_int32_t]) ])fi fidnl if there was no good C99 header file, do some typedef checks...if test "_$ac_cv_header_stdint_x" = "_" ; then AC_MSG_CHECKING([for stdint datatype model]) AC_MSG_RESULT([(..)]) AC_CHECK_SIZEOF(char) AC_CHECK_SIZEOF(short) AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(void*) ac_cv_stdint_char_model="" ac_cv_stdint_char_model="$ac_cv_stdint_char_model$ac_cv_sizeof_char" ac_cv_stdint_char_model="$ac_cv_stdint_char_model$ac_cv_sizeof_short" ac_cv_stdint_char_model="$ac_cv_stdint_char_model$ac_cv_sizeof_int" ac_cv_stdint_long_model="" ac_cv_stdint_long_model="$ac_cv_stdint_long_model$ac_cv_sizeof_int" ac_cv_stdint_long_model="$ac_cv_stdint_long_model$ac_cv_sizeof_long" ac_cv_stdint_long_model="$ac_cv_stdint_long_model$ac_cv_sizeof_voidp" name="$ac_cv_stdint_long_model" case "$ac_cv_stdint_char_model/$ac_cv_stdint_long_model" in 122/242) name="$name, IP16 (standard 16bit machine)" ;; 122/244) name="$name, LP32 (standard 32bit mac/win)" ;; 122/*) name="$name (unusual int16 model)" ;; 124/444) name="$name, ILP32 (standard 32bit unixish)" ;; 124/488) name="$name, LP64 (standard 64bit unixish)" ;; 124/448) name="$name, LLP64 (unusual 64bit unixish)" ;; 124/*) name="$name (unusual int32 model)" ;; 128/888) name="$name, ILP64 (unusual 64bit numeric)" ;; 128/*) name="$name (unusual int64 model)" ;; 222/*|444/*) name="$name (unusual dsptype)" ;; *) name="$name (very unusal model)" ;; esac AC_MSG_RESULT([combined for stdint datatype model... $name])fiif test "_$ac_cv_header_stdint_x" != "_" ; then ac_cv_header_stdint="$ac_cv_header_stdint_x"elif test "_$ac_cv_header_stdint_o" != "_" ; then ac_cv_header_stdint="$ac_cv_header_stdint_o"elif test "_$ac_cv_header_stdint_u" != "_" ; then ac_cv_header_stdint="$ac_cv_header_stdint_u"else ac_cv_header_stdint="stddef.h"fiAC_MSG_CHECKING([for extra inttypes in chosen header])AC_MSG_RESULT([($ac_cv_header_stdint)])dnl see if int_least and int_fast types are present in _this_ header.unset ac_cv_type_int_least32_tunset ac_cv_type_int_fast32_tAC_CHECK_TYPE(int_least32_t,,,[#include <$ac_cv_header_stdint>])AC_CHECK_TYPE(int_fast32_t,,,[#include<$ac_cv_header_stdint>])AC_CHECK_TYPE(intmax_t,,,[#include <$ac_cv_header_stdint>])fi # shortcircut to system "stdint.h"# ------------------ PREPARE VARIABLES ------------------------------if test "$GCC" = "yes" ; thenac_cv_stdint_message="using gnu compiler "`$CC --version | head -1` elseac_cv_stdint_message="using $CC"fiAC_MSG_RESULT([make use of $ac_cv_header_stdint in $ac_stdint_h dnl$ac_cv_stdint_result])# ----------------- DONE inttypes.h checks START header -------------AC_CONFIG_COMMANDS([$ac_stdint_h],[AC_MSG_NOTICE(creating $ac_stdint_h : $_ac_stdint_h)ac_stdint=$tmp/_stdint.hecho "#ifndef" $_ac_stdint_h >$ac_stdintecho "#define" $_ac_stdint_h "1" >>$ac_stdintecho "#ifndef" _GENERATED_STDINT_H >>$ac_stdintecho "#define" _GENERATED_STDINT_H '"'$PACKAGE $VERSION'"' >>$ac_stdintecho "/* generated $ac_cv_stdint_message */" >>$ac_stdintif test "_$ac_cv_header_stdint_t" != "_" ; then echo "#define _STDINT_HAVE_STDINT_H" "1" >>$ac_stdintficat >>$ac_stdint <<STDINT_EOF/* ................... shortcircuit part ........................... */#if defined HAVE_STDINT_H || defined _STDINT_HAVE_STDINT_H#include <stdint.h>#else#include <stddef.h>/* .................... configured part ............................ */STDINT_EOFecho "/* whether we have a C99 compatible stdint header file */" >>$ac_stdint
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -