This provides built-in support for cross-compiling a subset of libbsd for Windows using LLVM/Clang or MSYS2/MinGW. While many libbsd interfaces already support Windows, developers are currently required to manually modify libbsd's build system and header files in order to use them in a native environment. Changing/replacing libbsd code like this is difficult to maintain and it is not ideal for external projects which depend on libbsd and want to target Windows. I'm helping out with efforts to support the Swift programming language on Windows, and this is one of the roadblocks that we've hit. If this merge request is accepted, we will continue to maintain and test this through that project.
To simplify things, I've restricted this to only provide support for the libbsd interfaces that already work on Windows or which can be trivially ported to it. Interfaces that would require significant amounts of platform-specific code in order to build for Windows are not covered here, and some interfaces simply don't make sense on Windows (e.g. anything dealing with
mode_t or file descriptors). There is currently also no support for building libbsd as a DLL (shared library). These restrictions are generally sufficient for most libbsd consumers who want to target Windows anyway.
I've tested these changes by running the following commands on a Linux system to cross-compile for Windows using a recent build of LLVM/Clang. (This requires the Windows SDK to be available and the
LIB environment variables to be set properly.)
$ export CC=clang
$ export AR=llvm-ar
$ export RANLIB=llvm-ranlib
$ export CFLAGS="-target x86_64-pc-windows-msvc -fuse-ld=lld -Xclang --dependent-lib=msvcrtd -Xclang --dependent-lib=oldnames -nostdlib"
$ export CPPFLAGS="-target x86_64-pc-windows-msvc -D_DEBUG -D_MT -D_DLL"
$ ./autogen && ./configure --host=x86_64-pc-mingw64
$ make check