/* Copyright 2005 Chris Thomasson */


#ifndef AC_BASE_H
#define AC_BASE_H


#ifdef __cplusplus
extern "C"
{
#endif




/* attempt to determine the os type */
#if defined ( linux ) || \
    defined ( __linux ) || \
    defined ( AC_BUILD_OS_FORCE_LINUX32 ) 

#define AC_BUILD_OS_PTHREADS
#define AC_BUILD_OS_LINUX

#elif defined ( _WIN32 ) || \
      defined ( __TOS_WIN__ ) || \
      defined ( __WIN32__ ) ||  \
      defined ( WIN32 ) || \
      defined ( WIN64 ) || \
      defined ( _WIN32_WCE ) || \
      defined ( AC_BUILD_OS_FORCE_WIN32 ) || \
      defined ( AC_BUILD_OS_FORCE_WINCE )

#if defined ( _WIN32_WCE ) || \
    defined ( AC_BUILD_OS_FORCE_WINCE )
#define AC_BUILD_OS_WINDOWS_CE
#endif
#define AC_BUILD_OS_WINDOWS

#ifdef WIN64
#define AC_BUILD_OS_64_BIT
#endif

#elif defined ( AC_BUILD_OS_FORCE_PTHREAD )
#define AC_BUILD_OS_PTHREADS

#else
#error AC_BUILD_OS - Windows or PThreads OS required!
#endif




/* attempt to determine the cpu type */
#if defined ( _M_IX86 ) || \
    defined ( i386 ) || \
    defined ( __i386__ ) || \
    defined ( _X86_ ) || \
    defined ( AC_BUILD_CPU_FORCE_I686 )
    
#   define AC_CPU_X86

#   define AC_BUILD_32BIT

#   if defined ( AC_BUILD_OS_WINDOWS_CE ) || \
       defined ( AC_BUILD_CPU_FORCE_WINDOWS )

#       define AC_BUILD_CPU_WINDOWS

#else

#       define AC_BUILD_CPU_I686

#endif

#elif defined ( _WIN32_WCE ) || \
      defined ( AC_BUILD_CPU_FORCE_WINDOWS )

#   define AC_BUILD_32BIT
#   define AC_BUILD_CPU_WINDOWS

#else

#   error AC_BUILD_CPU - x86-32 or Windows required!

#endif




/*****  Simple Compiler Abstraction  *****/
#ifdef _MSC_VER
/* 4514: unreferenced inline function has been removed
   4710: function 'whatever' not inlined */
#   pragma warning ( disable : 4514 4710 )

#   define AC_INLINE_FORCE __forceinline
#   define AC_INLINE __inline

#   define AC_DECLSPEC_CALL_CDECL __cdecl
#   define AC_DECLSPEC_CALL_FAST_CALL __fastcall
#   define AC_DECLSPEC_CALL_STDCALL __stdcall

#   define AC_DECLSPEC_ALIGN( a ) __declspec ( align( a ) )
#   define AC_DECLSPEC_PACKED
#   define AC_DECLSPEC_MALLOC 
#   define AC_DECLSPEC_UNUSED 
#   define AC_DECLSPEC_NORET 


#   if defined ( AC_BUILD_OS_UNDER_WINDOWS ) || \
       defined ( AC_BUILD_OS_WINDOWS )

#   define AC_DECLSPEC_API_IMPORT __declspec ( dllimport )
#   define AC_DECLSPEC_API_EXPORT __declspec ( dllexport )

#   endif




#elif defined ( __GNUC__ )


#   define AC_INLINE_FORCE __attribute__ ( (always_inline) )
#   define AC_INLINE __inline__


#   ifdef AC_BUILD_CPU_I686

#       if defined ( AC_BUILD_OS_UNDER_WINDOWS ) || \
           defined ( AC_BUILD_OS_WINDOWS ) \

#           define AC_DECLSPEC_CALL_CDECL __attribute__ ( (cdecl) )
#           define AC_DECLSPEC_CALL_FAST_CALL __attribute__ ( (fastcall) )
#           define AC_DECLSPEC_CALL_STDCALL __attribute__ ( (stdcall) )

#       else

#           define AC_DECLSPEC_CALL_CDECL 
#           define AC_DECLSPEC_CALL_FAST_CALL 
#           define AC_DECLSPEC_CALL_STDCALL 

#       endif

#   endif 

#   define AC_DECLSPEC_ALIGN( a ) __attribute__ ( (aligned( a )) )
#   define AC_DECLSPEC_PACKED __attribute__ ( (packed) )
#   define AC_DECLSPEC_MALLOC __attribute__ ( (malloc) )
#   define AC_DECLSPEC_UNUSED __attribute__ ( (unused) )
#   define AC_DECLSPEC_NORET __attribute__ ( (noreturn) )


#   if defined ( AC_BUILD_OS_UNDER_WINDOWS ) || \
       defined ( AC_BUILD_OS_WINDOWS )\

#       define AC_DECLSPEC_API_IMPORT __attribute__ ( (dllimport) )
#       define AC_DECLSPEC_API_EXPORT __attribute__ ( (dllexport) )

#   else

#       define AC_DECLSPEC_CTOR __attribute__ ( (constructor) )
#       define AC_DECLSPEC_DTOR __attribute__ ( (destructor) )

#   endif

#else
#   error AC_BUILD: MSVC++(6.0+) or GCC required!
#endif


#ifndef AC_DECLSPEC_API_IMPORT
#define AC_DECLSPEC_API_IMPORT extern
#endif


#ifndef AC_DECLSPEC_API_EXPORT
#define AC_DECLSPEC_API_EXPORT extern
#endif


#ifndef AC_DECLSPEC_CTOR
#define AC_DECLSPEC_CTOR 
#endif


#ifndef AC_DECLSPEC_DTOR
#define AC_DECLSPEC_DTOR 
#endif


#ifndef AC_UNUSED
#define AC_UNUSED( ac_macro_state ) (void)ac_macro_state
#endif


#ifndef AC_DECLSPEC_INLINE
#define AC_DECLSPEC_INLINE static AC_INLINE
#endif


#define AC_DECLSPEC_PACKED_ALIGN( ac_macro_align ) \
  AC_DECLSPEC_PACKED AC_DECLSPEC_ALIGN( ac_macro_align )


#define AC_DECLSPEC_PACKED_ALIGN_CACHE_LINE \
  AC_DECLSPEC_PACKED AC_DECLSPEC_ALIGN_CACHE_LINE


#define AC_BUILD_DBG_ASSERT( ac_macro_name, ac_macro_exp ) \
struct AC_DECLSPEC_UNUSED \
ac_build_dbg_## ac_macro_name ##_ \
{ \
  int test[( (ac_macro_exp) ) ? 1 : -1]; \
}




#ifdef __cplusplus
}
#endif


#endif