SDL-1.2: more mingw32ce build / warning fixes.

From a19e7c39b283e62ebc08d9598530addf60890ee4 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sun, 18 Apr 2021 11:51:02 +0300
Subject: [PATCH] more mingw32ce build / warning fixes.

also don't enable gapi by default, which was the original behavior.
build-tested **only**.
---
 configure                           | 58 ++++++++++++++++++-----------
 configure.ac                        | 13 ++++++-
 src/main/win32/SDL_win32_main.c     |  2 +
 src/timer/wince/SDL_systimer.c      |  5 +--
 src/video/gapi/SDL_gapivideo.c      | 15 +++++---
 src/video/wincommon/SDL_sysevents.c |  2 +-
 src/video/windib/SDL_dibvideo.c     |  3 ++
 7 files changed, 66 insertions(+), 32 deletions(-)

diff --git a/configure b/configure
index bc73f3ac..7b187ea6 100755
--- a/configure
+++ b/configure
@@ -999,6 +999,7 @@ enable_pthreads
 enable_pthread_sem
 enable_stdio_redirect
 enable_directx
+enable_gapi
 enable_sdl_dlopen
 enable_atari_ldg
 enable_clock_gettime
@@ -1732,6 +1733,7 @@ Optional Features:
   --enable-pthread-sem    use pthread semaphores [default=yes]
   --enable-stdio-redirect Redirect STDIO to files on Win32 [default=yes]
   --enable-directx        use DirectX for Win32 audio/video [default=yes]
+  --enable-gapi           use GAPI for WinCE video [default=no]
   --enable-sdl-dlopen     use dlopen for shared object loading [default=yes]
   --enable-atari-ldg      use Atari LDG for shared object loading
                           [default=yes]
@@ -4828,13 +4830,13 @@ if ${lt_cv_nm_interface+:} false; then :
 else
   lt_cv_nm_interface="BSD nm"
   echo "int some_variable = 0;" > conftest.$ac_ext
-  (eval echo "\"\$as_me:4831: $ac_compile\"" >&5)
+  (eval echo "\"\$as_me:4833: $ac_compile\"" >&5)
   (eval "$ac_compile" 2>conftest.err)
   cat conftest.err >&5
-  (eval echo "\"\$as_me:4834: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
+  (eval echo "\"\$as_me:4836: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
   (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
   cat conftest.err >&5
-  (eval echo "\"\$as_me:4837: output\"" >&5)
+  (eval echo "\"\$as_me:4839: output\"" >&5)
   cat conftest.out >&5
   if $GREP 'External.*some_variable' conftest.out > /dev/null; then
     lt_cv_nm_interface="MS dumpbin"
@@ -6044,7 +6046,7 @@ ia64-*-hpux*)
   ;;
 *-*-irix6*)
   # Find out which ABI we are using.
-  echo '#line 6047 "configure"' > conftest.$ac_ext
+  echo '#line 6049 "configure"' > conftest.$ac_ext
   if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
@@ -7607,11 +7609,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:7610: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:7612: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:7614: \$? = $ac_status" >&5
+   echo "$as_me:7616: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -7946,11 +7948,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:7949: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:7951: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:7953: \$? = $ac_status" >&5
+   echo "$as_me:7955: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -8051,11 +8053,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:8054: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:8056: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:8058: \$? = $ac_status" >&5
+   echo "$as_me:8060: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -8106,11 +8108,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:8109: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:8111: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:8113: \$? = $ac_status" >&5
+   echo "$as_me:8115: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -10476,7 +10478,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 10479 "configure"
+#line 10481 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -10572,7 +10574,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 10575 "configure"
+#line 10577 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13987,11 +13989,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:13990: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:13992: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:13994: \$? = $ac_status" >&5
+   echo "$as_me:13996: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -14086,11 +14088,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:14089: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:14091: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:14093: \$? = $ac_status" >&5
+   echo "$as_me:14095: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -14138,11 +14140,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:14141: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:14143: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:14145: \$? = $ac_status" >&5
+   echo "$as_me:14147: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -21298,6 +21300,17 @@ fi
     fi
 }
 
