Name:          saga
Version:       9.0.3
Release:       1%{?dist}
Summary:       SAGA GIS - System for Automated Geoscientific Analyses

License:       GPL-2.0-or-later and LGPL-2.1-or-later

URL:           http://www.saga-gis.org
# Source0:       https://sourceforge.net/projects/saga-gis/files/SAGA%%20-%%208/SAGA%%20-%%20%%{version}/saga-%%{version}.tar.gz

# nonfree content in upstream tarball, link to old saga mailing list message 
# https://sourceforge.net/p/saga-gis/mailman/message/28391147/
Source0:       %{name}-%{version}.tar.xz
Source1:       %{name}_generate_tarball.sh

Patch1:        %{name}_logos.patch
Patch2:        %{name}_geotrans.patch
Patch3:        %{name}_python.patch

BuildRequires: cmake
BuildRequires: libgomp
BuildRequires: gcc-c++
BuildRequires: libtool
BuildRequires: wxGTK-devel >= 3.2
BuildRequires: proj-devel
BuildRequires: gdal-devel
BuildRequires: libtiff-devel
BuildRequires: unixODBC-devel
BuildRequires: libpq-devel
BuildRequires: jasper-devel
BuildRequires: libharu-devel
BuildRequires: vigra-devel
BuildRequires: hdf5-devel
BuildRequires: opencv-devel
BuildRequires: fftw3-devel
BuildRequires: libcurl-devel
BuildRequires: PDAL-devel
BuildRequires: libsvm-devel
BuildRequires: qhull-devel
BuildRequires: swig
BuildRequires: libappstream-glib
BuildRequires: desktop-file-utils
BuildRequires: python3-devel

%description
SAGA - System for Automated Geoscientific Analyses is a free geographic
information system (GIS) platform supporting raster, vector, tabular and 
pointcloud data. SAGA provides access to its tools via GUI, 
command line (shell) or its API.  


%package devel
Summary:        SAGA - System for Automated Geoscientific Analyses development package
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description    devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.


%package python
Summary:        SAGA - System for Automated Geoscientific Analyses python package
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description python 
This %{name}-python package includes the python bindings for %{name}.

%prep

%setup -q -n saga-%{version}/%{name}-gis
%patch 1 -p2 
%patch 2 -p2 
%patch 3 -p2
%py3_shebang_fix src/accessories/python/saga.py

%build
%cmake -DCMAKE_BUILD_TYPE=RELEASE \
    -DWITH_EXCERCISES=OFF \
    -DWITH_DEV_TOOLS=OFF \
    -DWITH_SYSTEM_SVM=ON \
    -DWITH_FIRE_SPREADING=OFF \
    -DWITH_MRMR=OFF \
    -DWITH_CLIPPER_ONE=OFF \
    -DWITH_TOOLS_PDAL=ON \
    -DWITH_PYTHON=ON

%cmake_build

%install
%cmake_install
desktop-file-validate %{buildroot}/%{_datadir}/applications/%{name}.desktop
appstream-util validate-relax --nonet %{buildroot}/%{_datadir}/metainfo/org.saga-gis.saga-gui.appdata.xml
# install german language file
install src/saga_core/saga_gui/res/saga.ger.txt  %{buildroot}/%{_datadir}/%{name} 
#remove some icons and pixmaps folder
rm -rf %{buildroot}%{_datadir}/icons/hicolor/{8x8,72x72,80x80,192x192}/
rm -rf %{buildroot}%{_datadir}/pixmaps

%ldconfig_scriptlets


%files
%defattr(644,root, root, -)
%doc readme.md
%license src/gpl.txt src/lgpl.txt
%{_datadir}/%{name}/*
%{_datadir}/icons/hicolor/*/apps/%{name}.png
%{_datadir}/applications/%{name}.desktop
%{_datadir}/metainfo/org.saga-gis.saga-gui.appdata.xml
%{_mandir}/man1/%{name}_*1*

%defattr(-,root, root, -)
%{_bindir}/%{name}_cmd
%{_bindir}/%{name}_gui
%{_libdir}/%{name}/*
%{_libdir}/lib%{name}_api.so.*
%{_libdir}/lib%{name}_gdi.so.*

%files devel
%{_includedir}/%{name}/
%{_libdir}/lib%{name}_api.so
%{_libdir}/lib%{name}_gdi.so

%files python
%{python3_sitearch}/saga_api.py
%attr(755, root, root) %{python3_sitearch}/saga.py
%{python3_sitearch}/_saga_api.so
%{python3_sitearch}/__pycache__/saga*.pyc

%changelog
* Wed Jul 5 2023 Manfred Egger - 9.0.3-1
- Update to 9.0.3

* Sat Jul 01 2023 Manfred Egger - 9.0.2-2
- Build with Clipper 2

* Thu Jun 01 2023 Manfred Egger - 9.0.2-1
- Update to 9.0.2

* Mon Apr 24 2023 Manfred Egger - 9.0.1-1
- Initial packaging