# RPM macros for Fedora MinGW.

%mingw32_pkg_name        %(echo %{name} | sed -E 's/^(mingw-|)/mingw32-/')
%mingw32_target          i686-w64-mingw32

# Paths.
%mingw32_sysroot         %{_prefix}/%{mingw32_target}/sys-root
%mingw32_prefix          %{mingw32_sysroot}/mingw
%mingw32_exec_prefix     %{mingw32_prefix}
%mingw32_bindir          %{mingw32_exec_prefix}/bin
%mingw32_sbindir         %{mingw32_exec_prefix}/sbin
%mingw32_libexecdir      %{mingw32_exec_prefix}/libexec
%mingw32_libdir          %{mingw32_exec_prefix}/lib
%mingw32_datadir         %{mingw32_prefix}/share
%mingw32_docdir          %{mingw32_prefix}/share/doc
%mingw32_infodir         %{mingw32_prefix}/share/info
%mingw32_mandir          %{mingw32_prefix}/share/man
%mingw32_sysconfdir      %{mingw32_prefix}/etc
%mingw32_sharedstatedir  %{mingw32_prefix}/com
%mingw32_localstatedir   %{mingw32_prefix}/var
%mingw32_includedir      %{mingw32_prefix}/include

# Build macros.
%mingw32_host            %{mingw32_target}

%mingw32_cflags          %{mingw32_cppflags} -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4
%mingw32_cppflags        %{nil}
%mingw32_fflags          -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4
%mingw32_ldflags         -fstack-protector -lssp

%mingw32_cc              %{mingw32_target}-gcc
%mingw32_cxx             %{mingw32_target}-g++
%mingw32_cpp             %{mingw32_target}-gcc -E
%mingw32_addr2line       %{mingw32_target}-addr2line
%mingw32_ar              %{mingw32_target}-ar
%mingw32_as              %{mingw32_target}-as
%mingw32_dlltool         %{mingw32_target}-dlltool
%mingw32_dllwrap         %{mingw32_target}-dllwrap
%mingw32_gcov            %{mingw32_target}-gcov
%mingw32_gprof           %{mingw32_target}-gprof
%mingw32_ld              %{mingw32_target}-ld
%mingw32_nm              %{mingw32_target}-nm
%mingw32_objcopy         %{mingw32_target}-objcopy
%mingw32_objdump         %{mingw32_target}-objdump
%mingw32_ranlib          %{mingw32_target}-ranlib
%mingw32_readelf         %{mingw32_target}-readelf
%mingw32_size            %{mingw32_target}-size
%mingw32_strings         %{mingw32_target}-strings
%mingw32_strip           %{mingw32_target}-strip
%mingw32_windmc          %{mingw32_target}-windmc
%mingw32_windres         %{mingw32_target}-windres

%mingw32_env unset $(/usr/bin/env | egrep '^(\w+)=(.*)$' | egrep -vw 'PWD|USER|LANG' | /usr/bin/cut -d= -f1); \
  if test -z "$PATH_ORIG" ; then \
    PATH_ORIG="$PATH"; export PATH_ORIG; \
  fi; \
  PATH="%{mingw32_bindir}:$PATH_ORIG"; export PATH; \
  HOST_CC=gcc; export HOST_CC; \
  unset PKG_CONFIG_PATH; \
  _PREFIX="%{_bindir}/%{mingw32_target}-"; \
  for i in `ls -1 ${_PREFIX}* | grep -v 'gcc-'`; do \
    x=`echo $i|sed "s,${_PREFIX},,"|tr "a-z+-." "A-ZX__"`; \
    declare -x $x="$i" ; export $x; \
  done; \
  unset _PREFIX; \
  CC="${MINGW32_CC:-%mingw32_cc}"; export CC; \
  CFLAGS="${MINGW32_CFLAGS-%mingw32_cflags}"; export CFLAGS; \
  CPPFLAGS="${MINGW32_CPPFLAGS-%mingw32_cppflags}"; export CPPFLAGS; \
  if [ -x "%{_bindir}/%{mingw32_cxx}" ]; then \
    CXX="${MINGW32_CXX:-%mingw32_cxx}"; export CXX; \
    CXXFLAGS="${MINGW32_CXXFLAGS-%mingw32_cflags}"; export CXXFLAGS; \
  else \
    CXX=; export CXX; \
    ac_cv_prog_CXX=no; export ac_cv_prog_CXX; \
    CXXFLAGS=; export CXXFLAGS; \
  fi; \
  FFLAGS="${MINGW32_FFLAGS-%mingw32_fflags}"; export FFLAGS; \
  FCFLAGS="${MINGW32_FCFLAGS-%mingw32_fflags}"; export FCFLAGS; \
  LDFLAGS="${MINGW32_LDFLAGS:-%mingw32_ldflags}"; export LDFLAGS; \
  for i in `ls %{mingw32_bindir}/*|grep -- "-config\$"` ; do \
    x=`basename $i|tr "a-z+-." "A-ZX_"`; \
    declare -x $x="$i" ; export $x; \
  done; \
  unset x i

