module alloca [system] {
  header "_modules/_alloca.h"
  export *
}

module nl_types [system] {
  header "_modules/_nl_types.h"
  export *
}

module runetype [system] {
  header "_modules/_runetype.h"
  export *
}

module sys_types [system] {
  header "_modules/_sys_types.h"
  export *
}


// Implementation detail modules. The names and contents of these modules
// are not stable, and they should never be directly imported. The modules
// above should be used instead.
module _DarwinFoundation2 [system] {
  // POSIX interfaces.
  explicit module nl_types {
    header "nl_types.h"
    export *

    module _nl_item {
      header "_types/_nl_item.h"
      export *
    }
  }

  explicit module sys_types {
    header "sys/types.h"
    export *

    module blkcnt_t {
      header "sys/_types/_blkcnt_t.h"
      export *
    }

    module blksize_t {
      header "sys/_types/_blksize_t.h"
      export *
    }

    module caddr_t {
      header "sys/_types/_caddr_t.h"
      export *
    }

    module clock_t {
      header "sys/_types/_clock_t.h"
      export *
    }

    module dev_t {
      header "sys/_types/_dev_t.h"
      export *
    }

    module fsblkcnt_t {
      header "sys/_types/_fsblkcnt_t.h"
      export *
    }

    module fsfilcnt_t {
      header "sys/_types/_fsfilcnt_t.h"
      export *
    }

    module gid_t {
      header "sys/_types/_gid_t.h"
      export *
    }

    module id_t {
      header "sys/_types/_id_t.h"
      export *
    }

    module ino_t {
      header "sys/_types/_ino_t.h"
      export *
    }

    module ino64_t {
      header "sys/_types/_ino64_t.h"
      export *
    }

    module key_t {
      header "sys/_types/_key_t.h"
      export *
    }

    module mode_t {
      header "sys/_types/_mode_t.h"
      export *
    }

    module nlink_t {
      header "sys/_types/_nlink_t.h"
      export *
    }

    module off_t {
      header "sys/_types/_off_t.h"
      export *
    }

    module pid_t {
      header "sys/_types/_pid_t.h"
      export *
    }

    module pthread_attr_t {
      header "sys/_pthread/_pthread_attr_t.h"
      export *
    }

    module pthread_cond_t {
      header "sys/_pthread/_pthread_cond_t.h"
      export *
    }

    module pthread_condattr_t {
      header "sys/_pthread/_pthread_condattr_t.h"
      export *
    }

    module pthread_key_t {
      header "sys/_pthread/_pthread_key_t.h"
      export *
    }

    module pthread_mutex_t {
      header "sys/_pthread/_pthread_mutex_t.h"
      export *
    }

    module pthread_mutexattr_t {
      header "sys/_pthread/_pthread_mutexattr_t.h"
      export *
    }

    module pthread_once_t {
      header "sys/_pthread/_pthread_once_t.h"
      export *
    }

    module pthread_rwlock_t {
      header "sys/_pthread/_pthread_rwlock_t.h"
      export *
    }

    module pthread_rwlockattr_t {
      header "sys/_pthread/_pthread_rwlockattr_t.h"
      export *
    }

    module pthread_t {
      header "sys/_pthread/_pthread_t.h"
      export *
    }

    module pthread_types {
      header "sys/_pthread/_pthread_types.h"
      export *
    }

    module ssize_t {
      header "sys/_types/_ssize_t.h"
      export *
    }

    module suseconds_t {
      header "sys/_types/_suseconds_t.h"
      export *
    }

    module time_t {
      header "sys/_types/_time_t.h"
      export *
    }

    module uid_t {
      header "sys/_types/_uid_t.h"
      export *
    }
  }

  // Historical BSD interfaces.
  explicit module runetype {
    header "runetype.h"
    export *

    module ct_rune_t {
      header "sys/_types/_ct_rune_t.h"
      export *
    }

    module rune_t {
      header "sys/_types/_rune_t.h"
      export *
    }
  }

