Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building on macOS does not use libraries installed by package managers #224

Open
thenktor opened this issue May 7, 2024 · 5 comments
Open

Comments

@thenktor
Copy link

thenktor commented May 7, 2024

Hi,

when builing on macOS libraries that are installed by package managers like pkgsrc or MacPorts are not used.

@ralph-irving
Copy link
Owner

This is on purpose as I build all the decoders and support libraries as part of the my macos squeezelite builds.
Adding the PATH(s) to these other package managers break my builds.

@thenktor
Copy link
Author

thenktor commented May 8, 2024

What about having extra Makefiles like Makefile.m1-pkgsrc and Makefile.m1-macports?

@dmangot
Copy link

dmangot commented May 9, 2024

I don't know if this is the kind of thing ./configure would fix, but I was able to get squeezelite compiled on my M2 Mac today. The packages available on the website the OS said were all corrupted.

I don't know what the cleanest way of handling these things are or I'd make a pull request so I'm documenting them here because the binary works fine. I haven't written C code since the 90s.

Apple M2 Mac running Ventura

  1. Comment out the -rt stuff because it's not Linux
  2. Force PORTAUDIO because it was trying to use ALSA
  3. add -I /opt/homebrew/include to CFLAGS and -L /opt/homebrew/lib to LDADD so it could find all the includes and lib.

Hope that helps!

@thenktor
Copy link
Author

thenktor commented May 9, 2024

I don't know if this is the kind of thing ./configure would fix,

Yes.

but I was able to get squeezelite compiled on my M2 Mac today. The packages available on the website the OS said were all corrupted.

Not sure, what you mean here.

1. Comment out the -rt stuff because it's not Linux

2. Force PORTAUDIO because it was trying to use ALSA

I guess you did not use the existing m1 Makefile. You can specify it like that: make -f Makefile.m1

3. add `-I /opt/homebrew/include`  to CFLAGS and `-L /opt/homebrew/lib` to LDADD so it could find all the includes and lib.

Yes, that is basically what you need to do. Tell the build system, where headers and libs are.

@dmangot
Copy link

dmangot commented May 10, 2024

Corrupted packages from the Sourceforge site:
Screenshot 2024-05-09 at 09 22 28

I tried using the Makefile.m1 and it looks like it was very hacked for someone's specific machine. I think the Opus stuff might just be a quirk in how Homebrew packages stuff so I wound up taking OPUS and ALAC out since it didn't seem worth fighting with right now to get a clean compile.

This is what I had to change:

diff --git a/Makefile b/Makefile
index 78511dc..07443b1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 #Cross compile support - create a Makefile which defines these three variables and then includes this Makefile...
 CFLAGS ?= -Wall -fPIC -O2
-CFLAGS += -fcommon -std=gnu99
+CFLAGS += -fcommon
 LDADD  ?= -lpthread -lm -lrt
 EXECUTABLE ?= squeezelite

@@ -41,7 +41,7 @@ SOURCES_OPUS     = opus.c
 SOURCES_MAD      = mad.c
 SOURCES_MPG123   = mpg.c

-LINK_LINUX       = -ldl
+LINK_LINUX       = -ldl -std=gnu99
 LINK_ALSA        = -lasound
 LINK_PORTAUDIO   = -lportaudio
 LINK_PULSEAUDIO  = -lpulse
diff --git a/Makefile.m1 b/Makefile.m1
index 1157732..032732e 100644
--- a/Makefile.m1
+++ b/Makefile.m1
@@ -1,7 +1,7 @@
 # OSX 12.0+ arm64 only
-OPTS = -DUSE_LIBOGG -DPORTAUDIO -DALAC -DOPUS -DRESAMPLE -DLINKALL -DVISEXPORT -DDSD -DUSE_SSL -I./includem1 -I./includem1/opus -I./includem1/alac -arch arm64 -O3 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=11.0
+OPTS = -DUSE_LIBOGG -DPORTAUDIO -DRESAMPLE -DLINKALL -DVISEXPORT -DDSD -DUSE_SSL -arch arm64 -O3 -mmacosx-version-min=11.0 -I /opt/homebrew/include

-LDFLAGS = -arch arm64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=11.0 -L./libm1
+LDFLAGS = -arch arm64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=11.0 -L /opt/homebrew/lib

 LDADD = -lportaudio -lpthread -ldl -lm -framework CoreVideo -framework VideoDecodeAcceleration -frame
work CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon

diff --git a/opus.c b/opus.c
index baabab0..edbe18b 100644
--- a/opus.c
+++ b/opus.c
@@ -41,7 +41,7 @@
 #define ALIGN(n)       (n << 16)
 #endif

-#include <opusfile.h>
+#include <opus/opusfile.h>

 struct opus {
        struct OggOpusFile *of

Briefly:

  1. The gnu99 stuff
  2. Removed the sysroot stuff as it wasn't needed and just broke things
  3. Took out DALAC and DOPUS because they were just causing headaches on my machine. I'm guessing I could fight to get the stuff in the right place to make it work because Homebrew didn't have it or do it. The ALAC stuff is over a decade old at this point.

tl;dr I think it would be cool to get the Sourceforge downloads to not be broken. Otherwise, the Makefile.m1 (and Makefile) needs a little love if people are going to use it without too much trouble. I think the package manager stuff could be handled more cleanly in variables than as hardcoded.

If we can get these sorted out so that most people are happy, I'm happy to submit a PR for the README which is currently not useful to anyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants