# SatDump RPM spec — Fedora 44
#
# Toggle optional feature sets with rpmbuild --with/--without, e.g.:
#   rpmbuild -ba satdump.spec --without gui --without live
#
# NOTE: these use the "bcond_without" form, which means "enabled by
# default, pass --without NAME on the rpmbuild command line to disable."
# An earlier draft tried to fake that same default-on behavior using the
# other form with an extra argument tacked on - that's not valid syntax
# (that other form takes exactly one argument and always defaults to
# *disabled*), so every "with"-conditional block below was silently false
# the whole time. Confirmed by an actual build: satdump-ui never got
# built, and yet satdump.desktop and satdump_sdr_server were installed
# anyway - meaning neither of those is actually gated by BUILD_GUI/
# BUILD_LIVE in this codebase to begin with. Both fixed below: correct
# bcond form, and desktop file/sdr server moved out of the conditional
# blocks entirely.
%bcond_without  gui
%bcond_without  live
%bcond_without  audio
%bcond_without  zstd
%bcond_without  hdf5
%bcond_without  opencl
# Unlike bcond_without gui, this one really does default OFF: Fedora's
# repos don't package bladeRF/libbladeRF at all (confirmed against a live
# Fedora 44 system - dnf gives "No match for argument: bladeRF-devel").
# SatDump's own docs hint at this too: their Red-Hat-specific dnf
# one-liner never lists a bladeRF package, only the openSUSE zypper one
# does. Pass --with bladerf only if you've built/installed libbladeRF from
# source yourself first.
%bcond_with     bladerf

# This build's LTO flags (-flto=auto -ffat-lto-objects) across ~15 plugin
# .so's plus the core library confuse Fedora's automatic debuginfo
# extraction into leaving orphaned files under /usr/lib/debug that never
# make it into an automatically generated -debuginfo/-debugsource
# package, which fails the build with "installed but unpackaged files".
# Simplest reliable fix: skip debuginfo packaging for this build entirely.
%global debug_package %{nil}

Name:           satdump
Version:        1.2.2
Release:        1%{?dist}
Summary:        Generic satellite data processing software

License:        GPL-3.0-only
URL:            https://www.satdump.org
Source0:        https://github.com/SatDump/SatDump/archive/refs/tags/%{version}.tar.gz#/%{name}-%{version}.tar.gz
# 1.2.2 vendors sol2 3.2.3, whose sol::optional<T&>::emplace() calls a
# construct() member that doesn't exist on that partial specialization.
# GCC < 13 never checked the un-instantiated branch closely enough to catch
# it; GCC 13+ (Fedora 44 ships GCC 15) turns it into a hard FTBFS:
# "class sol::optional<T&>' has no member named 'construct'". Upstream's own
# fix (used e.g. by Debian) was bumping the vendored header to a newer
# generated sol2 release in commit 2b0a874f3 - pull those two files straight
# from that commit so mock/koji's offline build phase already has them
# staged, rather than trying to network-fetch mid-build.
Source1:        https://raw.githubusercontent.com/SatDump/SatDump/2b0a874f38d9310e3e4cbc56cfcc69cb0a59e035/src-core/libs/sol2/sol.hpp
Source2:        https://raw.githubusercontent.com/SatDump/SatDump/2b0a874f38d9310e3e4cbc56cfcc69cb0a59e035/src-core/libs/sol2/config.hpp

BuildRequires:  gcc-c++
BuildRequires:  cmake >= 3.13
BuildRequires:  git
BuildRequires:  pkgconfig
BuildRequires:  desktop-file-utils
BuildRequires:  fftw-devel
BuildRequires:  volk-devel
BuildRequires:  libpng-devel
BuildRequires:  libtiff-devel
BuildRequires:  jemalloc-devel
BuildRequires:  libcurl-devel
BuildRequires:  sqlite-devel
BuildRequires:  nng-devel
BuildRequires:  armadillo-devel
BuildRequires:  lua-devel

%if %{with gui}
BuildRequires:  glfw-devel
BuildRequires:  dbus-devel
BuildRequires:  zenity
%endif

%if %{with audio}
BuildRequires:  portaudio-devel
%endif

%if %{with zstd}
BuildRequires:  libzstd-devel
%endif

%if %{with hdf5}
BuildRequires:  hdf5-devel
%endif

%if %{with opencl}
BuildRequires:  OpenCL-ICD-Loader-devel
BuildRequires:  opencl-headers
%endif

%if %{with live}
BuildRequires:  rtl-sdr-devel
BuildRequires:  hackrf-devel
BuildRequires:  airspyone_host-devel
BuildRequires:  airspyhf-devel
BuildRequires:  libiio-devel
BuildRequires:  libad9361-iio-devel
%endif

%if %{with bladerf}
BuildRequires:  bladeRF-devel
%endif

# NNG's Fedora package may lag behind upstream point releases; if configure
# fails to find nng >= 1.5 with the packaged nng-devel, see the NOTES file
# for the fallback of vendoring nng from source.