  // Historical non-standard interface.
  explicit module alloca {
    header "alloca.h"
    export *
  }

  // Implementation for host/network byte swapping, use <arpa/inet.h> instead.
  explicit module endian {
    header "machine/endian.h"
    export *

    module i386 {
      header "i386/endian.h"
      export *
    }

    module arm {
      header "arm/endian.h"
      export *
    }

    module sys_endian {
      header "sys/_endian.h"
      export *
    }
  }

  // Implementation for general byte swapping, use <libkern/OSByteOrder.h> instead.
  explicit module OSByteOrder {
    header "libkern/_OSByteOrder.h"
    export *

    module i386 {
      header "libkern/i386/_OSByteOrder.h"
      export *
    }

    module arm {
      header "libkern/arm/_OSByteOrder.h"
      export *
    }
  }

  // Common implementation for secure variants of some C standard library and
  // POSIX functions, use headers like <string.h> instead.
  explicit module secure {
    header "secure/_common.h"
    export *
  }

  explicit module mach {
    // Implementation for some <mach/port.h> types, use that header instead.
    // (These are used by <pthread/pthread.h>.
    explicit module port {
      explicit module mach_port_t {
        header "sys/_types/_mach_port_t.h"
        export *
      }
    }
  }

  // Implementation for some <netinet/in.h> types, use that header instead.
  // (These are used by <sys/types.h>.)
  explicit module netinet_in {
    explicit module in_addr_t {
      header "sys/_types/_in_addr_t.h"
      export *
    }

    explicit module in_port_t {
      header "sys/_types/_in_port_t.h"
      export *
    }
  }

  // Implementation for some <sys/select.h> types, use that header instead.
  // (These are used by <sys/types.h>.)
  explicit module select {
    explicit module fd_def {
      header "sys/_types/_fd_def.h"
      export *
    }

    explicit module fd_setsize {
      header "sys/_types/_fd_setsize.h"
      export *
    }

    explicit module fd_clr {
      header "sys/_types/_fd_clr.h"
      export *
    }

    explicit module fd_copy {
      header "sys/_types/_fd_copy.h"
      export *
    }

    explicit module fd_isset {
      header "sys/_types/_fd_isset.h"
      export *
    }

    explicit module fd_set {
      header "sys/_types/_fd_set.h"
      export *
    }

    explicit module fd_zero {
      header "sys/_types/_fd_zero.h"
      export *
    }
  }

  // Cover headers for <stdarg.h>, use that header instead. (These are used
  // by <sys/_types.h>.)
  explicit module stdarg {
    explicit module va_list {
      header "sys/_types/_va_list.h"
      export *
    }
  }

  // Cover headers for <stddef.h>, use that header instead. (These are used
  // by <machine/_types.h> and <sys/_types.h>.)
  explicit module stddef {
    explicit module null {
      header "sys/_types/_null.h"
      export *
    }

    explicit module offsetof {
      header "sys/_types/_offsetof.h"
      export *
    }

    explicit module ptrdiff_t {
      header "sys/_types/_ptrdiff_t.h"
      export *
    }

    explicit module rsize_t {
      header "sys/_types/_rsize_t.h"
      export *
    }

    explicit module size_t {
      header "sys/_types/_size_t.h"
      export *
    }

    explicit module wchar_t {
      header "sys/_types/_wchar_t.h"
      export *
    }
  }

  // Implementation for some <strings.h> interfaces, use that instead. (This
  // is used by <string.h>.)
  explicit module strings {
    header "_strings.h"
    private textual header "secure/_strings.h"
    export *
  }

  // Implementation for some <sys/time.h> types, use that instead. (This
  // is used by <sys/resource.h> and <sys/select.h>.)
  explicit module sys_time {
    explicit module timeval {
      header "sys/_types/_timeval.h"
      export *
    }
  }

  // Implementation for some <uuid/uuid.h> types, use that instead. (These
  // are used by several other low level interfaces.)
  explicit module uuid {
    explicit module uuid_t {
      header "sys/_types/_uuid_t.h"
      export *
    }
  }

