Browse Source

Native MIDI: Completely fix MinGW compilation problem

This commit reverts commits 2b7df3f & 1a48b13.
Due to some versions of MinGW distribution do not implement threads
completely, some part of the C++ 11 the concurrency library is unusable
under these environments. This commit imports the lightweight library
mingw-std-threads (https://github.com/meganz/mingw-std-threads) as a
submodule and makes win32 version of `native_midi.cpp` include its
headers for threading support.
LouYihua 7 years ago
parent
commit
039b1017b7
5 changed files with 37 additions and 42 deletions
  1. 3 0
      .gitmodules
  2. 1 0
      3rd/mingw-std-threads
  3. 1 9
      win32/Makefile
  4. 2 10
      win32/Makefile.mingw
  5. 30 23
      win32/native_midi.cpp

+ 3 - 0
.gitmodules

@@ -4,3 +4,6 @@
 [submodule "3rd/SDL"]
 	path = 3rd/SDL
 	url = https://github.com/sdlpal/SDL.git
+[submodule "3rd/mingw-std-threads"]
+	path = 3rd/mingw-std-threads
+	url = https://github.com/sdlpal/mingw-std-threads.git

+ 1 - 0
3rd/mingw-std-threads

@@ -0,0 +1 @@
+Subproject commit aabf8e384b9d5e1d4f9774865c942f274b7f68d7

+ 1 - 9
win32/Makefile

@@ -6,8 +6,6 @@ TEST_TARGET = sdlpal-tests.exe
 HOST =
 TEST_CCFLAGS =
 
-GCCV6P := $(shell expr `$(HOST)g++ -dumpversion | cut -f1 -d.` \>= 6)
-
 GTEST_DIR = ../3rd/googletest/googletest
 
 CFILES = $(wildcard ../adplug/*.c) $(wildcard ../libmad/*.c) $(wildcard ../liboggvorbis/src/*.c) $(wildcard ../*.c) $(wildcard ../native_midi/*.c) $(wildcard ../win32/*.c)
@@ -18,14 +16,8 @@ TEST_CPPFILES = $(wildcard ../tests/*.cpp)
 TEST_OBJFILES = $(TEST_CPPFILES:.cpp=.o)
 
 override CCFLAGS += `sdl2-config --cflags` -g -msse2 -Wall -O2 -fno-strict-aliasing -I. -I../ -I../liboggvorbis/include -I../liboggvorbis/src -DPAL_HAS_PLATFORM_SPECIFIC_UTILS $(TEST_CCFLAGS)
-CXXFLAGS = $(CCFLAGS)
+CXXFLAGS = $(CCFLAGS) -std=c++11
 CFLAGS = $(CCFLAGS) -std=gnu99
-# GCC v6 or higher has already defaults to gnu++14
-ifeq "$(GCCV6P)" "1"
-	CXXFLAGS += -std=gnu++14
-else
-    CXXFLAGS += -std=c++11
-endif
 LDFLAGS = `sdl2-config --libs` -lm -lwinmm -lole32 -loleaut32 -limm32 -lcomctl32 -luuid -ldxguid -lversion -static -static-libgcc -static-libstdc++
 TEST_CXXFLAGS += -isystem $(GTEST_DIR)/include -I $(GTEST_DIR) -g -Wall -Wextra -pthread
 

+ 2 - 10
win32/Makefile.mingw

@@ -6,8 +6,6 @@ TEST_TARGET = sdlpal-tests.exe
 HOST =
 TEST_CCFLAGS =
 
-GCCV6P := $(shell expr `$(HOST)g++ -dumpversion | cut -f1 -d.` \>= 6)
-
 GTEST_DIR = ../3rd/googletest/googletest
 
 CFILES = $(wildcard ../adplug/*.c) $(wildcard ../libmad/*.c) $(wildcard ../liboggvorbis/src/*.c) $(wildcard ../*.c) $(wildcard ../native_midi/*.c) $(wildcard ../win32/*.c)
@@ -17,15 +15,9 @@ OBJFILES = $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(RCFILES:.rc=.o)
 TEST_CPPFILES = $(wildcard ../tests/*.cpp)
 TEST_OBJFILES = $(TEST_CPPFILES:.cpp=.o)
 
-override CCFLAGS += -g -msse2 -Wall -O2 -fno-strict-aliasing -I. -I../ -I../liboggvorbis/include -I../liboggvorbis/src -DPAL_HAS_PLATFORM_SPECIFIC_UTILS $(TEST_CCFLAGS)
-CXXFLAGS = $(CCFLAGS)
+override CCFLAGS += -g -msse2 -Wall -O2 -fno-strict-aliasing -I../3rd/mingw-std-threads -I../3rd/SDL/include -I. -I../ -I../liboggvorbis/include -I../liboggvorbis/src -DPAL_HAS_PLATFORM_SPECIFIC_UTILS $(TEST_CCFLAGS)
+CXXFLAGS = $(CCFLAGS) -std=c++11
 CFLAGS = $(CCFLAGS) -std=gnu99
-# GCC v6 or higher has already defaults to gnu++14
-ifeq "$(GCCV6P)" "0"
-	CXXFLAGS += -std=gnu++14
-else
-    CXXFLAGS += -std=c++11
-endif
 LDFLAGS = -lmingw32 -lSDL2main -lSDL2 -mwindows -lm -lwinmm -lole32 -loleaut32 -limm32 -lcomctl32 -luuid -ldxguid -lversion -static -static-libgcc -static-libstdc++
 TEST_CXXFLAGS += -isystem $(GTEST_DIR)/include -I $(GTEST_DIR) -g -Wall -Wextra -pthread
 

+ 30 - 23
win32/native_midi.cpp

@@ -1,29 +1,30 @@
-/*
-    native_midi:  Hardware Midi support for the SDL_mixer library
-    Copyright (C) 2000,2001  Florian 'Proff' Schulze
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Library General Public
-    License as published by the Free Software Foundation; either
-    version 2 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Library General Public License for more details.
-
-    You should have received a copy of the GNU Library General Public
-    License along with this library; if not, write to the Free
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-    Florian 'Proff' Schulze
-    florian.proff.schulze@gmx.net
-*/
+/* -*- mode: c; tab-width: 4; c-basic-offset: 4; c-file-style: "linux" -*- */
+//
+// Copyright (c) 2009-2011, Wei Mingzhi <whistler_wmz@users.sf.net>.
+// Copyright (c) 2011-2017, SDLPAL development team.
+// All rights reserved.
+//
+// This file is part of SDLPAL.
+//
+// SDLPAL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+// native_midi.cpp: Native Windows Desktop MIDI player for SDLPal.
+//         @Author: Lou Yihua, 2017
+//
 
 #include "SDL.h"
 
-/* everything below is currently one very big bad hack ;) Proff */
-
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <mmsystem.h>
@@ -36,6 +37,12 @@
 #include <atomic>
 #include <vector>
 
+#if (defined(__MINGW32__) || defined(__MINGW64__)) && !defined(_GLIBCXX_HAS_GTHREADS)
+#include "mingw.condition_variable.h"
+#include "mingw.mutex.h"
+#include "mingw.thread.h"
+#endif
+
 #include "native_midi/native_midi.h"
 #include "native_midi/native_midi_common.h"