changeset 45:d85542c96791

Clean up the build some more, move platform specifics again.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 06 Aug 2013 00:23:45 +0300
parents f0073a47c31d
children a4a3700f9c96
files Makefile src/main.c src/midifile.c src/midifile.h src/mplatform.h src/platform.c src/platform.h
diffstat 7 files changed, 121 insertions(+), 206 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Tue Aug 06 00:04:37 2013 +0300
+++ b/Makefile	Tue Aug 06 00:23:45 2013 +0300
@@ -67,10 +67,9 @@
 TARGETS=demo.bin
 
 
-DEMO_OBJS=vertex-attribute.o vertex-buffer.o \
+DEMO_OBJS=platform.o vertex-attribute.o vertex-buffer.o \
 	texture-atlas.o texture-font.o mat4.o \
-	shader.o vector.o midifile.o \
-	midiutil.o main.o
+	shader.o vector.o midifile.o midiutil.o main.o
 
 LIBOGGPLAYER_OBJS= \
 	oggplayer.o open_close.o play.o \
--- a/src/main.c	Tue Aug 06 00:04:37 2013 +0300
+++ b/src/main.c	Tue Aug 06 00:23:45 2013 +0300
@@ -10,7 +10,7 @@
 #include <time.h>
 
 #include "bass.h"
-#include "mplatform.h"
+#include "platform.h"
 
 #include "freetype-gl.h"
 #include "vertex-buffer.h"
--- a/src/midifile.c	Tue Aug 06 00:04:37 2013 +0300
+++ b/src/midifile.c	Tue Aug 06 00:23:45 2013 +0300
@@ -21,12 +21,10 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include "mplatform.h"
+#include "midifile.h"
 #include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
-#include "midifile.h"
 
 
 /*
--- a/src/midifile.h	Tue Aug 06 00:04:37 2013 +0300
+++ b/src/midifile.h	Tue Aug 06 00:23:45 2013 +0300
@@ -2,7 +2,7 @@
 #define _MIDIFILE_H
 
 #include "midiinfo.h"           /* enumerations and constants for GM */
-#include "mplatform.h"
+#include "platform.h"
 
 
 /*
--- a/src/mplatform.h	Tue Aug 06 00:04:37 2013 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-#ifndef MPLATFORM_H
-#define MPLATFORM_H 1
-
-
-/* Some platform specifics
- */
-#if defined(_WIN32) || defined(_WIN64)
-#  define wcpncpy wcsncpy
-#  define wcpcpy  wcscpy
-#endif
-
-#ifndef  __APPLE__
-#include <malloc.h>
-#endif
-
-
-/* Sized integer types
- */
-#ifdef _WIN32
-#include <wtypes.h>
-typedef unsigned __int8 Uint8;
-typedef unsigned __int16 Uint16;
-typedef unsigned __int32 Uint32;
-typedef unsigned __int64 Uint64;
-#else
-#include <stdint.h>
-typedef uint8_t Uint8;
-typedef uint16_t Uint16;
-typedef uint32_t Uint32;
-typedef uint64_t Uint64;
-#endif
-
-
-/* Define a boolean type
- */
-#if !defined(FALSE) && !defined(TRUE) && !defined(BOOL)
-typedef enum { FALSE = 0, TRUE = 1 } BOOL;
-#endif
-
-#ifndef BOOL
-#  ifdef bool
-#    define BOOL bool
-#  else
-#    define BOOL int
-#  endif
-#endif
-
-
-/* Endianess swapping macros
- */
-#define DM_SWAP_16_LE_BE(value)    ((Uint16) (   \
-    (Uint16) ((Uint16) (value) >> 8) |      \
-    (Uint16) ((Uint16) (value) << 8)) )
-
-
-#define DM_SWAP_32_LE_BE(value) ((Uint32) (               \
-    (((Uint32) (value) & (Uint32) 0x000000ffU) << 24) | \
-    (((Uint32) (value) & (Uint32) 0x0000ff00U) <<  8) | \
-    (((Uint32) (value) & (Uint32) 0x00ff0000U) >>  8) | \
-    (((Uint32) (value) & (Uint32) 0xff000000U) >> 24)))
-
-
-/* Macros that swap only when needed ...
- */
-#if (BYTEORDER == BIG_ENDIAN)
-#  define DM_LE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value)
-#  define DM_LE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value)
-#  define DM_NATIVE_TO_LE16(value) DM_SWAP_16_LE_BE(value)
-#  define DM_NATIVE_TO_LE32(value) DM_SWAP_32_LE_BE(value)
-
-#  define DM_BE16_TO_NATIVE(value) ((Uint16) (value))
-#  define DM_BE32_TO_NATIVE(value) ((Uint32) (value))
-#  define DM_NATIVE_TO_BE16(value) ((Uint16) (value))
-#  define DM_NATIVE_TO_BE32(value) ((Uint32) (value))
-
-#elif (BYTEORDER == LIL_ENDIAN)
-
-#  define DM_LE16_TO_NATIVE(value) ((Uint16) (value))
-#  define DM_LE32_TO_NATIVE(value) ((Uint32) (value))
-#  define DM_NATIVE_TO_LE16(value) ((Uint16) (value))
-#  define DM_NATIVE_TO_LE32(value) ((Uint32) (value))
-
-#  define DM_BE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value)
-#  define DM_BE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value)
-#  define DM_NATIVE_TO_BE16(value) DM_SWAP_16_LE_BE(value)
-#  define DM_NATIVE_TO_BE32(value) DM_SWAP_32_LE_BE(value)
-
-#endif
-
-
-#endif // MPLATFORM_H
--- a/src/platform.c	Tue Aug 06 00:04:37 2013 +0300
+++ b/src/platform.c	Tue Aug 06 00:23:45 2013 +0300
@@ -1,65 +1,28 @@
-/* ============================================================================
- * Freetype GL - A C OpenGL Freetype engine
- * Platform:    Any
- * WWW:         http://code.google.com/p/freetype-gl/
- * ----------------------------------------------------------------------------
- * Copyright 2011,2012 Nicolas P. Rougier. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *  1. Redistributions of source code must retain the above copyright notice,
- *     this list of conditions and the following disclaimer.
- *
- *  2. 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.
- *
- * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''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 NICOLAS P. ROUGIER 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.
- *
- * The views and conclusions contained in the software and documentation are
- * those of the authors and should not be interpreted as representing official
- * policies, either expressed or implied, of Nicolas P. Rougier.
- * ============================================================================
- */
-#include <string.h>
 #include "platform.h"
 
