ekeeke / Genesis-Plus-GX

An enhanced port of Genesis Plus - accurate & portable Sega 8/16 bit emulator
Other
672 stars 193 forks source link

Fix SDL2 build on MacOS #544

Closed ekulabuhov closed 3 months ago

ekulabuhov commented 3 months ago

Hey! I've ran into some minor issues while trying to compile SDL2 Makefile on MacOS Ventura 13.6.4. This PR aims to fix them.

% gcc -v
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin22.6.0

Error 1 (fixed by adding a newline):

../core/input_hw/input.c:483:2: error: no newline at end of file [-Werror,-Wnewline-eof]

Error 2 (fixed by replacing define with typedef):

gcc -c `sdl2-config --cflags` -march=native -O6 -fomit-frame-pointer -Wall -Wno-strict-aliasing -std=c99 -pedantic-errors -Winvalid-utf8 -Wstrict-prototypes -I../core -I../core/z80 -I../core/m68k -I../core/sound -I../core/input_hw -I../core/cart_hw -I../core/cart_hw/svp -I../core/cd_hw -I../core/ntsc -I../core/tremor -I../core/../sdl -I../core/../sdl/sdl2 -DLSB_FIRST -DUSE_16BPP_RENDERING -DUSE_LIBTREMOR -DUSE_LIBCHDR -DMAXROMSIZE=33554432 -DHAVE_YM3438_CORE -DHAVE_OPLL_CORE -DENABLE_SUB_68K_ADDRESS_ERROR_EXCEPTIONS -DHAVE_ALLOCA_H ../core/../sdl/error.c -o build_sdl2/error.o
warning: optimization level '-O6' is not supported; using '-O3' instead
In file included from ../core/../sdl/error.c:6:
In file included from ../core/../sdl/osd.h:15:
In file included from ../core/../sdl/unzip.h:48:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/zlib.h:34:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/zconf.h:431:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/types.h:93:33: error: cannot combine with previous 'int' declaration specifier
typedef unsigned int            uint;           /* Sys V compatibility */
                                ^
../core/m68k/m68k.h:82:25: note: expanded from macro 'uint'
#define uint   unsigned int
                        ^
1 warning and 1 error generated.
make: *** [build_sdl2/error.o] Error 1

Error 3 (fixed by suppressing error using -Wstrict-prototypes): :

../core/../sdl/sdl2/main.c:69:26: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static int sdl_sound_init()
                         ^
                          void
../core/../sdl/sdl2/main.c:123:28: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void sdl_sound_close()
                           ^
                            void
../core/../sdl/sdl2/main.c:135:26: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static int sdl_video_init()
                         ^
                          void
../core/../sdl/sdl2/main.c:159:29: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void sdl_video_update()
                            ^
                             void
../core/../sdl/sdl2/main.c:251:28: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void sdl_video_close()
                           ^
                            void
../core/../sdl/sdl2/main.c:287:25: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static int sdl_sync_init()
                        ^
                         void
../core/../sdl/sdl2/main.c:300:27: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void sdl_sync_close()
                          ^
                           void
1 warning and 7 errors generated.
make: *** [build_sdl2/main.o] Error 1

Error 4 (fixed by suppressing error using -Winvalid-utf8):

../core/cart_hw/sms_cart.c:378:83: error: invalid UTF-8 in comment [-Werror,-Winvalid-utf8]
  {0x1890F407, 0, 1, 0, MAPPER_SEGA, SYSTEM_SMS,        REGION_USA}, /* Game Box S<E9>rie Esportes Radicais (BR) */
                                                                                  ^
../core/cart_hw/sms_cart.c:389:74: error: invalid UTF-8 in comment [-Werror,-Winvalid-utf8]
  {0x01D67C0B, 0, 1, 0, MAPPER_SEGA, SYSTEM_SMS,        REGION_USA}, /* M<F4>nica no Castelo do Drag<E3>o (BR) */
                                                                         ^
../core/cart_hw/sms_cart.c:389:98: error: invalid UTF-8 in comment [-Werror,-Winvalid-utf8]
  {0x01D67C0B, 0, 1, 0, MAPPER_SEGA, SYSTEM_SMS,        REGION_USA}, /* M<F4>nica no Castelo do Drag<E3>o (BR) */
                                                                                                    ^
../core/cart_hw/sms_cart.c:404:83: error: invalid UTF-8 in comment [-Werror,-Winvalid-utf8]
  {0x22CCA9BB, 0, 1, 0, MAPPER_SEGA, SYSTEM_SMS,        REGION_USA}, /* Turma da M<F4>nica em: O Resgate (BR) */
                                                                                  ^
../core/cart_hw/sms_cart.c:829:16: error: invalid UTF-8 in comment [-Werror,-Winvalid-utf8]
  /* Turma da M<F4>nica em: O Resgate & Wonder Boy III enable FM support on japanese hardware only */
               ^
1 warning and 5 errors generated.
make: *** [build_sdl2/sms_cart.o] Error 1
ekeeke commented 3 months ago

Hi, please see my remarks below on these changes:

1/ change to input.c : Ok with correction (it's strange that it results in a compilation error though, have you added -Werror compilation flag ?)

2/ change to m68k.h : a better correction to this compilation error would be to replace #include "shared.h in config.h by #include "types.h" and #include "input.h" to only include the needed types definition (and do not include m68k.h from shared.h as it conflicts with platform specific types and is not needed for compiling platform specific code)

3/ change to Makefile: I don't understand this change. It seems you are instead adding -Wstrict-prototypes and -Winvalid-utf8 to all platforms except OSX (ifneq means "if not equal" so platform variable is set to "osx" wh⁵en "DARWIN" string is NOT found in ushell return ?). This is confirmed by the compilation output you copypasted above where those two extra warning options appear although they are not in original Makefile, which serms to indicate you added them yourself for some unknown reason (which then produced those compilation errors)

ekulabuhov commented 3 months ago

Hi! Thanks for your comments! I will check 2.

Regarding 3 - I've picked up platform detection from libretro Makefile: https://github.com/ekeeke/Genesis-Plus-GX/blob/c6d1e5ac38ec768fcf4a93e37dd44088473f5001/Makefile.libretro#L27

I think it checks that output of findstring Darwin against $(shell uname -a) is not empty (hence the use of ifneq).

Please ignore the extra flags in gcc call for error 2, I was doing things in reverse to generate errors. I assure you that neither flags are there by default.

From the gcc doc for -Winvalid-utf8:

Warn if an invalid UTF-8 character is found. This warning is on by default for C++23 if -finput-charset=UTF-8 is used and turned into error with -pedantic-errors.

I believe the culprit that turns these simple warnings into errors is -pedantic-errors that is present by default. And adding -Winvalid-utf8 -Wstrict-prototypes turns them back into warnings.

ekeeke commented 3 months ago

Thanks, I indeed misunderstood how the findstring command works in Makefile.

You are probably right about -pedantic-errors error forced warning being turned into normal warnings with -W options.