File OpenLoco.spec of Package OpenLoco

#
# spec file for package OpenLoco
#
# Copyright (c) 2020-2025, Martin Hauke <mardnh@gmx.de>
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

# The 32bit package (OpenLoco-32bit) can be obtained using the following command:
# osc build --baselibs --disable-debuginfo openSUSE_Tumbleweed i586 OpenLoco.spec

# 64bit version is not ready yet
#  -> https://github.com/OpenLoco/OpenLoco/pull/3288

%define _sfl_version 2.0.2
%define _objects_version 0.1.0

Name:           OpenLoco
Version:        25.11
Release:        0
Summary:        An open source re-implementation of Chris Sawyer's Locomotion
License:        MIT
Group:          Amusements/Games/Strategy/Other
URL:            https://openloco.io/
#Git-Clone:     https://github.com/OpenLoco/OpenLoco.git
Source:         https://github.com/OpenLoco/OpenLoco/archive/refs/tags/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source1:        https://github.com/slavenf/sfl-library/archive/refs/tags/%{_sfl_version}.tar.gz#/sfl-library-%{_sfl_version}.tar.gz
Source2:        https://github.com/OpenLoco/OpenGraphics/releases/download/v%{_objects_version}/objects.zip
BuildRequires:  cmake
BuildRequires:  gcc-c++
BuildRequires:  pkgconfig
BuildRequires:  execstack
%if 0%{?suse_version} > 1600
BuildRequires:  fmt-10-devel
%else
BuildRequires:  pkgconfig(fmt)
%endif
BuildRequires:  pkgconfig(SDL2_mixer)
BuildRequires:  libpng16-devel
BuildRequires:  libpng16-compat-devel
BuildRequires:  pkgconfig(openal)
# HACK
#[   33s] In file included from /home/abuild/rpmbuild/BUILD/OpenLoco-25.03-build/OpenLoco-25.03/src/OpenLoco/src/Ui.cpp:29:
#[   33s] /usr/include/SDL2/SDL_syswm.h:68:10: fatal error: X11/Xlib.h: No such file or directory
#[   33s]    68 | #include <X11/Xlib.h>
#
BuildRequires:  pkgconfig(x11)
# / HACK
BuildRequires:  pkgconfig(sdl2)
BuildRequires:  pkgconfig(yaml-cpp)
BuildRequires:  pkgconfig(zlib)
BuildRequires:  pkgconfig(gtest)
BuildRequires:  cmake(span-lite)
BuildRequires:  unzip
Provides:       bundled(sfl)
ExclusiveArch:  %{ix86}

%description
An open source re-implementation of Chris Sawyer's Locomotion.
A construction and management simulation video game that
simulates running a transport company.

Note: OpenLoco requires original files of Chris Sawyer's Locomotion
to play! It can be bought at either Steam or GOG.com.
You will be asked for the folder where these file are located in case
if these files could not be found.

%prep
%autosetup
mkdir prefetched
pushd prefetched
for s in %{SOURCE1}; do tar xvf "$s"; done
unzip -d objects-%{_objects_version} %{SOURCE2}

%build
export CXXFLAGS='-DOPENLOCO_VERSION_TAG=\"%{version}\"'
# the game segfaults with the distro provided CFLAGS, lto ???
#%%cmake \
mkdir build
cd build
cmake .. \
  -DFETCHCONTENT_SOURCE_DIR_SFL=../prefetched/sfl-library-%{_sfl_version} \
  -DFETCHCONTENT_SOURCE_DIR_OPENLOCO_OBJECTS=../prefetched/objects-%{_objects_version}
%cmake_build

%install
#%%cmake_install
install -D -m0755 build/OpenLoco %{buildroot}/%{_bindir}/openloco
# HACK
execstack -c %{buildroot}%{_bindir}/openloco

### MISC
# * data/ aus dem repo muss ich gleichen pfad wie das binary liegen
#    -> passenden wrapper bauen (angefangen openloco-wrapper.sh)
# * Nettes game Icon gibts upstream
# * Desktop file
#   -> https://github.com/OpenLoco/OpenLoco/pull/410

# language files needs to be present in the gamedir
# cp -arv data/language/ /data/Games/Locomotion-GOG-installed/

# siehe make install

%check
%ctest

%files
%license LICENSE
%doc CHANGELOG.md README.md
%{_bindir}/openloco

%changelog
openSUSE Build Service is sponsored by