viraptor / fm_tune

Calculate rough PPM estimate for SDR devices
Apache License 2.0
37 stars 11 forks source link

Makefile doesn't work correctly on macOS 14 with Homebrew #6

Open kd8drx opened 3 months ago

kd8drx commented 3 months ago

When attempting to build on macOS 14 (Sonoma), the process kept failing because the compiler and linker couldn't find the Liquid-DSP headers or libraries. This was despite having the necessary packages installed (brew install liquid-dsp soapysdr).

The issue appears to be that the Makefile assumes that the paths returned by pkg-config for SoapySDR will also include the Liquid-DSP headers/libraries - but on macOS when using Homebrew, this isn't the case. Instead, the path returned is the specific folder in Homebrew's "Cellar" for SoapySDR (e.g. /opt/homebrew/Cellar/soapysdr/0.8.1_1/lib), which doesn't have anything related to Liquid-DSP for obvious reasons.

To work around this, I manually ran the compilation command (thankfully, there's only one) with the 'generic' Homebrew includes/lib paths (/opt/homebrew/include and /opt/homebrew/lib), which let everything compile happily. Said generic paths are just trees of symlinks to solve for this issue while allowing for multiple versions of a given app/library to be installed, to avoid Dependency Hell and the like.

As to a fix for the Makefile, I'm unsure of the best way, but an easy way would be to:

  1. Test if a system is running a Darwin-based OS using uname
  2. Test if homebrew is installed by running brew --env
  3. If true, set SOAPY_CFLAGS to $HOMEBREW_PREFIX/include and SOAPY_LDFLAGS $HOMEBREW_PREFIX/lib in the Makefile.

In my case - and if anyone having similar issues on macOS runs into this issue - the working build command ended up being:

cc fm_tune.c -std=c99 -O3 -Wall -Wextra -march=native -I/opt/homebrew/include -lliquid -lm -L/opt/homebrew/lib -lSoapySDR -o fm_tune