%description
SatDump is a generic satellite data processing software, aimed at providing
a nice UI/UX along with just as advanced features directly aimed at satellite
data reception, processing and product generation from a large number of
satellites, all this handled in an all-in-one software.

This build targets Fedora 44 and packages both the CLI (satdump) and, unless
disabled, the GUI (satdump-ui) and SDR server (satdump_sdr_server).

%package devel
Summary:        Development files for SatDump
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description devel
Headers for building third-party SatDump plugins or linking against
libsatdump_core directly.

%prep
%setup -q -n SatDump-%{version}

# Swap in the fixed sol2 header pair — see the Source1/Source2 comments
# above. rpmbuild has already staged these in SOURCES/, so this is a plain
# local copy and works fine under mock/koji's network-isolated build.
cp -f %{SOURCE1} src-core/libs/sol2/sol.hpp
cp -f %{SOURCE2} src-core/libs/sol2/config.hpp

# The vendored libacars copy (inmarsat_support plugin) declares its list
# callbacks with old K&R-style empty-parens prototypes, e.g.
# "void (*node_free)()". Under C17 and earlier that meant "unspecified
# arguments" (compatible with anything); GCC 15's C23-by-default treats
# empty parens as "takes no arguments", so every real call site now
# mismatches. (Passing -std=gnu17 does NOT reliably fix this here: this
# plugin's own CMakeLists.txt calls cmake_minimum_required(VERSION 3.12),
# which resets CMake's policy version for that subdirectory below 3.22
# and with it CMP0128, so CMAKE_C_STANDARD can silently fail to emit any
# -std= flag at all for these sources - confirmed by testing.) Give the
# three declarations/definitions their real prototypes instead, matching
# how every call site in this plugin already uses them.
sed -i \
  -e 's/void la_list_foreach(la_list \*l, void (\*cb)(), void \*ctx);/void la_list_foreach(la_list *l, void (*cb)(void const *, void *), void *ctx);/' \
  -e 's/void la_list_free_full(la_list \*l, void (\*node_free)());/void la_list_free_full(la_list *l, void (*node_free)(void *));/' \
  -e 's/void la_list_free_full_with_ctx(la_list \*l, void (\*node_free)(), void \*ctx);/void la_list_free_full_with_ctx(la_list *l, void (*node_free)(void *, void *), void *ctx);/' \
  plugins/inmarsat_support/aero/libacars/list.h
sed -i \
  -e 's/void la_list_foreach(la_list \*l, void (\*cb)(), void \*ctx) {/void la_list_foreach(la_list *l, void (*cb)(void const *, void *), void *ctx) {/' \
  -e 's/void la_list_free_full_with_ctx(la_list \*l, void (\*node_free)(), void \*ctx) {/void la_list_free_full_with_ctx(la_list *l, void (*node_free)(void *, void *), void *ctx) {/' \
  -e 's/void la_list_free_full(la_list \*l, void (\*node_free)()) {/void la_list_free_full(la_list *l, void (*node_free)(void *)) {/' \
  plugins/inmarsat_support/aero/libacars/list.c

%build
# Upstream's CMakeLists.txt appends -march=native unless it thinks it is
# running in CI, which is not what we want for a redistributable package.
export CI=true

%cmake \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=%{_prefix} \
%if %{with gui}
  -DBUILD_GUI=ON \
%else
  -DBUILD_GUI=OFF \
%endif
%if %{with live}
  -DBUILD_LIVE=ON \
%else
  -DBUILD_LIVE=OFF \
%endif
%if !%{with opencl}
  -DBUILD_OPENCL=OFF \
%endif
%if %{with bladerf}
  -DPLUGIN_BLADERF_SDR_SUPPORT=ON \
%else
  -DPLUGIN_BLADERF_SDR_SUPPORT=OFF \
%endif
  -DBUILD_ZIQ=%{?with_zstd:ON}%{!?with_zstd:OFF} \
  -DBUILD_ZIQ2=%{?with_zstd:ON}%{!?with_zstd:OFF}

%cmake_build

%install
%cmake_install

# Trim the CMake uninstall helper target artifact if present; it's not
# something the RPM should own.
rm -f %{buildroot}%{_prefix}/lib/cmake/satdump/cmake_uninstall.cmake 2>/dev/null || :

%check
desktop-file-validate %{buildroot}%{_datadir}/applications/satdump.desktop

%files
%license LICENSE
%doc README.md
%{_bindir}/satdump
%{_bindir}/satdump_sdr_server
%{_datadir}/applications/satdump.desktop
%if %{with gui}
%{_bindir}/satdump-ui
%endif
%{_datadir}/satdump/
%{_libdir}/satdump/
%{_libdir}/libsatdump_core.so
%{_libdir}/libsatdump_interface.so

%files devel
%{_includedir}/%{name}/

%changelog
* Tue Jul 07 2026 Packager <you@example.com> - 1.2.2-1
- Initial packaging of SatDump 1.2.2 for Fedora 44
