# If we have a prerelease version we can define it here
#%%global prever RC1

Name:           openttd
Version:        13.0
Release:        1%{?prever:.%{prever}}%{?dist}
Summary:        Transport system simulation game

License:        GPLv2+
URL:            https://www.openttd.org
Source0:        https://cdn.openttd.org/openttd-releases/%{version}%{?prever:-%{prever}}/%{name}-%{version}%{?prever:-%{prever}}-source.tar.xz

BuildRequires:  cmake
BuildRequires:  desktop-file-utils
BuildRequires:  doxygen
BuildRequires:  fontconfig-devel
BuildRequires:  fluidsynth-devel
BuildRequires:  freetype-devel
BuildRequires:  gcc-c++
BuildRequires:  libicu-devel
BuildRequires:  libpng-devel
BuildRequires:  lzo-devel
BuildRequires:  SDL2-devel
BuildRequires:  xz-devel
BuildRequires:  zlib-devel

Requires:       hicolor-icon-theme

Recommends:     openttd-opengfx => 0.5.0
Recommends:     fluid-soundfont-gm

%description
OpenTTD is modeled after a popular transportation business simulation game
by Chris Sawyer and enhances the game experience dramatically. Many features
were inspired by TTDPatch while others are original.


%package docs
Summary:        Documentation for OpenTTD
BuildArch:      noarch
Requires:       %{name} = %{version}-%{release}

%description docs
Development documentation for OpenTTD. Includes information on how to program
the AI.


%prep
%autosetup -p1 -n %{name}-%{version}%{?prever:-%{prever}}

sed -i "s|/usr/share|%{_datadir}|g" src/music/fluidsynth.cpp

%build
mkdir build
cd build  
%cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_BINDIR=bin \
    -DCMAKE_INSTALL_DATADIR=%{_datadir} \
    -DGLOBAL_DIR:PATH=%{_datadir}/%{name} ..

%make_build

%install
cd build
%make_install

# Remove the installed docs - we will install subset of those
rm -rf $RPM_BUILD_ROOT%{_docdir}

# install documentation
install -dpm 755 $RPM_BUILD_ROOT%{_datadir}/%{name}/docs/
cp -a docs/* $RPM_BUILD_ROOT%{_datadir}/%{name}/docs/
# this is installed into the proper path earlier
#rm $RPM_BUILD_ROOT%{_datadir}/%{name}/docs/%{name}.6


desktop-file-install --dir=$RPM_BUILD_ROOT%{_datadir}/applications \
        --add-category=StrategyGame \
        $RPM_BUILD_ROOT%{_datadir}/applications/openttd.desktop

# Register as an application to be visible in the software center
#
# NOTE: It would be *awesome* if this file was maintained by the upstream
# project, translated and installed into the right place during `make install`.
#
# See http://www.freedesktop.org/software/appstream/docs/ for more details.
#
mkdir -p $RPM_BUILD_ROOT%{_datadir}/appdata
cat > $RPM_BUILD_ROOT%{_datadir}/appdata/%{name}.appdata.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2014 Ankur Sinha <ankursinha@fedoraproject.org> -->
<!--
EmailAddress: alberth@openttd.org
SentUpstream: 2014-09-25
-->
<application>
  <id type="desktop">openttd.desktop</id>
  <metadata_license>CC0-1.0</metadata_license>
  <summary>A highly detailed transport simulation game</summary>
  <description>
  <p>
      OpenTTD is a transport tycoon simulation game that enhances the
      original Transport Tycoon game developed by Chris Sawyer.
      The game includes road, air, train and naval transport with a large
      selection of industries and passenger services that need to be provided.
    </p>
  <p>
      The game can be played in both single and multiplayer modes where
      you compete with other transport companies to dominate the markets.
  </p>
  </description>
  <url type="homepage">https://www.openttd.org</url>
  <screenshots>
    <screenshot type="default">https://www.openttd.org/screenshots/1.4-02-opengfx-1920x1200.png</screenshot>
    <screenshot>https://www.openttd.org/screenshots/1.9-darkuk-3.png</screenshot>
  </screenshots>
  <updatecontact>info@openttd.org</updatecontact>
</application>
EOF

%files
%license COPYING.md
%doc changelog.txt CONTRIBUTING.md CREDITS.md known-bugs.txt README.md
%{_bindir}/%{name}
%{_datadir}/appdata/%{name}.appdata.xml
%{_datadir}/applications/%{name}.desktop
%{_mandir}/man6/%{name}.6*
%{_datadir}/%{name}
%{_datadir}/pixmaps/%{name}.32.xpm
%{_datadir}/pixmaps/%{name}.64.xpm
%{_datadir}/icons/hicolor/*/apps/%{name}.png
%exclude %{_datadir}/%{name}/docs

%files docs
# These are really devel docs, but as we don't have -devel subpackage, we put it here
# Could be useful for people making graphics, AI scripts or translations
%{_datadir}/%{name}/docs/


%changelog
* Wed May 24 2023 wangtaozhi <wangtaozhi@kylinsec.com.cn> - 13.0-1
- Package init