  // Implementation for some <wchar.h> types, use that header instead. (This
  // is used by runetype.h.)
  explicit module wchar {
    explicit module wint_t {
      header "sys/_types/_wint_t.h"
      export *
    }
  }

  // Implementation for C standard library and POSIX types, use headers like
  // <stddef.h> or <sys/types.h> instead.
  explicit module types {
    header "machine/types.h"
    export *

    module i386 {
      header "i386/types.h"
      export *
    }

    module arm {
      header "arm/types.h"
      export *
    }

    module _types {
      header "_types.h"
      export *
    }

    module sys_types {
      header "sys/_types.h"
      export *
    }

    module machine_types {
      header "machine/_types.h"
      export *

      module i386 {
        header "i386/_types.h"
        export *
      }

      module arm {
        header "arm/_types.h"
        export *
      }
    }
  }

  // Low level type used by other low level interfaces.
  explicit module useconds_t {
    header "sys/_types/_useconds_t.h"
    export *
  }

  // C Standard Library implementation. Most of these headers are augmented,
  // or even replaced, by the compiler or C++ library. These submodules
  // should never be directly imported, the top level modules named after
  // each C Standard Library header, e.g. assert_h, should be used instead.
  explicit module _ctype {
    textual header "ctype.h"

    explicit module xlocale {
      header "xlocale/_ctype.h"
      export *
    }

    header "_ctype.h"
    export *
  }

  explicit module _locale {
    header "locale.h"
    export *

    module _locale {
      header "_locale.h"
      export *
    }

    explicit module _locale_posix2008 {
      header "_locale_posix2008.h"
      export *
    }
  }

  explicit module _stdint {
    header "stdint.h"
    export *

    module int8_t {
      header "sys/_types/_int8_t.h"
      export *
    }

    module int16_t {
      header "sys/_types/_int16_t.h"
      export *
    }

    module int32_t {
      header "sys/_types/_int32_t.h"
      export *
    }

    module int64_t {
      header "sys/_types/_int64_t.h"
      export *
    }

    module uint8_t {
      header "_types/_uint8_t.h"
      export *
    }

    module uint16_t {
      header "_types/_uint16_t.h"
      export *
    }

    module uint32_t {
      header "_types/_uint32_t.h"
      export *
    }

    module uint64_t {
      header "_types/_uint64_t.h"
      export *
    }

    module intptr_t {
      header "sys/_types/_intptr_t.h"
      export *
    }

    module uintptr_t {
      header "sys/_types/_uintptr_t.h"
      export *
    }

    module intmax_t {
      header "_types/_intmax_t.h"
      export *
    }

    module uintmax_t {
      header "_types/_uintmax_t.h"
      export *
    }
  }

  explicit module _stdio {
    textual header "stdio.h"

    explicit module xlocale {
      header "xlocale/_stdio.h"
      export *
    }

    header "_stdio.h"
    private textual header "secure/_stdio.h"
    export *

    module sys_stdio {
      header "sys/stdio.h"
      export *
    }

    module ctermid {
      header "_ctermid.h"
      export *
    }

    module printf {
      header "_printf.h"
      export *
    }

    module seek_set {
      header "sys/_types/_seek_set.h"
      export *
    }
  }

  explicit module _string {
    textual header "string.h"

    explicit module xlocale {
      header "xlocale/_string.h"
      export *
    }

    header "_string.h"
    private textual header "secure/_string.h"
    export *
  }

  // This header is replaced by the C++ library, and so must not build as part
  // of this module in C++ mode.
  explicit module _tgmath {
    requires !cplusplus
    header "tgmath.h"
    export *
  }

  explicit module _time {
    textual header "time.h"

    explicit module xlocale {
      header "xlocale/_time.h"
      export *
    }

    header "_time.h"
    export *

    module timespec {
      header "sys/_types/_timespec.h"
      export *
    }
  }
}
