2013-02-28 14:09:46 +00:00
|
|
|
/*
|
|
|
|
* Cross platform defines for exporting symbols from shared libraries
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Balint Reczey <balint@balintreczey.hu>
|
|
|
|
* Copyright 2013 Balint Reczey
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2013-03-07 17:20:12 +00:00
|
|
|
/** Reset symbol export behavior.
|
|
|
|
* If you {un}define WS_BUILD_DLL on the fly you'll have to define this
|
|
|
|
* as well.
|
|
|
|
*/
|
|
|
|
#ifdef RESET_SYMBOL_EXPORT
|
|
|
|
|
|
|
|
#ifdef SYMBOL_EXPORT_H
|
|
|
|
#undef SYMBOL_EXPORT_H
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WS_DLL_PUBLIC
|
|
|
|
#undef WS_DLL_PUBLIC
|
|
|
|
#endif
|
|
|
|
|
2013-07-03 01:43:39 +00:00
|
|
|
#ifdef WS_DLL_PUBLIC_DEF
|
|
|
|
#undef WS_DLL_PUBLIC_DEF
|
2013-03-07 17:20:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WS_DLL_LOCAL
|
|
|
|
#undef WS_DLL_LOCAL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* RESET_SYMBOL_EXPORT */
|
|
|
|
|
2013-02-28 14:09:46 +00:00
|
|
|
#ifndef SYMBOL_EXPORT_H
|
|
|
|
#define SYMBOL_EXPORT_H
|
|
|
|
|
2014-07-01 19:21:02 +00:00
|
|
|
/*
|
|
|
|
* NOTE: G_HAVE_GNUC_VISIBILITY is defined only if all of
|
|
|
|
*
|
|
|
|
* __attribute__ ((visibility ("hidden")))
|
|
|
|
*
|
|
|
|
* __attribute__ ((visibility ("internal")))
|
|
|
|
*
|
|
|
|
* __attribute__ ((visibility ("protected")))
|
|
|
|
*
|
|
|
|
* __attribute__ ((visibility ("default")))
|
|
|
|
*
|
|
|
|
* are supported, and at least some versions of GCC from Apple support
|
|
|
|
* "default" and "hidden" but not "internal" or "protected", so it
|
|
|
|
* shouldn't be used to determine whether "hidden" or "default" is
|
|
|
|
* supported.
|
|
|
|
*
|
|
|
|
* This also means that we shouldn't use G_GNUC_INTERNAL instead of
|
|
|
|
* WS_DLL_LOCAL, as GLib uses G_HAVE_GNUC_VISIBILITY to determine
|
|
|
|
* whether to use __attribute__ ((visibility ("hidden"))) for
|
|
|
|
* G_GNUC_INTERNAL, and that will not use it even with compilers
|
|
|
|
* that support it.
|
|
|
|
*/
|
|
|
|
|
2013-02-28 14:09:46 +00:00
|
|
|
/* Originally copied from GCC Wiki at http://gcc.gnu.org/wiki/Visibility */
|
2013-03-02 22:27:40 +00:00
|
|
|
#if defined _WIN32 || defined __CYGWIN__
|
2013-07-03 00:38:41 +00:00
|
|
|
/* Compiling for Windows, so we use the Windows DLL declarations. */
|
2013-02-28 14:09:46 +00:00
|
|
|
#ifdef WS_BUILD_DLL
|
2013-07-03 00:38:41 +00:00
|
|
|
/*
|
2013-07-03 01:43:39 +00:00
|
|
|
* Building a DLL; for all definitions, we want dllexport, and
|
2013-07-03 00:38:41 +00:00
|
|
|
* (presumably so source from DLL and source from a program using the
|
|
|
|
* DLL can both include a header that declares APIs and exported data
|
|
|
|
* for the DLL), for declarations, either dllexport or dllimport will
|
|
|
|
* work (they mean the same thing for a declaration when building a DLL).
|
|
|
|
*/
|
2013-02-28 14:09:46 +00:00
|
|
|
#ifdef __GNUC__
|
2013-07-03 00:38:41 +00:00
|
|
|
/* GCC */
|
2013-07-03 01:43:39 +00:00
|
|
|
#define WS_DLL_PUBLIC_DEF __attribute__ ((dllexport))
|
2013-02-28 14:09:46 +00:00
|
|
|
#else /* ! __GNUC__ */
|
2013-07-03 00:38:41 +00:00
|
|
|
/*
|
|
|
|
* Presumably MSVC.
|
|
|
|
* Note: actually gcc seems to also support this syntax.
|
|
|
|
*/
|
2013-07-03 01:43:39 +00:00
|
|
|
#define WS_DLL_PUBLIC_DEF __declspec(dllexport)
|
2013-02-28 14:09:46 +00:00
|
|
|
#endif /* __GNUC__ */
|
2013-07-02 22:08:23 +00:00
|
|
|
#else /* WS_BUILD_DLL */
|
2013-07-03 00:38:41 +00:00
|
|
|
/*
|
|
|
|
* Building a program; we should only see declarations, not definitions,
|
|
|
|
* with WS_DLL_PUBLIC, and they all represent APIs or data imported
|
|
|
|
* from a DLL, so use dllimport.
|
|
|
|
*
|
|
|
|
* For functions, export shouldn't be necessary; for data, it might
|
|
|
|
* be necessary, e.g. if what's declared is an array whose size is
|
|
|
|
* not given in the declaration.
|
|
|
|
*/
|
2013-02-28 14:09:46 +00:00
|
|
|
#ifdef __GNUC__
|
2013-07-03 00:38:41 +00:00
|
|
|
/* GCC */
|
2013-07-03 01:43:39 +00:00
|
|
|
#define WS_DLL_PUBLIC_DEF __attribute__ ((dllimport))
|
2013-02-28 14:09:46 +00:00
|
|
|
#elif ! (defined ENABLE_STATIC) /* ! __GNUC__ */
|
2013-07-03 00:38:41 +00:00
|
|
|
/*
|
2013-07-04 00:39:54 +00:00
|
|
|
* Presumably MSVC, and we're not building all-static.
|
2013-07-03 00:38:41 +00:00
|
|
|
* Note: actually gcc seems to also support this syntax.
|
|
|
|
*/
|
2013-07-03 01:43:39 +00:00
|
|
|
#define WS_DLL_PUBLIC_DEF __declspec(dllimport)
|
2013-02-28 14:09:46 +00:00
|
|
|
#else /* ! __GNUC__ && ENABLE_STATIC */
|
2013-07-04 00:39:54 +00:00
|
|
|
/*
|
|
|
|
* Presumably MSVC, and we're building all-static, so we're
|
|
|
|
* not building any DLLs.
|
|
|
|
*/
|
2013-07-03 01:43:39 +00:00
|
|
|
#define WS_DLL_PUBLIC_DEF
|
2013-02-28 14:09:46 +00:00
|
|
|
#endif /* __GNUC__ */
|
|
|
|
#endif /* WS_BUILD_DLL */
|
2013-07-04 00:39:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Symbols in a DLL are *not* exported unless they're specifically
|
|
|
|
* flagged as exported, so, for a non-static but non-exported
|
|
|
|
* symbol, we don't have to do anything.
|
|
|
|
*/
|
2013-02-28 14:09:46 +00:00
|
|
|
#define WS_DLL_LOCAL
|
2013-07-02 22:08:23 +00:00
|
|
|
#else /* defined _WIN32 || defined __CYGWIN__ */
|
2013-07-03 00:38:41 +00:00
|
|
|
/*
|
|
|
|
* Compiling for UN*X, where the dllimport and dllexport stuff
|
|
|
|
* is neither necessary nor supported; just specify the
|
|
|
|
* visibility if we have a compiler that claims compatibility
|
|
|
|
* with GCC 4 or later.
|
|
|
|
*/
|
2013-02-28 14:09:46 +00:00
|
|
|
#if __GNUC__ >= 4
|
2013-07-04 00:39:54 +00:00
|
|
|
/*
|
|
|
|
* Symbols exported from libraries.
|
|
|
|
*/
|
2013-07-03 01:43:39 +00:00
|
|
|
#define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default")))
|
2013-07-04 00:39:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Non-static symbols *not* exported from libraries.
|
|
|
|
*/
|
2013-02-28 14:09:46 +00:00
|
|
|
#define WS_DLL_LOCAL __attribute__ ((visibility ("hidden")))
|
|
|
|
#else /* ! __GNUC__ >= 4 */
|
2013-07-04 00:39:54 +00:00
|
|
|
/*
|
2014-07-01 19:21:02 +00:00
|
|
|
* We have no way to make stuff not explicitly marked as
|
|
|
|
* visible invisible outside a library, but we might have
|
|
|
|
* a way to make stuff explicitly marked as local invisible
|
|
|
|
* outside the library.
|
|
|
|
*
|
|
|
|
* This was lifted from GLib; see above for why we don't use
|
|
|
|
* G_GNUC_INTERNAL.
|
2013-07-04 00:39:54 +00:00
|
|
|
*/
|
2014-07-01 19:21:02 +00:00
|
|
|
#if defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
|
2014-07-01 23:03:34 +00:00
|
|
|
/* This supports GCC-style __attribute__ ((visibility (XXX))) */
|
|
|
|
#define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default")))
|
2014-07-01 19:21:02 +00:00
|
|
|
#define WS_DLL_LOCAL __attribute__ ((visibility ("hidden")))
|
|
|
|
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
|
2014-07-01 23:03:34 +00:00
|
|
|
/* This doesn't, but supports __global and __hidden */
|
|
|
|
#define WS_DLL_PUBLIC_DEF __global
|
2014-07-01 19:21:02 +00:00
|
|
|
#define WS_DLL_LOCAL __hidden
|
|
|
|
#else /* not Sun C with "hidden" support */
|
2014-07-01 23:03:34 +00:00
|
|
|
#define WS_DLL_PUBLIC_DEF
|
2014-07-01 19:21:02 +00:00
|
|
|
#define WS_DLL_LOCAL
|
|
|
|
#endif
|
2013-02-28 14:09:46 +00:00
|
|
|
#endif /* __GNUC__ >= 4 */
|
|
|
|
#endif
|
|
|
|
|
2013-07-03 01:43:39 +00:00
|
|
|
/*
|
2013-07-04 18:11:59 +00:00
|
|
|
* You *must* use this for exported data *declarations*; if you use
|
|
|
|
* WS_DLL_PUBLIC_DEF, some compilers, such as MSVC++, will complain
|
|
|
|
* about array definitions with no size.
|
|
|
|
*
|
|
|
|
* You must *not* use this for exported data *definitions*, as that
|
|
|
|
* will, for some compilers, cause warnings about items being initialized
|
|
|
|
* and declared extern.
|
|
|
|
*
|
|
|
|
* Either can be used for exported *function* declarations and definitions.
|
2013-07-03 01:43:39 +00:00
|
|
|
*/
|
2014-10-12 18:56:12 +00:00
|
|
|
#define WS_DLL_PUBLIC WS_DLL_PUBLIC_DEF extern
|
|
|
|
|
2014-10-14 19:58:21 +00:00
|
|
|
#endif /* SYMBOL_EXPORT_H */
|
|
|
|
|
2014-10-12 18:56:12 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 2
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
2014-10-14 19:58:21 +00:00
|
|
|
* vi: set shiftwidth=2 tabstop=8 expandtab:
|
2014-10-12 18:56:12 +00:00
|
|
|
* :indentSize=2:tabSize=8:noTabs=true:
|
|
|
|
*/
|