File meson.spec of Package meson

%define realname meson
# Meson >= 0.62 requires Python >= 3.7
%define realver  1.7.0
%define srcext   tar.gz

%if 0%{?rhel} >= 8
%define python3_pkg platform-python
%define __python3   /usr/libexec/platform-python
%else
%define python3_pkg python39
%define __python3   %{_bindir}/python3.9
%endif

%if ! 0%{?py3_ver:1}
%define py3_ver %(%{__python3} -c "import sys; v=sys.version_info[:2]; print ('%%d.%%d'%%v)" 2>/dev/null || echo PYTHON3-NOT-FOUND)
%endif
%define py3_gen %(%{__python3} -c "import sys; v=sys.version_info[:2]; print ('%%d%%d'%%v)" 2>/dev/null || echo PYTHON3-NOT-FOUND)

# Common info
Name:          %{realname}
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       Apache-2.0
Group:         Development/Tools/Building
URL:           https://mesonbuild.com/
Summary:       A high performance build system

# Install-time parameters
Requires:      python(abi) = %{py3_ver}
Requires:      %{python3_pkg}-setuptools
Requires:      ninja
Requires:      polkit

# Build-time parameters
BuildRequires: python3-rpm-macros
BuildRequires: %{python3_pkg}
BuildRequires: %{python3_pkg}-setuptools
%if 0%{?suse_version}
BuildRequires: fdupes
%endif
BuildRoot:     %{_tmppath}/%{name}-root
BuildArch:     noarch
Source:        https://github.com/mesonbuild/meson/releases/download/%{realver}/%{realname}-%{realver}%{?extraver}.%{srcext}

%description
Meson is a cross-platform build system designed to be both as fast and as user
friendly as possible. It supports many languages and compilers, including GCC,
Clang and Visual Studio. Its build definitions are written in a simple
non-turing complete DSL.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{version}%{?extraver}
# Fix shebang
%{__sed} -ri '1 s|#!/usr/bin/env .+|#!%{__python3}|' \
  mesonbuild/rewriter.py \
  mesonbuild/scripts/cmake_run_ctgt.py

%build
%{__python3} setup.py build

%install
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
%{__python3} setup.py install --prefix=%{_prefix} --root=%{buildroot} -O2 --skip-build
%{__install} -D -m0644 data/macros.meson %{buildroot}%{_sysconfdir}/rpm/macros.meson
%if 0%{?suse_version}
%fdupes %{buildroot}%{python3_sitelib}
%endif

%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

%files
%defattr(-,root,root)
%license COPYING
%doc README.md
%config(noreplace) %{_sysconfdir}/rpm/macros.meson
%{_bindir}/*
%{python3_sitelib}/mesonbuild/
%{python3_sitelib}/meson-%{version}-py%{py3_ver}.egg-info
%dir %{_datadir}/polkit-1
%dir %{_datadir}/polkit-1/actions
%{_datadir}/polkit-1/actions/com.mesonbuild.install.policy
%doc %{_mandir}/man1/*

%changelog
openSUSE Build Service is sponsored by