|
|
1.1.1.2 ! root 1: dnl $Id: acinclude.m4,v 1.8 2005/05/14 22:07:04 fredette Exp $ 1.1 root 2: 3: dnl acinclude.m4 - additional tme autoconf macros: 4: 1.1.1.2 ! root 5: dnl Copyright (c) 2001, 2003, 2004 Matt Fredette 1.1 root 6: dnl All rights reserved. 7: dnl 8: dnl Redistribution and use in source and binary forms, with or without 9: dnl modification, are permitted provided that the following conditions 10: dnl are met: 11: dnl 1. Redistributions of source code must retain the above copyright 12: dnl notice, this list of conditions and the following disclaimer. 13: dnl 2. Redistributions in binary form must reproduce the above copyright 14: dnl notice, this list of conditions and the following disclaimer in the 15: dnl documentation and/or other materials provided with the distribution. 16: dnl 3. All advertising materials mentioning features or use of this software 17: dnl must display the following acknowledgement: 18: dnl This product includes software developed by Matt Fredette. 19: dnl 4. The name of the author may not be used to endorse or promote products 20: dnl derived from this software without specific prior written permission. 21: dnl 22: dnl THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23: dnl IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24: dnl WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25: dnl DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26: dnl INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27: dnl (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28: dnl SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29: dnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30: dnl STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31: dnl ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32: dnl POSSIBILITY OF SUCH DAMAGE. 33: 34: dnl AC_CHECK_ALIGNOF(BITS) 35: AC_DEFUN(AC_CHECK_ALIGNOF, 36: [changequote(<<, >>)dnl 37: dnl The name to #define. 38: define(<<AC_TYPE_NAME>>, translit(alignof_int$1_t, [a-z *], [A-Z_P]))dnl 39: dnl The cache variable name. 40: define(<<AC_CV_NAME>>, translit(ac_cv_alignof_int$1_t, [ *], [_p]))dnl 41: changequote([, ])dnl 42: AC_MSG_CHECKING(minimum alignment of int$1_t) 43: AC_CACHE_VAL(AC_CV_NAME, 44: [AC_TRY_RUN([#include <stdio.h> 45: #include <sys/types.h> 46: main() 47: { 48: #if (SIZEOF_SHORT * 8) == $1 49: #define _type short 50: #elif (SIZEOF_INT * 8) == $1 51: #define _type int 52: #else 53: #define _type long 54: #endif 55: char try_align_buffer[sizeof(_type) * 2]; 56: int min_align, try_align, status; 57: _type value; 58: FILE *f=fopen("conftestval", "w"); 59: if (!f) exit(1); 60: min_align = sizeof(_type); 61: for(try_align = sizeof(_type); try_align-- > 1;) { 62: switch(fork()) { 63: case -1: exit(1); 64: case 0: value = *((_type *) &try_align_buffer[try_align]); 65: fprintf(stderr, "%d\n", (int) value); exit(0); 66: default: break; 67: } 68: wait(&status); 69: if (!status && try_align < min_align) { 70: min_align = try_align; 71: } 72: } 73: fprintf(f, "%d\n", min_align * 8); 74: exit(0); 75: }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=$1, AC_CV_NAME=$1)])dnl 76: AC_CV_NAME=`expr $AC_CV_NAME / 8` 77: AC_MSG_RESULT($AC_CV_NAME) 78: AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [Define to the minimum alignment, in bytes, of int$1_t.]) 79: undefine([AC_TYPE_NAME])dnl 80: undefine([AC_CV_NAME])dnl 81: ]) 82: 83: dnl AC_CHECK_SHIFTMAX(BITS) 84: AC_DEFUN(AC_CHECK_SHIFTMAX, 85: [changequote(<<, >>)dnl 86: dnl The name to #define. 87: define(<<AC_TYPE_NAME>>, translit(shiftmax_int$1_t, [a-z *], [A-Z_P]))dnl 88: dnl The cache variable name. 89: define(<<AC_CV_NAME>>, translit(ac_cv_shiftmax_int$1_t, [ *], [_p]))dnl 90: changequote([, ])dnl 91: AC_MSG_CHECKING(maximum shift count for int$1_t) 92: AC_CACHE_VAL(AC_CV_NAME, 93: [AC_TRY_RUN([#include <stdio.h> 94: #include <sys/types.h> 95: main() 96: { 97: #if 8 == $1 98: #define _type char 99: #elif (SIZEOF_SHORT * 8) == $1 100: #define _type short 101: #elif (SIZEOF_INT * 8) == $1 102: #define _type int 103: #elif (SIZEOF_LONG * 8) == $1 104: #define _type long 105: #endif 106: _type center, right, left; 107: unsigned int shift, max_shift; 108: FILE *f=fopen("conftestval", "w"); 109: if (!f) exit(1); 110: center = 3 << ((sizeof(center) * 4) - 1); 111: max_shift = 2047; 112: for (shift = (sizeof(center) * 8); 113: shift < 2048; 114: shift <<= 1) { 115: right = (center >> shift); 116: left = (center << shift); 117: if (right != 0 118: || left != 0) { 119: right = (center >> (shift | 1)); 120: left = (center << (shift | 1)); 121: max_shift = ((right == (center >> 1) 122: && left == (center << 1)) 123: ? shift - 1 124: : (sizeof(center) * 8) - 1); 125: break; 126: } 127: } 128: fprintf(f, "%d\n", max_shift + 1); 129: exit(0); 130: }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=$1, AC_CV_NAME=$1)])dnl 131: AC_CV_NAME=`expr $AC_CV_NAME - 1` 132: AC_MSG_RESULT($AC_CV_NAME) 133: AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [Define to the maximum shift count for a int$1_t.]) 134: undefine([AC_TYPE_NAME])dnl 135: undefine([AC_CV_NAME])dnl 136: ]) 137: 1.1.1.2 ! root 138: dnl AC_CHECK_SHIFTSIGNED(BITS) ! 139: AC_DEFUN(AC_CHECK_SHIFTSIGNED, ! 140: [changequote(<<, >>)dnl ! 141: dnl The name to #define. ! 142: define(<<AC_TYPE_NAME>>, translit(shiftsigned_int$1_t, [a-z *], [A-Z_P]))dnl ! 143: dnl The cache variable name. ! 144: define(<<AC_CV_NAME>>, translit(ac_cv_shiftsigned_int$1_t, [ *], [_p]))dnl ! 145: changequote([, ])dnl ! 146: AC_MSG_CHECKING(for arithmetic right shifts of int$1_t) ! 147: AC_CACHE_VAL(AC_CV_NAME, ! 148: [AC_TRY_RUN([#include <stdio.h> ! 149: #include <sys/types.h> ! 150: main() ! 151: { ! 152: #if 8 == $1 ! 153: #define _type signed char ! 154: #elif (SIZEOF_SHORT * 8) == $1 ! 155: #define _type signed short ! 156: #elif (SIZEOF_INT * 8) == $1 ! 157: #define _type signed int ! 158: #elif (SIZEOF_LONG * 8) == $1 ! 159: #define _type signed long ! 160: #endif ! 161: _type prime, shifted, dividend; ! 162: unsigned int shift, divides; ! 163: FILE *f; ! 164: ! 165: f=fopen("conftestval", "w"); ! 166: if (!f) exit(1); ! 167: ! 168: /* set value to the largest magnitude negative prime that it ! 169: will hold: */ ! 170: #if $1 == 8 ! 171: prime = -127; ! 172: #elif $1 == 16 ! 173: prime = -32749; ! 174: #elif $1 == 32 ! 175: prime = -2147483647; ! 176: #elif $1 == 64 ! 177: /* this is a crafty way of constructing -9223372036854775783, ! 178: which is 0x8000000000000000 - 0x19, without having to know ! 179: any compiler suffix for 64-bit literals: */ ! 180: prime = 1; ! 181: prime <<= ($1 - 2); ! 182: prime = -prime; ! 183: prime *= 2; ! 184: prime -= 0x19; ! 185: #else ! 186: #error "need another prime" ! 187: #endif ! 188: ! 189: /* all right shifts from a single bit up to SHIFTMAX_INT$1_T ! 190: must be arithmetic, otherwise shifts aren't arithmetic: */ ! 191: for (shift = 1; ! 192: shift <= SHIFTMAX_INT$1_T; ! 193: shift++) { ! 194: shifted = prime >> shift; ! 195: dividend = prime; ! 196: divides = 0; ! 197: do { ! 198: dividend &= ~((_type) 1); /* guarantee no remainder */ ! 199: dividend /= 2; ! 200: } while (++divides < shift); ! 201: if (shifted != dividend) { ! 202: break; ! 203: } ! 204: } ! 205: ! 206: fprintf(f, "%d\n", (shift > SHIFTMAX_INT$1_T ? 1 : 0)); ! 207: exit(0); ! 208: }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=0, AC_CV_NAME=0)])dnl ! 209: if test $AC_CV_NAME = 1; then ! 210: AC_MSG_RESULT(yes) ! 211: AC_DEFINE_UNQUOTED(AC_TYPE_NAME, [], [Define if all right shifts of int$1_t are arithmetic.]) ! 212: else ! 213: AC_MSG_RESULT(no) ! 214: fi ! 215: undefine([AC_TYPE_NAME])dnl ! 216: undefine([AC_CV_NAME])dnl ! 217: ]) ! 218: ! 219: dnl AC_CHECK_FLOAT_FORMAT(TYPE) ! 220: AC_DEFUN(AC_CHECK_FLOAT_FORMAT, ! 221: [changequote(<<, >>)dnl ! 222: dnl The name to #define. ! 223: define(<<AC_TYPE_NAME>>, translit(FLOAT_FORMAT_$1, [a-z *], [A-Z_P]))dnl ! 224: dnl The cache variable name. ! 225: define(<<AC_CV_NAME>>, translit(ac_cv_float_format_$1, [ *], [_p]))dnl ! 226: changequote([, ])dnl ! 227: AC_MSG_CHECKING(the floating point format of $1) ! 228: AC_CACHE_VAL(AC_CV_NAME, ! 229: [AC_TRY_RUN([#include <stdio.h> ! 230: #include <sys/types.h> ! 231: main() ! 232: { ! 233: $1 value; ! 234: unsigned short value_buffer[16]; ! 235: #ifdef WORDS_BIGENDIAN ! 236: #define UINT16_PART(v, i) (value_buffer[(sizeof(v) / sizeof(value_buffer[0])) - ((i) + 1)]) ! 237: #else ! 238: #define UINT16_PART(v, i) (value_buffer[(i)]) ! 239: #endif ! 240: ! 241: FILE *f=fopen("conftestval", "w"); ! 242: if (!f) exit(1); ! 243: ! 244: /* see if this type is IEEE754 single precision: */ ! 245: value = 3.4793309169e-05; ! 246: memcpy(value_buffer, &value, sizeof(value)); ! 247: if (sizeof(value) == 4 ! 248: && UINT16_PART(value, 1) == 0x3811 ! 249: && UINT16_PART(value, 0) == 0xef08) { ! 250: fprintf(f, "IEEE754_SINGLE\n"); ! 251: exit (0); ! 252: } ! 253: ! 254: /* see if this type is IEEE754 double precision: */ ! 255: value = 7.91534994289814532176e-04; ! 256: memcpy(value_buffer, &value, sizeof(value)); ! 257: if (sizeof(value) == 8 ! 258: && UINT16_PART(value, 3) == 0x3f49 ! 259: && UINT16_PART(value, 2) == 0xefe0 ! 260: && UINT16_PART(value, 1) == 0x7501 ! 261: && UINT16_PART(value, 0) == 0xb288) { ! 262: fprintf(f, "IEEE754_DOUBLE\n"); ! 263: exit (0); ! 264: } ! 265: ! 266: /* see if this type might be IEEE754 extended 80-bit precision: */ ! 267: value = 1.1356523406294143949491931077970765006170e+04; ! 268: memcpy(value_buffer, &value, sizeof(value)); ! 269: if (sizeof(value) >= 12 ! 270: && UINT16_PART(value, 0) == 0x7800 ! 271: && UINT16_PART(value, 1) == 0xd1cf ! 272: && UINT16_PART(value, 2) == 0x17f7 ! 273: && UINT16_PART(value, 3) == 0xb172) { ! 274: ! 275: /* check for i387-style IEEE754 extended precision: */ ! 276: if (sizeof(value) == 12 ! 277: && UINT16_PART(value, 4) == 0x400c) { ! 278: fprintf(f, "IEEE754_EXTENDED80_I387\n"); ! 279: exit (0); ! 280: } ! 281: ! 282: /* check for m68881-style IEEE754 extended precision: */ ! 283: if (sizeof(value) == 12 ! 284: && UINT16_PART(value, 5) == 0x400c) { ! 285: fprintf(f, "IEEE754_EXTENDED80_M68881\n"); ! 286: exit (0); ! 287: } ! 288: } ! 289: ! 290: /* otherwise, this is some native type: */ ! 291: fprintf(f, "NATIVE\n"); ! 292: exit (0); ! 293: }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=NATIVE, AC_CV_NAME=NATIVE)])dnl ! 294: AC_MSG_RESULT($AC_CV_NAME) ! 295: if test $AC_CV_NAME != NATIVE; then ! 296: AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [Define to the floating point format of a $1.]) ! 297: fi ! 298: undefine([AC_TYPE_NAME])dnl ! 299: undefine([AC_CV_NAME])dnl ! 300: ]) ! 301: ! 302: dnl AC_CHECK_FLOAT_LIMITS(TYPE, LIMITS) ! 303: AC_DEFUN(AC_CHECK_FLOAT_LIMITS, ! 304: [changequote(<<, >>)dnl ! 305: dnl The names to #define. ! 306: define(<<AC_TYPE_NAME_MAX>>, translit(FLOAT_MAX_$1, [a-z *], [A-Z_P]))dnl ! 307: define(<<AC_TYPE_NAME_MIN>>, translit(FLOAT_MIN_$1, [a-z *], [A-Z_P]))dnl ! 308: dnl The cache variable name. ! 309: define(<<AC_CV_NAME>>, translit(ac_cv_float_limits_$1, [ *], [_p]))dnl ! 310: changequote([, ])dnl ! 311: AC_MSG_CHECKING(the limits of $1) ! 312: AC_CACHE_VAL(AC_CV_NAME, ! 313: [for limits in $2; do ! 314: max=`echo $limits | sed -e 's%^\(.*\)/\(.*\)$%\1%'` ! 315: min=`echo $limits | sed -e 's%^\(.*\)/\(.*\)$%\2%'` ! 316: AC_TRY_COMPILE([#include <sys/types.h> ! 317: #ifdef HAVE_FLOAT_H ! 318: #include <float.h> ! 319: #endif ! 320: #ifdef HAVE_LIMITS_H ! 321: #include <limits.h> ! 322: #endif], [ $1 x; x = $max - $min; ], [AC_CV_NAME=$limits ; break], AC_CV_NAME= ) ! 323: done]) ! 324: if test "x$AC_CV_NAME" = x; then ! 325: AC_MSG_ERROR(can't determine the limits of $1) ! 326: fi ! 327: AC_MSG_RESULT($AC_CV_NAME) ! 328: max=`echo $AC_CV_NAME | sed -e 's%^\(.*\)/\(.*\)$%\1%'` ! 329: min=`echo $AC_CV_NAME | sed -e 's%^\(.*\)/\(.*\)$%\2%'` ! 330: AC_DEFINE_UNQUOTED(AC_TYPE_NAME_MAX, ($max), [Define to the maximum value of a $1.]) ! 331: AC_DEFINE_UNQUOTED(AC_TYPE_NAME_MIN, ($min), [Define to the minimum value of a $1.]) ! 332: undefine([AC_TYPE_NAME_MAX])dnl ! 333: undefine([AC_TYPE_NAME_MIN])dnl ! 334: undefine([AC_CV_NAME])dnl ! 335: ]) ! 336: ! 337: dnl AC_CHECK_FUNC_LONG(FUNC, FUNCTION-BODY, [INCLUDES, [LIBRARIES]]) ! 338: AC_DEFUN(AC_CHECK_FUNC_LONG, ! 339: [changequote(<<, >>)dnl ! 340: dnl The name to #define. ! 341: define(<<AC_FUNC_NAME>>, translit(have_$1, [a-z *], [A-Z_P]))dnl ! 342: dnl The cache variable name. ! 343: define(<<AC_CV_NAME>>, translit(ac_cv_have_$1, [ *], [_p]))dnl ! 344: changequote([, ])dnl ! 345: AC_MSG_CHECKING(for $1) ! 346: AC_CACHE_VAL(AC_CV_NAME, ! 347: [ac_func_long_LIBS=$LIBS ! 348: LIBS="${LIBS-} $4" ! 349: AC_TRY_LINK([ ! 350: $3 ! 351: ], [ ! 352: $2 ! 353: ], AC_CV_NAME=yes, AC_CV_NAME=no) ! 354: LIBS=$ac_func_long_LIBS])dnl ! 355: AC_MSG_RESULT($AC_CV_NAME) ! 356: if test $AC_CV_NAME = yes; then ! 357: AC_DEFINE_UNQUOTED(AC_FUNC_NAME, [], [Define if you have $1().]) ! 358: fi ! 359: undefine([AC_FUNC_NAME])dnl ! 360: undefine([AC_CV_NAME])dnl ! 361: ]) ! 362: 1.1 root 363: dnl The AC_HEADER_CHECK_PROTOTYPE, AC_HEADER_CHECK_PROTOTYPES, 364: dnl and AC_SYS_SOCKADDR_SA_LEN macros bear the following copyright: 365: dnl 366: dnl Copyright (C) 1997,1998,1999 by the Massachusetts Institute of Technology, 367: dnl Cambridge, MA, USA. All Rights Reserved. 368: dnl 369: dnl This software is being provided to you, the LICENSEE, by the 370: dnl Massachusetts Institute of Technology (M.I.T.) under the following 371: dnl license. By obtaining, using and/or copying this software, you agree 372: dnl that you have read, understood, and will comply with these terms and 373: dnl conditions: 374: dnl 375: dnl WITHIN THOSE CONSTRAINTS, permission to use, copy, modify and distribute 376: dnl this software and its documentation for any purpose and without fee or 377: dnl royalty is hereby granted, provided that you agree to comply with the 378: dnl following copyright notice and statements, including the disclaimer, and 379: dnl that the same appear on ALL copies of the software and documentation, 380: dnl including modifications that you make for internal use or for 381: dnl distribution: 382: dnl 383: dnl THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS 384: dnl OR WARRANTIES, EXPRESS OR IMPLIED. By way of example, but not 385: dnl limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF 386: dnl MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF 387: dnl THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY 388: dnl PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. 389: dnl 390: dnl The name of the Massachusetts Institute of Technology or M.I.T. may NOT 391: dnl be used in advertising or publicity pertaining to distribution of the 392: dnl software. Title to copyright in this software and any associated 393: dnl documentation shall at all times remain with M.I.T., and USER agrees to 394: dnl preserve same. 395: 396: dnl AC_HEADER_CHECK_PROTOTYPE(FUNCTION, INCLUDES, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) 397: AC_DEFUN(AC_HEADER_CHECK_PROTOTYPE, 398: [AC_MSG_CHECKING([for a prototype for $1]) 399: AC_CACHE_VAL(ac_cv_proto_$1, 400: [AC_TRY_COMPILE($2 [ 401: struct bonch { int a, b; }; 402: struct bonch $1(); 403: ], , eval "ac_cv_proto_$1=no", eval "ac_cv_proto_$1=yes")]) 404: if eval "test \"`echo '$ac_cv_proto_'$1`\" = yes"; then 405: AC_MSG_RESULT(yes) 406: ifelse([$3], , :, [$3]) 407: else 408: AC_MSG_RESULT(no) 409: ifelse([$4], , , [$4 410: ])dnl 411: fi 412: ]) 413: 414: dnl AC_HEADER_CHECK_PROTOTYPES(INCLUDES, FUNCTION...) 415: AC_DEFUN(AC_HEADER_CHECK_PROTOTYPES, 416: [for ac_func in $2 417: do 418: AC_HEADER_CHECK_PROTOTYPE($ac_func, $1, 419: [changequote(, )dnl 420: ac_tr_func=PROTO_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` 421: changequote([, ])dnl 422: AC_DEFINE_UNQUOTED($ac_tr_func)])dnl 423: done 424: ]) 425: 426: dnl AC_SYS_SOCKADDR_SA_LEN 427: AC_DEFUN(AC_SYS_SOCKADDR_SA_LEN, 428: [AC_MSG_CHECKING([for sa_len in struct sockaddr]) 429: AC_CACHE_VAL(ac_cv_sys_sockaddr_sa_len, 430: [AC_TRY_COMPILE([ 431: #include <sys/types.h> 432: #include <sys/socket.h> 433: ], [ 434: int length; 435: struct sockaddr sock; 436: length = sock.sa_len; 437: ], ac_cv_sys_sockaddr_sa_len=yes, ac_cv_sys_sockaddr_sa_len=no)])dnl 438: if test $ac_cv_sys_sockaddr_sa_len = yes; then 439: AC_MSG_RESULT(yes) 440: AC_DEFINE_UNQUOTED(HAVE_SOCKADDR_SA_LEN, [], [Define if your struct sockaddr has sa_len.]) 441: else 442: AC_MSG_RESULT(no) 443: fi 444: ])dnl
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.