## START: Set by rpmautospec
## (rpmautospec version 0.7.2)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 3;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

%global gittag 4.2.0
#%%global commit a2da14bfc6727b1255df6f31ac4ce89d4bd881c8
#%%global shortcommit %%(c=%%{commit}; echo ${c:0:7})
#%%global date 20240205

Name:           xephem
%if "%{?gittag}"
Version:        %{gittag}
%else
Version:        4.1.0^%{date}.git%{shortcommit}
%endif
Release:        %autorelease
Summary:        Scientific-grade interactive astronomical ephemeris software
License:        MIT-advertising and LGPL-2.1-or-later

URL:            https://%{name}.github.io
%if "%{?gittag}"
Source0:        https://github.com/XEphem/XEphem/archive/%{gittag}/XEphem-%{version}.tar.gz
%else
Source0:        https://github.com/XEphem/XEphem/archive/%{commit}/XEphem-%{commit}.tar.gz
%endif
# Desktop and appstream metadata files are not provided in upstream sources
Source1:        io.github.xephem.desktop
Source2:        io.github.xephem.metainfo.xml

# Patch to use system libraries and not override CFLAGS
# Proposed upstream: https://github.com/XEphem/XEphem/pull/58
Patch:          xephem_makefile.patch

# Patch to use cmake to build and install
# Proposed upstream: https://github.com/XEphem/XEphem/pull/60
Patch:          xephem_with_cmake.patch

# Define _GNU_SOURCE, so that <time.h> declares strptime, an X/Open
# extension that is not available by default in the glibc headers.
# Submitted upstream: <https://github.com/XEphem/XEphem/pull/73>
Patch:          xephem-c99.patch

ExcludeArch:    %{ix86}

BuildRequires:  desktop-file-utils
BuildRequires:  cmake
BuildRequires:  gcc
BuildRequires:  groff-base
BuildRequires:  libappstream-glib
BuildRequires:  make
BuildRequires:  motif-devel
BuildRequires:  ImageMagick
BuildRequires:  pkgconfig(libjpeg)
BuildRequires:  pkgconfig(libpng)
BuildRequires:  pkgconfig(libssl)
BuildRequires:  pkgconfig(libxml-2.0)
BuildRequires:  pkgconfig(zlib)

Requires:       %{name}-data = %{version}-%{release}
Requires:       curl
Requires:       gzip

%description
XEphem is a scientific-grade interactive astronomical ephemeris software.
It can calculate ephemeris for astronomical objects and display the results
in tabular or graphical output.

XEphem can also be used to control telescopes, generate sky maps, perform
image analysis and much more.


%package        data
Summary:        Data files for %{name}
BuildArch:      noarch
Requires:       %{name} = %{version}-%{release}

%description    data
The %{name}-data package contains data files for %{name} functionality.


%prep
%if "%{?gittag}"
%autosetup -p1 -n XEphem-%{version}
%else
%autosetup -p1 -n XEphem-%{commit}
%endif

# Remove libraries sources for which we want to use system libraries
rm -rf libpng/
rm -rf libjpegd/
rm -rf libz/
rm -rf libXm/

# Rename liblilxml license files
cp liblilxml/LICENSE LICENSE.liblilxml

# Change hardcoded resources directory for flatpak
%if 0%{?flatpak}
sed -i -e 's|/etc/XEphem|/app/etc/XEphem|g' GUI/xephem/{splash.c,xephem.c}
%endif


%build
%if 0%{?epel}
%set_build_flags
%endif

%cmake
%cmake_build

# Create standard size icons
for d in 32 48 64 128 ; do
    convert GUI/xephem/XEphem.png -geometry ${d}x${d} -depth 8 -background none xephem-${d}.png
done

# Old manual build method
#pushd GUI/xephem
#%%make_build
#popd


%install
%cmake_install

