dnl AUTOCONF configuration for syscalls
dnl Copyright (C) 2003-2011, 2014 Sam Steingold <sds@gnu.org>
dnl Copyright (C) 2020-2021 Bruno Haible <bruno@clisp.org>
dnl This is Free Software, distributed under the GNU GPL v2+

AC_PREREQ([2.64])
AC_INIT(syscalls, 1.0, clisp-list)
AC_CONFIG_SRCDIR(posix.lisp)
AC_CONFIG_HEADERS(config.h)

RSE_BOLD
BOLD_MSG([System Calls (Common)])
CL_MODULE_COMMON_CHECKS()
AM_INIT_AUTOMAKE([no-define])
AC_PROG_RANLIB

BOLD_MSG([System Calls (Headers)])
AC_CHECK_HEADERS(fcntl.h netdb.h utime.h dnl
pwd.h sys/unistd.h syslog.h signal.h grp.h utmpx.h shlobj.h dnl
sys/statvfs.h sys/statfs.h sys/param.h ftw.h)
AC_CANONICAL_HOST
if test "$ac_cv_header_shlobj_h" = yes ; then
  LIBS=${LIBS}' -luser32 -lole32 -loleaut32'
  case "$host_os" in
    cygwin*)
      dnl On Cygwin, there are /usr/lib/libuuid.a and /usr/lib/w32api/libuuid.a,
      dnl and only the latter defines the symbols IID_IPersistFile and
      dnl IID_IPropertySetStorage.
      LIBS=${LIBS}' /usr/lib/w32api/libuuid.a'
      ;;
    *)
      LIBS=${LIBS}' -luuid'
      ;;
  esac
  LIBS=${LIBS}' -lversion'
fi
AC_SYS_LARGEFILE    dnl ensure 64 bit size_t for AC_CHECK_SIZEOF below
AC_CHECK_SIZEOF(off_t)
AC_CHECK_SIZEOF(gid_t)
AC_CHECK_SIZEOF(pid_t)
AC_CHECK_SIZEOF(uid_t)
if test "$ac_cv_header_utmpx_h" = "yes"; then
 AC_CHECK_MEMBERS([struct utmpx.ut_host],,,[#include <utmpx.h>])
fi
gl_HEADER_ERRNO_H

BOLD_MSG([System Calls (Functions)])
AC_SEARCH_LIBS(erf, m)
AC_CHECK_FUNCS(confstr fcntl gethostent sysconf getrlimit setrlimit dnl
getlogin getpwent getpwnam getpwuid endpwent setpwent dnl
getservbyport getservbyname getservent setservent endservent dnl
openlog setlogmask syslog closelog chroot dnl
getppid getpgid getsid setpgid setsid kill pathconf fpathconf realpath dnl
getpgrp setpgrp getgrgid getgrnam getgrent endgrent setgrent dnl
endutxent getutxent getutxid getutxline pututxline setutxent dnl
getegid geteuid getgid getuid setegid seteuid setgid setuid dnl
setreuid setregid getgroups setgroups wait4 dnl
fchmod fchown fstat link stat symlink utime mknod chmod umask fsync sync dnl
ftruncate truncate getusershell endusershell dnl
erf erfc lgamma tgamma fstatvfs statvfs getpriority setpriority dnl
GlobalMemoryStatusEx dnl
gethostid sethostid getdomainname setdomainname nftw getdate)
if test $ac_cv_func_setrlimit = yes; then
  AC_CHECK_SIZEOF([rlim_t],,[
    #include <stdio.h>
    #include <sys/resource.h>
    ])
fi
AC_FUNC_CHOWN
AC_CHECK_DECLS([signgam],,,[#include <math.h>])
AC_CHECK_DECLS([getdate_err],,,[#include <time.h>])
if test "$ac_cv_header_sys_statvfs_h" = "yes"; then
 AC_MSG_CHECKING([whether f_fsid is scalar])
 AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM([[#include <sys/statvfs.h>]], [[struct statvfs x; x.f_fsid = 0;]])],
  ac_cv_struct_fsid_scalar=yes, ac_cv_struct_fsid_scalar=no)
 AC_MSG_RESULT([$]ac_cv_struct_fsid_scalar)
 if test "$ac_cv_struct_fsid_scalar" = yes; then
  AC_DEFINE([HAVE_SCALAR_FSID], 1,
    [Define to 1 if the f_fsid member of 'struct statvfs' has a integral type.])
 fi
 AC_CHECK_SIZEOF(fsblkcnt_t,,[#include <stdio.h>
#include <sys/statvfs.h>])
 AC_CHECK_SIZEOF(fsfilcnt_t,,[#include <stdio.h>
#include <sys/statvfs.h>])
fi
if test "$ac_cv_header_sys_stat_h" = "yes"; then
 AC_CHECK_MEMBERS([struct stat.st_rdev, struct stat.st_blksize, struct stat.st_blocks],,,[#include <sys/stat.h>])
fi
CL_RUSAGE
gl_FUNC_LINK_FOLLOWS_SYMLINK
if test "$ac_cv_func_setpgrp" = "yes"; then
dnl BSD versions of setpgrp() are identical to setpgid()
AC_CACHE_CHECK([whether setpgrp() is POSIX],ac_cv_func_setpgrp_posix,[
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#include <unistd.h>
#include <sys/types.h>
],[[pid_t pid = setpgrp();]])],
ac_cv_func_setpgrp_posix=yes,ac_cv_func_setpgrp_posix=no)])
if test "$ac_cv_func_setpgrp_posix" = "yes"; then
AC_DEFINE(HAVE_SETPGRP_POSIX,1,
[Define to 1 if setpgrp() does not accept arguments])
fi
fi
gl_GETLOADAVG

BOLD_MSG([System Calls (output)])
AC_CONFIG_FILES([Makefile link.sh])
AC_OUTPUT

BOLD_MSG([System Calls (done)])
