cmake.backbone/templates/library_constructor.c.in

63 lines
1.6 KiB
C

#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
@LC_WIN32_INCLUDES@
#elif defined(linux) || defined(UNIX) || defined(__unix__)
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
@LC_UNIX_INCLUDES@
#endif
@LC_COMMON_INCLUDES@
#include "gettext-config.h"
#if defined(_WIN32) || defined(_WIN64)
static HINSTANCE hCurrentModuleInstance;
#endif
@LC_GLOB_VARS@
gboolean get_library_path (gchar *so_path, void *addr)
{
gboolean ret;
#if defined(_WIN32) || defined(_WIN64)
ret = 0 != GetModuleFileName (hCurrentModuleInstance, so_path, FILENAME_MAX);
#elif defined(linux) || defined(UNIX) || defined(__unix__)
Dl_info dl_info;
ret = 0 != dladdr(addr, &dl_info);
strcpy (so_path, dl_info.dli_fname);
#endif
return ret;
}
#if defined(_WIN32) || defined(_WIN64)
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
#elif defined(linux) || defined(UNIX) || defined(__unix__)
void __attribute__ ((constructor)) load_library (void)
#endif
{
gchar *soDir, *localePath;
@LC_VARS@
gchar *so_path = g_new (gchar, FILENAME_MAX);
#if defined(_WIN32) || defined(_WIN64)
hCurrentModuleInstance = hInstance;
get_library_path (so_path, NULL);
@LC_WIN32_CODE@
#elif defined(linux) || defined(UNIX) || defined(__unix__)
get_library_path (so_path, load_library);
@LC_UNIX_CODE@
#endif
soDir = g_path_get_dirname (so_path);
g_free (so_path);
localePath = g_build_filename (soDir, "@LC_RELATIVE_PREFIX@/share/locale", NULL);
g_free (soDir);
bindtextdomain (GETTEXT_PACKAGE, localePath);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
g_free (localePath);
@LC_COMMON_CODE@
}