%mingw32_pkg_config %{mingw32_target}-pkg-config "$@"
%mingw32_pkgconfig_personalitydir %{mingw32_datadir}/pkgconfig/personality.d

%mingw32_configure %{mingw32_env} ; \
  __mingw32_topdir=.; if ! test -x configure; then __mingw32_topdir=..; fi; \\\
  $__mingw32_topdir/configure \\\
	--host=%{mingw32_host} \\\
	--build=%_build \\\
	--target=%{mingw32_target} \\\
	--prefix=%{mingw32_prefix} \\\
	--exec-prefix=%{mingw32_exec_prefix} \\\
	--bindir=%{mingw32_bindir} \\\
	--sbindir=%{mingw32_sbindir} \\\
	--sysconfdir=%{mingw32_sysconfdir} \\\
	--datadir=%{mingw32_datadir} \\\
	--includedir=%{mingw32_includedir} \\\
	--libdir=%{mingw32_libdir} \\\
	--libexecdir=%{mingw32_libexecdir} \\\
	--localstatedir=%{mingw32_localstatedir} \\\
	--sharedstatedir=%{mingw32_sharedstatedir} \\\
	--mandir=%{mingw32_mandir} \\\
	--infodir=%{mingw32_infodir} \\\
	${MINGW_CONFIGURE_ARGS} \\\
	${MINGW32_CONFIGURE_ARGS} "$@"

%mingw32_make %{mingw32_env} ; \
  make \\\
	prefix=%{mingw32_prefix} \\\
	exec_prefix=%{mingw32_exec_prefix} \\\
	bindir=%{mingw32_bindir} \\\
	sbindir=%{mingw32_sbindir} \\\
	sysconfdir=%{mingw32_sysconfdir} \\\
	datadir=%{mingw32_datadir} \\\
	includedir=%{mingw32_includedir} \\\
	libdir=%{mingw32_libdir} \\\
	libexecdir=%{mingw32_libexecdir} \\\
	localstatedir=%{mingw32_localstatedir} \\\
	sharedstatedir=%{mingw32_sharedstatedir} \\\
	mandir=%{mingw32_mandir} \\\
	infodir=%{mingw32_infodir} "$@"

%mingw32_cmake_generic %{mingw32_env} ; \
  PKG_CONFIG_LIBDIR="%{mingw32_libdir}/pkgconfig:%{mingw32_datadir}/pkgconfig"; export PKG_CONFIG_LIBDIR; \
  if test -f CMakeLists.txt; then __mingw32_topdir=.; \\\
  elif test -f ../CMakeLists.txt; then __mingw32_topdir=..; \\\
  else __mingw32_topdir=""; fi; \\\
  if test "${MINGW_CMAKE_NO_VERBOSE}" == "" ; then \
    MINGW32_CMAKE_ARGS="${MINGW32_CMAKE_ARGS} -DCMAKE_VERBOSE_MAKEFILE=ON" \
  fi \
  PATH=%{_prefix}/%{mingw32_target}/bin:$PATH %__cmake \\\
        -DCMAKE_TOOLCHAIN_FILE=/usr/share/mingw/toolchain-mingw32.cmake \\\
        -DBUILD_SHARED_LIBS:BOOL=ON \\\
        -DSYSCONF_INSTALL_DIR:PATH=%{mingw32_sysconfdir} \\\
        -DSHARE_INSTALL_PREFIX:PATH=%{mingw32_datadir} \\\
        -DCMAKE_INSTALL_PREFIX:PATH=%{mingw32_prefix} \\\
        -DCMAKE_INSTALL_LIBDIR:PATH=%{mingw32_libdir} \\\
        ${MINGW_CMAKE_ARGS} \\\
        ${MINGW32_CMAKE_ARGS} \\\
        "$@" $__mingw32_topdir

