dnl Process this file with autoconf to produce a configure script.
AC_INIT(libfakeroot.c)

AC_CANONICAL_SYSTEM


AM_INIT_AUTOMAKE(fakeroot, 0.4.4.2)

dnl AM_CONFIG_HEADER(config.h)

LIBTOOL=libtool

AM_PROG_LIBTOOL
AC_PROG_CC
AC_PROG_CXX
dnl Checks for programs.

dnl Checks for libraries.
dnl Replace `main' with a function in -ldl:
AC_CHECK_LIB(dl, dlopen)

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T

dnl The parameters to the wrapped functions have to match
dnl those in the system header files. I don't know how to
dnl really get the names of the paramters, but this seems to work.
AC_MSG_CHECKING([for second and third argument of readlink])
readlink_buf_arg=unknown
readlink_bufsize_arg=unknown
for second in void char; do
  for third in size_t int; do
    AC_TRY_COMPILE([#include <unistd.h>
      int readlink(const char *path, $second *buf, $third bufsiz);],
      [puts("hello, world");],
      [readlink_buf_arg=$second
       readlink_bufsize_arg=$third
      ],
      [])
  done
done
AC_MSG_RESULT([$readlink_buf_arg, $readlink_bufsize_arg])
AC_DEFINE_UNQUOTED(READLINK_BUF_TYPE, $readlink_buf_arg)
AC_DEFINE_UNQUOTED(READLINK_BUFSIZE_TYPE, $readlink_bufsize_arg)

AC_MSG_CHECKING([checking for union semun])
  AC_TRY_COMPILE([
       # include <sys/types.h>
       # include <sys/ipc.h>
       # include <sys/sem.h>
  ], [  
       union semun s;
  ],
  [AC_DEFINE(HAVE_SEMUN_DEF)
   AC_MSG_RESULT([yes])  
  ],
  [ AC_MSG_RESULT([no])]
  )

dnl glibc uses `* dev' as forth argument of __xmknod.
dnl Although the test below should probably be more general
dnl (not just __xmknod, but also mknod etc), at the moment this
dnl seems enough, as probably glibc is the only that does this.
AC_MSG_CHECKING([checking for type of arg of __xmknod])
  AC_TRY_COMPILE([
       #include <sys/types.h>
       #include <sys/stat.h>
       #include <fcntl.h>
       #include <unistd.h>
  ], [  
       int __xmknod  ( int ver, 
                       const char *pathname ,  
                       mode_t  mode ,  dev_t dev);
  ],
  [
   AC_DEFINE(XMKNOD_FRTH_ARG,)
   AC_MSG_RESULT([no extra *])]
  ],
  [ 
   AC_DEFINE(XMKNOD_FRTH_ARG,*)
   AC_MSG_RESULT([needs *])  
  ]
  )




for field in d_off d_type; do
AC_MSG_CHECKING([checking for ${field} in struct dirent])
AC_TRY_COMPILE([
       #include <sys/types.h>
       #include <dirent.h>
  ], [  

       struct dirent d;
       d.${field}=0
  ],
  [AC_DEFINE_UNQUOTED(STAT_HAS_${field},1)
   AC_MSG_RESULT([yes])  
  ],
  [ AC_MSG_RESULT([no])]
  )
done

dnl find out how stat() etc are called. On linux systems, we really
dnl need to wrap __xstat(), on Solaris _stat, on Digital Unix stat() (IIRC)

:>fakerootconfig.h.tmp

for SEARCH in %stat f%stat l%stat %stat64 f%stat64 l%stat64 %mknod; do
  FUNC=`echo $SEARCH|sed -e 's/.*%//'`
  PRE=`echo $SEARCH|sed -e 's/%.*//'`
  FOUND=
  for WRAPPED in __${PRE}x${FUNC} ${PRE}${FUNC}; do
    AC_CHECK_FUNCS($WRAPPED,FOUND=$WRAPPED)
dnl
dnl to unconditionally define only the _* functions, comment out the 2 lines above,
dnl and uncomment the 2 lines below.
dnl
dnl  for WRAPPED in _${PRE}${FUNC}; do
dnl    FOUND=$WRAPPED
    if test -n "$FOUND"; then
      PF=`echo ${PRE}${FUNC}| tr '[[:lower:]]' '[[:upper:]]'` 
      DEFINE_WRAP=`echo wrap_${PRE}${FUNC}| tr '[[:lower:]]' '[[:upper:]]'` 
      DEFINE_NEXT=`echo wrap_${FOUND}| tr '[[:lower:]]' '[[:upper:]]'` 
      DEFINE_ARG=`echo wrap_${FOUND}| tr '[[:lower:]]' '[[:upper:]]'` 
      AC_DEFINE_UNQUOTED(WRAP_${PF}, $FOUND)
      AC_DEFINE_UNQUOTED(WRAP_${PF}_QUOTE, "$FOUND")
      AC_DEFINE_UNQUOTED(TMP_${PF}, tmp_$FOUND)
      AC_DEFINE_UNQUOTED(NEXT_${PF}_NOARG, next_$FOUND)
      if test __"${PRE}x${FUNC}" != "${WRAPPED}"; then
        DEF_BEGIN=""
      else
        DEF_BEGIN="a,"
      fi
      if test "${FUNC}" = "mknod"; then
        DEF_END=",d"
      else
        DEF_END=""
      fi
      dnl no matter what I do, the resulting define looks like
      dnl #define macro (a,b,c) (a,b,c)
      dnl with a space in between "macro" and "(". To prevent this,
      dnl I leave the space here, and remove it later with sed 
      dnl at (end of configure.in)
      dnl AC_DEFINE_UNQUOTED(NEXT_${PF}(a,b,c${DEF_END}), 
      dnl 		     next_$FOUND(${DEF_BEGIN}b,c${DEF_END}))
      dnl AC_DEFINE_UNQUOTED(${PF}[_ARG(a,b,c${DEF_END})], 
      dnl 		     (${DEF_BEGIN}b,c${DEF_END}))

      dnl Anyway the trickery above also leads to automake problems
      dnl (tries to remake config.h.in, but fails). So, as a way
      dnl out, Yann DIRSON wrote this:
      {
       echo "#define NEXT_${PF}(a,b,c${DEF_END}) next_$FOUND(${DEF_BEGIN}b,c${DEF_END})"
       echo "#define ${PF}_ARG(a,b,c${DEF_END}) (${DEF_BEGIN}b,c${DEF_END})"
      } >>fakerootconfig.h.tmp

      break
    fi
  done      
done

if test -r fakerootconfig.h
then
       if test "`diff fakerootconfig.h fakerootconfig.h.tmp`" = ""
       then
               AC_MSG_RESULT([fakerootconfig.h not changed])
               rm fakerootconfig.h.tmp
       else
               AC_MSG_RESULT([recreated fakerootconfig.h])
               rm fakerootconfig.h ; mv fakerootconfig.h.tmp fakerootconfig.h
       fi
else
       AC_MSG_RESULT([created fakerootconfig.h])
       mv fakerootconfig.h.tmp fakerootconfig.h
fi


dnl Checks for library functions.
AC_CHECK_FUNCS(strdup strstr)

AC_OUTPUT([Makefile scripts/Makefile doc/Makefile])

dnl Local variables:
dnl mode: m4
dnl End:







