/***************************************************************
                            dcommon.d

                   Various platform configuration.
 ***************************************************************/

module allegro.platform.dcommon;

version (Tango) {
   import tango.stdc.stdint;
   public import tango.stdc.errno : EDOM;
}
else {
   import std.stdint;
}

import allegro.internal.dversion;


/**********************************************************
 *                 Platform descriptions                  *
 *                                                        *
 *            These correspond to the 'Describe this      *
 *            platform' stuff in C-Allegro's              *
 *            allegro/platform/*.h.                       *
 **********************************************************/

version (linux) version = Unix;  // DMD doesn't define Unix
version (Posix) version = Unix;
version (darwin) version = MacOSX;
version (OSX) version = MacOSX;


version (Windows) {
   const string ALLEGRO_PLATFORM_STR = "Windows";
   enum : bool {
      ALLEGRO_VRAM_SINGLE_SURFACE = false,
      ALLEGRO_CONSOLE_OK          = false,
      ALLEGRO_MULTITHREADED       = true,
      ALLEGRO_LFN                 = true
   }
}
else version (MacOSX) {  // based on allegro/platform/alosxcfg.h
   const string ALLEGRO_PLATFORM_STR = "MacOS X";
   enum : bool {
      ALLEGRO_VRAM_SINGLE_SURFACE = false,
      ALLEGRO_CONSOLE_OK          = true,
      ALLEGRO_MULTITHREADED       = true,
      ALLEGRO_LFN                 = true
   }
}
else version (Unix) {  // based on allegro/platform/alucfg.h
   const string ALLEGRO_PLATFORM_STR = "Unix";
   enum : bool {
      ALLEGRO_VRAM_SINGLE_SURFACE = true,
      ALLEGRO_CONSOLE_OK          = true,
      ALLEGRO_MULTITHREADED       = true,
      ALLEGRO_LFN                 = true
   }
}
else {
   static assert(0, "No description for this platform, please supply one.");
}


// Not sure if it's necessary to support setting ALLEGRO_NO_ASM on the
// command line (-version=ALLEGRO_NO_ASM), but why not.
version (X86) {
   // We have assembly for this platform.
}
else {
   version = ALLEGRO_NO_ASM;
}

version (ALLEGRO_NO_ASM) {
   enum : bool { ALLEGRO_NO_ASM = true }
}
else {
   enum : bool { ALLEGRO_NO_ASM = false }
}


/********************************************************
 *                Other configuration.                  *
 ********************************************************/

// Phobos doesn't define EDOM, which is found in errno.h in C.
version (Tango) {
}
else {
   // This should be correct for Windows, linux, and OS X.
   enum { EDOM = 33 }
}


// al_long has to be set to a type that matches the C compiler's long size,
// in order to be binary compatible with the Allegro library itself.
version (Windows) {
   // Windows x64 keeps the size of long as 32 bits.
   alias int al_long;
   alias uint al_ulong;
}
else {
   // I hope this is a safe assumption.
   alias intptr_t al_long;
   alias uintptr_t al_ulong;
}
