BAT has a Bouquet ID, no Service ID
[metze/wireshark/wip.git] / ws_symbol_export.h
1 /*
2  * Cross platform defines for exporting symbols from shared libraries
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Balint Reczey <balint@balintreczey.hu>
8  * Copyright 2013 Balint Reczey
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 /** Reset symbol export behavior.
26  * If you {un}define WS_BUILD_DLL on the fly you'll have to define this
27  * as well.
28  */
29 #ifdef RESET_SYMBOL_EXPORT
30
31 #ifdef SYMBOL_EXPORT_H
32 #undef SYMBOL_EXPORT_H
33 #endif
34
35 #ifdef WS_DLL_PUBLIC
36 #undef WS_DLL_PUBLIC
37 #endif
38
39 #ifdef WS_DLL_PUBLIC_DEF
40 #undef WS_DLL_PUBLIC_DEF
41 #endif
42
43 #ifdef WS_DLL_LOCAL
44 #undef WS_DLL_LOCAL
45 #endif
46
47 #endif /* RESET_SYMBOL_EXPORT */
48
49 #ifndef SYMBOL_EXPORT_H
50 #define SYMBOL_EXPORT_H
51
52 /* Originally copied from GCC Wiki at http://gcc.gnu.org/wiki/Visibility */
53 #if defined _WIN32 || defined __CYGWIN__
54   /* Compiling for Windows, so we use the Windows DLL declarations. */
55   #ifdef WS_BUILD_DLL
56     /*
57      * Building a DLL; for all definitions, we want dllexport, and
58      * (presumably so source from DLL and source from a program using the
59      * DLL can both include a header that declares APIs and exported data
60      * for the DLL), for declarations, either dllexport or dllimport will
61      * work (they mean the same thing for a declaration when building a DLL).
62      */
63     #ifdef __GNUC__
64       /* GCC */
65 #define WS_DLL_PUBLIC_DEF __attribute__ ((dllexport))
66     #else /* ! __GNUC__ */
67       /*
68        * Presumably MSVC.
69        * Note: actually gcc seems to also support this syntax.
70        */
71 #define WS_DLL_PUBLIC_DEF __declspec(dllexport)
72     #endif /* __GNUC__ */
73   #else /* WS_BUILD_DLL */
74     /*
75      * Building a program; we should only see declarations, not definitions,
76      * with WS_DLL_PUBLIC, and they all represent APIs or data imported
77      * from a DLL, so use dllimport.
78      *
79      * For functions, export shouldn't be necessary; for data, it might
80      * be necessary, e.g. if what's declared is an array whose size is
81      * not given in the declaration.
82      */
83     #ifdef __GNUC__
84       /* GCC */
85 #define WS_DLL_PUBLIC_DEF __attribute__ ((dllimport))
86     #elif ! (defined ENABLE_STATIC) /* ! __GNUC__ */
87       /*
88        * Presumably MSVC, and we're not building all-static.
89        * Note: actually gcc seems to also support this syntax.
90        */
91 #define WS_DLL_PUBLIC_DEF __declspec(dllimport)
92     #else /* ! __GNUC__  && ENABLE_STATIC */
93       /*
94        * Presumably MSVC, and we're building all-static, so we're
95        * not building any DLLs.
96        */
97 #define WS_DLL_PUBLIC_DEF
98     #endif /* __GNUC__ */
99   #endif /* WS_BUILD_DLL */
100
101   /*
102    * Symbols in a DLL are *not* exported unless they're specifically
103    * flagged as exported, so, for a non-static but non-exported
104    * symbol, we don't have to do anything.
105    */
106   #define WS_DLL_LOCAL
107 #else /* defined _WIN32 || defined __CYGWIN__ */
108   /*
109    * Compiling for UN*X, where the dllimport and dllexport stuff
110    * is neither necessary nor supported; just specify the
111    * visibility if we have a compiler that claims compatibility
112    * with GCC 4 or later.
113    */
114   #if __GNUC__ >= 4
115     /*
116      * Symbols exported from libraries.
117      */
118 #define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default")))
119
120     /*
121      * Non-static symbols *not* exported from libraries.
122      */
123 #define WS_DLL_LOCAL  __attribute__ ((visibility ("hidden")))
124   #else /* ! __GNUC__ >= 4 */
125     /*
126      * We have no way to control visibility.
127      */
128     #define WS_DLL_PUBLIC_DEF
129     #define WS_DLL_LOCAL
130   #endif /* __GNUC__ >= 4 */
131 #endif
132
133 /*
134  * You *must* use this for exported data *declarations*; if you use
135  * WS_DLL_PUBLIC_DEF, some compilers, such as MSVC++, will complain
136  * about array definitions with no size.
137  *
138  * You must *not* use this for exported data *definitions*, as that
139  * will, for some compilers, cause warnings about items being initialized
140  * and declared extern.
141  *
142  * Either can be used for exported *function* declarations and definitions.
143  */
144 #define WS_DLL_PUBLIC   WS_DLL_PUBLIC_DEF extern
145
146 #endif /* SYMBOL_EXPORT_H */