## START: Set by rpmautospec
## (rpmautospec version 0.7.3)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 2;
    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 real_name fjordlauncher
%global nice_name FjordLauncher
%bcond_without qt6

# Change this variables if you want to use custom keys
# Leave blank if you want to build Fjord Launcher without MSA id or curseforge api key
%define msa_id default
%define curseforge_key default

%if %{with qt6}
%global qt_version 6
%global min_qt_version 6
%else
%global qt_version 5
%global min_qt_version 5.12
%endif

%global build_platform unknown

%if 0%{?fedora}
%global build_platform Fedora
%endif

%if 0%{?rhel}
%global build_platform RedHat
%endif

%if 0%{?centos}
%global build_platform CentOS
%endif

%if %{with qt6}
Name:             fjordlauncher
%else
Name:             fjordlauncher-qt5
%endif
Version:          9.1.0
Release:          %autorelease
Summary:          Fjord Launcher is a fork of Prism Launcher.
# see COPYING.md for more information
# each file in the source also contains a SPDX-License-Identifier header that declares its license
License:          GPL-3.0-only AND Apache-2.0 AND LGPL-3.0-only AND GPL-3.0-or-later AND GPL-2.0-or-later AND ISC AND OFL-1.1 AND LGPL-2.1-only AND MIT AND BSD-2-Clause-FreeBSD AND BSD-3-Clause AND LGPL-3.0-or-later
Group:            Amusements/Games
URL:              https://github.com/unmojang/FjordLauncher
Source0:          https://github.com/unmojang/FjordLauncher/releases/download/%{version}/%{real_name}-%{version}.tar.gz

BuildRequires:    cmake >= 3.15
BuildRequires:    extra-cmake-modules
BuildRequires:    gcc-c++
BuildRequires:    java-17-openjdk-devel
BuildRequires:    desktop-file-utils
BuildRequires:    libappstream-glib
BuildRequires:    cmake(ghc_filesystem)
BuildRequires:    cmake(Qt%{qt_version}Concurrent) >= %{min_qt_version}
BuildRequires:    cmake(Qt%{qt_version}Core) >= %{min_qt_version}
BuildRequires:    cmake(Qt%{qt_version}Gui) >= %{min_qt_version}
BuildRequires:    cmake(Qt%{qt_version}Network) >= %{min_qt_version}
BuildRequires:    cmake(Qt%{qt_version}NetworkAuth) >= %{min_qt_version}
BuildRequires:    cmake(Qt%{qt_version}Test) >= %{min_qt_version}
BuildRequires:    cmake(Qt%{qt_version}Widgets) >= %{min_qt_version}
BuildRequires:    cmake(Qt%{qt_version}Xml) >= %{min_qt_version}

%if %{with qt6}
BuildRequires:    cmake(Qt6Core5Compat)
%endif

BuildRequires:    pkgconfig(libcmark)
%if 0%{?fedora} < 38 || 0%{?rhel} || 0%{?centos}
BuildRequires:    cmark
%endif
BuildRequires:    pkgconfig(scdoc)
BuildRequires:    pkgconfig(zlib)

Requires(post):   desktop-file-utils
Requires(postun): desktop-file-utils

Requires:         qt%{qt_version}-qtimageformats
Requires:         qt%{qt_version}-qtsvg
Requires:         javapackages-filesystem
Recommends:       java-21-openjdk
Recommends:       java-17-openjdk
Suggests:         java-1.8.0-openjdk

# xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
Recommends:       xrandr
# libflite needed for using narrator in minecraft
Recommends:       flite
# Fjord supports enabling gamemode
Suggests:         gamemode

%if %{without qt6}
Conflicts:        %{real_name}
%endif

%description
A custom launcher for Minecraft that allows you to easily manage
multiple installations of Minecraft at once (Fork of MultiMC)


%prep
%autosetup -n FjordLauncher-%{version}

