michaelforney / samurai

ninja-compatible build tool written in C
Other
824 stars 46 forks source link

Enables getloadavg on Darwin #95

Closed rsms closed 1 year ago

rsms commented 1 year ago

On darwin/macos, stdlib.h guards the definition of getloadavg with #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) ... #endif.

Without this change samurai doesn't build on darwin (without -DNO_GETLOADAVG), e.g:

build.c:535:6: error: implicit declaration of function 'getloadavg' is invalid in C99
    if (getloadavg(&load, 1) == -1) {
        ^

Thanks for an elegant ninja implementation!

wdlkmpx commented 1 year ago

I found this, you should edit your PR with these changes

https://github.com/michaelforney/samurai/pull/82#issuecomment-1191554714

All the pull requests are closed, it's hard to tell what has been merged or not. I get the feeling there should be an alternate repo where stuff is merged, samurai-staging perhaps

wdlkmpx commented 1 year ago

Iwas about to open a PR with this change, but this also applies to samu.c, it's enough to make the app compile on Haiku

#ifndef NO_GETLOADAVG
#if defined(__QNX__) || defined(__HAIKU__) || defined(_WIN32) || defined(MSDOS)
#define NO_GETLOADAVG 1
#endif
#endif

Perhaps there should be a special .h file, platform.h where compatibility issues are addressed in a more verbose way

michaelforney commented 1 year ago

I would really like to avoid this sort of ifdef. This is why I was hesitant to merge getloadavg support in the first place.

Instead, I made it default to disabled in c16d4501153512d87aaed43513189b3d1de5c14d. Those that want it can define '-D HAVE_GETLOADAVG` along with whatever else is needed for their system.