+
 #if defined(_WIN32) || defined(_WIN64)
-
 #include <math.h>
 
-double round (float v)
+double round(float v)
 {
-	return floor(v+0.5f);
+    return floor(v + 0.5f);
 }
 
-// strndup() is not available on Windows
-char *strndup( const char *s1, size_t n)
-{
-	char *copy= (char*)malloc( n+1 );
-	memcpy( copy, s1, n );
-	copy[n] = 0;
-	return copy;
-};
-#endif 
+#endif
 
 
-// strndup() was only added in OSX lion
-#if defined(__APPLE__)
-char *strndup( const char *s1, size_t n)
+#if defined(__APPLE__) || defined(_WIN32) || defined(_WIN64) 
+
+char * strndup(const char *s, size_t n)
 {
-    char *copy = calloc( n+1, sizeof(char) );
-    memcpy( copy, s1, n );
-    return copy;
-};
+    char *result = malloc(n + 1);
+    if (result == NULL)
+        return NULL;
+    
+    memcpy(result, s, n);
+    result[n] = 0;
+    return result;
+}
+
 #endif
--- a/src/platform.h	Tue Aug 06 00:04:37 2013 +0300
+++ b/src/platform.h	Tue Aug 06 00:23:45 2013 +0300
@@ -1,69 +1,115 @@
-/* ============================================================================
- * Freetype GL - A C OpenGL Freetype engine
- * Platform:    Any
- * WWW:         http://code.google.com/p/freetype-gl/
- * ----------------------------------------------------------------------------
- * Copyright 2011,2012 Nicolas P. Rougier. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *  1. Redistributions of source code must retain the above copyright notice,
- *     this list of conditions and the following disclaimer.
- *
- *  2. 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.
- *
- * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''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 NICOLAS P. ROUGIER 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.
- *
- * The views and conclusions contained in the software and documentation are
- * those of the authors and should not be interpreted as representing official
- * policies, either expressed or implied, of Nicolas P. Rougier.
- * ============================================================================
- */
-#ifndef __PLATFORM_H__
-#define __PLATFORM_H__
+#ifndef MPLATFORM_H
+#define MPLATFORM_H 1
 
 #include <stdlib.h>
+#ifndef  __APPLE__
+#include <malloc.h>
+#endif
 
