Commits

wahrhaft committed bfe79ce Merge

Merged in ecsv/mupen64plus-video-glide64-fixes (pull request #6)

MinGW/Cross compilation and related fixes

Comments (0)

Files changed (6)

projects/unix/Makefile

 # Makefile for Glide64 plugin in Mupen64Plus
 
 # detect operating system
-UNAME = $(shell uname -s)
+UNAME ?= $(shell uname -s)
 OS := NONE
 ifeq ("$(UNAME)","Linux")
   OS = LINUX
   SO_EXTENSION = so
   SHARED = -shared
 endif
+ifeq ("$(patsubst MINGW%,MINGW,$(UNAME))","MINGW")
+  OS = MINGW
+  SO_EXTENSION = dll
+  SHARED = -shared
+  PIC = 0
+endif
 ifeq ("$(OS)","NONE")
   $(error OS type "$(UNAME)" not supported.  Please file bug report at 'http://code.google.com/p/mupen64plus/issues')
 endif
   NO_ASM := 1
   $(warning Architecture "$(HOST_CPU)" not officially supported.')
 endif
+ifneq ("$(filter arm%,$(HOST_CPU))","")
+  ifeq ("$(filter arm%b,$(HOST_CPU))","")
+    CPU := ARM
+    ARCH_DETECTED := 32BITS
+    PIC ?= 1
+    NO_ASM := 1
+    $(warning Architecture "$(HOST_CPU)" not officially supported.')
+  endif
+endif
 ifeq ("$(CPU)","NONE")
   $(error CPU type "$(HOST_CPU)" not supported.  Please file bug report at 'http://code.google.com/p/mupen64plus/issues')
 endif
 
 # base CFLAGS, LDLIBS, and LDFLAGS
 OPTFLAGS ?= -O3
-CFLAGS += $(OPTFLAGS) -Wall -ffast-math -msse -fno-strict-aliasing -fvisibility=hidden -I../../src -I../../src/wrapper -DGCC
+WARNFLAGS ?= -Wall
+CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -fvisibility=hidden -I../../src -I../../src/wrapper -DGCC
 CXXFLAGS += -fvisibility-inlines-hidden
 LDFLAGS += $(SHARED)
 
+# default configuration programs
+SDL_CONFIG = $(CROSS_COMPILE)sdl-config
+PKG_CONFIG = $(CROSS_COMPILE)pkg-config
+
+ifeq ($(CPU), X86)
+  CFLAGS += -msse
+endif
+
 # Since we are building a shared library, we must compile with -fPIC on some architectures
 # On 32-bit x86 systems we do not want to use -fPIC because we don't have to and it has a big performance penalty on this arch
 ifeq ($(PIC), 1)
   LDLIBS += -ldl
 endif
 ifeq ($(OS), OSX)
+  # Select the proper SDK
+  # Also, SDKs are stored in a different location since XCode 4.3
+  OSX_SDK ?= $(shell sw_vers -productVersion | cut -f1 -f2 -d .)
+  OSX_XCODEMAJ = $(shell xcodebuild -version | grep '[0-9]*\.[0-9]*' | cut -f2 -d ' ' | cut -f1 -d .)
+  OSX_XCODEMIN = $(shell xcodebuild -version | grep '[0-9]*\.[0-9]*' | cut -f2 -d ' ' | cut -f2 -d .)
+  OSX_XCODEGE43 = $(shell echo "`expr $(OSX_XCODEMAJ) \>= 4``expr $(OSX_XCODEMIN) \>= 3`")
+  ifeq ($(OSX_XCODEGE43), 11)
+    OSX_SYSROOT := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
+  else
+    OSX_SYSROOT := /Developer/SDKs
+  endif
+
   ifeq ($(CPU), X86)
     ifeq ($(ARCH_DETECTED), 64BITS)
-      CFLAGS += -pipe -arch x86_64 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk
-      LDFLAGS += -bundle -framework OpenGL -arch x86_64
+      CFLAGS += -pipe -arch x86_64 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk
+      LDFLAGS += -bundle -arch x86_64
       LDLIBS += -ldl
     else
-      CFLAGS += -pipe -mmmx -msse -fomit-frame-pointer -arch i686 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk
-      LDFLAGS += -bundle -framework OpenGL -arch i686
+      CFLAGS += -pipe -mmmx -msse -fomit-frame-pointer -arch i686 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk
+      LDFLAGS += -bundle -arch i686
       LDLIBS += -ldl
     endif
   endif
   LDLIBS += -lc
 endif
 
-# test for essential build dependencies
-ifeq ($(shell which pkg-config 2>/dev/null),)
-  $(error pkg-config not found)
+# search for OpenGL libraries
+GL_LIBS=
+ifeq ($(OS), OSX)
+  GL_LIBS = -framework OpenGL
 endif
-ifeq ($(shell pkg-config --modversion gl 2>/dev/null),)
-  $(error No OpenGL development libraries found!)
+ifeq ($(OS), MINGW)
+  GL_LIBS = -lopengl32
 endif
-CFLAGS += $(shell pkg-config --cflags gl)
-LDLIBS += $(shell pkg-config --libs gl)
+ifeq ("$(GL_LIBS)", "")
+  ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null),)
+    $(error $(PKG_CONFIG) not found)
+  endif
+  ifeq ($(shell $(PKG_CONFIG) --modversion gl 2>/dev/null),)
+    $(error No OpenGL development libraries found!)
+  endif
+  CFLAGS += $(shell $(PKG_CONFIG) --cflags gl)
+  GL_LIBS = $(shell $(PKG_CONFIG) --libs gl)
+endif
+LDLIBS += $(GL_LIBS)
 
 # test for presence of SDL
-ifeq ($(shell which sdl-config 2>/dev/null),)
+ifeq ($(shell which $(SDL_CONFIG) 2>/dev/null),)
   $(error No SDL development libraries found!)
 endif
 ifeq ($(OS),FREEBSD)
-    CFLAGS  += $(shell sdl-config --cflags)
-    LDLIBS += $(shell sdl-config --libs)
+    CFLAGS  += $(shell $(SDL_CONFIG) --cflags)
+    LDLIBS += $(shell $(SDL_CONFIG) --libs)
 endif
 ifeq ($(OS),OSX)
-    CFLAGS  += $(shell sdl-config --cflags)
+    CFLAGS  += $(shell $(SDL_CONFIG) --cflags)
     # sdl-config on mac screws up when we're trying to build a library and not an executable
     # SDL 1.3 is supposed to fix that, if it's ever released
     LDLIBS += -L/usr/local/lib -lSDL -Wl,-framework,Cocoa
 endif
 ifeq ($(OS),LINUX)
-    CFLAGS  += $(shell sdl-config --cflags)
-    LDLIBS += $(shell sdl-config --libs)
+    CFLAGS  += $(shell $(SDL_CONFIG) --cflags)
+    LDLIBS += $(shell $(SDL_CONFIG) --libs)
+endif
+ifeq ($(OS), MINGW)
+  CFLAGS += $(shell $(SDL_CONFIG) --cflags)
+  LDLIBS += $(shell $(SDL_CONFIG) --libs)
 endif
 
 # set mupen64plus core API header path
 endif
 
 # set base program pointers and flags
-CC       ?= gcc
-CXX      ?= g++
+CC        = $(CROSS_COMPILE)gcc
+CXX       = $(CROSS_COMPILE)g++
 RM       ?= rm -f
 INSTALL  ?= install
 MKDIR ?= mkdir -p
 endif
 
 SRCDIR = ../../src
-OBJDIR = _obj
+OBJDIR = _obj$(POSTFIX)
 
 # list of source files to compile
 SOURCE = \
 	$(SRCDIR)/TexBuffer.cpp \
 	$(SRCDIR)/TexCache.cpp \
 	$(SRCDIR)/Util.cpp \
-	$(SRCDIR)/osal_dynamiclib_unix.c \
 	$(SRCDIR)/rdp.cpp \
 	$(SRCDIR)/wrapper/2xsai.cpp \
 	$(SRCDIR)/wrapper/combiner.cpp \
 	$(SRCDIR)/wrapper/hq2x.cpp \
 	$(SRCDIR)/wrapper/hq4x.cpp \
 	$(SRCDIR)/wrapper/main.cpp \
-	$(SRCDIR)/wrapper/textures.cpp 
+	$(SRCDIR)/wrapper/textures.cpp
+
+ifeq ($(OS),MINGW)
+SOURCE += $(SRCDIR)/osal_dynamiclib_win32.c
+else
+SOURCE += $(SRCDIR)/osal_dynamiclib_unix.c
+endif
 
 
 
 $(shell $(MKDIR) $(OBJDIRS))
 
 # build targets
-TARGET = mupen64plus-video-glide64.$(SO_EXTENSION)
+TARGET = mupen64plus-video-glide64$(POSTFIX).$(SO_EXTENSION)
 
 targets:
 	@echo "Mupen64plus-video-glide64 N64 Graphics plugin makefile. "
 	@echo "    NO_ASM=1      == build without inline assembly code (x86 MMX/SSE)"
 	@echo "    APIDIR=path   == path to find Mupen64Plus Core headers"
 	@echo "    OPTFLAGS=flag == compiler optimization (default: -O3)"
+	@echo "    WARNFLAGS=flag == compiler warning levels (default: -Wall)"
 	@echo "    PIC=(1|0)     == Force enable/disable of position independent code"
+	@echo "    POSTFIX=name  == String added to the name of the the build (default: '')"
 	@echo "  Install Options:"
 	@echo "    PREFIX=path   == install/uninstall prefix (default: /usr/local)"
 	@echo "    SHAREDIR=path == path to install shared data files (default: PREFIX/share/mupen64plus)"
 	$(RM) "$(DESTDIR)$(SHAREDIR)/Glide64.ini"
 
 clean:
-	$(RM) -r ./_obj $(TARGET)
+	$(RM) -r $(OBJDIR) $(TARGET)
 
 rebuild: clean all
 
 
 CXXFLAGS += $(CFLAGS)
 ifeq ($(LTO), 1)
-  CFLAGS += -flto
-  CXXFLAGS += -flto
-  LDFLAGS += -fuse-linker-plugin $(CXXFLAGS)
+  CFLAGS += -flto -ffunction-sections -fdata-sections
+  CXXFLAGS += -flto -ffunction-sections -fdata-sections
+  LDFLAGS += -fuse-linker-plugin -Wl,--gc-sections $(CXXFLAGS)
 endif
 
 # standard build rules
 #include "m64p_config.h"
 #include "m64p_vidext.h"
 #include "3dmath.h"
+#if !defined(NO_ASM)
 #include <xmmintrin.h>
+#endif
 
 void calc_light (VERTEX *v)
 {
 #ifdef WIN32
 #define LOGKEY      VK_LCONTROL     // this key
 #else
-#include <SDL/SDL.h>
+#include <SDL.h>
 #define LOGKEY KMOD_LCTRL
 inline int GetAsyncKeyState(int key) {
   return (SDL_GetModState() & key) != 0;
   for (i=0; i<0x200; i++)
   {
     // cur = ~*(data++), byteswapped
-#if !defined(__GNUC__) && !defined(NO_ASM)
-    __asm {
-      mov eax, dword ptr [data]
-        mov ecx, dword ptr [eax]
-        add eax, 4
-        mov dword ptr [data], eax
-        not ecx
-        bswap ecx
-        mov dword ptr [cur],ecx
-    }
-#elif !defined(NO_ASM)
-     asm volatile ("bswap %[cur]"
-           : [cur] "=g"(cur)
-           : "[cur]"(~*(data++))
-           );
+#if !defined(__GNUC__)
+     cur = _byteswap_ulong(~*(data++));
+#else
+     cur = __builtin_bswap32(~*(data++));
 #endif
 
     for (b=0x80000000; b!=0; b>>=1)
 
 int drawFlag = 1;	// draw flag for rendering callback
 
-#if defined(WIN32) || defined(NO_ASM)
-  #define BYTESWAP1(s1) s1 = ((s1 & 0xff) << 24) | ((s1 & 0xff00) << 8) | ((s1 & 0xff0000) >> 8) | ((s1 & 0xff000000) >> 24);
-  #define BYTESWAP2(s1,s2) s1 = ((s1 & 0xff) << 24) | ((s1 & 0xff00) << 8) | ((s1 & 0xff0000) >> 8) | ((s1 & 0xff000000) >> 24); \
-  s2 = ((s2 & 0xff) << 24) | ((s2 & 0xff00) << 8) | ((s2 & 0xff0000) >> 8) | ((s2 & 0xff000000) >> 24);
+#if defined(__GNUC__)
+  #define bswap32(x) __builtin_bswap32(x)
+#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
+  #include <stdlib.h>
+  #define bswap32(x) _byteswap_ulong(x)
 #else
-  #define BYTESWAP1(s1) asm volatile (" bswap %0; " : "+r" (s1) : :);
-  #define BYTESWAP2(s1,s2) asm volatile (" bswap %0; bswap %1; " : "+r" (s1), "+r" (s2) : :);
+static inline uint32_t bswap32(uint32_t val)
+{
+        return (((val & 0xff000000) >> 24) |
+                ((val & 0x00ff0000) >>  8) |
+                ((val & 0x0000ff00) <<  8) |
+                ((val & 0x000000ff) << 24));
+}
 #endif
 
 // global strings
         int *pSrc = (int *) ((uintptr_t) gfx.RDRAM + SrcOffs);
         for (unsigned int x = 0; x < cnt; x++)
         {
-            int s1 = *pSrc++;
-            int s2 = *pSrc++;
-            BYTESWAP2(s1, s2)
+            int s1 = bswap32(*pSrc++);
+            int s2 = bswap32(*pSrc++);
             *pDst++ = s1;
             *pDst++ = s2;
         }
         // set source pointer to 4-byte aligned RDRAM location before the start
         int *pSrc = (int *) ((uintptr_t) gfx.RDRAM + (SrcOffs & 0xfffffffc));
         // do the first partial 32-bit word
-        int s0 = *pSrc++;
-        BYTESWAP1(s0)
+        int s0 = bswap32(*pSrc++);
         for (int x = 0; x < rem; x++)
             s0 >>= 8;
         for (int x = 4; x > rem; x--)
             s0 >>= 8;
         }
         // do one full 32-bit word
-        s0 = *pSrc++;
-        BYTESWAP1(s0)
+        s0 = bswap32(*pSrc++);
         *pDst++ = s0;
         // do 'cnt-1' 64-bit dwords
         for (unsigned int x = 0; x < cnt-1; x++)
         {
-            int s1 = *pSrc++;
-            int s2 = *pSrc++;
-            BYTESWAP2(s1, s2)
+            int s1 = bswap32(*pSrc++);
+            int s2 = bswap32(*pSrc++);
             *pDst++ = s1;
             *pDst++ = s2;
         }
         // do last partial 32-bit word
-        s0 = *pSrc++;
-        BYTESWAP1(s0)
+        s0 = bswap32(*pSrc++);
         for (; rem > 0; rem--)
         {
             *((char *) pDst) = s0 & 0xff;

src/wrapper/3dfx.h

 #  else /* !macintosh */
 #    error "Unknown MetroWerks target platform"
 #  endif /* !macintosh */
+#elif defined(__APPLE__)
+#  define FX_ENTRY extern
+#  define FX_CALL
 #else
 #  warning define FX_ENTRY & FX_CALL for your compiler
 #  define FX_ENTRY extern