#ifndef	V_CONFIG_H
#define	V_CONFIG_H

/*
 * Disable implementation - specific extensions.
 */
#define	STRICT_ANSI

/*
 * -----------------------------------------------------------------------
 * Determine architecture and platform.
 * Currently only WIN32 + x86 and LINUX + x86 are supported.
 */
#ifndef __INTEL__
#define __INTEL__
#endif	/* __INTEL__ */

#if     defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || \
		defined(_MSC_VER) || defined(__BORLANDC__) || \
		defined(__CYGWIN32__) || defined(__WATCOMC__)
#ifndef __WIN32__
#define __WIN32__
#endif
#elif   defined(__ELF__) || defined(__linux) || defined(unix) || \
		defined(UNIX)
#ifndef __UNIX__
#define __UNIX__
#endif
#else
#error	Unsupported platform.
#endif

/*
 * -----------------------------------------------------------------------
 * Platform-specific config switches
 */
#ifdef	__WIN32__

/*
 *	Uncomment next line if you *HATE* MustDie9x (i hate it ... )
 *	Note: this will make LibV COMPLETELY unoperational on 95 / 98.
 *	WindowsME not tested.
#define	MUST_DIE_DEAD
 */

/*
 * Uncomment next line to enable NT native console APIs.
 * Console support seems to be broken under MustDie.
#define		NT_CONSOLE
 */

/*
 * Platform-specific features
 */

/*
 * Uncomment next line to enable native Win32 GDI support for metafiles.
 * Notes:
 *  - native support is several times slower than emulation;
 *	- LibV emulate only very small subset of GDI functions;
 *  - LibV doesn't expose GDI - like functions;
 *  - If GDI emulation disabled, than under WIN32 one can get DC of
 *    metafile (metaGetHandleNP()) and pass it to any GDI function.
#define	CONFIG_USE_NATIVE_METAFILE_API
 */

/*
 * Uncomment next line to enable GDI helper object for raster data.
 */
#define	CONFIG_WIN32_DIBOBJECT

/*
 * For broken VIA chipsets
#define	CONFIG_LARGE_WAVE_INPUT_BUFFER
 */

#endif	/* __WIN32__ */

#ifdef	__UNIX__

/*
 * Uncomment next line to enable EsounD sound output support.
 */
#define CONFIG_ESOUND

#endif	/* __UNIX__ */

/*
 * Determine default path style and delimiter.
 */
#if		defined(__UNIX__) || defined(__CYGWIN32__)
#define	RIGHT_SLASHED
#endif	/* !defined(__UNIX__) && !defined(__CYGWIN32__) */

/*
 * Under linux, prevent including ANSI - incompliant asm/io.h
 * FIXME: is this correct ?
 */
#ifdef		__linux
#define		_ASM_IO_H
#endif		/* __linux */

/*
 * 'Endian' macros.
 * Most UN*Ces (but NT) defines it.
 */
#ifndef		__BIG_ENDIAN
#define		__BIG_ENDIAN	4321
#endif		/* __BIG_ENDIAN */
#ifndef		__LITTLE_ENDIAN
#define		__LITTLE_ENDIAN	1234
#endif		/* __LITTLE_ENDIAN */

#if			defined(__INTEL__) || defined(__ALPHA__)
#ifndef		__BYTE_ORDER
#define		__BYTE_ORDER	__LITTLE_ENDIAN
#endif		/* __BYTE_ORDER */
#else		/* defined(__INTEL__) || (__ALPHA__) */
#ifndef		__BYTE_ORDER
#define		__BYTE_ORDER	__BIG_ENDIAN
#endif		/* __BYTE_ORDER */
#endif		/* ! (defined(__INTEL__) || (__ALPHA__)) */

/*
 * Next macros implements swaps for big-endian and do nothing
 * for little-endian architectures.
 */
#if			__BYTE_ORDER == __LITTLE_ENDIAN

#ifndef		LITTLE_SHORT
#define		LITTLE_SHORT(sw)	(sw)
#endif		/* LITTLE_SHORT */

#ifndef		LITTLE_LONG
#define		LITTLE_LONG(lw)		(lw)
#endif		/* LITTLE_LONG */

#elif		__BYTE_ORDER == __BIG_ENDIAN

/*
 * Note !
 * This is cut-and-paste from linux/byteorder/swab.h
 *
 * Byte-swapping, independently from CPU endianness
 *	swabXX[ps]?(foo)
 *
 * Francois-Rene Rideau <fare@tunes.org> 19971205
 *    separated swab functions from cpu_to_XX,
 *    to clean up support for bizarre-endian architectures.
 *
 * See asm-i386/byteorder.h and suches for examples of how to provide
 * architecture-dependent optimized versions
 *
 */
#ifndef	LITTLE_SHORT
#define LITTLE_SHORT(x) \
		((u16_t)( \
		(((u16_t)(x) & (u16_t)0x00ffU) << 8) | \
		(((u16_t)(x) & (u16_t)0xff00U) >> 8) ))