# Old manual install method
# There's no automated install
#mkdir -p %%{buildroot}%%{_bindir}
#mkdir -p %%{buildroot}%%{_mandir}/man1/
#mkdir -p %%{buildroot}%%{_datadir}/%%{name}
#pushd GUI/xephem
#install -p -m0755 %%{name} %%{buildroot}/%%{_bindir}
#install -p -m0644 %%{name}.1 %%{buildroot}/%%{_mandir}/man1/
#cp -pR auxil %%{buildroot}%%{_datadir}/%%{name}
#cp -pR catalogs %%{buildroot}%%{_datadir}/%%{name}
#cp -pR fifos %%{buildroot}%%{_datadir}/%%{name}
#cp -pR fits %%{buildroot}%%{_datadir}/%%{name}
#cp -pR gallery %%{buildroot}%%{_datadir}/%%{name}
#cp -pR help %%{buildroot}%%{_datadir}/%%{name}
#cp -pR lo %%{buildroot}%%{_datadir}/%%{name}
#popd

# Create file to tell xephem where to find resources
mkdir -p %{buildroot}%{_sysconfdir}
cat >%{buildroot}%{_sysconfdir}/XEphem <<EOF
XEphem.ShareDir: %{_datadir}/%{name}
EOF

# Provide a desktop entry
desktop-file-install --dir=%{buildroot}%{_datadir}/applications %{SOURCE1}

# Install icons
for d in 32 48 64 128 ; do
    mkdir -p %{buildroot}%{_datadir}/icons/hicolor/${d}x${d}/apps/
    install -p -m0644 xephem-${d}.png %{buildroot}%{_datadir}/icons/hicolor/${d}x${d}/apps/xephem.png
done

# Install appstream metadata
mkdir -p %{buildroot}%{_metainfodir}
install -p -m0644 %{SOURCE2} %{buildroot}%{_metainfodir}


%check
appstream-util validate-relax --nonet %{buildroot}%{_metainfodir}/*.metainfo.xml

pushd tests
make run-test
popd


%files
%license LICENSE LICENSE.liblilxml
%doc README.md
%{_bindir}/%{name}
%{_mandir}/man1/%{name}.1*
%{_datadir}/applications/io.github.%{name}.desktop
%{_datadir}/icons/hicolor/*/apps/xephem.png
%{_metainfodir}/io.github.%{name}.metainfo.xml

%files      data
%{_datadir}/%{name}
%config(noreplace) %{_sysconfdir}/XEphem


%changelog
## START: Generated by rpmautospec
* Sat Jul 20 2024 Fedora Release Engineering <releng@fedoraproject.org> - 4.2.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Thu Feb 15 2024 Mattia Verga <mattia.verga@proton.me> - 4.2.0-2
- Fix hardcoded dirs for flatpak compatibility

* Wed Feb 14 2024 Mattia Verga <mattia.verga@proton.me> - 4.2.0-1
- Update to stable 4.2.0 (fedora#2264118)

* Sun Feb 11 2024 Mattia Verga <mattia.verga@proton.me> - 4.1.0^320240205.gita2da14b-1
- Update to latest svn version
- Fix icons and desktop file
- Add appstream metainfo
- Fix versioning

* Sat Jan 27 2024 Fedora Release Engineering <releng@fedoraproject.org> - 4.1.0^202301140a1b505-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Sat Jul 22 2023 Fedora Release Engineering <releng@fedoraproject.org> - 4.1.0^202301140a1b505-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Sat Feb 11 2023 Mattia Verga <mattia.verga@proton.me> - 4.1.0^202301140a1b505-5
- Add missing cmake BuildRequires

* Sat Feb 11 2023 Mattia Verga <mattia.verga@proton.me> - 4.1.0^202301140a1b505-4
- Fix patch for new sources

* Sat Feb 11 2023 Mattia Verga <mattia.verga@proton.me> - 4.1.0^202301140a1b505-1
- Patch sources to use cmake for build and install

* Thu Jan 19 2023 Florian Weimer <fweimer@redhat.com> - 4.1.0^20221006b7bfc6e-4
- C99 compatibility fix

* Mon Oct 10 2022 Mattia Verga <mattia.verga@proton.me> - 4.1.0^20221006b7bfc6e-3
- Add libxml2 to BR and fix patch
- Add gzip and curl to runtime dependencies

* Fri Oct 07 2022 Mattia Verga <mattia.verga@proton.me> - 4.1.0^20221006b7bfc6e-2
- Set build flags for EPEL

* Fri Oct 07 2022 Mattia Verga <mattia.verga@proton.me> - 4.1.0^20221006b7bfc6e-1
- Initial import (fedora#2123242)
## END: Generated by rpmautospec