Merged with trunk revision 600
[ardour.git] / libs / libsndfile / acinclude.m4
1 dnl By default, many hosts won't let programs access large files;
2 dnl one must use special compiler options to get large-file access to work.
3 dnl For more details about this brain damage please see:
4 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
5
6 dnl Written by Paul Eggert <eggert@twinsun.com>.
7
8 dnl Internal subroutine of AC_SYS_EXTRA_LARGEFILE.
9 dnl AC_SYS_EXTRA_LARGEFILE_FLAGS(FLAGSNAME)
10 AC_DEFUN([AC_SYS_EXTRA_LARGEFILE_FLAGS],
11   [AC_CACHE_CHECK([for $1 value to request large file support],
12      ac_cv_sys_largefile_$1,
13      [ac_cv_sys_largefile_$1=`($GETCONF LFS_$1) 2>/dev/null` || {
14         ac_cv_sys_largefile_$1=no
15         ifelse($1, CFLAGS,
16           [case "$host_os" in
17            # IRIX 6.2 and later require cc -n32.
18 changequote(, )dnl
19            irix6.[2-9]* | irix6.1[0-9]* | irix[7-9].* | irix[1-9][0-9]*)
20 changequote([, ])dnl
21              if test "$GCC" != yes; then
22                ac_cv_sys_largefile_CFLAGS=-n32
23              fi
24              ac_save_CC="$CC"
25              CC="$CC $ac_cv_sys_largefile_CFLAGS"
26              AC_TRY_LINK(, , , ac_cv_sys_largefile_CFLAGS=no)
27              CC="$ac_save_CC"
28            esac])
29       }])])
30
31 dnl Internal subroutine of AC_SYS_EXTRA_LARGEFILE.
32 dnl AC_SYS_EXTRA_LARGEFILE_SPACE_APPEND(VAR, VAL)
33 AC_DEFUN([AC_SYS_EXTRA_LARGEFILE_SPACE_APPEND],
34   [case $2 in
35    no) ;;
36    ?*)
37      case "[$]$1" in
38      '') $1=$2 ;;
39      *) $1=[$]$1' '$2 ;;
40      esac ;;
41    esac])
42
43 dnl Internal subroutine of AC_SYS_EXTRA_LARGEFILE.
44 dnl AC_SYS_EXTRA_LARGEFILE_MACRO_VALUE(C-MACRO, CACHE-VAR, COMMENT, CODE-TO-SET-DEFAULT)
45 AC_DEFUN([AC_SYS_EXTRA_LARGEFILE_MACRO_VALUE],
46   [AC_CACHE_CHECK([for $1], $2,
47      [$2=no
48 changequote(, )dnl
49       $4
50       for ac_flag in $ac_cv_sys_largefile_CFLAGS no; do
51         case "$ac_flag" in
52         -D$1)
53           $2=1 ;;
54         -D$1=*)
55           $2=`expr " $ac_flag" : '[^=]*=\(.*\)'` ;;
56         esac
57       done
58 changequote([, ])dnl
59       ])
60    if test "[$]$2" != no; then
61      AC_DEFINE_UNQUOTED([$1], [$]$2, [$3])
62    fi])
63
64 AC_DEFUN([AC_SYS_EXTRA_LARGEFILE],
65   [AC_REQUIRE([AC_CANONICAL_HOST])
66    AC_ARG_ENABLE(largefile,
67      [  --disable-largefile     omit support for large files])
68    if test "$enable_largefile" != no; then
69      AC_CHECK_TOOL(GETCONF, getconf)
70      AC_SYS_EXTRA_LARGEFILE_FLAGS(CFLAGS)
71      AC_SYS_EXTRA_LARGEFILE_FLAGS(LDFLAGS)
72      AC_SYS_EXTRA_LARGEFILE_FLAGS(LIBS)
73
74      for ac_flag in $ac_cv_sys_largefile_CFLAGS no; do
75        case "$ac_flag" in
76        no) ;;
77        -D_FILE_OFFSET_BITS=*) ;;
78        -D_LARGEFILE_SOURCE | -D_LARGEFILE_SOURCE=*) ;;
79        -D_LARGE_FILES | -D_LARGE_FILES=*) ;;
80        -D?* | -I?*)
81          AC_SYS_EXTRA_LARGEFILE_SPACE_APPEND(CPPFLAGS, "$ac_flag") ;;
82        *)
83          AC_SYS_EXTRA_LARGEFILE_SPACE_APPEND(CFLAGS, "$ac_flag") ;;
84        esac
85      done
86      AC_SYS_EXTRA_LARGEFILE_SPACE_APPEND(LDFLAGS, "$ac_cv_sys_largefile_LDFLAGS")
87      AC_SYS_EXTRA_LARGEFILE_SPACE_APPEND(LIBS, "$ac_cv_sys_largefile_LIBS")
88      AC_SYS_EXTRA_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS,
89        ac_cv_sys_file_offset_bits,
90        [Number of bits in a file offset, on hosts where this is settable.])
91        [case "$host_os" in
92         # HP-UX 10.20 and later
93         hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)
94           ac_cv_sys_file_offset_bits=64 ;;
95         esac]
96      AC_SYS_EXTRA_LARGEFILE_MACRO_VALUE(_LARGEFILE_SOURCE,
97        ac_cv_sys_largefile_source,
98        [Define to make fseeko etc. visible, on some hosts.],
99        [case "$host_os" in
100         # HP-UX 10.20 and later
101         hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)
102           ac_cv_sys_largefile_source=1 ;;
103         esac])
104      AC_SYS_EXTRA_LARGEFILE_MACRO_VALUE(_LARGE_FILES,
105        ac_cv_sys_large_files,
106        [Define for large files, on AIX-style hosts.],
107        [case "$host_os" in
108         # AIX 4.2 and later
109         aix4.[2-9]* | aix4.1[0-9]* | aix[5-9].* | aix[1-9][0-9]*)
110           ac_cv_sys_large_files=1 ;;
111         esac])
112    fi
113   ])
114
115
116
117
118
119
120 dnl @synopsis AC_C_FIND_ENDIAN
121 dnl
122 dnl Determine endian-ness of target processor.
123 dnl @version 1.1        Mar 03 2002
124 dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
125 dnl
126 dnl Majority written from scratch to replace the standard autoconf macro 
127 dnl AC_C_BIGENDIAN. Only part remaining from the original it the invocation
128 dnl of the AC_TRY_RUN macro.
129 dnl
130 dnl Permission to use, copy, modify, distribute, and sell this file for any 
131 dnl purpose is hereby granted without fee, provided that the above copyright 
132 dnl and this permission notice appear in all copies.  No representations are
133 dnl made about the suitability of this software for any purpose.  It is 
134 dnl provided "as is" without express or implied warranty.
135
136 dnl Find endian-ness in the following way:
137 dnl    1) Look in <endian.h>.
138 dnl    2) If 1) fails, look in <sys/types.h> and <sys/param.h>.
139 dnl    3) If 1) and 2) fails and not cross compiling run a test program.
140 dnl    4) If 1) and 2) fails and cross compiling then guess based on target.
141
142 AC_DEFUN([AC_C_FIND_ENDIAN],
143 [AC_CACHE_CHECK(processor byte ordering, 
144         ac_cv_c_byte_order,
145
146 # Initialize to unknown
147 ac_cv_c_byte_order=unknown
148
149 if test x$ac_cv_header_endian_h = xyes ; then
150
151         # First try <endian.h> which should set BYTE_ORDER.
152
153         [AC_TRY_LINK([
154                 #include <endian.h>
155                 #if BYTE_ORDER != LITTLE_ENDIAN
156                         not big endian
157                 #endif
158                 ], return 0 ;, 
159                         ac_cv_c_byte_order=little
160                 )]
161                                 
162         [AC_TRY_LINK([
163                 #include <endian.h>
164                 #if BYTE_ORDER != BIG_ENDIAN
165                         not big endian
166                 #endif
167                 ], return 0 ;, 
168                         ac_cv_c_byte_order=big
169                 )]
170
171         fi
172
173 if test $ac_cv_c_byte_order = unknown ; then
174
175         [AC_TRY_LINK([
176                 #include <sys/types.h>
177                 #include <sys/param.h>
178                 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
179                         bogus endian macros
180                 #endif
181                 ], return 0 ;, 
182
183                 [AC_TRY_LINK([
184                         #include <sys/types.h>
185                         #include <sys/param.h>
186                         #if BYTE_ORDER != LITTLE_ENDIAN
187                                 not big endian
188                         #endif
189                         ], return 0 ;, 
190                                 ac_cv_c_byte_order=little
191                         )]
192                                 
193                 [AC_TRY_LINK([
194                         #include <sys/types.h>
195                         #include <sys/param.h>
196                         #if BYTE_ORDER != LITTLE_ENDIAN
197                                 not big endian
198                         #endif
199                         ], return 0 ;, 
200                                 ac_cv_c_byte_order=little
201                         )]
202
203                 )]
204
205         fi
206
207 if test $ac_cv_c_byte_order = unknown ; then
208         if test $cross_compiling = yes ; then
209                 # This is the last resort. Try to guess the target processor endian-ness
210                 # by looking at the target CPU type.    
211                 [
212                 case "$target_cpu" in
213                         alpha* | i?86* | mipsel* | ia64*)
214                                 ac_cv_c_big_endian=0
215                                 ac_cv_c_little_endian=1
216                                 ;;
217                         
218                         m68* | mips* | powerpc* | hppa* | sparc*)
219                                 ac_cv_c_big_endian=1
220                                 ac_cv_c_little_endian=0
221                                 ;;
222         
223                         esac
224                 ]
225         else
226                 AC_TRY_RUN(
227                 [[
228                 int main (void) 
229                 {       /* Are we little or big endian?  From Harbison&Steele.  */
230                         union
231                         {       long l ;
232                                 char c [sizeof (long)] ;
233                         } u ;
234                         u.l = 1 ;
235                         return (u.c [sizeof (long) - 1] == 1);
236                         }
237                         ]], , ac_cv_c_byte_order=big, 
238                         ac_cv_c_byte_order=unknown
239                         )
240
241                 AC_TRY_RUN(
242                 [[int main (void) 
243                 {       /* Are we little or big endian?  From Harbison&Steele.  */
244                         union
245                         {       long l ;
246                                 char c [sizeof (long)] ;
247                         } u ;
248                         u.l = 1 ;
249                         return (u.c [0] == 1);
250                         }]], , ac_cv_c_byte_order=little, 
251                         ac_cv_c_byte_order=unknown
252                         )
253                 fi      
254         fi
255
256 )
257 ]
258
259 if test $ac_cv_c_byte_order = big ; then
260         ac_cv_c_big_endian=1
261         ac_cv_c_little_endian=0
262 elif test $ac_cv_c_byte_order = little ; then
263         ac_cv_c_big_endian=0
264         ac_cv_c_little_endian=1
265 else
266         ac_cv_c_big_endian=0
267         ac_cv_c_little_endian=0
268
269         AC_MSG_WARN([[*****************************************************************]])
270         AC_MSG_WARN([[*** Not able to determine endian-ness of target processor.       ]])
271         AC_MSG_WARN([[*** The constants CPU_IS_BIG_ENDIAN and CPU_IS_LITTLE_ENDIAN in  ]])
272         AC_MSG_WARN([[*** src/config.h may need to be hand editied.                    ]])
273         AC_MSG_WARN([[*****************************************************************]])
274         fi
275
276 )# AC_C_FIND_ENDIAN
277
278
279
280
281
282 dnl @synopsis AC_C99_FLEXIBLE_ARRAY
283 dnl
284 dnl Dose the compiler support the 1999 ISO C Standard "stuct hack".
285 dnl @version 1.1        Mar 15 2004
286 dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
287 dnl
288 dnl Permission to use, copy, modify, distribute, and sell this file for any 
289 dnl purpose is hereby granted without fee, provided that the above copyright 
290 dnl and this permission notice appear in all copies.  No representations are
291 dnl made about the suitability of this software for any purpose.  It is 
292 dnl provided "as is" without express or implied warranty.
293
294 AC_DEFUN([AC_C99_FLEXIBLE_ARRAY],
295 [AC_CACHE_CHECK(C99 struct flexible array support, 
296         ac_cv_c99_flexible_array,
297
298 # Initialize to unknown
299 ac_cv_c99_flexible_array=no
300
301 AC_TRY_LINK([[
302         #include <stdlib.h>
303         typedef struct {
304         int k;
305         char buffer [] ;
306         } MY_STRUCT ;
307         ]], 
308         [  MY_STRUCT *p = calloc (1, sizeof (MY_STRUCT) + 42); ],
309         ac_cv_c99_flexible_array=yes,
310         ac_cv_c99_flexible_array=no
311         ))]
312 ) # AC_C99_FLEXIBLE_ARRAY
313
314
315      
316
317
318 dnl @synopsis AC_C99_FUNC_LRINT
319 dnl
320 dnl Check whether C99's lrint function is available.
321 dnl @version 1.3        Feb 12 2002
322 dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
323 dnl
324 dnl Permission to use, copy, modify, distribute, and sell this file for any 
325 dnl purpose is hereby granted without fee, provided that the above copyright 
326 dnl and this permission notice appear in all copies.  No representations are
327 dnl made about the suitability of this software for any purpose.  It is 
328 dnl provided "as is" without express or implied warranty.
329 dnl
330 AC_DEFUN([AC_C99_FUNC_LRINT],
331 [AC_CACHE_CHECK(for lrint,
332   ac_cv_c99_lrint,
333 [
334 lrint_save_CFLAGS=$CFLAGS
335 CFLAGS="-O2 -lm"
336 AC_TRY_LINK([
337 #define         _ISOC9X_SOURCE  1
338 #define         _ISOC99_SOURCE  1
339 #define         __USE_ISOC99    1
340 #define         __USE_ISOC9X    1
341
342 #include <math.h>
343 ], if (!lrint(3.14159)) lrint(2.7183);, ac_cv_c99_lrint=yes, ac_cv_c99_lrint=no)
344
345 CFLAGS=$lrint_save_CFLAGS
346
347 ])
348
349 if test "$ac_cv_c99_lrint" = yes; then
350   AC_DEFINE(HAVE_LRINT, 1,
351             [Define if you have C99's lrint function.])
352 fi
353 ])# AC_C99_FUNC_LRINT
354 dnl @synopsis AC_C99_FUNC_LRINTF
355 dnl
356 dnl Check whether C99's lrintf function is available.
357 dnl @version 1.3        Feb 12 2002
358 dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
359 dnl
360 dnl Permission to use, copy, modify, distribute, and sell this file for any 
361 dnl purpose is hereby granted without fee, provided that the above copyright 
362 dnl and this permission notice appear in all copies.  No representations are
363 dnl made about the suitability of this software for any purpose.  It is 
364 dnl provided "as is" without express or implied warranty.
365 dnl
366 AC_DEFUN([AC_C99_FUNC_LRINTF],
367 [AC_CACHE_CHECK(for lrintf,
368   ac_cv_c99_lrintf,
369 [
370 lrintf_save_CFLAGS=$CFLAGS
371 CFLAGS="-O2 -lm"
372 AC_TRY_LINK([
373 #define         _ISOC9X_SOURCE  1
374 #define         _ISOC99_SOURCE  1
375 #define         __USE_ISOC99    1
376 #define         __USE_ISOC9X    1
377
378 #include <math.h>
379 ], if (!lrintf(3.14159)) lrintf(2.7183);, ac_cv_c99_lrintf=yes, ac_cv_c99_lrintf=no)
380
381 CFLAGS=$lrintf_save_CFLAGS
382
383 ])
384
385 if test "$ac_cv_c99_lrintf" = yes; then
386   AC_DEFINE(HAVE_LRINTF, 1,
387             [Define if you have C99's lrintf function.])
388 fi
389 ])# AC_C99_FUNC_LRINTF
390
391
392
393
394 dnl @synopsis AC_C99_FUNC_LLRINT
395 dnl
396 dnl Check whether C99's llrint function is available.
397 dnl @version 1.1        Sep 30 2002
398 dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
399 dnl
400 dnl Permission to use, copy, modify, distribute, and sell this file for any 
401 dnl purpose is hereby granted without fee, provided that the above copyright 
402 dnl and this permission notice appear in all copies.  No representations are
403 dnl made about the suitability of this software for any purpose.  It is 
404 dnl provided "as is" without express or implied warranty.
405 dnl
406 AC_DEFUN([AC_C99_FUNC_LLRINT],
407 [AC_CACHE_CHECK(for llrint,
408   ac_cv_c99_llrint,
409 [
410 llrint_save_CFLAGS=$CFLAGS
411 CFLAGS="-O2 -lm"
412 AC_TRY_LINK([
413 #define         _ISOC9X_SOURCE  1
414 #define         _ISOC99_SOURCE  1
415 #define         __USE_ISOC99    1
416 #define         __USE_ISOC9X    1
417
418 #include <math.h>
419 #include <stdint.h>
420 ], int64_t      x ; x = llrint(3.14159) ;, ac_cv_c99_llrint=yes, ac_cv_c99_llrint=no)
421
422 CFLAGS=$llrint_save_CFLAGS
423
424 ])
425
426 if test "$ac_cv_c99_llrint" = yes; then
427   AC_DEFINE(HAVE_LLRINT, 1,
428             [Define if you have C99's llrint function.])
429 fi
430 ])# AC_C99_FUNC_LLRINT
431
432
433
434 dnl @synopsis AC_C_CLIP_MODE
435 dnl
436 dnl Determine the clipping mode when converting float to int.
437 dnl @version 1.0        May 17 2003
438 dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
439 dnl
440 dnl Permission to use, copy, modify, distribute, and sell this file for any 
441 dnl purpose is hereby granted without fee, provided that the above copyright 
442 dnl and this permission notice appear in all copies.  No representations are
443 dnl made about the suitability of this software for any purpose.  It is 
444 dnl provided "as is" without express or implied warranty.
445
446
447
448 dnl Find the clipping mode in the following way:
449 dnl    1) If we are not cross compiling test it.
450 dnl    2) IF we are cross compiling, assume that clipping isn't done correctly.
451
452 AC_DEFUN([AC_C_CLIP_MODE],
453 [AC_CACHE_CHECK(processor clipping capabilities, 
454         ac_cv_c_clip_type,
455
456 # Initialize to unknown
457 ac_cv_c_clip_positive=unknown
458 ac_cv_c_clip_negative=unknown
459
460 if test $ac_cv_c_clip_positive = unknown ; then
461         AC_TRY_RUN(
462         [[
463         #define _ISOC9X_SOURCE  1
464         #define _ISOC99_SOURCE  1
465         #define __USE_ISOC99    1
466         #define __USE_ISOC9X    1
467         #include <math.h>
468         int main (void)
469         {       double  fval ;
470                 int k, ival ;
471
472                 fval = 1.0 * 0x7FFFFFFF ;
473                 for (k = 0 ; k < 100 ; k++)
474                 {       ival = (lrint (fval)) >> 24 ;
475                         if (ival != 127)
476                                 return 1 ;
477                 
478                         fval *= 1.2499999 ;
479                         } ;
480                 
481                         return 0 ;
482                 }
483                 ]],
484                 ac_cv_c_clip_positive=yes,
485                 ac_cv_c_clip_positive=no,
486                 ac_cv_c_clip_positive=unknown
487                 )
488
489         AC_TRY_RUN(
490         [[
491         #define _ISOC9X_SOURCE  1
492         #define _ISOC99_SOURCE  1
493         #define __USE_ISOC99    1
494         #define __USE_ISOC9X    1
495         #include <math.h>
496         int main (void)
497         {       double  fval ;
498                 int k, ival ;
499
500                 fval = -8.0 * 0x10000000 ;
501                 for (k = 0 ; k < 100 ; k++)
502                 {       ival = (lrint (fval)) >> 24 ;
503                         if (ival != -128)
504                                 return 1 ;
505                 
506                         fval *= 1.2499999 ;
507                         } ;
508                 
509                         return 0 ;
510                 }
511                 ]],
512                 ac_cv_c_clip_negative=yes,
513                 ac_cv_c_clip_negative=no,
514                 ac_cv_c_clip_negative=unknown
515                 )
516         fi
517
518 if test $ac_cv_c_clip_positive = yes ; then
519         ac_cv_c_clip_positive=1
520 else
521         ac_cv_c_clip_positive=0
522         fi
523
524 if test $ac_cv_c_clip_negative = yes ; then
525         ac_cv_c_clip_negative=1
526 else
527         ac_cv_c_clip_negative=0
528         fi
529
530 [[
531 case "$ac_cv_c_clip_positive$ac_cv_c_clip_negative" in
532         "00")
533                 ac_cv_c_clip_type="none"
534                 ;;
535         "10")
536                 ac_cv_c_clip_type="positive"
537                 ;;
538         "01")
539                 ac_cv_c_clip_type="negative"
540                 ;;
541         "11")
542                 ac_cv_c_clip_type="both"
543                 ;;
544         esac
545         ]]
546
547 )
548 ]
549
550 )# AC_C_CLIP_MODE
551
552
553 dnl @synopsis AC_ADD_CFLAGS
554 dnl
555 dnl Add the given option to CFLAGS, if it doesn't break the compiler
556
557 AC_DEFUN([AC_ADD_CFLAGS],
558 [AC_MSG_CHECKING([if $CC accepts $1])
559         ac_add_cflags__old_cflags="$CFLAGS"
560         CFLAGS="$CFLAGS $1"
561         AC_TRY_LINK([#include <stdio.h>],
562                 [printf("Hello, World!\n"); return 0;],
563                 AC_MSG_RESULT([yes]),
564                 AC_MSG_RESULT([no])
565                 CFLAGS="$ac_add_cflags__old_cflags")
566 ])
567
568
569
570
571 ifelse(dnl      
572
573  Do not edit or modify anything in this comment block.
574  The arch-tag line is a file identity tag for the GNU Arch 
575  revision control system.
576
577  arch-tag: bc38294d-bb5c-42ad-90b9-779def5eaab7
578
579 )dnl