xiph_compiler.m4 4.16 KB
Newer Older
brendan's avatar
brendan committed
1
dnl xiph_compiler.m4
2
dnl $Id$
brendan's avatar
brendan committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

dnl XIPH_FUNC_VA_COPY
dnl Karl Heyes
dnl
# XIPH_FUNC_VA_COPY
# Test for implementation of va_copy, or define appropriately if missing
AC_DEFUN([XIPH_FUNC_VA_COPY],
[dnl
AC_MSG_CHECKING([for va_copy])
AC_TRY_LINK([#include <stdarg.h>], [va_list ap1, ap2; va_copy(ap1, ap2);],
  AC_MSG_RESULT([va_copy]),
  [dnl
  AH_TEMPLATE([va_copy], [define if va_copy is not available])
  AC_TRY_LINK([#include <stdarg.h>], [va_list ap1, ap2; __va_copy(ap1, ap2);],
    [dnl
    AC_DEFINE([va_copy], [__va_copy])
    AC_MSG_RESULT([__va_copy])],
    [dnl
    AC_DEFINE([va_copy(dest,src)], [memcpy(&dest,&src,sizeof(va_list))])
    AC_MSG_RESULT([memcpy])
    ])
  ])
])
])dnl XIPH_FUNC_VA_COPY

dnl XIPH_C_ATTRIBUTE
dnl Karl Heyes
dnl
# XIPH_C_ATTRIBUTE
# Define __attribute__ to be empty if the compiler does not support it
AC_DEFUN([XIPH_C_ATTRIBUTE],
[dnl
AC_TRY_COMPILE([int func(void) __attribute__((unused));],
  [int x __attribute__ ((unused));],,[dnl
Karl Heyes's avatar
Karl Heyes committed
37 38
  AH_TEMPLATE([__attribute__],[Define to empty if __attribute__ is not supported])
  AC_DEFINE([__attribute__(x)],[])
brendan's avatar
brendan committed
39 40 41
])
])dnl XIPH_C_ATTRIBUTE

42
dnl XIPH_GCC_WARNING
brendan's avatar
brendan committed
43 44
dnl Karl Heyes
dnl
45 46 47 48
# XIPH_GCC_WARNING(flag, action-if-warning, action-if-not)
# Tests whether GCC emits a warning if explicitly asked to use flag.
# Useful for eg system default include paths
AC_DEFUN([XIPH_GCC_WARNING],
brendan's avatar
brendan committed
49
[AC_REQUIRE([AC_PROG_CC])
50
xt_warning=no
brendan's avatar
brendan committed
51 52 53
if test x"$GCC" = "xyes"
then
  save_cflags="$CFLAGS"
54 55
  CFLAGS="-Werror $1"
  AC_TRY_COMPILE(,,,xt_warning=yes)
brendan's avatar
brendan committed
56 57
  CFLAGS="$save_cflags"
fi
58
if test "$xt_warning" = "yes"
brendan's avatar
brendan committed
59 60 61 62 63
then
  ifelse([$2],,:,[$2])
else
  ifelse([$3],,:,[$3])
fi
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
])dnl XIPH_GCC_WARNING

dnl XIPH_CLEAN_CCFLAGS
dnl Brendan Cully <brendan@xiph.org> 20030612
dnl
# XIPH_CLEAN_CCFLAGS(flag-list, dest-shell-var-name)
# Filters out duplicate compiler flags, and -I flags if XIPH_GCC_WARNING
# complains about them
# Operates right-to-left on -l flags, left-to-right on everything else
# eg XIPH_CLEAN_CCFLAGS([-L/opt/lib -lfoo -lm -L/opt/lib -lbar -lm], [MY_LDFLAGS])
# => MY_LDFLAGS="-L/opt/lib -lfoo -lbar -lm"
# the cat<<EOF construct makes sure echo doesn't pick, say, -n
AC_DEFUN([XIPH_CLEAN_CCFLAGS],
[AC_REQUIRE([AC_PROG_FGREP])
xt_FLAGS=''

for flag in $1
do
  case "$flag" in
  -l*)
    xt_FLAGS="$flag $xt_FLAGS"
    ;;
  *)
    if { cat <<EOF
 $xt_FLAGS x
EOF
} | $FGREP -v -e " $flag " > /dev/null
    then
      xt_FLAGS="$flag $xt_FLAGS"
    fi
    ;;
  esac
