|
|
1.1.1.4 ! root 1: dnl $Id: acinclude.m4,v 1.10 2010/02/15 14:51:50 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) 1.1.1.4 ! root 35: AC_DEFUN([AC_CHECK_ALIGNOF], 1.1 root 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]); 1.1.1.3 root 65: fprintf(stderr, "%d\n", (int) (value / 2)); exit(0); 1.1 root 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) 1.1.1.4 ! root 84: AC_DEFUN([AC_CHECK_SHIFTMAX], 1.1 root 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); 1.1.1.3 root 110: center = 3; 111: center <<= ((sizeof(center) * 4) - 1); 1.1 root 112: max_shift = 2047; 1.1.1.3 root 113: sscanf("0", "%d", &shift); 114: for (shift += (sizeof(center) * 8); 1.1 root 115: shift < 2048; 116: shift <<= 1) { 117: right = (center >> shift); 118: left = (center << shift); 119: if (right != 0 120: || left != 0) { 121: right = (center >> (shift | 1)); 122: left = (center << (shift | 1)); 123: max_shift = ((right == (center >> 1) 124: && left == (center << 1)) 125: ? shift - 1 126: : (sizeof(center) * 8) - 1); 127: break; 128: } 129: } 130: fprintf(f, "%d\n", max_shift + 1); 131: exit(0); 132: }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=$1, AC_CV_NAME=$1)])dnl 133: AC_CV_NAME=`expr $AC_CV_NAME - 1` 134: AC_MSG_RESULT($AC_CV_NAME) 135: AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [Define to the maximum shift count for a int$1_t.]) 136: undefine([AC_TYPE_NAME])dnl 137: undefine([AC_CV_NAME])dnl 138: ]) 139: 1.1.1.2 root 140: dnl AC_CHECK_SHIFTSIGNED(BITS) 1.1.1.4 ! root 141: AC_DEFUN([AC_CHECK_SHIFTSIGNED], 1.1.1.2 root 142: [changequote(<<, >>)dnl 143: dnl The name to #define. 144: define(<<AC_TYPE_NAME>>, translit(shiftsigned_int$1_t, [a-z *], [A-Z_P]))dnl 145: dnl The cache variable name. 146: define(<<AC_CV_NAME>>, translit(ac_cv_shiftsigned_int$1_t, [ *], [_p]))dnl 147: changequote([, ])dnl 148: AC_MSG_CHECKING(for arithmetic right shifts of int$1_t) 149: AC_CACHE_VAL(AC_CV_NAME, 150: [AC_TRY_RUN([#include <stdio.h> 151: #include <sys/types.h> 152: main() 153: { 154: #if 8 == $1 155: #define _type signed char 156: #elif (SIZEOF_SHORT * 8) == $1 157: #define _type signed short 158: #elif (SIZEOF_INT * 8) == $1 159: #define _type signed int 160: #elif (SIZEOF_LONG * 8) == $1 161: #define _type signed long 162: #endif 163: _type prime, shifted, dividend; 164: unsigned int shift, divides; 165: FILE *f; 166: 167: f=fopen("conftestval", "w"); 168: if (!f) exit(1); 169: 170: /* set value to the largest magnitude negative prime that it 171: will hold: */ 172: #if $1 == 8 173: prime = -127; 174: #elif $1 == 16 175: prime = -32749; 176: #elif $1 == 32 177: prime = -2147483647; 178: #elif $1 == 64 179: /* this is a crafty way of constructing -9223372036854775783, 180: which is 0x8000000000000000 - 0x19, without having to know 181: any compiler suffix for 64-bit literals: */ 182: prime = 1; 183: prime <<= ($1 - 2); 184: prime = -prime; 185: prime *= 2; 186: prime -= 0x19; 187: #else 188: #error "need another prime" 189: #endif 190: 191: /* all right shifts from a single bit up to SHIFTMAX_INT$1_T 192: must be arithmetic, otherwise shifts aren't arithmetic: */ 193: for (shift = 1; 194: shift <= SHIFTMAX_INT$1_T; 195: shift++) { 196: shifted = prime >> shift; 197: dividend = prime; 198: divides = 0; 199: do { 200: dividend &= ~((_type) 1); /* guarantee no remainder */ 201: dividend /= 2; 202: } while (++divides < shift); 203: if (shifted != dividend) { 204: break; 205: } 206: } 207: 208: fprintf(f, "%d\n", (shift > SHIFTMAX_INT$1_T ? 1 : 0)); 209: exit(0); 210: }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=0, AC_CV_NAME=0)])dnl 211: if test $AC_CV_NAME = 1; then 212: AC_MSG_RESULT(yes) 213: AC_DEFINE_UNQUOTED(AC_TYPE_NAME, [], [Define if all right shifts of int$1_t are arithmetic.]) 214: else 215: AC_MSG_RESULT(no) 216: fi 217: undefine([AC_TYPE_NAME])dnl 218: undefine([AC_CV_NAME])dnl 219: ]) 220: 221: dnl AC_CHECK_FLOAT_FORMAT(TYPE) 1.1.1.4 ! root 222: AC_DEFUN([AC_CHECK_FLOAT_FORMAT], 1.1.1.2 root 223: [changequote(<<, >>)dnl 224: dnl The name to #define. 225: define(<<AC_TYPE_NAME>>, translit(FLOAT_FORMAT_$1, [a-z *], [A-Z_P]))dnl 226: dnl The cache variable name. 227: define(<<AC_CV_NAME>>, translit(ac_cv_float_format_$1, [ *], [_p]))dnl 228: changequote([, ])dnl 229: AC_MSG_CHECKING(the floating point format of $1) 230: AC_CACHE_VAL(AC_CV_NAME, 231: [AC_TRY_RUN([#include <stdio.h> 232: #include <sys/types.h> 233: main() 234: { 235: $1 value; 236: unsigned short value_buffer[16]; 237: #ifdef WORDS_BIGENDIAN 238: #define UINT16_PART(v, i) (value_buffer[(sizeof(v) / sizeof(value_buffer[0])) - ((i) + 1)]) 239: #else 240: #define UINT16_PART(v, i) (value_buffer[(i)]) 241: #endif 242: 243: FILE *f=fopen("conftestval", "w"); 244: if (!f) exit(1); 245: 246: /* see if this type is IEEE754 single precision: */ 247: value = 3.4793309169e-05; 248: memcpy(value_buffer, &value, sizeof(value)); 249: if (sizeof(value) == 4 250: && UINT16_PART(value, 1) == 0x3811 251: && UINT16_PART(value, 0) == 0xef08) { 252: fprintf(f, "IEEE754_SINGLE\n"); 253: exit (0); 254: } 255: 256: /* see if this type is IEEE754 double precision: */ 257: value = 7.91534994289814532176e-04; 258: memcpy(value_buffer, &value, sizeof(value)); 259: if (sizeof(value) == 8 260: && UINT16_PART(value, 3) == 0x3f49 261: && UINT16_PART(value, 2) == 0xefe0 262: && UINT16_PART(value, 1) == 0x7501 263: && UINT16_PART(value, 0) == 0xb288) { 264: fprintf(f, "IEEE754_DOUBLE\n"); 265: exit (0); 266: } 267: 268: /* see if this type might be IEEE754 extended 80-bit precision: */ 269: value = 1.1356523406294143949491931077970765006170e+04; 270: memcpy(value_buffer, &value, sizeof(value)); 271: if (sizeof(value) >= 12 272: && UINT16_PART(value, 0) == 0x7800 273: && UINT16_PART(value, 1) == 0xd1cf 274: && UINT16_PART(value, 2) == 0x17f7 275: && UINT16_PART(value, 3) == 0xb172) { 276: 277: /* check for i387-style IEEE754 extended precision: */ 278: if (sizeof(value) == 12 279: && UINT16_PART(value, 4) == 0x400c) { 280: fprintf(f, "IEEE754_EXTENDED80_I387\n"); 281: exit (0); 282: } 283: 284: /* check for m68881-style IEEE754 extended precision: */ 285: if (sizeof(value) == 12 286: && UINT16_PART(value, 5) == 0x400c) { 287: fprintf(f, "IEEE754_EXTENDED80_M68881\n"); 288: exit (0); 289: } 290: } 291: 292: /* otherwise, this is some native type: */ 293: fprintf(f, "NATIVE\n"); 294: exit (0); 295: }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=NATIVE, AC_CV_NAME=NATIVE)])dnl 296: AC_MSG_RESULT($AC_CV_NAME) 297: if test $AC_CV_NAME != NATIVE; then 298: AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [Define to the floating point format of a $1.]) 299: fi 300: undefine([AC_TYPE_NAME])dnl 301: undefine([AC_CV_NAME])dnl 302: ]) 303: 304: dnl AC_CHECK_FLOAT_LIMITS(TYPE, LIMITS) 1.1.1.4 ! root 305: AC_DEFUN([AC_CHECK_FLOAT_LIMITS], 1.1.1.2 root 306: [changequote(<<, >>)dnl 307: dnl The names to #define. 308: define(<<AC_TYPE_NAME_MAX>>, translit(FLOAT_MAX_$1, [a-z *], [A-Z_P]))dnl 309: define(<<AC_TYPE_NAME_MIN>>, translit(FLOAT_MIN_$1, [a-z *], [A-Z_P]))dnl 310: dnl The cache variable name. 311: define(<<AC_CV_NAME>>, translit(ac_cv_float_limits_$1, [ *], [_p]))dnl 312: changequote([, ])dnl 313: AC_MSG_CHECKING(the limits of $1) 314: AC_CACHE_VAL(AC_CV_NAME, 315: [for limits in $2; do 316: max=`echo $limits | sed -e 's%^\(.*\)/\(.*\)$%\1%'` 317: min=`echo $limits | sed -e 's%^\(.*\)/\(.*\)$%\2%'` 318: AC_TRY_COMPILE([#include <sys/types.h> 319: #ifdef HAVE_FLOAT_H 320: #include <float.h> 321: #endif 322: #ifdef HAVE_LIMITS_H 323: #include <limits.h> 324: #endif], [ $1 x; x = $max - $min; ], [AC_CV_NAME=$limits ; break], AC_CV_NAME= ) 325: done]) 326: if test "x$AC_CV_NAME" = x; then 327: AC_MSG_ERROR(can't determine the limits of $1) 328: fi 329: AC_MSG_RESULT($AC_CV_NAME) 330: max=`echo $AC_CV_NAME | sed -e 's%^\(.*\)/\(.*\)$%\1%'` 331: min=`echo $AC_CV_NAME | sed -e 's%^\(.*\)/\(.*\)$%\2%'` 332: AC_DEFINE_UNQUOTED(AC_TYPE_NAME_MAX, ($max), [Define to the maximum value of a $1.]) 333: AC_DEFINE_UNQUOTED(AC_TYPE_NAME_MIN, ($min), [Define to the minimum value of a $1.]) 334: undefine([AC_TYPE_NAME_MAX])dnl 335: undefine([AC_TYPE_NAME_MIN])dnl 336: undefine([AC_CV_NAME])dnl 337: ]) 338: 339: dnl AC_CHECK_FUNC_LONG(FUNC, FUNCTION-BODY, [INCLUDES, [LIBRARIES]]) 1.1.1.4 ! root 340: AC_DEFUN([AC_CHECK_FUNC_LONG], 1.1.1.2 root 341: [changequote(<<, >>)dnl 342: dnl The name to #define. 343: define(<<AC_FUNC_NAME>>, translit(have_$1, [a-z *], [A-Z_P]))dnl 344: dnl The cache variable name. 345: define(<<AC_CV_NAME>>, translit(ac_cv_have_$1, [ *], [_p]))dnl 346: changequote([, ])dnl 347: AC_MSG_CHECKING(for $1) 348: AC_CACHE_VAL(AC_CV_NAME, 349: [ac_func_long_LIBS=$LIBS 350: LIBS="${LIBS-} $4" 351: AC_TRY_LINK([ 352: $3 353: ], [ 354: $2 355: ], AC_CV_NAME=yes, AC_CV_NAME=no) 356: LIBS=$ac_func_long_LIBS])dnl 357: AC_MSG_RESULT($AC_CV_NAME) 358: if test $AC_CV_NAME = yes; then 359: AC_DEFINE_UNQUOTED(AC_FUNC_NAME, [], [Define if you have $1().]) 360: fi 361: undefine([AC_FUNC_NAME])dnl 362: undefine([AC_CV_NAME])dnl 363: ]) 364: 1.1 root 365: dnl The AC_HEADER_CHECK_PROTOTYPE, AC_HEADER_CHECK_PROTOTYPES, 366: dnl and AC_SYS_SOCKADDR_SA_LEN macros bear the following copyright: 367: dnl 368: dnl Copyright (C) 1997,1998,1999 by the Massachusetts Institute of Technology, 369: dnl Cambridge, MA, USA. All Rights Reserved. 370: dnl 371: dnl This software is being provided to you, the LICENSEE, by the 372: dnl Massachusetts Institute of Technology (M.I.T.) under the following 373: dnl license. By obtaining, using and/or copying this software, you agree 374: dnl that you have read, understood, and will comply with these terms and 375: dnl conditions: 376: dnl 377: dnl WITHIN THOSE CONSTRAINTS, permission to use, copy, modify and distribute 378: dnl this software and its documentation for any purpose and without fee or 379: dnl royalty is hereby granted, provided that you agree to comply with the 380: dnl following copyright notice and statements, including the disclaimer, and 381: dnl that the same appear on ALL copies of the software and documentation, 382: dnl including modifications that you make for internal use or for 383: dnl distribution: 384: dnl 385: dnl THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS 386: dnl OR WARRANTIES, EXPRESS OR IMPLIED. By way of example, but not 387: dnl limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF 388: dnl MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF 389: dnl THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY 390: dnl PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. 391: dnl 392: dnl The name of the Massachusetts Institute of Technology or M.I.T. may NOT 393: dnl be used in advertising or publicity pertaining to distribution of the 394: dnl software. Title to copyright in this software and any associated 395: dnl documentation shall at all times remain with M.I.T., and USER agrees to 396: dnl preserve same. 397: 398: dnl AC_HEADER_CHECK_PROTOTYPE(FUNCTION, INCLUDES, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) 1.1.1.4 ! root 399: AC_DEFUN([AC_HEADER_CHECK_PROTOTYPE], 1.1 root 400: [AC_MSG_CHECKING([for a prototype for $1]) 401: AC_CACHE_VAL(ac_cv_proto_$1, 402: [AC_TRY_COMPILE($2 [ 403: struct bonch { int a, b; }; 404: struct bonch $1(); 405: ], , eval "ac_cv_proto_$1=no", eval "ac_cv_proto_$1=yes")]) 406: if eval "test \"`echo '$ac_cv_proto_'$1`\" = yes"; then 407: AC_MSG_RESULT(yes) 408: ifelse([$3], , :, [$3]) 409: else 410: AC_MSG_RESULT(no) 411: ifelse([$4], , , [$4 412: ])dnl 413: fi 414: ]) 415: 416: dnl AC_HEADER_CHECK_PROTOTYPES(INCLUDES, FUNCTION...) 1.1.1.4 ! root 417: AC_DEFUN([AC_HEADER_CHECK_PROTOTYPES], 1.1 root 418: [for ac_func in $2 419: do 420: AC_HEADER_CHECK_PROTOTYPE($ac_func, $1, 421: [changequote(, )dnl 422: ac_tr_func=PROTO_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` 423: changequote([, ])dnl 424: AC_DEFINE_UNQUOTED($ac_tr_func)])dnl 425: done 426: ]) 427: 428: dnl AC_SYS_SOCKADDR_SA_LEN 1.1.1.4 ! root 429: AC_DEFUN([AC_SYS_SOCKADDR_SA_LEN], 1.1 root 430: [AC_MSG_CHECKING([for sa_len in struct sockaddr]) 431: AC_CACHE_VAL(ac_cv_sys_sockaddr_sa_len, 432: [AC_TRY_COMPILE([ 433: #include <sys/types.h> 434: #include <sys/socket.h> 435: ], [ 436: int length; 437: struct sockaddr sock; 438: length = sock.sa_len; 439: ], ac_cv_sys_sockaddr_sa_len=yes, ac_cv_sys_sockaddr_sa_len=no)])dnl 440: if test $ac_cv_sys_sockaddr_sa_len = yes; then 441: AC_MSG_RESULT(yes) 442: AC_DEFINE_UNQUOTED(HAVE_SOCKADDR_SA_LEN, [], [Define if your struct sockaddr has sa_len.]) 443: else 444: AC_MSG_RESULT(no) 445: fi 446: ])dnl
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.