#endif	/* LITTLE_SHORT */

#ifndef	LITTLE_LONG
#define LITTLE_LONG(x) \
		((u32_t)( \
		(((u32_t)(x) & (u32_t)0x000000ffUL) << 24) | \
		(((u32_t)(x) & (u32_t)0x0000ff00UL) <<  8) | \
		(((u32_t)(x) & (u32_t)0x00ff0000UL) >>  8) | \
		(((u32_t)(x) & (u32_t)0xff000000UL) >> 24) ))
#endif	/* LITTLE_LONG */

#endif	/* __BYTE_ORDER == __BIG_ENDIAN */

/*
 * There are a lot mutual incompatibilities with int64 type,
 * so we are better disabple it at all.
 */
#if		defined(STRICT_ANSI) || defined(__WATCOMC__) || defined(__GNUC__)
#define	INT64BROKEN
#endif	/* __WATCOMC__ ... */

/*
 * Default calling convention is 'stdcall' for NT, 'cdecl' for UNIX | GNUC
 */
#if		defined(__WIN32__) && !defined(__GNUC__)
#define	V_CALL	__stdcall
#else	/* __GNUC__ || !__WIN32__ */
#define	V_CALL	/* default calling convention */
#endif	/* __GNUC__ */

/*
 * Structure packing macro for GNUC, stub for other compilers.
 * For non-GCC's, packing must be handled in pack0.h / ppack.h.
 */
#ifndef	ATTRIBUTE_PACKED
#ifndef	__GNUC__
#define	ATTRIBUTE_PACKED
#else	/* __GNUC__ */
#define	ATTRIBUTE_PACKED	__attribute__((packed))
#endif	/* __GNUC__ */
#endif	/* !ATTRIBUTE_PACKED */

/*
 * Macro prefix to export functions.
 * NOTE: dynamic linking currently supported only under Win32.
 */
#ifdef		BUILD_DLL
#define		EXPORT				__declspec(dllexport)
#else		/* !BUILD_DLL */
#define		EXPORT
#endif		/* !BUILD_DLL */

#define		V_LOCAL			static
#define		V_GLOBAL		EXPORT	V_CALL

/*
 * CBuilder refuses to import function with variable set of parameters
 * if such function declared with 'stdcall' calling convention.
 */
#if			defined(BCB_COMPAT) || defined(__BORLANDC__)
#define		V_GLOBAL_VA		EXPORT	__cdecl
#else		/* !BCB_COMPAT */
#define		V_GLOBAL_VA		V_GLOBAL
#endif		/* BCB_COMPAT */

/*
 * Workaround for MS cl.exe + Borland tlink32.exe.
 * FIXME: is this still needed ?
 */
#if		defined(BUILD_DLL) && defined(BCB_COMPAT) && !defined(__BORLANDC__)
#define	conPrintf	_conPrintf
#define	conlPrintf	_conlPrintf
#define	filePrintf	_filePrintf
#define	vglPrintf	_vglPrintf
#endif

/*
 * This hack allows us to use UNIX Makefile with CYGWIN32.
 */
#ifdef	__CYGWIN32__
#ifdef	__UNIX__
#undef	__UNIX__
#endif	/* __UNIX__ */
#endif	/* __CYGWIN32__ */

/*
 * ANSI version of some functions HAS underscores; but GNU libc and
 * all Win32 RTLs (except MS Visual C RTL) uses functions without them.
 */
#ifndef		_MSC_VER
#define		_stricmp	strcmpi
#define		_chdir		chdir
#define 	_mkdir      mkdir
#define		_getcwd		getcwd
#endif		/* !_MSC_VER */

/*
 * GNU libc has strncasecmp(); MS / BORLAND RTL has strnicmp.
 * For WATCOM C we implement strncasecmp() in TAL/string.c.
 */
#if			!defined(__UNIX__) && !defined(__GNUC__) && \
			!defined(__WATCOMC__)
#define		strcasecmp		_stricmp
#define		strncasecmp		_strnicmp
#endif		/* !defined(__UNIX__) ... */

/*
 * -----------------------------------------------------------------------
 * Data type switches
 */
/*
 * Uncomment next line to set base floating point type to 'double'
#define DOUBLEVEC
 */

/*
 * Uncomment next line to set floating point type for scientific
 * functions to 'double'
#define	MATRIX_DOUBLE
 */

/*
 * -----------------------------------------------------------------------
 * Basic features
 */

/*
 * Uncomment next line, if you want LibV to:
 *  - perform a lot of validity checks;
 *  - emit error descriptions, warnings, diagnostic and trace messages
 *    to console.
 * FIXME: to be honest, you CAN NOT currently compile LibV without
 * CHECKED_BUILD defined (moreover, and i've never tried to do that).
 */
