# This should never enabled for official Fedora build
# https://gitlab.com/fedora/legal/fedora-license-data/-/issues/345
%bcond_with build_with_assets

Name:           opentyrian
Version:        2.1.20221123
Release:        1%{?dist}
Summary:        An open-source port of the DOS shoot-em-up Tyrian

# GNU Lesser General Public License v2.1 or later
# -----------------------------------------------
# src/opl.c
# src/opl.h
#
# BSD 3-Clause License
# --------------------
# src/mtrand.c
#
# ========================================
#
# Tyrian was released as Freeware in 2004.
#
# From http://www.freewebs.com/worldtreegames/ :
# > Feel free to play it all you want and share it with friends, but for
# > the moment I'd like to just have a central backup place (here) for
# > the game.  In the future I might not mind other sites sharing it,
# > but I do enjoy amusing fans. :)
#
# From http://www.camanis.net/ :
# > Tyrian has been released as freeware by Jason Emery.
#
# These terms overide the one from the license.doc
# present in tyrian21.zip.
License:        GPL-2.0-or-later and LGPL-2.1-or-later and BSD-3-Clause
URL:            https://github.com/opentyrian/opentyrian
Source0:        %{url}/archive/v%{version}/%{name}-%{version}.tar.gz
%if %{with build_with_assets}
# Tyrian Freeware game assets
Source1:        https://camanis.net/tyrian/tyrian21.zip
%endif
# AppData rejected by upstream
# https://github.com/opentyrian/opentyrian/pull/13
Source2:        https://raw.githubusercontent.com/flathub/com.github.%{name}.OpenTyrian/master/%{name}.appdata.xml
# Currently only system path for data/assets files allowed, see
# https://github.com/opentyrian/opentyrian/issues/73
Source3:        %{name}-install-data-files.sh

BuildRequires:  desktop-file-utils
BuildRequires:  gcc-c++
BuildRequires:  libappstream-glib

BuildRequires:  pkgconfig(SDL2_net)
BuildRequires:  pkgconfig(sdl2)

Requires:       %{name}-data = %{version}-%{release}
Requires:       hicolor-icon-theme

%global _description %{expand:
OpenTyrian is an open-source port of the DOS game Tyrian.

Tyrian is an arcade-style vertical scrolling shooter.  The story is set in
20,031 where you play as Trent Hawkins, a skilled fighter-pilot employed to
fight MicroSol and save the galaxy.

Tyrian features a story mode, one- and two-player arcade modes, and networked
multiplayer.}

%description %{_description}

# Tyrian Freeware game assets
%package        data
Summary:        Game assets files for %{name}
BuildArch:      noarch

Requires:       %{name} = %{version}-%{release}

%description    data %{_description}

Game assets files for %{name}.


%prep
%autosetup -p1
%if %{with build_with_assets}
%autosetup -p1 -a1
%endif

%if %{with build_with_assets}
# Clean useless Windows files of Tyrian Freeware game assets
pushd tyrian21
rm -rf {*.exe,tyrian.ico,helpme.doc,manual.doc,order.doc,shipedit.doc,dpmi16bi.ovl}
# Remove obsoleted license file
rm -f license.doc
popd
%endif


%build
%set_build_flags
%make_build \
    gamesdir=%{_datadir} \
    OPENTYRIAN_VERSION=%{version} \
    prefix=%{_prefix} \


%install
%make_install \
    docdir=%{_docdir}/%{name} \
    gamesdir=%{_datadir} \
    OPENTYRIAN_VERSION=%{version} \
    prefix=%{_prefix} \


mkdir -p %{buildroot}%{_datadir}/tyrian
%if %{with build_with_assets}
# Install Tyrian Freeware game assets
cp -a tyrian21/* %{buildroot}%{_datadir}/tyrian/
%endif
# Install AppData manifest
install -D -p -m 0644 %{SOURCE2} %{buildroot}%{_metainfodir}/%{name}.appdata.xml
%if %{without build_with_assets}
# Install OpenTyrian data/assets files installation script
install -D -p -m 0755 %{SOURCE3} %{buildroot}%{_bindir}/%{name}-install-data-files.sh
%endif


%check
appstream-util validate-relax --nonet %{buildroot}%{_metainfodir}/*.xml
desktop-file-validate %{buildroot}%{_datadir}/applications/*.desktop


%files
%license COPYING
%doc %{_docdir}/%{name}
%{_bindir}/%{name}
%{_datadir}/applications/%{name}.desktop
%{_datadir}/icons/hicolor/*/apps/*.png
%{_mandir}/man6/*.6*
%{_metainfodir}/%{name}.appdata.xml

%files data
%if %{without build_with_assets}
%{_bindir}/%{name}-install-data-files.sh
%endif
%{_datadir}/tyrian/


%changelog
* Sun Oct 01 2023 Artem Polishchuk <ego.cordatus@gmail.com> - 2.1.20221123-1
- build: Allow to build with/without data files
- license: Convert to SPDX

* Tue Dec 20 2022 Artem Polishchuk <ego.cordatus@gmail.com> - 2.1.20221123-1
- chore: Update to v2.1.20221123

* Fri May 20 2022 Artem Polishchuk <ego.cordatus@gmail.com> - 2.1.20220318-1
- Initial