standalone: refactor for becoming also a SDL driver
[sdl_omap.git] / include / begin_code.h
CommitLineData
e14743d1 1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22
23/**
24 * @file begin_code.h
25 * This file sets things up for C dynamic library function definitions,
26 * static inlined functions, and structures aligned at 4-byte alignment.
27 * If you don't like ugly C preprocessor code, don't look at this file. :)
28 */
29
30/**
31 * @file begin_code.h
32 * This shouldn't be nested -- included it around code only.
33 */
34#ifdef _begin_code_h
35#error Nested inclusion of begin_code.h
36#endif
37#define _begin_code_h
38
39/**
40 * @def DECLSPEC
41 * Some compilers use a special export keyword
42 */
43#ifndef DECLSPEC
44# if defined(__BEOS__) || defined(__HAIKU__)
45# if defined(__GNUC__)
46# define DECLSPEC __declspec(dllexport)
47# else
48# define DECLSPEC __declspec(export)
49# endif
50# elif defined(__WIN32__)
51# ifdef __BORLANDC__
52# ifdef BUILD_SDL
53# define DECLSPEC
54# else
55# define DECLSPEC __declspec(dllimport)
56# endif
57# else
58# define DECLSPEC __declspec(dllexport)
59# endif
60# elif defined(__OS2__)
61# ifdef __WATCOMC__
62# ifdef BUILD_SDL
63# define DECLSPEC __declspec(dllexport)
64# else
65# define DECLSPEC
66# endif
67# elif defined (__GNUC__) && __GNUC__ < 4
68# /* Added support for GCC-EMX <v4.x */
69# /* this is needed for XFree86/OS2 developement */
70# /* F. Ambacher(anakor@snafu.de) 05.2008 */
71# ifdef BUILD_SDL
72# define DECLSPEC __declspec(dllexport)
73# else
74# define DECLSPEC
75# endif
76# else
77# define DECLSPEC
78# endif
79# else
80# if defined(__GNUC__) && __GNUC__ >= 4
81# define DECLSPEC __attribute__ ((visibility("default")))
82# else
83# define DECLSPEC
84# endif
85# endif
86#endif
87
88/**
89 * @def SDLCALL
90 * By default SDL uses the C calling convention
91 */
92#ifndef SDLCALL
93# if defined(__WIN32__) && !defined(__GNUC__)
94# define SDLCALL __cdecl
95# elif defined(__OS2__)
96# if defined (__GNUC__) && __GNUC__ < 4
97# /* Added support for GCC-EMX <v4.x */
98# /* this is needed for XFree86/OS2 developement */
99# /* F. Ambacher(anakor@snafu.de) 05.2008 */
100# define SDLCALL _cdecl
101# else
102# /* On other compilers on OS/2, we use the _System calling convention */
103# /* to be compatible with every compiler */
104# define SDLCALL _System
105# endif
106# else
107# define SDLCALL
108# endif
109#endif /* SDLCALL */
110
111#ifdef __SYMBIAN32__
112#ifndef EKA2
113#undef DECLSPEC
114#define DECLSPEC
115#elif !defined(__WINS__)
116#undef DECLSPEC
117#define DECLSPEC __declspec(dllexport)
118#endif /* !EKA2 */
119#endif /* __SYMBIAN32__ */
120
121/**
122 * @file begin_code.h
123 * Force structure packing at 4 byte alignment.
124 * This is necessary if the header is included in code which has structure
125 * packing set to an alternate value, say for loading structures from disk.
126 * The packing is reset to the previous value in close_code.h
127 */
128#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
129#ifdef _MSC_VER
130#pragma warning(disable: 4103)
131#endif
132#ifdef __BORLANDC__
133#pragma nopackwarning
134#endif
135#pragma pack(push,4)
136#elif (defined(__MWERKS__) && defined(__MACOS__))
137#pragma options align=mac68k4byte
138#pragma enumsalwaysint on
139#endif /* Compiler needs structure packing set */
140
141/**
142 * @def SDL_INLINE_OKAY
143 * Set up compiler-specific options for inlining functions
144 */
145#ifndef SDL_INLINE_OKAY
146#ifdef __GNUC__
147#define SDL_INLINE_OKAY
148#else
149/* Add any special compiler-specific cases here */
150#if defined(_MSC_VER) || defined(__BORLANDC__) || \
151 defined(__DMC__) || defined(__SC__) || \
152 defined(__WATCOMC__) || defined(__LCC__) || \
153 defined(__DECC) || defined(__EABI__)
154#ifndef __inline__
155#define __inline__ __inline
156#endif
157#define SDL_INLINE_OKAY
158#else
159#if !defined(__MRC__) && !defined(_SGI_SOURCE)
160#ifndef __inline__
161#define __inline__ inline
162#endif
163#define SDL_INLINE_OKAY
164#endif /* Not a funky compiler */
165#endif /* Visual C++ */
166#endif /* GNU C */
167#endif /* SDL_INLINE_OKAY */
168
169/**
170 * @def __inline__
171 * If inlining isn't supported, remove "__inline__", turning static
172 * inlined functions into static functions (resulting in code bloat
173 * in all files which include the offending header files)
174 */
175#ifndef SDL_INLINE_OKAY
176#define __inline__
177#endif
178
179/**
180 * @def NULL
181 * Apparently this is needed by several Windows compilers
182 */
183#if !defined(__MACH__)
184#ifndef NULL
185#ifdef __cplusplus
186#define NULL 0
187#else
188#define NULL ((void *)0)
189#endif
190#endif /* NULL */
191#endif /* ! Mac OS X - breaks precompiled headers */