bakelite
bakelite copied to clipboard
misc: build with macOS
this pull request makes the changes needed to allow bakelite to build in macOS successfully, namely:
- introducing a new file
endian.hwhich does the proper macros to supply the expected functions in macOS, or simply includes<endian.h>in other platforms - including the
<sys/random.h>header on macOS for all the files usinggetentropy(2) - defining
pipe2as a function on macOS forstore.c, since it's not supplied by the standard library - defining the expected fields to
struct statas macros, since they have different names on macOS
changes have been tested in both Linux (Fedora 35) and macOS (macOS 12.3.1) and it builds, backups and restores successfully in both platforms
(I am aware that defining pipe2 like this can result in race conditions, but it's the only solution, sadly)
Maybe a sort of configure script looking for these specific features would be a better solution instead? I'm currently installing a couple virtual machines to test on other platforms as well, so maybe I could expand the scope of this to encompass more platforms than just macOS
A portable implementation for the endian.h macros and for getentropy(2) are still pending, but I was wondering, is it really worth it, considering (nearly) all UNIX-like OSes have them?
For getentropy, there is no portable implementation or safe fallback that widely works. What we can easily do though is just declare it ourselves (int getentropy(void*, size_t);) so as not to care if unistd.h didn't declare it. Then, if the system doesn't have it, you need to provide a library giving a safe version via LDFLAGS (but AIUI OSX does have it so that's a non-issue).