+CheckGAPI()
+{
+    # Check whether --enable-gapi was given.
+if test "${enable_gapi+set}" = set; then :
+  enableval=$enable_gapi;
+else
+  enable_gapi=no
+fi
+
+}
+
 CheckDLOPEN()
 {
     # Check whether --enable-sdl-dlopen was given.
@@ -22124,10 +22137,13 @@ case "$host" in
         CheckDiskAudio
         CheckDummyAudio
         CheckWIN32
+        CheckGAPI
         CheckNASM
         SOURCES="$SOURCES $srcdir/src/video/gapi/*.c"
-        $as_echo "#define SDL_VIDEO_DRIVER_GAPI 1" >>confdefs.h
+        if test x$enable_gapi = xyes; then
+            $as_echo "#define SDL_VIDEO_DRIVER_GAPI 1" >>confdefs.h
 
+        fi
         EXTRA_CFLAGS="$EXTRA_CFLAGS -D_WIN32_WCE=0x420"
         if test x$enable_audio = xyes; then
             $as_echo "#define SDL_AUDIO_DRIVER_WAVEOUT 1" >>confdefs.h
diff --git a/configure.ac b/configure.ac
index 69ee434f..278fcc02 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2213,6 +2213,14 @@ CheckDIRECTX()
     fi
 }
 
+dnl Setup for WinCE GAPI video
+CheckGAPI()
+{
+    AC_ARG_ENABLE(gapi,
+[AS_HELP_STRING([--enable-gapi], [use GAPI for WinCE video [default=no]])],
+                  , enable_gapi=no)
+}
+
 dnl Check for the dlfcn.h interface for dynamically loading objects
 CheckDLOPEN()
 {
@@ -2622,9 +2630,12 @@ case "$host" in
         CheckDiskAudio
         CheckDummyAudio
         CheckWIN32
+        CheckGAPI
         CheckNASM
         SOURCES="$SOURCES $srcdir/src/video/gapi/*.c"
-        AC_DEFINE(SDL_VIDEO_DRIVER_GAPI)
+        if test x$enable_gapi = xyes; then
+            AC_DEFINE(SDL_VIDEO_DRIVER_GAPI)
+        fi
         EXTRA_CFLAGS="$EXTRA_CFLAGS -D_WIN32_WCE=0x420"
         if test x$enable_audio = xyes; then
             AC_DEFINE(SDL_AUDIO_DRIVER_WAVEOUT)
diff --git a/src/main/win32/SDL_win32_main.c b/src/main/win32/SDL_win32_main.c
index 672b48c1..c49b5331 100644
--- a/src/main/win32/SDL_win32_main.c
+++ b/src/main/win32/SDL_win32_main.c
@@ -256,6 +256,8 @@ static void redirect_output(void)
 		}
 #endif
 	}
+#else
+	(void) newfp;
 #endif /* _WIN32_WCE */
 
 	setvbuf(stdout, NULL, _IOLBF, BUFSIZ);	/* Line buffered */
diff --git a/src/timer/wince/SDL_systimer.c b/src/timer/wince/SDL_systimer.c
index 2b018b0e..09810695 100644
--- a/src/timer/wince/SDL_systimer.c
+++ b/src/timer/wince/SDL_systimer.c
@@ -92,8 +92,6 @@ void SDL_StartTicks(void)
   start_ticks=wce_ticks();
 }
 
-static UINT WIN_timer;
-
 #if ( _WIN32_WCE <= 420 )
 
 static HANDLE timersThread = 0;
@@ -143,8 +141,9 @@ void SDL_SYS_TimerQuit(void)
 
 #else
 
+#if defined _MSC_VER
 #pragma comment(lib, "mmtimer.lib")
-
+#endif
 /* Data to handle a single periodic alarm */
 static UINT timerID = 0;
 
diff --git a/src/video/gapi/SDL_gapivideo.c b/src/video/gapi/SDL_gapivideo.c
index a8c550f8..0aafe394 100644
--- a/src/video/gapi/SDL_gapivideo.c
+++ b/src/video/gapi/SDL_gapivideo.c
@@ -382,7 +382,7 @@ VideoBootStrap GAPI_bootstrap = {
 
 static void FillStructs(_THIS, BOOL useVga)
 {
-#ifdef _ARM_
+#if defined(_ARM_) || defined(__arm__)
 	WCHAR oemstr[100];
 #endif
 	/* fill a device properties */
@@ -395,7 +395,7 @@ static void FillStructs(_THIS, BOOL useVga)
 		gapi->useVga = 0;
 		gapi->useGXOpenDisplay = 1;
 
-#ifdef _ARM_
+#if defined(_ARM_) || defined(__arm__)
 		/* check some devices and extract addition info */
 		SystemParametersInfo( SPI_GETOEMINFO, sizeof( oemstr ), oemstr, 0 );
 
@@ -409,7 +409,7 @@ static void FillStructs(_THIS, BOOL useVga)
 		}
 #if (EMULATE_AXIM_X30 == 0)
 		// buggy Dell Axim X30
-		if( _tcsncmp(oemstr, L"Dell Axim X30", 13) == 0 )
+		if( wcsncmp(oemstr, L"Dell Axim X30", 13) == 0 )
 #endif
 		{
 			GXDeviceInfo gxInfo = {0};
@@ -727,7 +727,11 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,
 			gapi->dstLineStep = gapi->gxProperties.cbxPitch;
 			gapi->dstPixelStep = -gapi->gxProperties.cbyPitch;
 			break;
+		default:/* silence gcc -Wswitch */
+			break;
 		}
+	default:	/* silence gcc -Wswitch */
+		break;
 	}
 
 	video->w = gapi->w = width;
