%__meson %{_bindir}/meson
%__meson_wrap_mode nodownload
%__meson_auto_features enabled

%_smp_mesonflags %([ -z "$MESON_BUILD_NCPUS" ] \\\
	&& MESON_BUILD_NCPUS="`/usr/bin/getconf _NPROCESSORS_ONLN`"; \\\
        ncpus_max=%{?_smp_ncpus_max}; \\\
        if [ -n "$ncpus_max" ] && [ "$ncpus_max" -gt 0 ] && [ "$MESON_BUILD_NCPUS" -gt "$ncpus_max" ]; then MESON_BUILD_NCPUS="$ncpus_max"; fi; \\\
        if [ "$MESON_BUILD_NCPUS" -gt 1 ]; then echo "--num-processes $MESON_BUILD_NCPUS"; fi)

%meson \
    %set_build_flags \
    %{shrink:%{__meson} \
        --buildtype=plain \
        --prefix=%{_prefix} \
        --libdir=%{_libdir} \
        --libexecdir=%{_libexecdir} \
        --bindir=%{_bindir} \
        --sbindir=%{_sbindir} \
        --includedir=%{_includedir} \
        --datadir=%{_datadir} \
        --mandir=%{_mandir} \
        --infodir=%{_infodir} \
        --localedir=%{_datadir}/locale \
        --sysconfdir=%{_sysconfdir} \
        --localstatedir=%{_localstatedir} \
        --sharedstatedir=%{_sharedstatedir} \
        --wrap-mode=%{__meson_wrap_mode} \
        --auto-features=%{__meson_auto_features} \
        %{_vpath_srcdir} %{_vpath_builddir} \
	%{nil}}

%meson_build \
    %ninja_build -C %{_vpath_builddir}

%meson_install \
    %ninja_install -C %{_vpath_builddir}

%meson_test \
    %{shrink: %{__meson} test \
        -C %{_vpath_builddir} \
        %{?_smp_mesonflags} \
        --print-errorlogs \
    %{nil}}