-//-------------------------------------------------
-// stdint.h is not available on VS2008 or lower
-//-------------------------------------------------
-#ifdef _MSC_VER
-typedef __int32 int32_t;
-typedef unsigned __int32 uint32_t;
-typedef __int64 int64_t;
-typedef unsigned __int64 uint64_t;
+
+/* Some platform specifics
+ */
+#if defined(_WIN32) || defined(_WIN64)
+#  define wcpncpy wcsncpy
+#  define wcpcpy  wcscpy
+#endif
+
+
+/* Sized integer types
+ */
+#ifdef _WIN32
+#include <wtypes.h>
+typedef unsigned __int8 Uint8;
+typedef unsigned __int16 Uint16;
+typedef unsigned __int32 Uint32;
+typedef unsigned __int64 Uint64;
+
+typedef unsigned __int8 int8_t;
+typedef unsigned __int16 int16_t;
+typedef unsigned __int32 int32_t;
+typedef unsigned __int64 int64_t;
 #else
 #include <stdint.h>
-#endif // _MSC_VER
+typedef uint8_t Uint8;
+typedef uint16_t Uint16;
+typedef uint32_t Uint32;
+typedef uint64_t Uint64;
+#endif
+
+
+/* Define a boolean type
+ */
+#if !defined(FALSE) && !defined(TRUE) && !defined(BOOL)
+typedef enum { FALSE = 0, TRUE = 1 } BOOL;
+#endif
+
+#ifndef BOOL
+#  ifdef bool
+#    define BOOL bool
+#  else
+#    define BOOL int
+#  endif
+#endif
+
+
+/* Endianess swapping macros
+ */
+#define DM_SWAP_16_LE_BE(value)    ((Uint16) (   \
+    (Uint16) ((Uint16) (value) >> 8) |      \
+    (Uint16) ((Uint16) (value) << 8)) )
+
+
+#define DM_SWAP_32_LE_BE(value) ((Uint32) (               \
+    (((Uint32) (value) & (Uint32) 0x000000ffU) << 24) | \
+    (((Uint32) (value) & (Uint32) 0x0000ff00U) <<  8) | \
+    (((Uint32) (value) & (Uint32) 0x00ff0000U) >>  8) | \
+    (((Uint32) (value) & (Uint32) 0xff000000U) >> 24)))
+
+
+/* Macros that swap only when needed ...
+ */
+#if (BYTEORDER == BIG_ENDIAN)
+#  define DM_LE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value)
+#  define DM_LE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value)
+#  define DM_NATIVE_TO_LE16(value) DM_SWAP_16_LE_BE(value)
+#  define DM_NATIVE_TO_LE32(value) DM_SWAP_32_LE_BE(value)
+
+#  define DM_BE16_TO_NATIVE(value) ((Uint16) (value))
+#  define DM_BE32_TO_NATIVE(value) ((Uint32) (value))
+#  define DM_NATIVE_TO_BE16(value) ((Uint16) (value))
+#  define DM_NATIVE_TO_BE32(value) ((Uint32) (value))
+
+#elif (BYTEORDER == LIL_ENDIAN)
+
+#  define DM_LE16_TO_NATIVE(value) ((Uint16) (value))
+#  define DM_LE32_TO_NATIVE(value) ((Uint32) (value))
+#  define DM_NATIVE_TO_LE16(value) ((Uint16) (value))
+#  define DM_NATIVE_TO_LE32(value) ((Uint32) (value))
+
+#  define DM_BE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value)
+#  define DM_BE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value)
+#  define DM_NATIVE_TO_BE16(value) DM_SWAP_16_LE_BE(value)
+#  define DM_NATIVE_TO_BE32(value) DM_SWAP_32_LE_BE(value)
+
+#endif
+
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#ifdef __APPLE__
-    /* strndup() was only added in OSX lion */
-    char * strndup( const char *s1, size_t n);
-#elif defined(_WIN32) || defined(_WIN64) 
-    /* does not exist on windows */
-    char * strndup( const char *s1, size_t n);
-//    double round (float v);
-#    pragma warning (disable: 4244) // suspend warnings
-#endif // _WIN32 || _WIN64
+#if defined(__APPLE__) || defined(_WIN32) || defined(_WIN64) 
+char * strndup(const char *s, size_t n);
+#    pragma warning (disable: 4244)
+#endif
+
+#if defined(_WIN32) || defined(_WIN64) 
+double round(float v);
+#endif
 
 #ifdef __cplusplus
 }
 #endif // __cplusplus
 
-#endif /* __PLATFORM_H__ */
+
+#endif // MPLATFORM_H