package  = 'luaposix'
version  = '$USER'

defines  = {
   PACKAGE           = '"$package"',
   VERSION           = '"$version"',
   NDEBUG            = 1,
   _FORTIFY_SOURCE   = 2,
   platforms    = {
      aix       = {_ALL_SOURCE       = 1},
      bsd       = {_BSD_SOURCE       = 1},
      freebsd   = {__BSD_VISIBLE     = 1},
      macosx    = {_DARWIN_C_SOURCE  = 1},
      -- QNX is only POSIX 2001, but _XOPEN_SOURCE turns off other functions
      -- luaposix can bind.
      qnx       = {_POSIX_C_SOURCE   = '200112L'},
      unix      = {
         _POSIX_C_SOURCE   = '200809L',
         _XOPEN_SOURCE     = 700,
      },
      -- Otherwise, enable POSIX 2008.   Please send the output of `uname -s` if
      -- your host is not compliant.
      _POSIX_C_SOURCE      = '200809L',
   },
}

incdirs  = {
   'ext/include',
   '$LUA_INCDIR',
}

ldocs    = 'build-aux/config.ld.in'

modules  = {
   ['posix']               = 'lib/posix/init.lua',
   ['posix._base']         = 'lib/posix/_base.lua',
   ['posix._bitwise']      = 'lib/posix/_bitwise.lua',
   ['posix._strict']       = 'lib/posix/_strict.lua',
   ['posix.compat']        = 'lib/posix/compat.lua',
   ['posix.deprecated']    = 'lib/posix/deprecated.lua',
   ['posix.sys']           = 'lib/posix/sys.lua',
   ['posix.util']          = 'lib/posix/util.lua',

   ['posix.ctype']         = 'ext/posix/ctype.c',
   ['posix.dirent']        = 'ext/posix/dirent.c',
   ['posix.errno']         = 'ext/posix/errno.c',
   ['posix.fcntl']         = {
      defines  = {
         HAVE_POSIX_FADVISE   = {checkfunc='posix_fadvise'},
      },
      sources   = 'ext/posix/fcntl.c',
   },
   ['posix.fnmatch']       = 'ext/posix/fnmatch.c',
   ['posix.glob']          = 'ext/posix/glob.c',
   ['posix.grp']           = 'ext/posix/grp.c',
   ['posix.libgen']        = 'ext/posix/libgen.c',
   ['posix.poll']          = 'ext/posix/poll.c',
   ['posix.pwd']           = 'ext/posix/pwd.c',
   ['posix.sched']         = {
      defines   = {
         HAVE_SCHED_H            = {checkheader='sched.h'},
         HAVE_SCHED_GETSCHEDULER = {checkfunc='sched_getscheduler'},
         HAVE_SCHED_SETSCHEDULER = {checkfunc='sched_setscheduler'},
      },
      sources   = 'ext/posix/sched.c',
   },
   ['posix.signal']        = 'ext/posix/signal.c',
   ['posix.stdio']         = 'ext/posix/stdio.c',
   ['posix.stdlib']        = 'ext/posix/stdlib.c',
   ['posix.sys.msg']       = {
      defines   = {
         HAVE_SYS_MSG_H    = {checkheader='sys/msg.h'},
         HAVE_MSGRCV       = {checkfunc='msgrcv'},
         HAVE_MSGSND       = {checkfunc='msgsnd'},
      },
      sources   = 'ext/posix/sys/msg.c',
   },
   ['posix.sys.resource']  = 'ext/posix/sys/resource.c',
   ['posix.sys.socket']    = {
      defines   = {
         HAVE_NET_IF_H         = {checkheader='net/if.h', include='sys/socket.h'},
         HAVE_LINUX_NETLINK_H  = {checkheader='linux/netlink.h', include='sys/socket.h'},
      },
      libraries = {
         {checksymbol='socket', library='socket'},
      },
      sources   = 'ext/posix/sys/socket.c',
   },
   ['posix.sys.stat']      = 'ext/posix/sys/stat.c',
   ['posix.sys.statvfs']   = {
      defines   = {
         HAVE_STATVFS      = {checkfunc='statvfs'},
      },
      sources   = 'ext/posix/sys/statvfs.c',
   },
   ['posix.sys.time']      = 'ext/posix/sys/time.c',
   ['posix.sys.times']     = 'ext/posix/sys/times.c',
   ['posix.sys.utsname']   = 'ext/posix/sys/utsname.c',
   ['posix.sys.wait']      = 'ext/posix/sys/wait.c',
   ['posix.syslog']        = 'ext/posix/syslog.c',
   ['posix.termio']        = 'ext/posix/termio.c',
   ['posix.time']          = {
      libraries = {
         {
            ifdef          = '_POSIX_TIMERS',
            include        = 'unistd.h',
            checksymbol    = 'clock_gettime',
            library        = 'rt',
         },
      },
      sources   = 'ext/posix/time.c',
   },
   ['posix.unistd']        = {
      defines   = {
         HAVE_CRYPT           = {checkfunc='crypt'},
         HAVE_CRYPT_H         = {checkheader='crypt.h'},
         HAVE_DECL_FDATASYNC  = {checkdecl='fdatasync', include='unistd.h'},
         HAVE_FDATASYNC       = {checkfunc='fdatasync'},
         HAVE_GETHOSTID       = {checkfunc='gethostid'},
      },
      libraries = {
         {checksymbol='crypt', library='crypt'},
      },
      sources   = 'ext/posix/unistd.c',
   },
   ['posix.utime']         = 'ext/posix/utime.c',
   ['posix.version']       = 'lib/posix/version.lua.in',
}
