#ifndef __LIB_EXPORTS_H_2006
#define __LIB_EXPORTS_H_2006

/*
 * Copyright (c) 2006, Andreas Stricker <andy@knitter.ch>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met:
 *
 *   * Redistributions of source code must retain the above copyright 
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above 
 *     copyright notice, this list of conditions and the following 
 *     disclaimer in the documentation and/or other materials provided 
 *     with the distribution.
 *   * The names of its contributors must not be used to endorse or 
 *     promote products derived from this software without specific 
 *     prior written permission.
 *   
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * This header file provide two macros to tag API functions for export.
 *
 * The resulting shared library (so or dll) allows only access to the
 * desired API function to ensure ABI compatibility and fast relocation.
 *
 * If GCC is used on UNIX systems (with shared libraries in ELF format),
 * the flag -fvisibility=hidden should be passed to it to ensure all
 * symbols not tagged with those macros are not exported.
 *
 *
 * Literature sources:
 *
 * How To Write Shared Libraries, by Ulrich Drepper
 * http://people.redhat.com/drepper/dsohowto.pdf
 *
 * Microsoft® Visual C++® .NET Language Reference
 * http://www.microsoft.com/mspress/books/sampchap/5799.asp
 *
 *
 * I was also inspired by libxml, Python and AL on how the different
 * platforms must be dealt with.
 *
 * 
 * The original file is located at http://www.knitter.ch/src/snipplets/
 */

/**
 * Macro to tag public API functions
 */
#define API_FUNCTION(rettype, name, args) rettype name args

/**
 * Macro to tag public global API variables
 */
#define API_VARIABLE(vartype, name) extern vartype name

/* Windows platform with Visual C compiler */
#if defined(_WIN32) && defined(_MSC_VER)
#   undef API_FUNCTION
#   undef API_VARIABLE
#   if defined(COMPILE_LIB) && !defined(STATIC_LIB)
#       define API_FUNCTION(rettype, name, args) \
            __declspec(dllexport) rettype __cdecl name args
#       define API_VARIABLE(vartype, name) \
            __declspec(dllexport) vartype name
#   else
#       define API_FUNCTION(rettype, name, args) \
            rettype __cdecl name args
#       if !defined(STATIC_LIB)
#           define API_VARIABLE(vartype, name) \
                __declspec(dllimport) extern vartype name
#       else
#           define API_VARIABLE(vartype, name) \
                extern vartype name
#       endif
#   endif
#endif

/* Windows platform with Borland compiler */
#if defined(_WIN32) && defined(__BORLANDC__)
#   undef API_FUNCTION
#   undef API_VARIABLE
#   if defined(COMPILE_LIB) && !defined(STATIC_LIB)
#       define API_FUNCTION(rettype, name, args) \
            __declspec(dllexport) rettype __cdecl name args
#       define API_VARIABLE(vartype, name) \
            __declspec(dllexport) extern vartype name
#   else
#       define API_FUNCTION(rettype, name, args) \
            rettype __cdecl name args
#       if !defined(STATIC_LIB)
#           define API_VARIABLE(vartype, name) \
                __declspec(dllimport) extern vartype name
#       else
#           define API_VARIABLE(vartype, name) \
                extern vartype name
#       endif
#   endif
#endif

/* Windows platform with GNU compiler (Mingw) */
#if defined(_WIN32) && defined(__MINGW32__)
#   undef API_FUNCTION
#   undef API_VARIABLE
#   if defined(COMPILE_LIB) && !defined(STATIC_LIB)
#       define API_FUNCTION(rettype, name, args) \
            __declspec(dllexport) rettype name args
#       define API_VARIABLE(vartype, name) \
            __declspec(dllexport) vartype name
#   else
#       define API_FUNCTION(rettype, name, args) \
            rettype name args
#       if !defined(STATIC_LIB)
#           define API_VARIABLE(vartype, name) \
                __declspec(dllimport) extern vartype name
#       else
#           define API_VARIABLE(vartype, name) \
                extern vartype name
#       endif
#   endif
#endif

/* Cygwin platform, GNU compiler */
#if defined(_WIN32) && defined(__CYGWIN__)
#   undef API_FUNCTION
#   undef API_VARIABLE
#   if defined(COMPILE_LIB) && !defined(STATIC_LIB)
#       define API_FUNCTION(rettype, name, args) \
            __declspec(dllexport) rettype name args
#       define API_VARIABLE(vartype, name) \
            __declspec(dllexport) vartype name
#   else
#       define API_FUNCTION(rettype, name, args) \
            rettype name args
#       if !defined(STATIC_LIB)
#           define API_VARIABLE(vartype, name) \
                __declspec(dllimport) extern vartype name
#       else
#           define API_VARIABLE(vartype, name) \
                vartype name
#       endif
#   endif
#endif

/* POSIX platform, GNU compiler */
#if defined(__GNUC__) && !defined(_WIN32)
#   if __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ > 1 )
#       undef API_FUNCTION
#       undef API_VARIABLE
#       if defined(COMPILE_LIB) && !defined(STATIC_LIB)
#           define API_FUNCTION(rettype, name, args) \
                rettype name args __attribute__((visibility("default")))
#           define API_VARIABLE(vartype, name) \
                vartype name __attribute__((visibility("default")))
#       else
#           if !defined(STATIC_LIB)
#               define API_FUNCTION(rettype, name, args) \
                    rettype name args
#               define API_VARIABLE(vartype, name) \
                    extern vartype name
#           else
#               define API_FUNCTION(rettype, name, args) \
                    rettype name args
#               define API_VARIABLE(vartype, name) \
                    vartype name
#           endif
#       endif
#   endif
#endif

#endif /* __LIB_EXPORTS_H_2006 */

