module pthread [system] {
  header "_modules/_pthread.h"
  export *
}

module sched [system] {
    header "_modules/_sched.h"
    export *
}

module sys_resource [system] {
  header "_modules/_sys_resource.h"
  export *
}

module sys_select [system] {
  header "_modules/_sys_select.h"
  export *
}

module sys_wait [system] {
  header "_modules/_sys_wait.h"
  export *
}

module unistd [system] {
  header "_modules/_unistd.h"
  export *
}

module xlocale [system] {
  textual header "xlocale.h"
  header "_xlocale.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 _DarwinFoundation3 [system] {
  // POSIX interfaces.
  // Low level hardware structures used in the implementations of things
  // like <signal.h> and <mach/thread_status.h>, use those headers instead.
  explicit module pthread {
    header "pthread/pthread.h"
    export *

    module pthread_impl {
      header "pthread/pthread_impl.h"
      export *
    }

    // Apple extension.
    module qos {
      header "pthread/qos.h"
      export *
    }
  }

  explicit module sched {
    header "pthread/sched.h"
    export *
  }

  explicit module sys_resource {
    header "sys/resource.h"
    export *
  }

  explicit module sys_select {
    header "sys/select.h"
    export *

    module _select {
      header "sys/_select.h"
      export *
    }
  }

  explicit module sys_wait {
    header "sys/wait.h"
    export *
  }

  explicit module unistd {
    header "unistd.h"
    export *

    module sys_unistd {
      header "sys/unistd.h"
      export *
    }

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

    // Apple extension.
    module gethostuuid {
      header "gethostuuid.h"
      export *
    }
  }

  // Low level hardware structures used in the implementations of things
  // like <signal.h> and <mach/thread_status.h>, use those headers instead.
  explicit module mach {
    explicit module structs {
      header "mach/machine/_structs.h"
      export *

      module i386 {
        header "mach/i386/_structs.h"
        export *
      }

      module arm {
        header "mach/arm/_structs.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 _inttypes {
    textual header "inttypes.h"

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

    header "_inttypes.h"
    export *
  }

  explicit module _signal {
    header "signal.h"
    export *

    module machine_signal {
      header "machine/signal.h"
      export *

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

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

    module sys_signal {
      header "sys/signal.h"
      export *
    }

    module mcontext {
      header "machine/_mcontext.h"
      export *

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

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

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

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

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

  explicit module _stdlib {
    textual header "stdlib.h"

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

    header "_stdlib.h"
    export *

    module abort {
      header "_abort.h"
      export *
    }

    module malloc {
      header "malloc/_malloc.h"
      export *

      module malloc_type {
        header "malloc/_malloc_type.h"
        export *
      }

      module ptrcheck {
        header "malloc/_ptrcheck.h"
        export *
      }
    }
  }

  explicit module _wchar {
    textual header "wchar.h"

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

    header "_wchar.h"
    export *

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

  explicit module _wctype {
    textual header "wctype.h"

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

    header "_wctype.h"
    export *

    module __wctype {
      textual header "__wctype.h"

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

      header "___wctype.h"
      export *
    }

    module wctrans_t {
      header "_types/_wctrans_t.h"
      export *
    }

    module wctype_t {
      header "_types/_wctype_t.h"
      export *
    }
  }
}
