Skip to content

Instantly share code, notes, and snippets.

@Forst
Last active April 19, 2024 15:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Forst/db68106136be3380086e3c38be094d99 to your computer and use it in GitHub Desktop.
Save Forst/db68106136be3380086e3c38be094d99 to your computer and use it in GitHub Desktop.
Gqrx macOS build script (including Apple Silicon support)
#!/bin/sh
set -eux
BREW_PREFIX="$(brew --prefix)"
CPU_COUNT="$(sysctl -n hw.ncpu)"
# Homebrew dependencies
brew update
brew install airspy airspyhf boost dylibbundler gnuradio hackrf libbladerf librtlsdr libserialport libsndfile portaudio pybind11 uhd qt@6
brew tap pothosware/homebrew-pothos
brew install soapyremote
if [ ! -e /Library/Frameworks/iio.framework ]; then
if [ ! -e libiio ]; then
git clone -b v0.23 https://github.com/analogdevicesinc/libiio.git
fi
(
cd libiio
rm -rf build
mkdir build
cd build
cmake ..
make -j${CPU_COUNT}
sudo cp -a iio.framework /Library/Frameworks/
)
fi
if [ ! -e "${BREW_PREFIX}/lib/libiio.dylib" ]; then
cp -p /Library/Frameworks/iio.framework/iio "${BREW_PREFIX}/lib/libiio.dylib"
install_name_tool -id "${BREW_PREFIX}/lib/libiio.dylib" "${BREW_PREFIX}/lib/libiio.dylib"
fi
if [ ! -e /Library/Frameworks/ad9361.framework ]; then
if [ ! -e libad9361-iio ]; then
git clone https://github.com/analogdevicesinc/libad9361-iio.git
fi
(
cd libad9361-iio
rm -rf build
mkdir build
cd build
cmake ..
make -j${CPU_COUNT}
sudo cp -a ad9361.framework /Library/Frameworks/
)
fi
if [ ! -e "${BREW_PREFIX}/lib/libad9361.dylib" ]; then
cp -p /Library/Frameworks/ad9361.framework/ad9361 "${BREW_PREFIX}/lib/libad9361.dylib"
install_name_tool -id "${BREW_PREFIX}/lib/libad9361.dylib" "${BREW_PREFIX}/lib/libad9361.dylib"
install_name_tool -delete_rpath /Library/Frameworks "${BREW_PREFIX}/lib/libad9361.dylib"
install_name_tool -change @rpath/iio.framework/Versions/0.23/iio "${BREW_PREFIX}/lib/libiio.dylib" "${BREW_PREFIX}/lib/libad9361.dylib"
fi
if [ ! -e "${BREW_PREFIX}"/lib/SoapySDR/modules0.*/libPlutoSDRSupport.so ]; then
if [ ! -e SoapyPlutoSDR ]; then
git clone https://github.com/pothosware/SoapyPlutoSDR.git
fi
(
cd SoapyPlutoSDR
rm -rf build
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX="${BREW_PREFIX}" ..
make -j${CPU_COUNT}
make install
)
install_name_tool -change @rpath/iio.framework/Versions/0.23/iio "${BREW_PREFIX}/lib/libiio.dylib" "${BREW_PREFIX}"/lib/SoapySDR/modules0.*/libPlutoSDRSupport.so
install_name_tool -change @rpath/ad9361.framework/Versions/0.2/ad9361 "${BREW_PREFIX}/lib/libad9361.dylib" "${BREW_PREFIX}"/lib/SoapySDR/modules0.*/libPlutoSDRSupport.so
fi
if [ ! -e "${BREW_PREFIX}/lib/libgnuradio-iqbalance.dylib" ]; then
if [ ! -e gr-iqbal ]; then
git clone https://gitea.osmocom.org/sdr/gr-iqbal.git
fi
(
cd gr-iqbal
git submodule update --init --recursive
rm -rf build
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX="${BREW_PREFIX}" ..
make -j${CPU_COUNT}
make install
)
fi
if [ ! -e "${BREW_PREFIX}/lib/libgnuradio-osmosdr.dylib" ]; then
if [ ! -e gr-osmosdr ]; then
git clone https://gitea.osmocom.org/sdr/gr-osmosdr.git
fi
(
cd gr-osmosdr
rm -rf build
mkdir -p build
cd build
cmake -DCMAKE_CXX_FLAGS=-Wno-register -DCMAKE_INSTALL_PREFIX="${BREW_PREFIX}" ..
LIBRARY_PATH="${BREW_PREFIX}/opt/icu4c/lib" make -j${CPU_COUNT}
make install
)
fi
if [ ! -e gqrx ]; then
git clone https://github.com/gqrx-sdr/gqrx.git
fi
cd gqrx
(
rm -rf build
mkdir -p build
cd build
cmake ..
make -j${CPU_COUNT}
)
GQRX_VERSION="$(cat version.txt)"
rm -rf Gqrx.app
mkdir -p Gqrx.app/Contents/MacOS
mkdir -p Gqrx.app/Contents/Resources
mkdir -p Gqrx.app/Contents/soapy-modules
/bin/cat <<EOM >Gqrx.app/Contents/Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleGetInfoString</key>
<string>Gqrx</string>
<key>CFBundleExecutable</key>
<string>gqrx</string>
<key>CFBundleIdentifier</key>
<string>dk.gqrx.gqrx</string>
<key>CFBundleName</key>
<string>Gqrx</string>
<key>CFBundleIconFile</key>
<string>gqrx.icns</string>
<key>CFBundleShortVersionString</key>
<string>$GQRX_VERSION</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>IFMajorVersion</key>
<integer>1</integer>
<key>IFMinorVersion</key>
<integer>0</integer>
</dict>
</plist>
EOM
/bin/cat <<EOM >build/Entitlements.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
</dict>
</plist>
EOM
cp -p build/src/gqrx Gqrx.app/Contents/MacOS
cp -p resources/icons/gqrx.icns Gqrx.app/Contents/Resources
cp -p "${BREW_PREFIX}"/lib/SoapySDR/modules*/libPlutoSDRSupport.so Gqrx.app/Contents/soapy-modules
cp -p "${BREW_PREFIX}"/lib/SoapySDR/modules*/libremoteSupport.so Gqrx.app/Contents/soapy-modules
chmod 644 Gqrx.app/Contents/soapy-modules/*
dylibbundler \
-s "${BREW_PREFIX}/opt/icu4c/lib/" \
-od -b \
-x Gqrx.app/Contents/MacOS/gqrx \
-x Gqrx.app/Contents/soapy-modules/libPlutoSDRSupport.so \
-x Gqrx.app/Contents/soapy-modules/libremoteSupport.so \
-d Gqrx.app/Contents/libs/
"${BREW_PREFIX}/opt/qt@6/bin/macdeployqt" Gqrx.app -no-strip -always-overwrite
"${BREW_PREFIX}/opt/qt@6/bin/macdeployqt" Gqrx.app -no-strip -always-overwrite # This is a workaround macdeployqt
cp -p "${BREW_PREFIX}/lib/libbrotlicommon.1.dylib" Gqrx.app/Contents/Frameworks
find Gqrx.app -name '*.framework' -or -name '*.dylib' -or -name '*.so' -or -name gqrx | {
while read -r f; do
codesign --sign - --force --preserve-metadata=entitlements,requirements,flags,runtime "${f}"
done
}
codesign --sign - --force --preserve-metadata=entitlements,requirements,flags,runtime Gqrx.app
rm -f Gqrx.dmg
hdiutil create Gqrx.dmg -srcfolder Gqrx.app -format UDZO -fs HFS+ -volname Gqrx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment