From 4422c3a54682d1318575909857e3e9e8ae5f3b44 Mon Sep 17 00:00:00 2001 From: Ismael Dibene Date: Thu, 23 Apr 2026 00:13:21 +0200 Subject: [PATCH] Bugfix/TODO: add support for "-std=c99", "-D_POSIX_C_SOURCE=200112L" for MacOS --- nob.h | 7 +++++++ shared.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/nob.h b/nob.h index 2735a93..1f59842 100644 --- a/nob.h +++ b/nob.h @@ -166,7 +166,9 @@ # include #else # ifdef __APPLE__ +# define _DARWIN_C_SOURCE 1 # include +# include # endif # ifdef __FreeBSD__ # include @@ -1226,6 +1228,11 @@ NOBDEF int nob_nprocs(void) SYSTEM_INFO siSysInfo; GetSystemInfo(&siSysInfo); return siSysInfo.dwNumberOfProcessors; +#elif __APPLE__ + int nprocs = 0; + size_t len = sizeof(nprocs); + sysctlbyname("hw.logicalcpu", &nprocs, &len, NULL, 0); + return nprocs; #else return sysconf(_SC_NPROCESSORS_ONLN); #endif diff --git a/shared.h b/shared.h index f3bb3e1..35c6ce3 100644 --- a/shared.h +++ b/shared.h @@ -23,7 +23,7 @@ #elif defined(__APPLE__) || defined(__MACH__) // TODO: "-std=c99", "-D_POSIX_C_SOURCE=200112L" didn't work for MacOS, don't know why, don't really care that much at the moment. // Anybody who does feel free to investigate. - #define nob_cc_flags(cmd) cmd_append(cmd, "-Wall", "-Wextra", "-Wswitch-enum", "-I.") + #define nob_cc_flags(cmd) cmd_append(cmd, "-Wall", "-Wextra", "-Wswitch-enum", "-std=c99", "-D_POSIX_C_SOURCE=200112L", "-I.") #elif defined(__FreeBSD__) // "-D_POSIX_C_SOURCE=200112L" hides required symbols on FreeBSD #define nob_cc_flags(cmd) cmd_append(cmd, "-Wall", "-Wextra", "-Wswitch-enum", "-std=c99", "-ggdb", "-I.");