%_kf5_prefix %_prefix
%_kf5_archdatadir %_qt5_archdatadir
%_kf5_bindir %_kf5_prefix/bin
%_kf5_datadir %_datadir
%_kf5_docdir %_docdir
%_kf5_includedir %_includedir/KF5
%_kf5_libdir %_libdir
%_kf5_libexecdir %_libexecdir/kf5
%_kf5_metainfodir %_metainfodir
%_kf5_qtplugindir %_qt5_plugindir
%_kf5_plugindir %_qt5_plugindir/kf5
%_kf5_sysconfdir %_sysconfdir
%_kf5_mandir %_kf5_datadir/man
%_kf5_buildtype release
%_kf5_qmldir %_kf5_archdatadir/qml
%_kf5_version @@KF5_VERSION@@

%cmake_kf5 \\\
  %undefine __cmake_in_source_build \
  CC=clang ; export CC; \
  CXX=clang++ ; export CXX ; \
  QTDIR="%{_qt5_prefix}" ; export QTDIR ; \
  PATH="%{_qt5_bindir}:$PATH" ; export PATH ; \
  CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ; \
  CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ; \
  FFLAGS="${FFLAGS:-%optflags%{?_fmoddir: -I%_fmoddir}}" ; export FFLAGS ; \
  %{?__global_ldflags:LDFLAGS="${LDFLAGS:-%__global_ldflags}" ; export LDFLAGS ;} \
    %{__cmake} \\\
    %{?__cmake_builddir:-S "%{_vpath_srcdir}"} \\\
    %{?__cmake_builddir:-B "%{__cmake_builddir}"} \\\
    -DCMAKE_C_FLAGS_RELEASE:STRING="-DNDEBUG" \\\
    -DCMAKE_CXX_FLAGS_RELEASE:STRING="-DNDEBUG" \\\
    -DCMAKE_Fortran_FLAGS_RELEASE:STRING="-DNDEBUG" \\\
    -DBUILD_SHARED_LIBS:BOOL=ON \\\
    -DBUILD_TESTING:BOOL=FALSE \\\
    -DCMAKE_BUILD_TYPE=%{_kf5_buildtype} \\\
    -DCMAKE_INSTALL_INCLUDEDIR_KF5:PATH=%{_kf5_includedir} \\\
    -DCMAKE_INSTALL_LIBEXECDIR_KF5:PATH=%{_kf5_libexecdir} \\\
    -DCMAKE_INSTALL_PREFIX:PATH=%{_kf5_prefix} \\\
    -DCMAKE_USE_RELATIVE_PATHS:BOOL=ON \\\
    -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \\\
    -DECM_MKSPECS_INSTALL_DIR:PATH=%{_kf5_archdatadir}/mkspecs/modules \\\
    -DKDE_INSTALL_BINDIR:PATH=%{_kf5_bindir} \\\
    -DKDE_INSTALL_INCLUDEDIR:PATH=%{_includedir} \\\
    -DKDE_INSTALL_KCFGDIR:PATH=%{_datadir}/config.kcfg \\\
    -DKDE_INSTALL_LIBDIR:PATH=%{_kf5_libdir} \\\
    -DKDE_INSTALL_LIBEXECDIR:PATH=%{_libexecdir} \\\
    -DKDE_INSTALL_METAINFODIR:PATH=%{_kf5_metainfodir} \\\
    -DKDE_INSTALL_PLUGINDIR:PATH=%{_qt5_plugindir} \\\
    -DKDE_INSTALL_QMLDIR:PATH=%{_kf5_qmldir} \\\
    -DKDE_INSTALL_QTPLUGINDIR:PATH=%{_qt5_plugindir} \\\
    -DKDE_INSTALL_QTQUICKIMPORTSDIR:PATH=%{_qt5_importdir} \\\
    -DKDE_INSTALL_SYSCONFDIR:PATH=%{_kf5_sysconfdir} \\\
    -DKDE_INSTALL_USE_QT_SYS_PATHS:BOOL=ON

# %%find_lang_kf5
#
# This macro is used in KDE Frameworks 5 packages instead of %%find_lang,
# becasue find_lang is broken an it thinks that "_qt" in foobar_qt.qm is
# the name of the language.
# This macro should NOT be used with anything else but KDE Frameworks, since
# it does some assumptions regarding the names and locations and it might not
# work with other packages.
# We should eventually get this to RPM, or fix %%find_lang
#                                                       -- dvratil
# Usage: find_lang_kf5 fooBar5
#   - will look for fooBar5_qt.qm files in %%{buildroot}/usr/share/locale/
#
%find_lang_kf5() \
    (find %{buildroot}/%{_datadir}/locale/ -name "%1.qm" -type f | sed ' \
        s:%{buildroot}/:: \
        s:%{_datadir}/locale/\\([a-zA-Z_\\@]*\\)/\\([a-zA-Z_]*\\)/%1.qm:%lang(\\1) %{_datadir}/locale/\\1/\\2/%1.qm:' > %1.lang)

# Start of backwards compatible macros
# Used mostly in plasma and gear packages:
# %%maj_ver_kf5
# %%min_ver_kf5
# %%bug_ver_kf5
# %%majmin_ver_kf5
# %%stable_kf5

%maj_ver_kf5 %(echo %{version} | cut -d. -f1)
%min_ver_kf5 %(echo %{version} | cut -d. -f2)
%bug_ver_kf5 %(echo %{version} | cut -d. -f3)

%stable_kf5 %( \
    if test %bug_ver_kf5 -ge 50 ; then
        echo "unstable"
    else
        echo "stable"
    fi
    )

%majmin_ver_kf5 %( \
    if test %bug_ver_kf5 -ge 50 ; then
        echo %{maj_ver_kf5}.%{min_ver_kf5}.50
    else
        echo %{maj_ver_kf5}.%{min_ver_kf5}
    fi
    )
# End of backwards compatible macros
