Created
September 25, 2016 06:31
-
-
Save flisboac/bec38b65cf04c36e549008324af418ad to your computer and use it in GitHub Desktop.
A simple library template for multi-link mode (static/shared) library headers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #if 0 | |
| To use, copy/paste and substitute LIBNAME with your library's name. | |
| Names: | |
| - Exported -> void function(); | |
| - Imported -> extern void function(); | |
| - Internal -> static function(); | |
| [ API] Exported names, when compiling: | |
| /* Header-implementation */ | |
| /* lib.h */ void function(); | |
| /* lib.c */ void function() {} | |
| [ API] Exported names, when referenced: | |
| /* lib.h */ export void function(); | |
| /* lib.c */ /* No definition */ | |
| [IAPI] Library-Internal names, when compiling: | |
| /* lib.h */ <attribute_hidden> void function(); | |
| /* lib.c */ void function(); | |
| [IAPI] Library-Internal names, when referenced: | |
| /* lib.h */ <attribute_hidden> extern void function(); | |
| /* lib.c */ /* No definition */ | |
| [SAPI] Static-Internal Referenced names, when compiling: | |
| /* lib.h */ static void function(); | |
| /* lib.c */ void function(); | |
| [SAPI] Static-Internal Referenced names, when referencing: | |
| /* lib.h */ static void function(); | |
| /* lib.c */ /* No definition */ | |
| #endif | |
| #ifndef LIBNAME_H_ | |
| #define LIBNAME_H_ | |
| #define LIBNAME | |
| #define LIBNAME_NAME "LIBNAME" | |
| #define LIBNAME_MAJORVERSION 0 | |
| #define LIBNAME_MINORVERSION 1 | |
| #define LIBNAME_PATCHVERSION 0 | |
| #define LIBNAME_RELEASETYPE "dev" | |
| #ifdef LIBNAME_STATICLIB | |
| # ifdef LIBNAME_SHAREDLIB | |
| # error "Can not specify two linkage modes (detected: STATIC)." | |
| # endif | |
| #elif LIBNAME_SHAREDLIB | |
| # ifdef LIBNAME_STATICLIB | |
| # error "Can not specify two linkage modes (detected: SHARED)." | |
| # endif | |
| #else | |
| # define LIBNAME_STATICLIB /* Change here the default linkage, if needed */ | |
| #endif | |
| #define LIBNAME_STRQT(s) #s | |
| #define LIBNAME_STRFY(s) LIBNAME_STRQT(s) | |
| #ifndef LIBNAME_RELEASENAME | |
| # define LIBNAME_RELEASENAME LIBNAME_NAME \ | |
| " " LIBNAME_STRFY(LIBNAME_MAJORVERSION) \ | |
| "." LIBNAME_STRFY(LIBNAME_MINORVERSION) \ | |
| "." LIBNAME_STRFY(LIBNAME_PATCHVERSION) \ | |
| "-" LIBNAME_RELEASETYPE | |
| #endif | |
| #ifndef LIBNAME_SKIP_CONFIG_OS | |
| # if defined _WIN32 || defined __WIN32__ || defined __WINDOWS__ || defined __TOS_WIN__ || defined _WIN64 | |
| # define LIBNAME_CONFIG_OS_WINDOWS | |
| # endif | |
| #endif | |
| #ifndef LIBNAME_SKIP_CONFIG_OS | |
| # if defined(__INTEL_COMPILER) || defined(__GNUC__) || defined __MINGW__ || defined __CYGWIN__ | |
| # define LIBNAME_CONFIG_COMPILER_GCC | |
| # endif | |
| #endif | |
| #ifdef LIBNAME_SKIP_COMPILER_EXPORT_IMPORT | |
| /* Nothing, will be defined later on */ | |
| #elif defined LIBNAME_CONFIG_OS_WINDOWS && defined LIBNAME_CONFIG_COMPILER_GCC | |
| # ifdef LIBNAME_STATICLIB | |
| # define LIBNAME_EXTERNAL_GCC_ATTRIBUTE_ | |
| # else | |
| # define LIBNAME_EXTERNAL_GCC_DECLSPEC_ | |
| # endif | |
| # define LIBNAME_INTERNAL_GCC_ATTRIBUTE_ | |
| #elif defined LIBNAME_CONFIG_OS_WINDOWS | |
| # ifdef LIBNAME_SHAREDLIB | |
| # define LIBNAME_EXTERNAL_DECLSPEC_ | |
| # endif | |
| #elif defined LIBNAME_CONFIG_COMPILER_GCC | |
| # define LIBNAME_INTERNAL_GCC_ATTRIBUTE_ | |
| # define LIBNAME_INTERNAL_GCC_ATTRIBUTE_ | |
| #endif /* LIBNAME_H_ */ | |
| #ifdef LIBNAME_FORCE_DEFAULT_VISIBILITY | |
| # pragma GCC visibility push(hidden) | |
| #endif | |
| #define LIBNAME_SAPI_EXPORT static | |
| #define LIBNAME_SAPI_IMPORT static | |
| #define LIBNAME_SAPI_IMPL | |
| #define LIBNAME_SVAR_EXPORT static | |
| #define LIBNAME_SVAR_IMPORT static | |
| #define LIBNAME_SVAR_IMPL | |
| #ifdef LIBNAME_EXTERNAL_DECLSPEC_ | |
| # undef LIBNAME_EXTERNAL_DECLSPEC_ | |
| # define LIBNAME_API_EXPORT __declspec(dllexport) | |
| # define LIBNAME_API_IMPORT __declspec(dllimport) extern | |
| # define LIBNAME_API_IMPL | |
| # define LIBNAME_VAR_EXPORT __declspec(dllexport) | |
| # define LIBNAME_VAR_IMPORT __declspec(dllimport) extern | |
| # define LIBNAME_VAR_IMPL | |
| #elif defined(LIBNAME_EXTERNAL_GCC_DECLSPEC_) | |
| # undef LIBNAME_EXTERNAL_GCC_DECLSPEC_ | |
| # define LIBNAME_API_EXPORT __attribute__((dllexport)) | |
| # define LIBNAME_API_IMPORT __attribute__((dllimport)) extern | |
| # define LIBNAME_API_IMPL | |
| # define LIBNAME_VAR_EXPORT __attribute__((dllexport)) | |
| # define LIBNAME_VAR_IMPORT __attribute__((dllimport)) extern | |
| # define LIBNAME_VAR_IMPL | |
| #elif defined(LIBNAME_EXTERNAL_GCC_ATTRIBUTE_) | |
| # undef LIBNAME_EXTERNAL_GCC_ATTRIBUTE_ | |
| # define LIBNAME_API_EXPORT __attribute__((visibility("default"))) | |
| # define LIBNAME_API_IMPORT extern | |
| # define LIBNAME_API_IMPL | |
| # define LIBNAME_VAR_EXPORT __attribute__((visibility("default"))) | |
| # define LIBNAME_VAR_IMPORT extern | |
| # define LIBNAME_VAR_IMPL | |
| #else | |
| # define LIBNAME_IAPI_EXPORT extern | |
| # define LIBNAME_IAPI_IMPORT | |
| # define LIBNAME_IAPI_IMPL | |
| # define LIBNAME_IVAR_EXPORT | |
| # define LIBNAME_IVAR_IMPORT | |
| # define LIBNAME_IVAR_IMPL | |
| #endif | |
| #ifdef LIBNAME_INTERNAL_GCC_ATTRIBUTE_ | |
| # undef LIBNAME_INTERNAL_GCC_ATTRIBUTE_ | |
| # define LIBNAME_IAPI_EXPORT __attribute__((visibility("hidden"))) | |
| # define LIBNAME_IAPI_IMPORT extern | |
| # define LIBNAME_IAPI_IMPL | |
| # define LIBNAME_IVAR_EXPORT __attribute__((visibility("hidden"))) | |
| # define LIBNAME_IVAR_IMPORT extern | |
| # define LIBNAME_IVAR_IMPL | |
| #else | |
| # define LIBNAME_IAPI_EXPORT extern | |
| # define LIBNAME_IAPI_IMPORT | |
| # define LIBNAME_IAPI_IMPL | |
| # define LIBNAME_IVAR_EXPORT | |
| # define LIBNAME_IVAR_IMPORT | |
| # define LIBNAME_IVAR_IMPL | |
| #endif | |
| #ifdef LIBNAME_BUILDING | |
| # define LIBNAME_API LIBNAME_API_EXPORT | |
| # define LIBNAME_IAPI LIBNAME_IAPI_EXPORT | |
| # define LIBNAME_SAPI LIBNAME_SAPI_EXPORT | |
| # define LIBNAME_VAR LIBNAME_VAR_EXPORT | |
| # define LIBNAME_IVAR LIBNAME_IVAR_EXPORT | |
| # define LIBNAME_SVAR LIBNAME_SVAR_EXPORT | |
| # ifdef LIBNAME_STATICLIB | |
| # define LIBNAME_BUILDING_STATICLIB | |
| # else | |
| # define LIBNAME_BUILDING_SHAREDLIB | |
| # endif | |
| #else | |
| # define LIBNAME_API LIBNAME_API_IMPORT | |
| # define LIBNAME_IAPI LIBNAME_IAPI_IMPORT | |
| # define LIBNAME_SAPI LIBNAME_SAPI_IMPORT | |
| # define LIBNAME_VAR LIBNAME_VAR_IMPORT | |
| # define LIBNAME_IVAR LIBNAME_IVAR_IMPORT | |
| # define LIBNAME_SVAR LIBNAME_SVAR_IMPORT | |
| # ifdef LIBNAME_STATICLIB | |
| # define LIBNAME_USING_STATICLIB | |
| # else | |
| # define LIBNAME_USING_SHAREDLIB | |
| # endif | |
| #endif | |
| #ifdef LIBNAME_DEBUG_MACRO_DEFINITIONS | |
| # pragma message LIBNAME_STRQT(LIBNAME_API) ": " LIBNAME_STRFY(LIBNAME_API) | |
| # pragma message LIBNAME_STRQT(LIBNAME_API_IMPL) ": " LIBNAME_STRFY(LIBNAME_API_IMPL) | |
| # pragma message LIBNAME_STRQT(LIBNAME_IAPI) ": " LIBNAME_STRFY(LIBNAME_IAPI) | |
| # pragma message LIBNAME_STRQT(LIBNAME_IAPI_IMPL) ": " LIBNAME_STRFY(LIBNAME_IAPI_IMPL) | |
| # pragma message LIBNAME_STRQT(LIBNAME_SAPI) ": " LIBNAME_STRFY(LIBNAME_SAPI) | |
| # pragma message LIBNAME_STRQT(LIBNAME_SAPI_IMPL) ": " LIBNAME_STRFY(LIBNAME_SAPI_IMPL) | |
| # pragma message LIBNAME_STRQT(LIBNAME_VAR) ": " LIBNAME_STRFY(LIBNAME_VAR) | |
| # pragma message LIBNAME_STRQT(LIBNAME_VAR_IMPL) ": " LIBNAME_STRFY(LIBNAME_VAR_IMPL) | |
| # pragma message LIBNAME_STRQT(LIBNAME_IVAR) ": " LIBNAME_STRFY(LIBNAME_IVAR) | |
| # pragma message LIBNAME_STRQT(LIBNAME_IVAR_IMPL) ": " LIBNAME_STRFY(LIBNAME_IVAR_IMPL) | |
| # pragma message LIBNAME_STRQT(LIBNAME_SVAR) ": " LIBNAME_STRFY(LIBNAME_SVAR) | |
| # pragma message LIBNAME_STRQT(LIBNAME_SVAR_IMPL) ": " LIBNAME_STRFY(LIBNAME_SVAR_IMPL) | |
| #endif | |
| /* Library content here */ | |
| #endif /* LIBNAME_H_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment