Build:projects:windows:mingw:win32

Jump to: navigation, search

Cross-toolchain for 32/64-bit Windows and 32/64-bit Windows packages

Create a bug report

Bug reports for a whole project can be opened by clicking on one of the links below:

Bug reports for a single package can be opened on the OBS page for that package by clicking on Report bug there [see bug 1173190] or by clicking on one the following links:

FAQ

How to configure a cmake project to build for Windows outside a *.spec file ?

You can use the command line tools mingw32-cmake for 32bit builds and mingw64-cmake for 64bit builds as replacement for cmake.

what do I have to keep in mind when working with a project linked to windows:mingw... linked ?

With changes to packages, which are made over a copy of the concerning package created with osc, after confirmation a copy in the current project is created and need to be submited to the original project. Changes made via the web interface are made directly to the original package, please note.

In rpm macros, how do I process parameters ?

I found two working solution:

1. Use shell variables

%_mymacro \
  if [ -n "$1" ]; then PARAMS="$*" else; PARAMS="default"; fi; \

or

%_mymacro \
  if [ $# -ne 0 ]; then PARAMS="$*" else; PARAMS="default"; fi; \


2. Use rpm variables

%_mymacro() \
  if [ -n "%1" ]; then PARAMS="%*" else; PARAMS="default"; fi; \

Note: I noticed that using "%#" to get the number of parameters does not work, as it always returns '\', which will be expanded to "\" and results into this runtime error 'unexpected EOF while looking for matching `"'.

How to debug hidden osc build issues ?

If osc build fails, for example after it fails with something like /var/tmp/rpm-tmp.0iMJGE: line 41: syntax error near unexpected token `else, it would help to see the content of the mentioned script file for inspecting purpose.

Unfortunally I did not find an option, when running the osc build, to prevent deleting of the script file.

A workaround is to use

rpmbuild --noclean -ba xxx.spec

instead, after copying the source tarball and patch files from the current osc related package directory into $HOME/rpmbuild/SOURCES.

How to prevent issues using shell scripting for defining macros

Shell scripting to define macros can be used by specifing %define <name> %(...) as mentioned at Defining Macros in Spec Files. Please note that when using shell scripting, on building a warning will be printed as reported at can't expand %(...)" warnings not clear

rpm --queryformat %{xxx} cannot be used for depending packages

If you want to get the version from an installed package added as build requirement, you cannot use

rpm -q <packagename> --qf "%{VERSION}

as the term '%{VERSION}' will be replaced by the version of the current spec file.


Workaround: If the package name is for example

mingw32-gwenhywfar5-devel-5.9+20220101+git.2356767

you can use

%define gw_version %(rpm -q <packagename> | awk -F"[-+]" '{print $4}')

Prevent defining a macro multiple times

Macros defined with %define are expanded on each usage. To prevent multiple expanding, the following trick can be used.

%{!?<macro-name>: %define <macro-name>  %(...)}

How do I find packages failing with a specific error ?

You can use 'osc results -f ...` combined with 'osc buildlog ..' in a checked out project as shown by the following example:

for i in $(osc results -f -r openSUSE_Leap_15.3 | gawk '{ print $1}' ); do \
(cd $i; n=$(osc buildlog openSUSE_Leap_15.3 | grep "...."); if test -n "$n"; then echo $i; fi) \
done

How do I exclude certain library from being added as a dependency ?

The rpm dependency generator, used to generate package dependencies, supports options to exclude dependencies. See these simple examples:

Exclude required library dependencies

To exclude one or more required dependencies, add a line with the following content to the beginning of the associated specification file:

mingw32:

%global __requires_exclude mingw32\(mydll\.dll\)

mingw64:

%global __requires_exclude mingw64\(mydll\.dll\)

Exclude provided library(s)

To exclude one or more provided libraries as a possible dependency, add a line with the following content to the beginning of the associated specification file:

mingw32:

# one library
%global __provides_exclude mingw32\(mydll\.dll\) 
# all provided libraries
%global __provides_exclude mingw32\(.*\.dll\)
# TODO more than one library

mingw64:

# one library
%global __provides_exclude mingw64\(mydll\.dll\) 
# all provided libraries
%global __provides_exclude mingw64\(.*\.dll\)
# TODO more than one library

For further instructions, see Tweaking Dependency Generators.

osc: rerun packaging step without building

If there is a problem with the %files sections when osc is called, e.g. if an installed file has not been packed or vice versa, after fixing the issue in the associated spec file, building can be skipped to save time. The build option --stage=i+ can be used for this:

 osc build --build-opt="--stage=i+" openSUSE_Leap_15.5

Hints

spec file hints

Tagging patches

See openSUSE:Packaging_Patches_guidelines for details

check for a specific version

Leap 15.3

%if 0%{?sle_version} == 150300
...
%endif

Leap 15.4

%if 0%{?sle_version} == 150400
...
%endif

Tumbleweed

%if 0%{?suse_version} >= 1599
...
%endif

Comment out macros

%macro 
# %%macro

Link

show macro processing

insert %trace 

show all macros

insert %dump 

find language files

simple case

%define _name kwindowsaddons
... 
%lang_package
...
%prep
...
%install
 # install compiled package
 %_mingw32_find_lang %{_name} || true
... 
%files lang -f %{_name}.lang
%defattr(-,root,root,-)

multiple language files

...
%install
 %_mingw32_find_lang %{_name} || true
 %_mingw32_find_lang onlinequoteseditor %{_name}.lang || true
 %_mingw32_find_lang plasma_applet_onlinequote %{_name}.lang || true
 %_mingw32_find_lang plasma_applet_org.wincak.foreigncurrencies2 %{_name}.lang || true

Provides/Requires basics

  • mingw32(libxxx.dll) specifies that a packages provides or requires a shared library
  • mingw32(lib:xxxx) specifies that a package provides or requires an import or static library
  • mingw32(pkg:xxxx) specifies that a package provides or requires a library specified by pkg config
  • mingw32(cmake:xxxx) specifies that a package provides or requires a library specified by cmake (supported by mingwXX-filesystem >= 20200816)

basic libraries

debugging of internal dependency generator

osc

osc build --buildtool-opt="--rpmfcdebug" openSUSE_Leap_15.5

rpmbuild - single call

sudo rpmbuild -ba --rpmfcdebug /usr/src/packages/SPECS/mingw32-dbus-1.spec 2>&1 | less

rpmbuild - splitted build from checking

sudo rpmbuild -bi --rpmfcdebug /usr/src/packages/SPECS/mingw32-dbus-1.spec 2>&1  | less
sudo rpmbuild -bl --rpmfcdebug /usr/src/packages/SPECS/mingw32-dbus-1.spec 2>&1  | less

Conditional builds

%bcond_with     shared
...
%if %{with shared}
...
%endif

Package type related

Access files in local installation root

%{buildroot}%{_mingwXX_prefix}
%{buildroot}%{_mingwXX_prefix}

Setting compiler flags

Compiler flags for autotools and/or cmake packages

MINGWxx_CFLAGS="%_mingwxx_cflags ..."
MINGWxx_CXXFLAGS="%_mingwxx_cxxflags ..."
MINGWxx_LDFLAGS="%_mingwxx_ldflags ..."
%_mingw32_configure | %_mingw32_cmake | %_mingw32_make

KDE4 specific compiler flags settings

by specifing rpm variables

%define _mingwXX_kde4_cxxflags ...
%define _mingwXX_kde4_cflags ...
%define _mingwXX_kde4_ldflags ...

Note: Do not use shell variable MINGWxx_yyFLAGS, they will be overwritten internally

Note2: The value of rpm variable %_mingwxx_yyflags is added by default

by using environment variable

CFLAGS="%_mingwxx_cflags ..."
CXXFLAGS="%_mingwxx_cxxflags ..."
LDFLAGS="%_mingwxx_ldflags ..."

KF5 specific compiler flags

by specifing rpm variables

%define _mingwXX_kf5_cxxflags ...
%define _mingwXX_kf5_cflags ...
%define _mingwXX_kf5_ldflags ...

Note: The value of rpm variable %_mingwxx_yyflags is added by default

by using environment variable

CFLAGS="%_mingwxx_cflags ..."
CXXFLAGS="%_mingwxx_cxxflags ..."
LDFLAGS="%_mingwxx_ldflags ..."

Porting native packages

Mingw32

Porting native autotools packages to mingw32

%define _name chmlib
Name:           mingw32-%{_name}
...
BuildRequires:  mingw32-cross-gcc 
# mingw32-cross-gcc-c++ in case of c++ project
... 
# pkg-config file support is included by default as a compiler dependency
...
%_mingw32_package_header_debug
BuildArch: noarch

...
%_mingw32_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
# optional set custom flags (%_mingw32_..flags are used by default)
MINGW32_CFLAGS="%_mingw32_cflags ..."
MINGW32_CXXFLAGS="%_mingw32_cxxflags ..."
MINGW32_LDFLAGS="%_mingw32_ldflags ..."
%_mingw32_configure \
  --options
%make_jobs

%install
%make DESTDIR=%{buildroot} install %{?_smp_mflags}

%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw32_xxxdir
%{_libdir}/xxx*.so  -> %{_mingw32_bindir}/xxx*.dll

%files devel
%{_libdir}/xxx*.so  -> %{_mingw64_libdir}/xxx*.dll.a

Porting native cmake packages to mingw32

%define _name dlfcn-win32
Name:           mingw21-%{_name}
...
BuildRequires:  mingw32-cross-gcc 
# mingw32-cross-gcc-c++ in case of c++ project
... 
# pkg-config file support is included by default as a compiler dependency
...
%_mingw32_package_header_debug
BuildArch: noarch
...
%_mingw32_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
# optional set custom flags (%_mingw32_..flags are used by default)
MINGW32_CFLAGS="%_mingw32_cflags ..."
MINGW32_CXXFLAGS="%_mingw32_cxxflags ..."
MINGW32_LDFLAGS="%_mingw32_ldflags ..."
%_mingw32_cmake
%_mingw32_cmake_build

%install
%_mingw32_cmake_install

%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw32_xxxdir
%{_libdir}/xxx*.so  -> %{_mingw32_bindir}/xxx*.dll

%files devel
%{_libdir}/xxx*.so  -> %{_mingw32_libdir}/xxx*.dll.a

Porting native Qt4/cmake packages to mingw32

%define _name   libalkimia
Name:           mingw32-%{_name}
...
BuildRequires:  cmake >= 3.0.0
BuildRequires:  mingw32-cross-gcc-c++
BuildRequires:  mingw32-cross-qmake
BuildRequires:  mingw32-libqt4-devel
...
%_mingw32_package_header_debug
BuildArch: noarch
...
## for language support
%lang_package
...
## add debug package
%_mingw32_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
# optional set custom flags (%_mingw32_..flags are used by default)
MINGW32_CFLAGS="%_mingw32_cflags ..."
MINGW32_CXXFLAGS="%_mingw32_cxxflags ..."
MINGW32_LDFLAGS="%_mingw32_ldflags ..."
%_mingw32_cmake_qt4 
%_mingw32_cmake_build

%install
%_mingw32_cmake_install
## for language support
%_mingw32_find_lang %{_name} || true

%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw32_xxxdir
%{_libdir}/xxx*.so  -> %{_mingw32_bindir}/xxx*.dll

%files devel
%{_libdir}/xxx*.so  -> %{_mingw32_libdir}/xxx*.dll.a

Porting native KDE4 packages to mingw32

%define _name kmymoney
Name:           mingw32-%{_name}
...
BuildRequires:  cmake >= 3.0.0 [1]
BuildRequires:  mingw32-cross-gcc-c++ [1]
  1. pkgconfig file support is included by default
BuildRequires:  mingw32-cross-kde4-tools [1]
BuildRequires:  mingw32-libkde4-devel
..
%_mingw32_package_header_debug
BuildArch: noarch
...
%lang_package
%_mingw32_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
# option 1
CFLAGS="%_mingw32_cflags ..."
CXXFLAGS="%_mingw32_cxxflags ..."
LDFLAGS="%_mingw32_ldflags ..."
## option 2 (%_mingw32_...flags are added by default)
%define _mingw32_kde4_cxxflags ...
%define _mingw32_kde4_cflags ...
%define _mingw32_kde4_ldflags ...
# end option
%_mingw32_cmake_kde4 -d build -- -Dxxx=yyy
%_mingw32_cmake_build

%install
%_mingw32_kde4_makeinstall -C build
%_mingw32_kde4_post_install
%_mingw32_find_lang %{_name} || true

%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw32_xxxdir
%{_libdir}/xxx*.so  -> %{_mingw32_bindir}/xxx*.dll
%{_kde4_modulesdir}/xxx.so.* %{_mingw32_kde4_modulesdir}/xxx*.dll

%files devel
%{_libdir}/xxx*.so  -> %{_mingw32_libdir}/xxx*.dll.a

[1] These packages should be dependencencies of package mingw32-libkde4-devel

Porting native Qt5/qmake packages to mingw32

%define _name   prismatik
Name:           mingw32-%{_name}
...
BuildRequires:  mingw32-cross-gcc-c++
BuildRequires:  mingw32-libqt5-qtbase-devel
...

%_mingw32_package_header_debug
BuildArch: noarch
...
%_mingw32_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
mkdir build
cd build
mingw32-qmake-qt5 -r ..
%make_jobs

%install
cd build
%{_mingw32_make} install INSTALL_ROOT=%{buildroot} %{?_smp_mflags}
# .prl files aren't interesting for us
find %{buildroot} -name "*.prl" -delete

%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw32_xxxdir
%{_libdir}/xxx*.so  -> %{_mingw32_bindir}/xxx*.dll

%files devel
%{_libdir}/xxx*.so  -> %{_mingw32_libdir}/xxx*.dll.a

Porting native Qt5/cmake packages to mingw32

%define _name grantlee5
Name:           mingw32-%{_name}
...
BuildRequires:  cmake >= 3.0.0
BuildRequires:  mingw32-cross-gcc-c++
...
BuildRequires:  mingw32-libqt5-qtbase-devel
..
%_mingw32_package_header_debug
BuildArch: noarch
...
%_mingw32_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
%_mingw32_cmake
%_mingw32_cmake_build

%install
%_mingw32_cmake_install

%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw32_xxxdir
%{_libdir}/xxx*.so  -> %{_mingw32_bindir}/xxx*.dll

%files devel
%{_libdir}/xxx*.so  -> %{_mingw32_libdir}/xxx*.dll.a

Porting native Qt6/cmake packages to mingw32

%define _name qt6-xxxx
Name:           mingw32-%{_name}
...
BuildRequires:  mingw32(cmake:Qt6Core)
..
%_mingw32_package_header_debug
BuildArch: noarch
...
%_mingw32_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
%_mingw32_cmake_qt6
%_mingw32_qt6_build

%install
%_mingw32_qt6_install

%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw32_xxxdir
%{_qt6_libdir}/xxx*.so  -> %{_mingw32_qt6_bindir}/xxx*.dll

%files devel
%{_qt6_libdir}/xxx*.so  -> %{_mingw32_qt6_libdir}/xxx*.dll.a

Mingw64

Porting native autotools packages to mingw64

%define _name chmlib
Name:           mingw64-%{_name}
...
BuildRequires:  mingw64-cross-gcc 
# mingw64-cross-gcc-c++ in case of c++ project
... 
# pkg-config file support is included by default as a compiler dependency
...
%_mingw64_package_header_debug
BuildArch: noarch
...
%_mingw64_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
# optional set custom flags (%_mingw64_..flags are used by default)
MINGW64_CFLAGS="%_mingw64_cflags ..."
MINGW64_CXXFLAGS="%_mingw64_cxxflags ..."
MINGW64_LDFLAGS="%_mingw64_ldflags ..."
%_mingw64_configure \
  --options
%make_jobs

%install
%make DESTDIR=%{buildroot} install %{?_smp_mflags}

%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw64_xxxdir
%{_libdir}/xxx*.so  -> %{_mingw64_bindir}/xxx*.dll

%files devel
%{_libdir}/xxx*.so  -> %{_mingw64_libdir}/xxx*.dll.a

Porting native cmake packages to mingw64

%define _name dlfcn-win32
Name:           mingw64-%{_name}
...
BuildRequires:  mingw64-cross-gcc 
# mingw64-cross-gcc-c++ in case of c++ project
... 
# pkg-config file support is included by default as a compiler dependency
...
%_mingw64_package_header_debug
BuildArch: noarch
...
%_mingw64_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
# optional set custom flags (%_mingw64_..flags are used by default)
MINGW64_CFLAGS="%_mingw64_cflags ..."
MINGW64_CXXFLAGS="%_mingw64_cxxflags ..."
MINGW64_LDFLAGS="%_mingw64_ldflags ..."
%_mingw64_cmake
%_mingw64_cmake_build

%install
%_mingw64_cmake_install
%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw64_xxxdir
%{_libdir}/xxx*.so  -> %{_mingw64_bindir}/xxx*.dll

%files devel
%{_libdir}/xxx*.so  -> %{_mingw64_libdir}/xxx*.dll.a

Porting native Qt4/cmake packages to mingw64

%define _name   libalkimia
Name:           mingw64-%{_name}
...
BuildRequires:  cmake >= 3.0.0
BuildRequires:  mingw64-cross-gcc-c++
BuildRequires:  mingw64-cross-qmake
BuildRequires:  mingw64-libqt4-devel
...
%_mingw64_package_header_debug
BuildArch: noarch
...
## for language support
%lang_package
...
## add debug package
%_mingw64_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
# optional set custom flags (%_mingw64_..flags are used by default)
MINGW64_CFLAGS="%_mingw64_cflags ..."
MINGW64_CXXFLAGS="%_mingw64_cxxflags ..."
MINGW64_LDFLAGS="%_mingw64_ldflags ..."
%_mingw64_cmake_qt4 
%_mingw64_cmake_build

%install
%_mingw64_cmake_install
## for language support
%_mingw64_find_lang %{_name} || true

%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw64_xxxdir
%{_libdir}/xxx*.so  -> %{_mingw64_bindir}/xxx*.dll

%files devel
%{_libdir}/xxx*.so  -> %{_mingw64_libdir}/xxx*.dll.a

Porting native KDE4 packages to mingw64

%define _name kmymoney
Name:           mingw64-%{_name}
...
BuildRequires:  cmake >= 3.0.0
BuildRequires:  mingw64-cross-gcc-c++
...
# pkg-config file support is included by default as a compiler dependency
...
BuildRequires:  mingw64-cross-kde4-tools
BuildRequires:  mingw64-libkde4-devel
..
%_mingw64_package_header_debug
BuildArch: noarch
...
%lang_package
%_mingw64_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
# option 1
CFLAGS="%_mingw64_cflags ..."
CXXFLAGS="%_mingw64_cxxflags ..."
LDFLAGS="%_mingw64_ldflags ..."
# option 2 (%_mingw64_...flags are added by default)
%define _mingw64_kde4_cflags ...
%define _mingw64_kde4_cxxflags ...
%define _mingw64_kde4_ldflags ...
# end option
%_mingw64_cmake_kde4 -d build -- -Dxxx=yyy
%_mingw64_cmake_build

%install
%_mingw64_kde4_makeinstall -C build
%_mingw64_kde4_post_install
%_mingw64_find_lang %{_name} || true

%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw64_xxxdir
%{_libdir}/xxx*.so  -> %{_mingw64_bindir}/xxx*.dll
%{_kde4_modulesdir}/xxx.so.* %{_mingw64_kde4_modulesdir}/xxx*.dll

%files devel
%{_libdir}/xxx*.so  -> %{_mingw64_libdir}/xxx*.dll.a

Porting native Qt5/qmake packages to mingw64

%define _name prismatik
Name:           mingw64-%{_name}
...
BuildRequires:  mingw64-cross-gcc-c++
BuildRequires:  mingw64-libqt5-qtbase-devel
...
%_mingw64_package_header_debug
BuildArch: noarch
...
%_mingw64_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
mkdir build
cd build
mingw64-qmake-qt5 -r ..
%make_jobs

%install
cd build
%{_mingw64_make} install INSTALL_ROOT=%{buildroot} %{?_smp_mflags}
# .prl files aren't interesting for us
find %{buildroot} -name "*.prl" -delete

%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw64_xxxdir
%{_libdir}/xxx*.so  -> %{_mingw64_bindir}/xxx*.dll

%files devel
%{_libdir}/xxx*.so  -> %{_mingw64_libdir}/xxx*.dll.a

Porting native Qt5/cmake packages to mingw64

%define _name grantlee5
Name:           mingw64-%{_name}
...
BuildRequires:  cmake >= 3.0.0
BuildRequires:  mingw64-cross-gcc-c++
...
BuildRequires:  mingw64-libqt5-qtbase-devel
..
%_mingw64_package_header_debug
BuildArch: noarch
...
%_mingw64_debug_package

%prep
%setup -q -n %{_name}-%{version}

%build
%_mingw64_cmake
%_mingw64_cmake_build

%install
%_mingw64_cmake_build

%files
## rename *.so* -> *.dll
## add .exe to executables
## rename _xxxdir to _mingw64_xxxdir
%{_libdir}/xxx*.so  -> %{_mingw64_bindir}/xxx*.dll

%files devel
%{_libdir}/xxx*.so  -> %{_mingw64_libdir}/xxx*.dll.a

Knowledge base

Structure of debugging support

  • Debugging support is provided with gdb either on a native Windows host or by using wineconsole gdb.
  • The symbols required for debugging are provided by special mingwXX-packageYY-debug packages.
  • A debug package contains for each dynamic library and executable concerned a file with the extension '.sym', which contains symbol information (in TODO format) and a file with the extension '.debug', which has the same format as the original binary, but contains only debug information.

Links

Related projects