%global libapogee_pkg indi-3rdparty-libapogee

Name:           indi-3rdparty-libraries
Version:        1.9.3
Release:        3%{?dist}
Summary:        INDI 3rdparty libraries
License:        LGPLv2+
URL:            http://indilib.org

# Tar is generated from the huge all-in-one tar from INDI
# by using ./generate-libraries-tarball.sh %%{version}
# The main source from upstream is at
# https://github.com/indilib/indi-3rdparty/archive/refs/tags/v%%{version}.tar.gz
Source0:        %{name}-%{version}.tar.xz
Source1:        generate-libraries-tarball.sh

Patch0:         modify_cmake_common_flags.patch

BuildRequires:  cmake
BuildRequires:  gcc-c++
BuildRequires:  systemd-rpm-macros
BuildRequires:  pkgconfig(libusb-1.0)
BuildRequires:  pkgconfig(libcurl)
BuildRequires:  pkgconfig(libindi) = %{version}

# We want this metapackage to install all libraries at once.
# Just use weak dependencies to avoid possible errors.
Recommends:     %{libapogee_pkg}%{?_isa} = %{version}-%{release}

%description
This is a metapackage for installing all INDI 3rdparty libraries
at once. You probably don't want to install everything, but just pick
the libraries you need from the appropriate subpackage.


%package -n %{libapogee_pkg}
License:        LGPLv2+ and MPLv2.0
Summary:        Library for Apogee CCD Cameras

Provides:       libapogee = 1:%{version}-%{release}
Obsoletes:      libapogee <= 1:1.9.3-2

%description -n %{libapogee_pkg}
Apogee library is used by applications to control Apogee CCDs.

%package -n %{libapogee_pkg}-devel
Summary:        Development files %{libapogee_pkg}
Requires:       %{libapogee_pkg}%{?_isa} = %{version}-%{release}

Provides:       libapogee-devel = 1:%{version}-%{release}
Obsoletes:      libapogee-devel <= 1:1.9.3-2

%description -n %{libapogee_pkg}-devel
These are the header files needed to develop a
%{libapogee_pkg} application


%prep
%autosetup -p1

# Do not hardcode udev rules and libs paths
sed -i 's|/etc/udev/rules.d|%{_udevrulesdir}|g' libapogee/CMakeLists.txt
sed -i 's|DESTINATION lib|DESTINATION lib${LIB_SUFFIX}|g' libapogee/CMakeLists.txt

%build
%cmake -DBUILD_LIBS=ON \
    -DWITH_APOGEE=ON \
    -DWITH_ASICAM=OFF \
    -DWITH_ATIK=OFF \
    -DWITH_FISHCAMP=OFF \
    -DWITH_FLI=OFF \
    -DWITH_MI=OFF \
    -DWITH_INOVAPLX=OFF \
    -DWITH_QHY=OFF \
    -DWITH_QSI=OFF \
    -DWITH_SBIG=OFF \
    -DWITH_PENTAX=OFF \
    -DWITH_AHP_XC=OFF \
    -DWITH_TOUPBASE=OFF \
    -DWITH_SV305=OFF \
    -DWITH_PLAYERONE=OFF \

%cmake_build


%install
%cmake_install


%files
%license LICENSE
%doc README.md


%files -n %{libapogee_pkg}
%license libapogee/LICENSE
%doc libapogee/README
%{_libdir}/libapogee.so.3*
# The following are config files not intended to be modified by users
%config %{_sysconfdir}/Apogee
%{_udevrulesdir}/99-apogee.rules

%files -n %{libapogee_pkg}-devel
%{_includedir}/libapogee
%{_libdir}/*.so


%changelog
* Sun Jan 09 2022 Mattia Verga <mattia.verga@protonmail.com> - 1.9.3-3
- Override some builder and linker flags

* Sat Jan 08 2022 Mattia Verga <mattia.verga@protonmail.com> - 1.9.3-2
- Initial packaging