#define	CHECKED_BUILD

/*
 * Uncomment next line to turn on hash-based dictionary for tracking
 * memory allocations; this slows allocation code about 1.5 times.
 */
#define	MALLOC_DEBUG

/*
 * -----------------------------------------------------------------------
 * Code generation
 */

/*
 * No macros for math & base algorithms: generate code instead.
 *
 * TODO: rename these stuff, test implementation of macros, etc.
 */
#define	FIFO_NO_MACRO
#define	STACK_NO_MACRO
#define	MATH_NO_MACRO
#define	VECTOR_NO_MACRO
#define	MATRIX_NO_MACRO
#define	PLANE_NO_MACRO

/*
 * -----------------------------------------------------------------------
 * Abstract data types
 * (currently ignored, TODO)
 */
#define	CONFIG_U8_STACK
#define	CONFIG_VP_STACK
#define	CONFIG_BLOCK_STACK
#define	CONFIG_U8_FIFO
#define	CONFIG_BLOCK_FIFO
#define	CONFIG_BINARY_TREE
#define	CONFIG_NWAY_TREE
#define	CONFIG_LINUX_LIST

/*
 * -----------------------------------------------------------------------
 * Key features
 */

/*
 * Wrappers for kernel objects
 * (currently ignored, TODO)
 */
#define	CONFIG_MUTEX
#define	CONFIG_THREAD
#define	CONFIG_COND
/*
 * VFS & IO
 * (currently ignored, TODO)
 */
#define	CONFIG_VFS
#define	CONFIG_MAPPED_IO
#define	CONFIG_IO_USES_NATIVE_PATH
#define	CONFIG_VFS_DIRECTORY_ENUMERATOR
#define	CONFIG_LFS_DIRECTORY_ENUMERATOR
/*
 * Virtual filesystems
 */
#define	CONFIG_VFS_PAKFS
#define	CONFIG_VFS_WADFS
#define	CONFIG_VFS_ZIPFS

#if		defined(__WIN32__) && !defined(__WATCOMC__) && !defined(__CYGWIN32__)
#define	CONFIG_VFS_PEFS
#endif	/* defined(__WIN32__) ... */

/*
 * Device drivers
 * (currently ignored, TODO)
 */
#define	CONFIG_DEV_WAVE_IN
#define	CONFIG_DEV_WAVE_OUT
#define	CONFIG_DEV_COMM


/*
 * TODO
 */

/*
 * Utility objects
 * (currently ignored, TODO)
 */

/* Flexible, multifunction scanner */
#define	CONFIG_SCANNER

/*
 *	Comment next line to exclude MP3 decompressor class.
 *	FIXME: rewrite makefiles !
 */
#define	CONFIG_AUDIO_MP3

/*
 *	Comment next line to exclude transparent .gz file decompressing
 *	FIXME: rewrite makefiles !
 */
#define	CONFIG_COMPRESSION_ZLIB


/*
 * Uncomment next line to enable native Win32 clipboard support.
 * Enabling clipboard support extends file namespace of metafile
 * and bitmap output functions with predefined path '//./clipboard'.
 */
#define	CONFIG_CLIPBOARD

/*
 * -----------------------------------------------------------------------
 * Support for different data formats
 */

/*
 * Comment lines below to exclude support for corresponding
 * raster format.
 */
#define	CONFIG_RASTER_TARGA
#define	CONFIG_RASTER_BITMAP
#define	CONFIG_RASTER_JPEG

/*
 * Comment next line to exclude support for Windows 3.1
 * placeable metafiles.
 */
#define CONFIG_METAFILE

/*
 * -----------------------------------------------------------------------
 * OpenGL helper function
 */

/* Base functinality */
#define CONFIG_VGL
/* Helper functions for OpenGL view tranformation */
#define CONFIG_CAMERA_CONTROL

/*
 * Comment next line to exclude precompiled OpenGL font
 */
#define	CONFIG_GL_PRECOMPILED_FONT

/*
 * -----------------------------------------------------------------------
 * The rest of config file are meaningful only for LibV itself.
 */
#ifdef	__LIBV__

#if	defined(__WIN32__) && defined(BUILD_DLL)
#define HAVE_NSP
#endif

/*
 * Format buffer size for printf()-like functions
 * TODO: snprintf() - like function + u8_stack_t; eliminate
 * limits such MAX_FORMAT_BUFFER at all.
 */
#define	MAX_FORMAT_BUFFER			512

#ifdef	CHECKED_BUILD
/*
 * Size of buffer which is returned by some strXXX functions when
 * caller requests pointer to string which can't be obtained.
 */
#define	STRING_GUARD_SIZE			512
#endif	/* CHECKED_BUILD */

/*
 * Force some dirty tricks for cyrillic text support
 */
#define	CONFIG_CYRILLIC_HACKS

#endif	/* __LIBV__ */

#endif	/* V_CONFIG_H */
