Render96 / Render96ex

Fork of https://github.com/sm64-port/sm64-port with additional features.
246 stars 43 forks source link

building on M1 mac #47

Open halpz opened 2 years ago

halpz commented 2 years ago

I spent a long time trying to figure out how to build this on my M1 computer, I found a fix, in the makefile there is this section:

# macOS overrides
ifeq ($(HOST_OS),Darwin)
  OSX_BUILD := 1
  # Using MacPorts?
  ifeq ($(shell test -d /opt/local/lib && echo y),y)
    OSX_GCC_VER = $(shell find /opt/local/bin/gcc* | grep -oE '[[:digit:]]+' | sort -n | uniq | tail -1)
    CC := gcc-mp-$(OSX_GCC_VER)
    CXX := g++-mp-$(OSX_GCC_VER)
    CPP := cpp-mp-$(OSX_GCC_VER) -P
    PLATFORM_CFLAGS := -I /opt/local/include
    PLATFORM_LDFLAGS := -L /opt/local/lib
  else
    # Using Homebrew?
    ifeq ($(shell which brew >/dev/null 2>&1 && echo y),y)
      OSX_GCC_VER = $(shell find `brew --prefix`/bin/gcc* | grep -oE '[[:digit:]]+' | sort -n | uniq | tail -1)
      CC := gcc-$(OSX_GCC_VER)
      CXX := g++-$(OSX_GCC_VER)
      CPP := cpp-$(OSX_GCC_VER) -P
      PLATFORM_CFLAGS := -I /usr/local/include
      PLATFORM_LDFLAGS := -L /usr/local/lib
    else
      $(error No suitable macOS toolchain found, have you installed Homebrew?)
    endif
  endif
endif

on M1, the homebrew folder is /opt/homebrew/ so if you change this to:

# macOS overrides
ifeq ($(HOST_OS),Darwin)
  OSX_BUILD := 1
  # Using MacPorts?
  ifeq ($(shell test -d /opt/local/lib && echo y),y)
    OSX_GCC_VER = $(shell find /opt/local/bin/gcc* | grep -oE '[[:digit:]]+' | sort -n | uniq | tail -1)
    CC := gcc-mp-$(OSX_GCC_VER)
    CXX := g++-mp-$(OSX_GCC_VER)
    CPP := cpp-mp-$(OSX_GCC_VER) -P
    PLATFORM_CFLAGS := -I /opt/local/include
    PLATFORM_LDFLAGS := -L /opt/local/lib
  else
    # Using Homebrew?
    ifeq ($(shell which brew >/dev/null 2>&1 && echo y),y)
      OSX_GCC_VER = $(shell find `brew --prefix`/bin/gcc* | grep -oE '[[:digit:]]+' | sort -n | uniq | tail -1)
      CC := gcc-$(OSX_GCC_VER)
      CXX := g++-$(OSX_GCC_VER)
      CPP := cpp-$(OSX_GCC_VER) -P
      PLATFORM_CFLAGS := -I /opt/homebrew/include
      PLATFORM_LDFLAGS := -L /opt/homebrew/lib
    else
      $(error No suitable macOS toolchain found, have you installed Homebrew?)
    endif
  endif
endif

it will now build using gmake

not sure if there is a way to edit the makefile to set the cflags to the brew prefix rather than setting it explicitly

halpz commented 2 years ago

i've made a PR with changes related to this

retropieuser commented 1 year ago

This works on my 2020 MacBook Air M1 (8gb) with Ventura 13.0.1. Thanks!

flatmapthatshit commented 1 year ago

Hi folks, I'm working on a version that automatically detects arm64 vs Intel architecture and uses the right flag.

Were you folks able to build a recent version of the tester branch on the M1? I'm getting a lot of issues with miniaudio including Apple Frameworks and getting lost.

E.g.,

