82 lines
1.4 KiB
C
82 lines
1.4 KiB
C
// baby context cracking
|
|
|
|
#if defined(_WIN32)
|
|
# define OS_WINDOWS 1
|
|
#elif defined(__gnu_linux__)
|
|
# define OS_LINUX 1
|
|
#else
|
|
# error this configuration of compiler & OS is not supported
|
|
#endif
|
|
|
|
#if !defined(OS_WINDOWS)
|
|
# define OS_WINDOWS 0
|
|
#endif
|
|
#if !defined(OS_LINUX)
|
|
# define OS_LINUX 0
|
|
#endif
|
|
|
|
|
|
// linkage keyword abstraction
|
|
|
|
#if OS_WINDOWS
|
|
# define EXPORT_SYMBOL __declspec(dllexport)
|
|
#elif OS_LINUX
|
|
# define EXPORT_SYMBOL __attribute__ ((visibility ("default")))
|
|
#else
|
|
# error keyword abstractions missing for this OS
|
|
#endif
|
|
|
|
|
|
#if OS_WINDOWS
|
|
|
|
# pragma section(".CRT$XCU", read)
|
|
|
|
# define BEFORE_MAIN(n) static void n(void); \
|
|
__declspec(allocate(".CRT$XCU")) \
|
|
__pragma(comment(linker, "/INCLUDE:" #n "__")) \
|
|
void (*n##__)(void) = n; \
|
|
static void n(void)
|
|
|
|
#elif OS_LINUX
|
|
|
|
# define BEFORE_MAIN(n) \
|
|
__attribute__((constructor)) static void n(void)
|
|
|
|
#else
|
|
# error BEFORE_MAIN missing for this OS
|
|
#endif
|
|
|
|
// base layer types
|
|
|
|
typedef void BASE_Library;
|
|
|
|
|
|
// base symbols shared
|
|
|
|
#if defined(BASE_IMPLEMENTOR)
|
|
|
|
void base_func(void);
|
|
|
|
#endif
|
|
|
|
|
|
// dynamic function linkage protocol
|
|
|
|
typedef struct BASE_Funcs{
|
|
#define X(N,R,P) R (*N) P;
|
|
#include "base.xlist.h"
|
|
#undef X
|
|
} BASE_Funcs;
|
|
|
|
typedef BASE_Funcs* BASE_ExportFuncs(void);
|
|
|
|
#if defined(BASE_IMPLEMENTOR)
|
|
EXPORT_SYMBOL BASE_Funcs* base_export_functions(void);
|
|
#endif
|
|
|
|
#if !defined(BASE_IMPLEMENTOR)
|
|
#define X(N,R,P) R (*N) P = 0;
|
|
#include "base.xlist.h"
|
|
#undef X
|
|
#endif
|