rm -rf libraries/{extra-cmake-modules,filesystem,zlib}

# Do not set RPATH
sed -i "s|\$ORIGIN/||" CMakeLists.txt


%build
%cmake \
  -DLauncher_QT_VERSION_MAJOR="%{qt_version}" \
  -DLauncher_BUILD_PLATFORM="%{build_platform}" \
  %if "%{msa_id}" != "default"
  -DLauncher_MSA_CLIENT_ID="%{msa_id}" \
  %endif
  %if "%{curseforge_key}" != "default"
  -DLauncher_CURSEFORGE_API_KEY="%{curseforge_key}" \
  %endif
  -DBUILD_TESTING=OFF

%cmake_build


%install
%cmake_install


%check
## disabled due to inconsistent results in copr builds that are not reproducible locally
# %ctest

%if 0%{?rhel} && 0%{?rhel} < 9
# disabled due to rhel not shipping a new enough version of libappstream-glib
# appstream-util validate-relax --nonet \
#     %{buildroot}%{_metainfodir}/org.unmojang.FjordLauncher.metainfo.xml

desktop-file-validate %{buildroot}%{_datadir}/applications/org.unmojang.FjordLauncher.desktop
%endif


%post
%if 0%{?rhel} && 0%{?rhel} < 9
/usr/bin/update-desktop-database &> /dev/null || :
/bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :
/bin/touch --no-create %{_datadir}/mime/packages &>/dev/null || :
%endif


%postun
%if 0%{?rhel} && 0%{?rhel} < 9
/usr/bin/update-desktop-database &> /dev/null || :
if [ $1 -eq 0 ] ; then
    /bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null
    /usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
    /usr/bin/update-mime-database %{_datadir}/mime &> /dev/null || :
fi
%endif


%posttrans
%if 0%{?rhel} && 0%{?rhel} < 9
/usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
/usr/bin/update-mime-database %{?fedora:-n} %{_datadir}/mime &> /dev/null || :
%endif


%files
%doc README.md
%license LICENSE COPYING.md
%dir %{_datadir}/%{nice_name}
%{_bindir}/fjordlauncher
%{_datadir}/%{nice_name}/NewLaunch.jar
%{_datadir}/%{nice_name}/JavaCheck.jar
%{_datadir}/%{nice_name}/qtlogging.ini
%{_datadir}/%{nice_name}/NewLaunchLegacy.jar
%{_datadir}/applications/org.unmojang.FjordLauncher.desktop
%{_datadir}/icons/hicolor/scalable/apps/org.unmojang.FjordLauncher.svg
%{_datadir}/mime/packages/modrinth-mrpack-mime.xml
%{_datadir}/qlogging-categories%{qt_version}/fjordlauncher.categories
%{_mandir}/man?/fjordlauncher.*
%{_metainfodir}/org.unmojang.FjordLauncher.metainfo.xml


%changelog
## START: Generated by rpmautospec
* Wed Oct 30 2024 Anton Perstenev <antonperstenev@gmail.com> - 9.1.0-2
- Update fjordlauncher.spec

* Wed Oct 30 2024 Anton Perstenev <antonperstenev@gmail.com> - 9.1.0-1
- Update fjordlauncher.spec

* Fri Aug 30 2024 miokudev <anton.perstenyov@gmail.com> - 8.4.2-1
- update to 8.4.2

* Sun Jul 07 2024 nobody <nobody@nodoby.com> - 8.4.1-1
- update version

* Tue May 28 2024 nobody <nobody@android> - 8.3.2-1
- update to 8.3.2

* Fri May 17 2024 miokudev <anton.perstenyov@gmail.com> - 8.3.1-1
- update to 8.3.1

* Thu May 16 2024 nobody <nobody@android> - 8.3-2
- fix .spec file

* Thu May 16 2024 nobody <nobody@android> - 8.3-1
- initial commit
## END: Generated by rpmautospec