gcc-12 -c -O2 -I /opt/homebrew/include -I include -I build/us_pc -I build/us_pc/include -I src -I . -DDYNOS -DRAPI_GL=1 -DWAPI_SDL2=1 -DAAPI_SDL2=1 -DCAPI_SDL2=1 -I`sdl2-config --prefix`/include -DHAVE_SDL2=1 `sdl2-config --cflags` -DVERSION_US -D_LANGUAGE_C -DGIT_HASH="\"b86a6827\"" -DNON_MATCHING -DAVOID_UB -DOSX_BUILD -DF3DEX_GBI_2E -fno-strict-aliasing -fwrapv -DEXT_OPTIONS_MENU -DFS_BASEDIR="\"res\"" -o build/us_pc/levels/wmotr/geo.o levels/wmotr/geo.c
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/CoreAudio.h:18,
                 from ./include/miniaudio.h:30305,
                 from data/r96/r96_miniaudio.h:7,
                 from data/dynos_audio.cpp:5:
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardware.h:162:2: error: expected unqualified-id before '^' token
  162 | (^AudioObjectPropertyListenerBlock)(    UInt32                              inNumberAddresses,
      |  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardware.h:162:2: error: expected ')' before '^' token
  162 | (^AudioObjectPropertyListenerBlock)(    UInt32                              inNumberAddresses,
      | ~^
      |  )
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardware.h:400:41: error: 'AudioObjectPropertyListenerBlock' has not been declared
  400 |                                         AudioObjectPropertyListenerBlock    inListener)             __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_7_0);
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardware.h:421:41: error: 'AudioObjectPropertyListenerBlock' has not been declared
  421 |                                         AudioObjectPropertyListenerBlock    inListener)             __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_7_0);
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardware.h:804:2: error: expected unqualified-id before '^' token
  804 | (^AudioDeviceIOBlock)(  const AudioTimeStamp*   inNow,
      |  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardware.h:804:2: error: expected ')' before '^' token
  804 | (^AudioDeviceIOBlock)(  const AudioTimeStamp*   inNow,
      | ~^
      |  )

I can easily build this with clang, but then again it would be easier if I could build everything with the same compiler.

sofakng commented 1 year ago

I've submitted a pull request with the changes needed to compile this on macOS: https://github.com/Render96/Render96ex/pull/74

flatmapthatshit commented 1 year ago

@sofakng, I'm a few months late and not sure if something else broken the branch, but while I can compile the tester branch on macOS (both Intel and M1 Apple Silicon), the application fails to start ("Can't start the container"). alpha and tester_rt64alpha are building and running fine. Can you check if the game is still building / working for you? I'm on macOS Ventura 13.4.1, following the build instructions at https://github.com/flatmapthatshit/Render96ex_macOS#build-instructions btw.

retropieuser commented 1 year ago

I get an error in the tester branch as well:-

neil@Neils-Air Render96ex_macOS % gmake -j4
find: /opt/local/bin/gcc: No such file or directory find: /opt/local/bin/gcc: No such file or directory find: /opt/local/bin/gcc*: No such file or directory gmake[1]: Entering directory '/Users/neil/Desktop/Render96ex_macOS/tools' gcc-mp- -I../include -I. -Wall -Wextra -Wno-unused-parameter -pedantic -std=c99 -O2 -s aiff_extract_codebook.c -o aiff_extract_codebook -lm gmake[1]: gcc-mp-: No such file or directory gmake[1]: [Makefile:47: aiff_extract_codebook] Error 127 gmake[1]: Waiting for unfinished jobs.... gmake[2]: Entering directory '/Users/neil/Desktop/Render96ex_macOS/tools/audiofile' g++-mp- -std=c++11 -DNDEBUG -fno-rtti -fno-exceptions -fvisibility-inlines-hidden -O2 -I. -c audiofile.cpp gmake[2]: g++-mp-: No such file or directory gmake[2]: [Makefile:7: audiofile.o] Error 127 gmake[2]: Leaving directory '/Users/neil/Desktop/Render96ex_macOS/tools/audiofile' gmake[1]: [Makefile:34: audiofile/libaudiofile.a] Error 2 gmake[1]: Leaving directory '/Users/neil/Desktop/Render96ex_macOS/tools' Makefile:214: *** Failed to build tools. Stop.

flatmapthatshit commented 1 year ago

I get an error in the tester branch as well:-.

Do you have the latest gcc version installed with homebrew + all dependencies (see Step 4 from my guide above)? I got the tester branch to compile, but the application errors out during initialisation. The other two branches that I've mentioned are working fine for me.

flatmapthatshit commented 1 year ago

I get an error in the tester branch as well:-.

Also, drop the -j4 for now as they haven't merged my fix to parallel builds to all branches (#84).

artiqeltt commented 6 months ago

how are you supposed to do the tester rt64? i tried with render api rt64 but it is only supported on windows. i used only gmake -j4 and it worked but no raytracing.