#include <libcork/config.h>
Several libcork features have different implementations on different platforms. Since we want libcork to be easily embeddable into projects with a wide range of build systems, we try to autodetect which implementations to use, using only the C preprocessor and the predefined macros that are available on the current system.
This module provides a layer of indirection, with all of the preprocessor-based autodetection in one place. This module’s task is to define a collection of libcork-specific configuration macros, which all other libcork modules will use to select which implementation to use.
This design also lets you skip the autodetection, and provide values for the configuration macros directly. This is especially useful if you’re embedding libcork into another project, and already have a configure step in your build system that performs platform detection. See CORK_CONFIG_SKIP_AUTODETECT for details.
Note
The autodetection logic is almost certainly incomplete. If you need to port libcork to another platform, this is where an important chunk of edits will take place. Patches are welcome!
This section lists all of the macros that are defined by libcork’s autodetection logic. Other libcork modules will use the values of these macros to choose among the possible implementations.
Exactly one of these macros should be defined to 1 to indicate the architecture of the current platform. All of the other macros should be defined to 0 or left undefined. The macros correspond to the following architectures:
Macro suffix | Architecture |
---|---|
X86 | 32-bit Intel (386 or greater) |
X64 | 64-bit Intel/AMD (AMD64/EM64T, not IA-64) |
PPC | 32-bit PowerPC |
Whether the GCC inline assembler syntax is available. (This doesn’t imply that the compiler is specifically GCC.) Should be defined to 0 or 1.
Whether the GCC-style syntax for compiler attributes is available. (This doesn’t imply that the compiler is specifically GCC.) Should be defined to 0 or 1.
Whether GCC-style atomic intrinsics are available. (This doesn’t imply that the compiler is specifically GCC.) Should be defined to 0 or 1.
Whether the GCC-style 128-bit integer types (__int128 and unsigned __int128) are available. (This doesn’t imply that the compiler is specifically GCC.) Should be defined to 0 or 1.
Whether GCC-style machine modes are available. (This doesn’t imply that the compiler is specifically GCC.) Should be defined to 0 or 1.
Whether GCC-style statement expressions are available. (This doesn’t imply that the compiler is specifically GCC.) Should be defined to 0 or 1.
Whether this platform defines a reallocf function in stdlib.h. reallocf is a BSD extension to the standard realloc function that frees the existing pointer if a reallocation fails. If this function exists, we can use it to implement cork_realloc().
If you want to skip libcork’s autodetection logic, then you are responsible for providing the appropriate values for all of the macros defined in Configuration macros. To do this, have your build system define this macro, with a value of 1. This will override the default value of 0 provided in the libcork/config/config.h header file.
Then, create (or have your build system create) a libcork/config/custom.h header file. You can place this file anywhere in your header search path. We will load that file instead of libcork’s autodetection logic. Place the appropriate definitions for each of the configuration macros into this file. If needed, you can generate this file as part of the configure step of your build system; the only requirement is that it’s available once you start compiling the libcork source files.