done

$2=''
for flag in $xt_FLAGS
do
  if { cat <<EOF
 $$2 x
EOF
} | $FGREP -v -e " $flag " > /dev/null
  then
    $2="$flag $$2"
  fi
done

# Prune -I flags if $CC warns about them
xt_FLAGS=''
for flag in $$2
do
  case "$flag" in
  -I*)
    XIPH_GCC_WARNING([$flag], [], [xt_FLAGS="$xt_FLAGS $flag"])
    ;;
  *)
    xt_FLAGS="$xt_FLAGS $flag"
    ;;
  esac
done
$2="$xt_FLAGS"
])dnl XIPH_CLEAN_CCFLAGS
brendan's avatar
brendan committed
125 126 127 128 129 130 131 132 133 134 135 136 137

dnl XIPH_VAR_APPEND
dnl Karl Heyes
dnl
# XIPH_VAR_APPEND(shell-var, list)
# Append each item in list to shell-var iff shell-var doesn't already have it
# eg XIPH_VAR_APPEND([CFLAGS], [-O2 -I/opt/packages/include])
AC_DEFUN([XIPH_VAR_APPEND],
[dnl
AC_REQUIRE([AC_PROG_FGREP])
for arg in $2
do
  if { cat <<EOF
138
 $$1 x
brendan's avatar
brendan committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
EOF
} | $FGREP -v -e " $arg " > /dev/null
  then
    $1="$$1 $arg"
  fi
done
])dnl XIPH_VAR_APPEND

dnl XIPH_VAR_PREPEND
dnl Karl Heyes
dnl
# XIPH_VAR_PREPEND(shell-var, list)
# see XIPH_VAR_APPEND
AC_DEFUN([XIPH_VAR_PREPEND],
[dnl
AC_REQUIRE([AC_PROG_FGREP])
Karl Heyes's avatar
Karl Heyes committed
155
xt_compare="$$1"
156
xt_filtered=""   
brendan's avatar
brendan committed
157 158 159
for arg in $2
do
  if { cat <<EOF
Karl Heyes's avatar
Karl Heyes committed
160
 $xt_compare x
brendan's avatar
brendan committed
161 162 163
EOF
} | $FGREP -v -e " $arg " > /dev/null
  then
164 165
    xt_compare="$arg $xt_compare"
    xt_filtered="$xt_filtered $arg"
brendan's avatar
brendan committed
166 167
  fi
done
168
$1="$xt_filtered $$1"
brendan's avatar
brendan committed
169
])dnl XIPH_VAR_PREPEND
170 171 172 173 174 175 176 177 178 179 180

dnl XIPH_C__FUNC__
dnl Karl Heyes <karl@xiph.org> 07/2004
AC_DEFUN([XIPH_C__FUNC__],
[dnl
AC_MSG_CHECKING([for __func__])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[const char *x = __func__;])],
    [ AC_MSG_RESULT([yes])],
    [ AH_TEMPLATE([__func__], [Replace __func__ if not supported])
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[const char *x = __FUNCTION__;])],
        [ AC_DEFINE([__func__],[__FUNCTION__])
Karl Heyes's avatar
Karl Heyes committed
181 182 183
        AC_MSG_RESULT([Using __FUNCTION__])],
        [ AC_DEFINE([__func__],["__FILE__"])
        AC_MSG_RESULT([using __FILE__])
184 185 186 187
        ])
    ])
])dnl XIPH_C__FUNC__