%mingw32_cmake \
  MINGW32_CMAKE_ARGS="-DINCLUDE_INSTALL_DIR:PATH=%{mingw32_includedir} ${MINGW32_CMAKE_ARGS}" \
  %mingw32_cmake_generic

%mingw32_cmake_kde4 \
  MINGW32_CMAKE_ARGS="-DINCLUDE_INSTALL_DIR:PATH=%{mingw32_includedir}/kde4 ${MINGW32_CMAKE_ARGS}" \
  %mingw32_cmake_generic

%mingw32_qmake_qt5 /usr/bin/mingw32-qmake-qt5

%mingw32_meson %{mingw32_env} ; \
  unset CC CFLAGS CPPFLAGS CXX CXXFLAGS LD LDFLAGS; \\\
  CFLAGS="${MINGW32_CFLAGS-%mingw32_cflags}"; export CFLAGS; \\\
  CPPFLAGS="${MINGW32_CPPFLAGS-%mingw32_cppflags}"; export CPPFLAGS; \\\
  FFLAGS="${MINGW32_FFLAGS-%mingw32_fflags}"; export FFLAGS; \
  FCFLAGS="${MINGW32_FCFLAGS-%mingw32_fflags}"; export FCFLAGS; \
  LDFLAGS="${MINGW32_LDFLAGS:-%mingw32_ldflags}"; export LDFLAGS; \\\
  if test -f meson.build; then __mingw32_topdir=.; \\\
  elif test -f ../meson.build; then __mingw32_topdir=..; \\\
  else __mingw32_topdir=""; fi; \\\
  %__meson \\\
        --cross-file /usr/share/mingw/toolchain-mingw32.meson \\\
        --default-library shared \\\
        --prefix %{mingw32_prefix} \\\
        --bindir %{mingw32_bindir} \\\
        --sbindir %{mingw32_sbindir} \\\
        --sysconfdir %{mingw32_sysconfdir} \\\
        --datadir %{mingw32_datadir} \\\
        --includedir %{mingw32_includedir} \\\
        --libdir %{mingw32_libdir} \\\
        --libexecdir %{mingw32_libexecdir} \\\
        --localstatedir %{mingw32_localstatedir} \\\
        --sharedstatedir %{mingw32_sharedstatedir} \\\
        --mandir %{mingw32_mandir} \\\
        --infodir %{mingw32_infodir} \\\
        ${MINGW_MESON_ARGS} \\\
        ${MINGW32_MESON_ARGS} \\\
        "$@" $__mingw32_topdir

%mingw32_description This is the cross-compiled version of this library / tool.\
You should only install this package if you want to cross-compile programs for \
Win32 (32 bit Windows).

%mingw32_debug_package                                                   \
%package -n %{mingw32_pkg_name}-debuginfo                                \
Summary: Debug information for package %{mingw32_pkg_name}               \
Group: Development/Debug                                                 \
BuildArch: noarch                                                        \
%description -n %{mingw32_pkg_name}-debuginfo                            \
This package provides debug information for package %{mingw32_pkg_name}. \
Debug information is useful when developing applications that use this   \
package or when debugging this package.                                  \
%files -n %{mingw32_pkg_name}-debuginfo -f mingw32-debugfiles.list       \
%defattr(-,root,root,-)                                                  \
%{nil}

