vygr / ChrysaLisp

Parallel OS, with GUI, Terminal, OO Assembler, Class libraries, C-Script compiler, Lisp interpreter and more...
GNU General Public License v2.0
1.62k stars 96 forks source link

SDL2 dep for building on Macs - tweaks needed? #271

Closed paul-hammant closed 1 year ago

paul-hammant commented 1 year ago
$ make install 
rm -rf ./src/obj/gui/*
rm -rf ./src/obj/tui/*
rm -rf ./obj/
unzip -oq snapshot.zip
mkdir -p obj/x86_64/AMD64/Darwin    
c++ -O3 -std=c++14 -nostdlib -fno-exceptions -MMD -c \
        -o src/obj/tui/gui_sdl.o src/gui_sdl.cpp
c++ -O3 -std=c++14 -nostdlib -fno-exceptions -MMD -c \
        -o src/obj/tui/main.o src/main.cpp
c++ -O3 -std=c++14 -nostdlib -fno-exceptions -MMD -c \
        -o src/obj/tui/vp64.o src/vp64.cpp
c++ -o obj/x86_64/AMD64/Darwin/main_tui src/obj/tui/gui_sdl.o src/obj/tui/main.o src/obj/tui/vp64.o
c++ -O3 -std=c++14 -nostdlib -fno-exceptions -MMD -c -D_HOST_GUI=0 \
        -I/Library/Frameworks/SDL2.framework/Headers/ \
        -o src/obj/gui/gui_sdl.o src/gui_sdl.cpp
src/gui_sdl.cpp:2:10: fatal error: 'SDL.h' file not found
#include <SDL.h>
         ^~~~~~~
1 error generated.

Homebrew has a sdl2 package: https://github.com/Homebrew/homebrew-core/blob/master/Formula/sdl2.rb. It installs just fine, it says.

After that though, there is no ..

  1. /Library/Frameworks/SDL2.framework
  2. nor ~/Library/Frameworks/SDL2.framework

.. hence make barfing.

I can see these though:

./usr/local/include/SDL/SDL.h
./usr/local/include/SDL2/SDL.h

I'm on 12.6.5 (Monteray) with a 2018 i5 chip, if that matters

vygr commented 1 year ago

Did you use the Makefile_Homebrew Makefile ?

Two Makefile provided. And we are just having a convo on the Element chat about switching to just a Homebrew based Makefile. So go back to just 1 and that's only Homebrew.

vygr commented 1 year ago

If you have sdl installed via Homebrew and prefer that way.

make -f Makefile_Homebrew install

This is yet more weight to the Homebrew only install argument.

vygr commented 1 year ago

I will add a comment to the intro install doc mentioning the two makesfiles.

ghaerr commented 1 year ago

include

The standard way of installing SDL2 requires that the above line be changed in the C source file to #include <SDL2/SDL.h>. This works and allows for multiple installations of SDL to be installed (SDL 3 is now current, but that's another topic). I am already having to do this whenever I pull upstream, or I can't get things to compile, even with my homebrew installation.

I would be in favor of having the 'default' method be one that uses -lSDL2 on the command line and the above #include, as that's what is required for either installing via Homebrew or building and installing SDL from source on macOS or another system.

IIRC, only the very earliest of SDL2 installs required manually installing the framework, which was a big pain. I've only had to do it once on the many macOS systems I have running.

@vygr, you might try running brew install sdl2 (I think that's the correct name) on your system, it can coexist with the framework you've already installed and then we could possibly change to only having and maintaining a single Makefile.

ghaerr commented 1 year ago

I think the idea of having two Makefiles is an issue for newbies (like myself): frankly, I never even looked for secondary Makefiles, etc. Just typed make to see what happened. I was able to correct it because I'm using SDL2 for a number of other projects on macOS.

I have just been applying this patch when updating:

diff --git a/Makefile b/Makefile
index f0181f33a..cae570719 100644
--- a/Makefile
+++ b/Makefile
@@ -47,7 +47,7 @@ obj/$(CPU)/$(ABI)/$(OS)/main_gui: $(OBJ_FILES_GUI)
 ifeq ($(OS),Darwin)
    c++ -o $@ $^ \
        -F/Library/Frameworks \
-       -framework SDL2
+       -lSDL2
 endif
 ifeq ($(OS),Linux)
    c++ -o $@ $^ \
diff --git a/src/main.cpp b/src/main.cpp
index 5ca7f3f85..ad67010dc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -35,7 +35,8 @@
    #include <libkern/OSCacheControl.h>
 #endif
 #ifdef _GUI
-   #include <SDL.h>
+   #include <SDL2/SDL.h>
 #endif

 #define VP64_STACK_SIZE 8192
vygr commented 1 year ago

I have Homebrew installed on my Mac and the SDL2 package.

That why I'm leaning towards a Homebrew only make as it does make things easier.

I had Macports at one point but Homebrew proved better (hope that doesn't start a flame war)

ghaerr commented 1 year ago

Another idea would be to just swap the Makefiles - make the Homebrew version the default Makefile, and see whether anyone complains. If so, have them use the other renamed Makefile_macOSFrameworks. I haven't tested to see whether this method fixes the problematic #include <SDL2/SDL.h> or not though.

vygr commented 1 year ago

I have just pushed the changes for Homebrew only. I hope this works for everyone. It works here after I deleted my Frameworks folder for sdl, so fingers crossed.

I've added links to the docs to point at Homebrew installer etc.

paul-hammant commented 1 year ago

Yay - confirmed as working for me