@@ -1135,7 +1139,6 @@ static void GAPI_UpdateRectsColor(_THIS, int numrects, SDL_Rect *rects)
 				linesProcessed = updateLine8to8(this, srcPointer, destPointer, rects[i].w, rects[i].h, height);
 				break;
 			case 2:
-#pragma warning(disable: 4133)
 				linesProcessed = updateLine16to16(this, (PIXEL*) srcPointer, (PIXEL*) destPointer, rects[i].w, rects[i].h, height);
 				break;
 			}
@@ -1235,7 +1238,7 @@ static void GAPI_WinPAINT(_THIS, HDC hdc)
 
 	int bpp = 16; // we always use either 8 or 16 bpp internally
 	HGDIOBJ prevObject;
-	unsigned short *bitmapData;
+	void* bitmapData; /* unsigned short* */
 	HBITMAP hb;
 	HDC srcDC;
 
@@ -1266,7 +1269,7 @@ static void GAPI_WinPAINT(_THIS, HDC hdc)
 		pHeader->biCompression = BI_BITFIELDS;
 	}
     // Create the DIB
-    hb =  CreateDIBSection( 0, pBMI, DIB_RGB_COLORS, (void**)&bitmapData, 0, 0 );
+    hb =  CreateDIBSection( 0, pBMI, DIB_RGB_COLORS, &bitmapData, 0, 0 );
 
 	// copy data
 	// FIXME: prevent misalignment, but I've never seen non aligned width of screen
diff --git a/src/video/wincommon/SDL_sysevents.c b/src/video/wincommon/SDL_sysevents.c
index 4f72d521..3b90fb00 100644
--- a/src/video/wincommon/SDL_sysevents.c
+++ b/src/video/wincommon/SDL_sysevents.c
@@ -445,7 +445,7 @@ LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 				} else {
 					x = (Sint16)LOWORD(lParam);
 					y = (Sint16)HIWORD(lParam);
-#ifdef _WIN32_WCE
+#ifdef SDL_VIDEO_DRIVER_GAPI
 					extern void GapiTransform(GapiInfo*, LONG*, LONG*);
 					if (SDL_VideoSurface && this->hidden->gapiInfo)
 						GapiTransform(this->hidden->gapiInfo, &x, &y);
diff --git a/src/video/windib/SDL_dibvideo.c b/src/video/windib/SDL_dibvideo.c
index 81563c02..23b78073 100644
--- a/src/video/windib/SDL_dibvideo.c
+++ b/src/video/windib/SDL_dibvideo.c
@@ -67,6 +67,7 @@
   #if _WIN32_WCE < 420
     #define NO_CHANGEDISPLAYSETTINGS
   #else
+    #undef ChangeDisplaySettings
     #define ChangeDisplaySettings(lpDevMode, dwFlags) ChangeDisplaySettingsEx(NULL, (lpDevMode), 0, (dwFlags), 0)
   #endif
 #endif
@@ -966,6 +967,7 @@ static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
 	ReleaseDC(SDL_Window, hdc);
 }
 
+#if defined(SYSPAL_NOSTATIC) && !defined(_WIN32_WCE)
 static int FindPaletteIndex(LOGPALETTE *pal, BYTE r, BYTE g, BYTE b)
 {
 	PALETTEENTRY *entry;
@@ -1001,6 +1003,7 @@ static BOOL CheckPaletteEntry(LOGPALETTE *pal, int index, BYTE r, BYTE g, BYTE b
 
 	return moved;
 }
+#endif
 
 int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
 {