From Fedora Project Wiki

m (Fix typo (accidentally omitted underscore in _mingw32_libdir).)
(Writeup of https://fedorahosted.org/fpc/ticket/294)
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Packaging Guidelines for MinGW Windows cross-compiler =
= Packaging Guidelines for MinGW Cross Compilers =


{{admon/important|Future Changes|These guidelines apply to all active Fedora releases (including RHEL-6 and older). New guidelines for MinGW have been approved, but are not yet in use: [[Packaging:MinGW_Future]] }}
{{admon/important|Updated Guidelines|These guidelines apply to all current Fedora releases. For RHEL-5 and RHEL-6 the old guidelines still apply which can be be found here: [[Packaging:MinGW_Old]] }}


= Introduction =
= Introduction =


The Fedora MinGW project's mission is to provide an excellent
The Fedora MinGW project's mission is to provide an excellent development environment for Fedora users who wish to cross-compile their programs to run on Windows, minimizing the need to use Windows at all.  In the past developers have had to port and compile all of the libraries and tools they have needed, and this huge effort has happened independently many times over.  We aim to eliminate duplication of work for application developers by providing a range of libraries and development tools which have already been ported to the MinGW cross-compiler environment.  This means that developers will not need to recompile the application stack themselves, but can concentrate just on the changes needed to their own application.
development environment for Fedora users who wish to cross-compile
 
their programs to run on Windows, minimizing the need to use Windows
As of Fedora 17 a set of RPM macros and packages have been introduced which help packagers compile binaries for multiple targets. The targets Win32 and Win64 are supported.
at all.  In the past developers have had to port and compile all of
the libraries and tools they have needed, and this huge effort has
happened independently many times over.  We aim to eliminate
duplication of work for application developers by providing a range of
libraries and development tools which have already been ported to the
cross-compiler environment.  This means that developers will not need
to recompile the application stack themselves, but can concentrate
just on the changes needed to their own application.


= Track Fedora native package versions =
= Track Fedora native package versions =


In general terms, MinGW packages which provide cross-compiled versions
In general terms, cross-compiled MinGW versions of packages which are already natively available in Fedora, should follow the native Fedora package as closely as possible. This means they should stay at the same version, include all the same patches as the native
of packages already natively available in Fedora, should follow the
native Fedora package as closely as possible. This means they should
stay at the same version, include all the same patches as the native
Fedora package, and be built with the same configuration options.
Fedora package, and be built with the same configuration options.


The MinGW SIG have written an RPM comparison tool which makes it
The MinGW SIG have written an RPM comparison tool which makes it possible to compare cross compiled MinGW packages with the Fedora native packages, in order to determine whether versions, patches and configuration are aligned.
possible to compare MinGW packages with the Fedora native packages, in
order to determine whether versions, patches and configuration are
aligned.


= Follow Fedora policy =
= Follow Fedora policy =


MinGW packages must follow Fedora policy, except where noted in this
Cross compiled MinGW packages must follow Fedora policy, except where noted in this document. Cross compiled packages go through the same review process, GIT admin process etc as other Fedora packages.
document. MinGW packages go through the same review process, CVS
admin process etc as other Fedora packages.


= Package naming =
= Package naming =


Built packages should be named by prefixing the upstream package name
MinGW packages require special naming to denote the appropriate CPU architecture the binaries have been built for. There should '''never''' be a package prefixed with <code>mingw-</code> output during a build. The <code>mingw-</code> prefix is exclusive for RPM spec file names and the source RPM file name. The CPU architecture specific packages are created by sections with <code>%files -n mingw32-foo</code> or <code>%files -n mingw64-foo</code>.
with <code>mingw32-</code>


Source packages can be named starting with <code>mingw-</code> in order to more easily support a transition to the new MinGW guidelines which mandate that naming.  Otherwise two separate package repositories must be set up ("mingw32-foo" and "mingw-foo") with one needing to be marked EOL.
{|
| <code>mingw-</code> || Used for source package and RPM spec name
|-
| <code>mingw32-</code> || Used for packages which are built for Win32
|-
| <code>mingw64-</code> || Used for packages which are built for Win64
|}


= Base packages =
= Base packages =


The base packages provide a root filesystem, base libraries, binutils
The base packages provide a root filesystem, base libraries, binutils (basic programs like 'strip', 'ld' etc), the compiler (gcc) and the Win32/Win64 API.  Packages may need to depend on one or more of these. In particular, almost all packages should BuildRequire <code>mingw32-filesystem</code>, <code>mingw64-filesystem</code>, <code>mingw32-gcc</code> and <code>mingw64-gcc</code>. The correct Requires flags will get added automatically when the <code>%{?mingw_package_header}</code> macro is mentioned in the spec file (as will be described later on in these guidelines)
(basic programs like 'strip', 'ld' etc), the compiler (gcc) and the
Win32 API.  Packages may need to depend on one or more of these. In
particular, almost any conceivable package should depend on
<code>mingw32-filesystem</code> and <code>mingw32-runtime</code>.


{|
{|
| <code>mingw32-filesystem</code> || Core filesystem directory layout, and RPM macros for spec files.  Equivalent to 'filesystem' RPM
| <code>mingw32-filesystem</code> / <code>mingw64-filesystem</code> || Core filesystem directory layout, and RPM macros for spec files.  Equivalent to 'filesystem' RPM
|-
|-
| <code>mingw32-runtime</code> || Base libraries for core MinGW runtime & development environment.  Equivalent to glibc & glibc-devel RPMs
| <code>mingw32-binutils</code> / <code>mingw64-binutils</code> || Cross-compiled binutils (utilities like 'strip', 'as', 'ld') which understand Windows executables and DLLs.  Equivalent to 'binutils' RPM
|-
|-
| <code>mingw32-binutils</code> || Cross-compiled binutils (utilities like 'strip', 'as', 'ld') which understand Windows executables and DLLs.  Equivalent to 'binutils' RPM
| <code>mingw32-gcc</code> / <code>mingw64-gcc</code> || GNU compiler collection.  Compilers for C and C++ which cross-compile to a Windows target.  Equivalent to gcc RPM
|-
|-
| <code>mingw32-w32api</code> || Win32 APIA [http://www.mingw.org/MinGWiki/index.php/w32api free (public domain) reimplementation] of the header files required to link to the Win32 API.  No direct equivalent in base Fedora - glibc-devel is closest
| <code>mingw32-crt</code> / <code>mingw64-crt</code> || Base libraries for core MinGW runtime & development environmentEquivalent to 'glibc' RPM
|-
|-
| <code>mingw32-gcc</code> || GNU compiler collectionCompilers for C and C++ which cross-compile to a Windows targetEquivalent to gcc RPM
| <code>mingw32-headers</code> / <code>mingw64-headers</code> || Win32 and Win64 APIA free (public domain) reimplementation of the header files required to link to the Win32 and Win64 APINo direct equivalent in base Fedora - glibc-devel is closest
|}
|}
= Build for multiple targets =
The goal of the MinGW framework is to provide an easy way for package maintainers to build their packages for multiple targets using one .spec file. To aid developers in this several RPM macros have been developed which are part of the mingw-filesystem package.
These RPM macros will be explained later on in these guidelines.
By default a MinGW package will be built for both the Win32 and Win64 targets.
When a package can only be built for either one of these targets this can be indicated by setting one of these:
{|
| <code>%global mingw_build_win32 0</code> || Don't build for the Win32 target
|-
| <code>%global mingw_build_win64 0</code> || Don't build for the Win64 target
|}
= One source RPM, separate binary RPMs per-target =
Each cross compiled MinGW package which builds binaries for a specific target should put the binaries for that target in a separate subpackage. So if a package <code>foo</code> builds binaries for the Win32 and Win64 targets, then the source RPM should provide two subpackages named <code>mingw32-foo</code> and <code>mingw64-foo</code>.
This means that a spec file must contains %package and %files sections for all the targets.
If a package contains translations then all calls to the <code>%find_lang</code> must be replaced by <code>%mingw_find_lang</code>.
This causes all translation filelists to be split in per-target filelists.
For example: when a spec file contains something like this:
<pre>
%install
<snip>
%mingw_find_lang foo
</pre>
then two files will get created named <code>mingw32-foo.lang</code> and <code>mingw64-foo.lang</code>.
These file lists can be included in the %files section for the targets:
<pre>
%files -n mingw32-foo -f mingw32-foo.lang
<snip>
%files -n mingw64-foo -f mingw64-foo.lang
</pre>


= Filesystem layout =
= Filesystem layout =
Line 71: Line 92:
   |  +- rpm
   |  +- rpm
   |      |
   |      |
  |      +- macros.mingw
   |      +- macros.mingw32
   |      +- macros.mingw32
  |      +- macros.mingw64
   |
   |
   +- usr
   +- usr
       |
       |
       +- bin  - Links to cross compiler toolchain
       +- bin  - Links to MinGW cross compiler toolchain
       |  |
       |  |
       |  +- i686-pc-mingw32-cpp
       |  +- i686-w64-mingw32-cpp
       |  +- i686-pc-mingw32-gcc
       |  +- i686-w64-mingw32-gcc
       |  +- i686-pc-mingw32-g++
       |  +- i686-w64-mingw32-g++
      |  +- x86_64-w64-mingw32-cpp
      |  +- x86_64-w64-mingw32-gcc
      |  +- x86_64-w64-mingw32-g++
       |  +- ... etc..
       |  +- ... etc..
       |
       |
Line 86: Line 112:
       |  +- rpm
       |  +- rpm
       |      |
       |      |
       |      +- mingw32-defs  - custom helper scripts for auto-requires, binary stripping, etc
       |      +- mingw-find-debuginfo.sh - extract debug information from Win32 and Win64 binaries
       |      +- mingw32-find-provides.sh - extra DLL names
      |      +- mingw-find-lang.sh - generates per-target file lists containing translations
       |      +- mingw32-find-requires.sh - discover required DLL names
       |      +- mingw-find-provides.sh - extra DLL names
       |      +- mingw-find-requires.sh - discover required DLL names
       |
       |
       +- i686-pc-mingw32  - root of mingw toolchain and binaries - see next diagram
       +- i686-w64-mingw32  - root of mingw toolchain and binaries for the Win32 target - see next diagram
      +- x86_64-w64-mingw32  - root of mingw toolchain and binaries for the Win64 target - see next diagram




  /usr/i686-pc-mingw32
  /usr/i686-w64-mingw32
/usr/x86_64-w64-mingw32
   |
   |
   +- bin  - Cross compiler toolchain
   +- bin  - Binutils toolchain binaries for the target
   |  |
   |  |
   |  +- cpp
   |  +- ar
   |  +- gcc
   |  +- as
   |  +- g++
   |  +- dlltool
  |  +- ld
   |  +- ... etc ...
   |  +- ... etc ...
   |
   |
   +- lib  - Cross compiler toolchain support libraries / files
   +- lib  - Binutils toolchain support libraries / files for the target
   |
   |
   +- sys-root  - root for cross compiled binaries
   +- sys-root  - root for cross compiled MinGW binaries
       |
       |
       +- mingw
       +- mingw
           |
           |
           +- bin    - cross-compiled binaries & runtime DLL parts
           +- bin    - cross-compiled MinGW binaries & runtime DLL parts
           +- doc     - documentation
           +- etc     - configuration files
           +- include - include files for cross compiled libs
           +- include - include files for cross compiled MinGW libs
           +- lib    - cross-compiled static libraries & linktime DLL parts
           +- lib    - cross-compiled static MinGW libraries & linktime DLL parts
           |  |
           |  |
           |  +- pkgconfig  - pkg-config definitions for libraries
           |  +- pkgconfig  - pkg-config definitions for libraries
Line 121: Line 151:
= Filenames of the cross-compilers and binutils =
= Filenames of the cross-compilers and binutils =


The cross-compilers and binutils are Fedora binaries and are therefore
The MinGW cross-compilers and binutils are Fedora binaries and are therefore placed in <code>%{_bindir}</code> (ie. <code>/usr/bin</code>) according to the FHS and Fedora guidelines.
placed in <code>%{_bindir}</code> (ie. <code>/usr/bin</code>)
according to the FHS and Fedora guidelines.


The cross-compilers and binutils which generate i686 binaries for Windows are named:
The MinGW cross-compilers and binutils which generate i686 binaries for Windows are named:
 
<pre>
  %{_bindir}/i686-pc-mingw32-gcc
  %{_bindir}/i686-w64-mingw32-gcc
  %{_bindir}/i686-pc-mingw32-g++
  %{_bindir}/i686-w64-mingw32-g++
  %{_bindir}/i686-pc-mingw32-ld
  %{_bindir}/i686-w64-mingw32-ld
  %{_bindir}/i686-pc-mingw32-as
  %{_bindir}/i686-w64-mingw32-as
  %{_bindir}/i686-pc-mingw32-strip
  %{_bindir}/i686-w64-mingw32-strip
  etc.
  etc.
</pre>


The same binaries are present in
The same binaries are present in
<code>%{_prefix}/i686-pc-mingw32/bin</code> without any prefix in the
<code>%{_prefix}/i686-w64-mingw32/bin</code> without any prefix in the
name, ie:
name, ie:
<pre>
%{_prefix}/i686-w64-mingw32/bin/gcc
%{_prefix}/i686-w64-mingw32/bin/g++
%{_prefix}/i686-w64-mingw32/bin/ld
%{_prefix}/i686-w64-mingw32/bin/as
%{_prefix}/i686-w64-mingw32/bin/strip
etc.
</pre>


%{_prefix}/i686-pc-mingw32/bin/gcc
The same also applies for the x86_64 target. This target uses 'x86_64-w64-mingw32' as prefix instead of 'i686-w64-mingw32'
%{_prefix}/i686-pc-mingw32/bin/g++
%{_prefix}/i686-pc-mingw32/bin/ld
%{_prefix}/i686-pc-mingw32/bin/as
%{_prefix}/i686-pc-mingw32/bin/strip
etc.


= Naming of the root filesystem =
= Naming of the root filesystem =


The root filesystem contains Windows executables and DLLs and any other Windows-only
The root filesystem contains Windows executables and DLLs and any other Windows-only files.  It is necessary both because we need to store Windows libraries in order to link further libraries which depend on them, and also because MinGW requires a root filesystem location.  
files.  It is necessary both because we need to store Windows libraries in order to
link further libraries which depend on them, and also because MinGW requires a
root filesystem location. The location (for i686 target) is provided by the macro:


  %{_mingw32_sysroot}  %{_prefix}/i686-pc-mingw32/sys-root
The location for Win32 target is provided by the macro:
<pre>
  %{mingw32_sysroot}  %{_prefix}/i686-w64-mingw32/sys-root
</pre>
And the Win64 target is provided by the macro:
<pre>
%{mingw64_sysroot}  %{_prefix}/x86_64-w64-mingw32/sys-root
</pre>


= Standard mingw RPM macros =
= Standard mingw RPM macros =


The <code>mingw32-filesystem</code> package provides a number of
The <code>mingw-filesystem</code> package provides a number of convenience macros for the cross compiled sysroot directories, and
convenience macros for the cross compiled sysroot directories, and
toolchain. It is mandatory to use these macros in all MinGW cross compiled packages submitted to Fedora.
toolchain. It is mandatory to use these macros in all MinGW packages
submitted to Fedora.


== Toolchain macros ==
== Toolchain macros ==
Line 165: Line 199:
The following macros are for the %build and %install section of the spec
The following macros are for the %build and %install section of the spec


Generic macros:
{|
| <b>Macro</b> || <b>Available in<br>mingw-filesystem</b> || <b>Explanation</b>
|-
| mingw_cmake  || >= 95 || Call the cmake binary for all the configured targets
|-
| mingw_cmake_kde4 || >= 95 || Call the cmake binary for all the configured targets with KDE4 specific parameters set
|-
| mingw_configure || >= 95 || Call the configure command for all the configured targets
|-
| mingw_make  || >= 95 || Call the 'make' command for all the configured targets
|-
| mingw_objcopy || >= 95 || cross compiler 'objcopy' binary (which supports both Win32 and Win64 binaries)
|-
| mingw_objdump || >= 95 || cross compiler 'objdump' binary (which supports both Win32 and Win64 binaries)
|-
| mingw_qmake_qt4 || >= 95 || Call the Qt4 qmake binary for all configured targets (requires mingw32-qt-qmake and/or mingw64-qt-qmake to be installed)
|-
| mingw_qmake_qt5 || >= 96 || Call the Qt5 qmake binary for all configured targets (requires mingw32-qt5-qmake and/or mingw64-qt5-qmake to be installed)
|-
| mingw_strip || >= 95 || cross compiler 'strip' binary (which supports both Win32 and Win64 binaries)
|}
Win32 specific macros:
{|
{|
| _mingw32_ar || i686-pc-mingw32-ar || cross compiler 'ar' binary
| <b>Macro</b> || <b>Available in<br>mingw32-filesystem</b> || <b> Value</b> || <b>Explanation</b>
|-
| mingw32_ar || >= 95 || i686-w64-mingw32-ar || cross compiler 'ar' binary
|-
| mingw32_cc || >= 95 || i686-w64-mingw32-gcc || cross compiler 'gcc' binary
|-
|-
| _mingw32_cc || i686-pc-mingw32-gcc || cross compiler 'gcc' binary
| mingw32_cflags  || >= 95 || -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 || Default compiler flags for C/C++ binaries
|-
|-
| _mingw32_cflags || -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 ||
| mingw32_cmake  || >= 95 ||  || Call the cmake binary for the Win32 target
|-
|-
| _mingw32_configure || CC="%{_mingw32_cc}"  CFLAGS="%{_mingw32_cflags}"  ./configure --build=%_build --host=%{_mingw32_host} --target=%{_mingw32_target}  --prefix=%{_mingw32_prefix} || standard invocation for autotools 'configure' scripts
| mingw32_configure || >= 95 || || standard invocation for autotools 'configure' scripts
|-
|-
| _mingw32_cpp || i686-pc-mingw32-gcc -E || cross compiler 'cpp' binary
| mingw32_cpp || >= 95 || i686-w64-mingw32-gcc -E || cross compiler 'cpp' binary
|-
|-
| _mingw32_host || i686-pc-mingw32 || Host platform for build
| mingw32_env  || >= 95 ||  || Set the correct environment variables for the Win32 target
|-
|-
| _mingw32_objdump || i686-pc-mingw32-objdump || cross compiler 'objdump' binary
| mingw32_host || >= 95 || i686-w64-mingw32 || Host platform for build
|-
|-
| _mingw32_ranlib || i686-pc-mingw32-ranlib || cross compiler 'ranlib' binary
| mingw32_objcopy || >= 95 ||  i686-w64-mingw32-objcopy || cross compiler 'objcopy' binary
|-
|-
| _mingw32_strip || i686-pc-mingw32-strip || cross compiler 'strip' binary  
| mingw32_objdump || >= 95 || i686-w64-mingw32-objdump || cross compiler 'objdump' binary
|-
|-
| _mingw32_target || i686-pc-mingw32 || Target platform for build
| mingw32_pkg_config  || >= 95 || i686-w64-mingw32-pkg-config || Call the pkg-config command for the Win32 target
|-
| mingw32_qmake_qt4 || >= 95 || mingw32-qmake-qt4  || Call the Qt4 qmake command for the Win32 target
|-
| mingw32_qmake_qt5 || >= 96 || mingw32-qmake-qt5  || Call the Qt5 qmake command for the Win32 target
|-
| mingw32_ranlib || >= 95 || i686-w64-mingw32-ranlib || cross compiler 'ranlib' binary
|-
| mingw32_strip || >= 95 || i686-w64-mingw32-strip || cross compiler 'strip' binary
|-
| mingw32_target || >= 95 || i686-w64-mingw32 || Target platform for build
|}
 
 
Win64 specific macros:
{|
| <b>Macro</b> || <b>Available in<br>mingw64-filesystem</b> || <b> Value</b> || <b>Explanation</b>
|-
| mingw64_ar || >= 95 || x86_64-w64-mingw32-ar || cross compiler 'ar' binary
|-
| mingw64_cc || >= 95 || x86_64-w64-mingw32-gcc || cross compiler 'gcc' binary
|-
| mingw64_cflags  || >= 95 || -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 || Default compiler flags for C/C++ binaries
|-
| mingw64_cmake  || >= 95 ||  || Call the cmake binary for the Win64 target
|-
| mingw64_configure || >= 95 ||  || standard invocation for autotools 'configure' scripts
|-
| mingw64_cpp || >= 95 || x86_64-w64-mingw32-gcc -E || cross compiler 'cpp' binary
|-
| mingw64_env  || >= 95 ||  || Set the correct environment variables for the Win64 target
|-
| mingw64_host || >= 95 || x86_64-w64-mingw32  || Host platform for build
|-
| mingw64_objcopy || >= 95 ||  x86_64-w64-mingw32-objcopy || cross compiler 'objcopy' binary
|-
| mingw64_objdump || >= 95 || x86_64-w64-mingw32-objdump || cross compiler 'objdump' binary
|-
| mingw64_pkg_config  || >= 95 || x86_64-w64-mingw32-pkg-config || Call the pkg-config command for the Win64 target
|-
| mingw64_qmake_qt4 || >= 95 || mingw64-qmake-qt4  || Call the Qt4 qmake command for the Win64 target
|-
| mingw64_qmake_qt5 || >= 96 || mingw64-qmake-qt5  || Call the Qt5 qmake command for the Win64 target
|-
| mingw64_ranlib || >= 95 || x86_64-w64-mingw32-ranlib || cross compiler 'ranlib' binary
|-
| mingw64_strip || >= 95 || x86_64-w64-mingw32-strip || cross compiler 'strip' binary
|-
| mingw64_target || >= 95 || x86_64-w64-mingw32 || Target platform for build
|}
|}


Line 191: Line 302:
The following macros are for use in %build, %install and %files sections of the RPM spec
The following macros are for use in %build, %install and %files sections of the RPM spec


For the Win32 target:
{|
{|
|_mingw32_bindir || %{_mingw32_prefix}/bin || Location of Windows executables.
| mingw32_bindir || %{mingw32_prefix}/bin || Location of Windows executables.
|-
|-
|_mingw32_datadir || %{_mingw32_prefix}/share || Shared data used under Windows.
| mingw32_datadir || %{mingw32_prefix}/share || Shared data used under Windows.
|-
|-
|_mingw32_docdir || %{_mingw32_prefix}/share/doc || Documentation.
| mingw32_docdir || %{mingw32_prefix}/share/doc || Documentation.
|-
|-
|_mingw32_infodir || %{_mingw32_prefix}/share/info || Info files (see note below).
| mingw32_infodir || %{mingw32_prefix}/share/info || Info files (see note below).
|-
|-
|_mingw32_includedir || %{_mingw32_prefix}/include || Header files used when cross-compiling for Windows.
| mingw32_includedir || %{mingw32_prefix}/include || Header files used when cross-compiling for Windows.
|-
|-
|_mingw32_libdir || %{_mingw32_prefix}/lib || Windows libraries (see sections below).
| mingw32_libdir || %{mingw32_prefix}/lib || Windows libraries (see sections below).
|-
|-
|_mingw32_libexecdir || %{_mingw32_prefix}/libexec ||
| mingw32_libexecdir || %{mingw32_prefix}/libexec ||
|-
|-
|_mingw32_mandir || %{_mingw32_prefix}/share/man || Man pages (see note below).
| mingw32_mandir || %{mingw32_prefix}/share/man || Man pages (see note below).
|-
|-
|_mingw32_prefix || %{_mingw32_sysroot}/mingw || Windows equivalent of %{_prefix}, required by MinGW.
| mingw32_prefix || %{mingw32_sysroot}/mingw || Windows equivalent of %{_prefix}, required by MinGW.
|-
|-
|_mingw32_sbindir || %{_mingw32_prefix}/sbin ||
| mingw32_sbindir || %{mingw32_prefix}/sbin ||
|-
|-
|_mingw32_sysconfdir || %{_mingw32_prefix}/etc || Configuration files used when running under Windows.
| mingw32_sysconfdir || %{mingw32_prefix}/etc || Configuration files used when running under Windows.
|-
|-
|_mingw32_sysroot || %{_prefix}/i686-pc-mingw32/sys-root || Windows system root.
| mingw32_sysroot || %{_prefix}/i686-w64-mingw32/sys-root || Windows system root.
|}
|}


= Dependencies =


If a package contains binaries which depend on a DLL provided by
For the Win64 target:
another package, these dependencies should be expressed in the form:
{|
| mingw64_bindir || %{mingw64_prefix}/bin || Location of Windows executables.
|-
| mingw64_datadir || %{mingw64_prefix}/share || Shared data used under Windows.
|-
| mingw64_docdir || %{mingw64_prefix}/share/doc || Documentation.
|-
| mingw64_infodir || %{mingw64_prefix}/share/info || Info files (see note below).
|-
| mingw64_includedir || %{mingw64_prefix}/include || Header files used when cross-compiling for Windows.
|-
| mingw64_libdir || %{mingw64_prefix}/lib || Windows libraries (see sections below).
|-
| mingw64_libexecdir || %{mingw64_prefix}/libexec ||
|-
| mingw64_mandir || %{mingw64_prefix}/share/man || Man pages (see note below).
|-
| mingw64_prefix || %{mingw64_sysroot}/mingw || Windows equivalent of %{_prefix}, required by MinGW.
|-
| mingw64_sbindir || %{mingw64_prefix}/sbin ||
|-
| mingw64_sysconfdir || %{mingw64_prefix}/etc || Configuration files used when running under Windows.
|-
| mingw64_sysroot || %{_prefix}/x86_64-w64-mingw32/sys-root || Windows system root.
|}
 
= Compilation of binaries =
 
In order to build binaries for multiple targets we have to call commands like <code>./configure</code> and <code>make</code> multiple times (once for each target).
If one has to write this all out in a spec file then it will lead to duplicate code.
To reduce the amount of duplication, several RPM macros have been introduced to help with the compilation.
These macros are <code>%mingw_configure</code>, <code>%mingw_cmake</code>, <code>%mingw_cmake_kde4</code>, <code>%mingw_qmake_qt4</code>, <code>%mingw_qmake_qt5</code> and <code>%mingw_make</code>


mingw32(foo.dll)
These macros use out of source compilation to build binaries for all the targets.
Almost all packages support out of source compilation or require slight patching. The only known exceptions to date are zlib and openssl.
Packages which don't support out of source compilation may require a different approach like performing everything in the %install phase.
If you happen to stumble across a package which requires a different approach feel free to contact us on the Fedora MinGW mailing list


where <code>foo.dll</code> is the name of the DLL. The name must be
Some packages need to be built multiple times for each target. Examples of this are packages which have to be built once for a static version and once for a shared version.
converted to lowercase because Windows binaries contain case
Such packages can add a custom suffix to the build directory used.
insensitive dependencies.
Say you've got something like below:
<pre>
mkdir build_shared
pushd build_shared
%{mingw32_configure} --enable-shared
popd
mkdir build_static
pushd build_static
%{mingw32_configure} --enable-static
popd
</pre>
This can be rewritten to something like this:
<pre>
  MINGW_BUILDDIR_SUFFIX=shared %mingw_configure --enable-shared
MINGW_BUILDDIR_SUFFIX=static %mingw_configure --enable-static
</pre>


All packages should depend on <code>mingw32-filesystem</code>.
Most packages used the command <code>make %{?_smp_mflags}</code> to build the package.
In the MinGW cross compiler framework you have to use <code>%mingw_make %{?_smp_mflags}</code> to build the package for all configured targets.
As with the <code>%mingw_configure</code> macro you can also use the MINGW_BUILDDIR_SUFFIX environment variable to indicate a custom suffix to the build directory used


Correct dependency generation is done automatically. Packagers should
To install the package the command <code>make install DESTDIR=$RPM_BUILD_ROOT</code> was used in almost all cases.
include these lines in all library packages:
This can be rewritten to <code>%mingw_make install DESTDIR=$RPM_BUILD_ROOT</code> to install the package for all configured targets
The environment variable MINGW_BUILDDIR_SUFFIX can also be used here


%global _use_internal_dependency_generator 0
Some packages require some custom instructions before the files are ready to be packaged. Such code can remain as is. However, you may need to duplicate these instructions multiple times (for all configured targets).
%global __find_requires %{_mingw32_findrequires}
%global __find_provides %{_mingw32_findprovides}


All specfiles should BuildRequire at least:
= Dependencies =
 
If a package contains binaries which depend on a DLL provided by another package, these dependencies should be expressed in the form:
<pre>
mingw32(foo.dll)
</pre>
where <code>foo.dll</code> is the name of the DLL.  The name must be converted to lowercase because Windows binaries contain case
insensitive dependencies. The form 'mingw32(foo.dll)' should be used for Win32 binaries and the form 'mingw64(foo.dll)' for Win64 binaries.
 
Correct dependency generation is done automatically.  Packagers should start their spec files with this line:
<pre>
%{?mingw_package_header}
</pre>
All binary packages should depend on <code>mingw32-filesystem</code> or <code>mingw64-filesystem</code> (depending on the files in the package). If the line mentioned above is used then it will be added automatically, so you don't have to add it yourself
 
All specfiles should BuildRequire at least one of these (depending on the targets for which you want to build):


  BuildRequires:  mingw32-filesystem >= minimum-version
  BuildRequires:  mingw32-filesystem >= minimum-version
BuildRequires:  mingw64-filesystem >= minimum-version


and any other BuildRequires that they need.
and any other BuildRequires that they need.
The <code>minimum-version</code> must be at least 95 or any later version which provides the functionality you need


= Build architecture =
= Build architecture =
Line 255: Line 434:
All libraries must be built as DLLs.
All libraries must be built as DLLs.


Because of the peculiarity of Windows, DLLs are stored in the
Because of the peculiarity of Windows, DLLs are stored in the <code>%{mingw32_bindir}</code> directory, along with a control file in
<code>%{_mingw32_bindir}</code> directory, along with a control file in
the <code>%{mingw32_libdir}</code> directory.  For example, for a library called <code>foo</code> there would be:
the <code>%{_mingw32_libdir}</code> directory.  For example, for a
<pre>
library called <code>foo</code> there would be:
%{mingw32_bindir}/foo.dll
%{mingw32_libdir}/foo.dll.a
</pre>
The <code>foo.dll</code> file is the main library, <code>foo.dll.a</code> is a stub linked to applications so they can find the library at runtime.  All of these files are required in those locations in order to link successfully. The <code>.dll</code> may contain a version number although not always (eg. <code>foo-0.dll</code>).
 
== Do not use %{mingw32_bindir}/* or %{mingw32_libdir}/* in %files section ==


%{_mingw32_bindir}/foo.dll
The <code>%files</code> section must list DLLs and import libraries separatelyPackages must NOT use <code>%{mingw32_bindir}/*</code> or
  %{_mingw32_bindir}/foo.def
<code>%{mingw32_libdir}/*</code>
%{_mingw32_libdir}/foo.dll.a
%{_mingw32_libdir}/foo.la


All files are required in those locations in order to link
The reason for this is that libtool is very fragile and will give up on building a DLL very easily. Therefore we force the name of the DLL to be listed explicitly in the <code>%files</code> section in order to catch this during RPM builds.
successfully, except that the <code>.def</code> file is not always
built by libtool for reasons unknown, and the <code>.dll</code> may
contain a version number although not always
(eg. <code>foo-0.dll</code>).


== Do not use %{_mingw32_bindir}/* or %{_mingw32_libdir}/* in %files section ==
== Stripping ==


The <code>%files</code> section must list DLLs separatelyPackages
Libraries and executables should be strippedThis is done correctly and automatically if the spec file starts with this line:
must NOT use <code>%{_mingw32_bindir}/*</code> or
<code>%{_mingw32_libdir}/*</code>


The reason for this is that libtool is very fragile and will give up
<pre>
on building a DLL very easily. Therefore we force the name of the DLL
  %{?mingw_package_header}
to be listed explicitly in the <code>%files</code> section in order to
</pre>
catch this during RPM builds.


== Manpages and info files ==
{{admon/warning|%mingw_package_header|The %mingw_package_header macro sets the strip, objdump, and debuginfo generating commands appropriately for windows binaries.  Without this line Windows binaries may be corrupted by the automatic tasks that rpm performs on the built binaries.}}


If manpages or info files are simply duplicates of equivalent
== Debuginfo subpackage ==
documentation found in Fedora native packages, then they should not be
packaged in the MinGW package.


== Static libraries ==
Most binaries contain debugging symbols when the package gets built. To split the debugging symbols to a separate debuginfo package (as is done with native Fedora packages) the spec file must include these lines:
<pre>
%{?mingw_package_header}
[...]
%{?mingw_debug_package}
</pre>


In accordance with ordinary Fedora policy, static libraries should not
The <code>%{?mingw_debug_package}</code> line must be placed after the <code>%description tag</code>. Otherwise spectool and other RPM tools may fail to function
be built, and if they are then they should be placed in a
<code>-static</code> subpackage.


The exception is the base package <code>mingw32-w32api</code> which
= Executables (EXEs) =
contains static libraries that are required for GCC to create
executables.


== Stripping ==
Most libraries also provide executables. These can include executables which can be used to test or showcase the library in question (for example gtk3-demo.exe in mingw-gtk3).
Other examples are helper executables which are used by the library itself internally (for example gspawn-win32-helper.exe in mingw-glib2).


Libraries and executables should be stripped. This is done correctly
Executables which are required for proper functionality of the libraries must be packaged in the matching mingw32/mingw64 subpackage. All other executables are discouraged, but may be packaged in optional (dependent) subpackages at a packager's discretion.
and automatically if the spec file includes these lines:


%global __strip %{_mingw32_strip}
= Files which are already part of native packages =
%global __objdump %{_mingw32_objdump}


(Note that if __strip and __objdump are not overridden in the specfile
There are various types of files which are simply duplicates of equivalent files found in Fedora native packages. These files should not be packaged in the MinGW package.
then this can sometimes cause Windows binaries to be corrupted).
The following files don't need to be packaged in the MinGW package when their native counterpart already contains them:
* Man pages (<code>%{mingw32_mandir}</code> / <code>%{mingw64_mandir}</code>)
* Info files (<code>%{mingw32_infodir}</code> / <code>%{mingw64_infodir}</code>)
* Generic documentation (<code>%{mingw32_docdir}</code> / <code>%{mingw64_docdir}</code>)
* Autoconf files (<code>%{mingw32_datadir}/aclocal</code> / <code>%{mingw64_datadir}/aclocal</code>)
* gtk-doc files (<code>%{mingw32_datadir}/gtk-doc</code> / <code>%{mingw64_datadir}/gtk-doc</code>)


== Example Specfile ==
= Example Specfile =
<pre>
<pre>
%global __strip %{_mingw32_strip}
%{?mingw_package_header}
%global __objdump %{_mingw32_objdump}
%global _use_internal_dependency_generator 0
%global __find_requires %{_mingw32_findrequires}
%global __find_provides %{_mingw32_findprovides}
%define __debug_install_post %{_mingw32_debug_install_post}


Name:          mingw-example
Name:          mingw-example
Version:        1.2.3
Version:        1.0.0
Release:        1%{?dist}
Release:        1%{?dist}
Summary:         
Summary:        MinGW compiled example library


License:        LGPLv2+
License:        LGPLv2+
Group:          Development/Libraries
URL:            http://fedoraproject.org
URL:             
Source0:        http://fedoraproject.org/example-%{version}.tar.bz2
Source0:         


BuildArch:      noarch
BuildArch:      noarch


BuildRequires:  mingw32-filesystem
BuildRequires:  mingw32-filesystem >= 95
BuildRequires:  mingw32-gcc
BuildRequires:  mingw32-gcc
BuildRequires:  mingw32-binutils
BuildRequires:  mingw32-binutils
# Any additional BuildRequires.
BuildRequires:  mingw32-gettext
BuildRequires:  mingw32-win-iconv
BuildRequires:  mingw32-zlib
 
BuildRequires:  mingw64-filesystem >= 95
BuildRequires:  mingw64-gcc
BuildRequires:  mingw64-binutils
BuildRequires:  mingw64-gettext
BuildRequires:  mingw64-win-iconv
BuildRequires:  mingw64-zlib
 


%description
%description
# description
MinGW compiled example library.
 
 
# If a package maintainer wishes to bundle static libraries then they
# can be placed in -static subpackages. Otherwise, the -static subpackages
# can be dropped


# Win32
%package -n mingw32-example
%package -n mingw32-example
Summary:
Summary:       MinGW compiled example library for the Win32 target
 
%description -n mingw32-example
%description -n mingw32-example
# description
MinGW compiled example library for the Win32 target.
 
%package -n mingw32-example-static
Summary:      Static version of the MinGW Win32 compiled example library
Requires:      mingw32-example = %{version}-%{release}
 
%description -n mingw32-example-static
Static version of the MinGW Win32 compiled example library.
 
# Win64
%package -n mingw64-example
Summary:      MinGW compiled example library for the Win64 target
 
%description -n mingw64-example
MinGW compiled example library for the Win64 target.
 
%package -n mingw64-example-static
Summary:      Static version of the MinGW Win64 compiled example library
Requires:      mingw64-example = %{version}-%{release}
 
%description -n mingw64-example-static
Static version of the MinGW Win64 compiled example library.




%{?_mingw32_debug_package}
%{?mingw_debug_package}




Line 352: Line 562:


%build
%build
%{_mingw32_configure}
%mingw_configure --enable-static --enable-shared --enable-foo
make %{?_smp_mflags}
%mingw_make %{?_smp_mflags}




%install
%install
make DESTDIR=$RPM_BUILD_ROOT install
%mingw_make install DESTDIR=$RPM_BUILD_ROOT
 
# Libtool files don't need to be bundled
find $RPM_BUILD_ROOT -name "*.la" -delete
 
%mingw_find_lang example
 
 
# Note: there should be no %%files section for the main package!
 
# Static subpackages are optional (as mentioned earlier)
 
# Win32
%files -n mingw32-example -f mingw32-example.lang
%{mingw32_bindir}/libexample-0.dll
%{mingw32_includedir}/example/
%{mingw32_libdir}/libexample.dll.a
%{mingw32_libdir}/pkgconfig/example.pc


# Remove static libraries but DON'T remove *.dll.a files.
%files -n mingw32-example-static
rm $RPM_BUILD_ROOT%{_mingw32_libdir}/libfoo.a
%{mingw32_libdir}/libexample.a


# Win64
%files -n mingw64-example -f mingw64-example.lang
%{mingw64_bindir}/libexample-0.dll
%{mingw64_includedir}/example/
%{mingw64_libdir}/libexample.dll.a
%{mingw64_libdir}/pkgconfig/example.pc


%files -n mingw32-example
%files -n mingw64-example-static
%doc COPYING
%{mingw64_libdir}/libexample-0.a
%{_mingw32_bindir}/foo.dll
%{_mingw32_libdir}/foo.dll.a
# etc.




%changelog
%changelog
* Wed Sep 10 2008 Richard W.M. Jones <rjones@redhat.com> - 1.2.3-1
* Sun Apr 15 2012 Erik van Pienbroek <epienbro@fedoraproject.org> - 1.0.0-1
- Initial RPM release.
- Initial release
</pre>
</pre>


[[Category:Packaging guidelines]]
[[Category:Packaging guidelines]]

Revision as of 02:15, 28 January 2015

Packaging Guidelines for MinGW Cross Compilers

Important.png
Updated Guidelines
These guidelines apply to all current Fedora releases. For RHEL-5 and RHEL-6 the old guidelines still apply which can be be found here: Packaging:MinGW_Old

Introduction

The Fedora MinGW project's mission is to provide an excellent development environment for Fedora users who wish to cross-compile their programs to run on Windows, minimizing the need to use Windows at all. In the past developers have had to port and compile all of the libraries and tools they have needed, and this huge effort has happened independently many times over. We aim to eliminate duplication of work for application developers by providing a range of libraries and development tools which have already been ported to the MinGW cross-compiler environment. This means that developers will not need to recompile the application stack themselves, but can concentrate just on the changes needed to their own application.

As of Fedora 17 a set of RPM macros and packages have been introduced which help packagers compile binaries for multiple targets. The targets Win32 and Win64 are supported.

Track Fedora native package versions

In general terms, cross-compiled MinGW versions of packages which are already natively available in Fedora, should follow the native Fedora package as closely as possible. This means they should stay at the same version, include all the same patches as the native Fedora package, and be built with the same configuration options.

The MinGW SIG have written an RPM comparison tool which makes it possible to compare cross compiled MinGW packages with the Fedora native packages, in order to determine whether versions, patches and configuration are aligned.

Follow Fedora policy

Cross compiled MinGW packages must follow Fedora policy, except where noted in this document. Cross compiled packages go through the same review process, GIT admin process etc as other Fedora packages.

Package naming

MinGW packages require special naming to denote the appropriate CPU architecture the binaries have been built for. There should never be a package prefixed with mingw- output during a build. The mingw- prefix is exclusive for RPM spec file names and the source RPM file name. The CPU architecture specific packages are created by sections with %files -n mingw32-foo or %files -n mingw64-foo.

mingw- Used for source package and RPM spec name
mingw32- Used for packages which are built for Win32
mingw64- Used for packages which are built for Win64

Base packages

The base packages provide a root filesystem, base libraries, binutils (basic programs like 'strip', 'ld' etc), the compiler (gcc) and the Win32/Win64 API. Packages may need to depend on one or more of these. In particular, almost all packages should BuildRequire mingw32-filesystem, mingw64-filesystem, mingw32-gcc and mingw64-gcc. The correct Requires flags will get added automatically when the %{?mingw_package_header} macro is mentioned in the spec file (as will be described later on in these guidelines)

mingw32-filesystem / mingw64-filesystem Core filesystem directory layout, and RPM macros for spec files. Equivalent to 'filesystem' RPM
mingw32-binutils / mingw64-binutils Cross-compiled binutils (utilities like 'strip', 'as', 'ld') which understand Windows executables and DLLs. Equivalent to 'binutils' RPM
mingw32-gcc / mingw64-gcc GNU compiler collection. Compilers for C and C++ which cross-compile to a Windows target. Equivalent to gcc RPM
mingw32-crt / mingw64-crt Base libraries for core MinGW runtime & development environment. Equivalent to 'glibc' RPM
mingw32-headers / mingw64-headers Win32 and Win64 API. A free (public domain) reimplementation of the header files required to link to the Win32 and Win64 API. No direct equivalent in base Fedora - glibc-devel is closest

Build for multiple targets

The goal of the MinGW framework is to provide an easy way for package maintainers to build their packages for multiple targets using one .spec file. To aid developers in this several RPM macros have been developed which are part of the mingw-filesystem package. These RPM macros will be explained later on in these guidelines.

By default a MinGW package will be built for both the Win32 and Win64 targets.

When a package can only be built for either one of these targets this can be indicated by setting one of these:

%global mingw_build_win32 0 Don't build for the Win32 target
%global mingw_build_win64 0 Don't build for the Win64 target

One source RPM, separate binary RPMs per-target

Each cross compiled MinGW package which builds binaries for a specific target should put the binaries for that target in a separate subpackage. So if a package foo builds binaries for the Win32 and Win64 targets, then the source RPM should provide two subpackages named mingw32-foo and mingw64-foo.

This means that a spec file must contains %package and %files sections for all the targets.

If a package contains translations then all calls to the %find_lang must be replaced by %mingw_find_lang. This causes all translation filelists to be split in per-target filelists. For example: when a spec file contains something like this:

 %install
 <snip>
 %mingw_find_lang foo

then two files will get created named mingw32-foo.lang and mingw64-foo.lang. These file lists can be included in the %files section for the targets:

 %files -n mingw32-foo -f mingw32-foo.lang
 <snip>
 %files -n mingw64-foo -f mingw64-foo.lang

Filesystem layout

[root]
  |
  +- etc
  |   |
  |   +- rpm
  |       |
  |       +- macros.mingw
  |       +- macros.mingw32
  |       +- macros.mingw64
  |
  +- usr
      |
      +- bin   - Links to MinGW cross compiler toolchain
      |   |
      |   +- i686-w64-mingw32-cpp
      |   +- i686-w64-mingw32-gcc
      |   +- i686-w64-mingw32-g++
      |   +- x86_64-w64-mingw32-cpp
      |   +- x86_64-w64-mingw32-gcc
      |   +- x86_64-w64-mingw32-g++
      |   +- ... etc..
      |
      +- lib
      |   |
      |   +- rpm
      |       |
      |       +- mingw-find-debuginfo.sh - extract debug information from Win32 and Win64 binaries
      |       +- mingw-find-lang.sh - generates per-target file lists containing translations
      |       +- mingw-find-provides.sh - extra DLL names
      |       +- mingw-find-requires.sh - discover required DLL names
      |
      +- i686-w64-mingw32  - root of mingw toolchain and binaries for the Win32 target - see next diagram
      +- x86_64-w64-mingw32  - root of mingw toolchain and binaries for the Win64 target - see next diagram


/usr/i686-w64-mingw32
/usr/x86_64-w64-mingw32
  |
  +- bin  - Binutils toolchain binaries for the target
  |   |
  |   +- ar
  |   +- as
  |   +- dlltool
  |   +- ld
  |   +- ... etc ...
  |
  +- lib  - Binutils toolchain support libraries / files for the target
  |
  +- sys-root  - root for cross compiled MinGW binaries
      |
      +- mingw
          |
          +- bin     - cross-compiled MinGW binaries & runtime DLL parts
          +- etc     - configuration files
          +- include - include files for cross compiled MinGW libs
          +- lib     - cross-compiled static MinGW libraries & linktime DLL parts
          |   |
          |   +- pkgconfig  - pkg-config definitions for libraries
          |
          +- share
              |
              +- man

Filenames of the cross-compilers and binutils

The MinGW cross-compilers and binutils are Fedora binaries and are therefore placed in %{_bindir} (ie. /usr/bin) according to the FHS and Fedora guidelines.

The MinGW cross-compilers and binutils which generate i686 binaries for Windows are named:

 %{_bindir}/i686-w64-mingw32-gcc
 %{_bindir}/i686-w64-mingw32-g++
 %{_bindir}/i686-w64-mingw32-ld
 %{_bindir}/i686-w64-mingw32-as
 %{_bindir}/i686-w64-mingw32-strip
 etc.

The same binaries are present in %{_prefix}/i686-w64-mingw32/bin without any prefix in the name, ie:

 %{_prefix}/i686-w64-mingw32/bin/gcc
 %{_prefix}/i686-w64-mingw32/bin/g++
 %{_prefix}/i686-w64-mingw32/bin/ld
 %{_prefix}/i686-w64-mingw32/bin/as
 %{_prefix}/i686-w64-mingw32/bin/strip
 etc.

The same also applies for the x86_64 target. This target uses 'x86_64-w64-mingw32' as prefix instead of 'i686-w64-mingw32'

Naming of the root filesystem

The root filesystem contains Windows executables and DLLs and any other Windows-only files. It is necessary both because we need to store Windows libraries in order to link further libraries which depend on them, and also because MinGW requires a root filesystem location.

The location for Win32 target is provided by the macro:

 %{mingw32_sysroot}   %{_prefix}/i686-w64-mingw32/sys-root

And the Win64 target is provided by the macro:

 %{mingw64_sysroot}   %{_prefix}/x86_64-w64-mingw32/sys-root

Standard mingw RPM macros

The mingw-filesystem package provides a number of convenience macros for the cross compiled sysroot directories, and toolchain. It is mandatory to use these macros in all MinGW cross compiled packages submitted to Fedora.

Toolchain macros

The following macros are for the %build and %install section of the spec

Generic macros:

Macro Available in
mingw-filesystem
Explanation
mingw_cmake >= 95 Call the cmake binary for all the configured targets
mingw_cmake_kde4 >= 95 Call the cmake binary for all the configured targets with KDE4 specific parameters set
mingw_configure >= 95 Call the configure command for all the configured targets
mingw_make >= 95 Call the 'make' command for all the configured targets
mingw_objcopy >= 95 cross compiler 'objcopy' binary (which supports both Win32 and Win64 binaries)
mingw_objdump >= 95 cross compiler 'objdump' binary (which supports both Win32 and Win64 binaries)
mingw_qmake_qt4 >= 95 Call the Qt4 qmake binary for all configured targets (requires mingw32-qt-qmake and/or mingw64-qt-qmake to be installed)
mingw_qmake_qt5 >= 96 Call the Qt5 qmake binary for all configured targets (requires mingw32-qt5-qmake and/or mingw64-qt5-qmake to be installed)
mingw_strip >= 95 cross compiler 'strip' binary (which supports both Win32 and Win64 binaries)


Win32 specific macros:

Macro Available in
mingw32-filesystem
Value Explanation
mingw32_ar >= 95 i686-w64-mingw32-ar cross compiler 'ar' binary
mingw32_cc >= 95 i686-w64-mingw32-gcc cross compiler 'gcc' binary
mingw32_cflags >= 95 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 Default compiler flags for C/C++ binaries
mingw32_cmake >= 95 Call the cmake binary for the Win32 target
mingw32_configure >= 95 standard invocation for autotools 'configure' scripts
mingw32_cpp >= 95 i686-w64-mingw32-gcc -E cross compiler 'cpp' binary
mingw32_env >= 95 Set the correct environment variables for the Win32 target
mingw32_host >= 95 i686-w64-mingw32 Host platform for build
mingw32_objcopy >= 95 i686-w64-mingw32-objcopy cross compiler 'objcopy' binary
mingw32_objdump >= 95 i686-w64-mingw32-objdump cross compiler 'objdump' binary
mingw32_pkg_config >= 95 i686-w64-mingw32-pkg-config Call the pkg-config command for the Win32 target
mingw32_qmake_qt4 >= 95 mingw32-qmake-qt4 Call the Qt4 qmake command for the Win32 target
mingw32_qmake_qt5 >= 96 mingw32-qmake-qt5 Call the Qt5 qmake command for the Win32 target
mingw32_ranlib >= 95 i686-w64-mingw32-ranlib cross compiler 'ranlib' binary
mingw32_strip >= 95 i686-w64-mingw32-strip cross compiler 'strip' binary
mingw32_target >= 95 i686-w64-mingw32 Target platform for build


Win64 specific macros:

Macro Available in
mingw64-filesystem
Value Explanation
mingw64_ar >= 95 x86_64-w64-mingw32-ar cross compiler 'ar' binary
mingw64_cc >= 95 x86_64-w64-mingw32-gcc cross compiler 'gcc' binary
mingw64_cflags >= 95 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 Default compiler flags for C/C++ binaries
mingw64_cmake >= 95 Call the cmake binary for the Win64 target
mingw64_configure >= 95 standard invocation for autotools 'configure' scripts
mingw64_cpp >= 95 x86_64-w64-mingw32-gcc -E cross compiler 'cpp' binary
mingw64_env >= 95 Set the correct environment variables for the Win64 target
mingw64_host >= 95 x86_64-w64-mingw32 Host platform for build
mingw64_objcopy >= 95 x86_64-w64-mingw32-objcopy cross compiler 'objcopy' binary
mingw64_objdump >= 95 x86_64-w64-mingw32-objdump cross compiler 'objdump' binary
mingw64_pkg_config >= 95 x86_64-w64-mingw32-pkg-config Call the pkg-config command for the Win64 target
mingw64_qmake_qt4 >= 95 mingw64-qmake-qt4 Call the Qt4 qmake command for the Win64 target
mingw64_qmake_qt5 >= 96 mingw64-qmake-qt5 Call the Qt5 qmake command for the Win64 target
mingw64_ranlib >= 95 x86_64-w64-mingw32-ranlib cross compiler 'ranlib' binary
mingw64_strip >= 95 x86_64-w64-mingw32-strip cross compiler 'strip' binary
mingw64_target >= 95 x86_64-w64-mingw32 Target platform for build

Filesystem location macros

The following macros are for use in %build, %install and %files sections of the RPM spec

For the Win32 target:

mingw32_bindir %{mingw32_prefix}/bin Location of Windows executables.
mingw32_datadir %{mingw32_prefix}/share Shared data used under Windows.
mingw32_docdir %{mingw32_prefix}/share/doc Documentation.
mingw32_infodir %{mingw32_prefix}/share/info Info files (see note below).
mingw32_includedir %{mingw32_prefix}/include Header files used when cross-compiling for Windows.
mingw32_libdir %{mingw32_prefix}/lib Windows libraries (see sections below).
mingw32_libexecdir %{mingw32_prefix}/libexec
mingw32_mandir %{mingw32_prefix}/share/man Man pages (see note below).
mingw32_prefix %{mingw32_sysroot}/mingw Windows equivalent of %{_prefix}, required by MinGW.
mingw32_sbindir %{mingw32_prefix}/sbin
mingw32_sysconfdir %{mingw32_prefix}/etc Configuration files used when running under Windows.
mingw32_sysroot %{_prefix}/i686-w64-mingw32/sys-root Windows system root.


For the Win64 target:

mingw64_bindir %{mingw64_prefix}/bin Location of Windows executables.
mingw64_datadir %{mingw64_prefix}/share Shared data used under Windows.
mingw64_docdir %{mingw64_prefix}/share/doc Documentation.
mingw64_infodir %{mingw64_prefix}/share/info Info files (see note below).
mingw64_includedir %{mingw64_prefix}/include Header files used when cross-compiling for Windows.
mingw64_libdir %{mingw64_prefix}/lib Windows libraries (see sections below).
mingw64_libexecdir %{mingw64_prefix}/libexec
mingw64_mandir %{mingw64_prefix}/share/man Man pages (see note below).
mingw64_prefix %{mingw64_sysroot}/mingw Windows equivalent of %{_prefix}, required by MinGW.
mingw64_sbindir %{mingw64_prefix}/sbin
mingw64_sysconfdir %{mingw64_prefix}/etc Configuration files used when running under Windows.
mingw64_sysroot %{_prefix}/x86_64-w64-mingw32/sys-root Windows system root.

Compilation of binaries

In order to build binaries for multiple targets we have to call commands like ./configure and make multiple times (once for each target). If one has to write this all out in a spec file then it will lead to duplicate code. To reduce the amount of duplication, several RPM macros have been introduced to help with the compilation. These macros are %mingw_configure, %mingw_cmake, %mingw_cmake_kde4, %mingw_qmake_qt4, %mingw_qmake_qt5 and %mingw_make

These macros use out of source compilation to build binaries for all the targets. Almost all packages support out of source compilation or require slight patching. The only known exceptions to date are zlib and openssl. Packages which don't support out of source compilation may require a different approach like performing everything in the %install phase. If you happen to stumble across a package which requires a different approach feel free to contact us on the Fedora MinGW mailing list

Some packages need to be built multiple times for each target. Examples of this are packages which have to be built once for a static version and once for a shared version. Such packages can add a custom suffix to the build directory used. Say you've got something like below:

 mkdir build_shared
 pushd build_shared
 %{mingw32_configure} --enable-shared
 popd
 mkdir build_static
 pushd build_static
 %{mingw32_configure} --enable-static
 popd

This can be rewritten to something like this:

 MINGW_BUILDDIR_SUFFIX=shared %mingw_configure --enable-shared
 MINGW_BUILDDIR_SUFFIX=static %mingw_configure --enable-static

Most packages used the command make %{?_smp_mflags} to build the package. In the MinGW cross compiler framework you have to use %mingw_make %{?_smp_mflags} to build the package for all configured targets. As with the %mingw_configure macro you can also use the MINGW_BUILDDIR_SUFFIX environment variable to indicate a custom suffix to the build directory used

To install the package the command make install DESTDIR=$RPM_BUILD_ROOT was used in almost all cases. This can be rewritten to %mingw_make install DESTDIR=$RPM_BUILD_ROOT to install the package for all configured targets The environment variable MINGW_BUILDDIR_SUFFIX can also be used here

Some packages require some custom instructions before the files are ready to be packaged. Such code can remain as is. However, you may need to duplicate these instructions multiple times (for all configured targets).

Dependencies

If a package contains binaries which depend on a DLL provided by another package, these dependencies should be expressed in the form:

 mingw32(foo.dll)

where foo.dll is the name of the DLL. The name must be converted to lowercase because Windows binaries contain case insensitive dependencies. The form 'mingw32(foo.dll)' should be used for Win32 binaries and the form 'mingw64(foo.dll)' for Win64 binaries.

Correct dependency generation is done automatically. Packagers should start their spec files with this line:

 %{?mingw_package_header}

All binary packages should depend on mingw32-filesystem or mingw64-filesystem (depending on the files in the package). If the line mentioned above is used then it will be added automatically, so you don't have to add it yourself

All specfiles should BuildRequire at least one of these (depending on the targets for which you want to build):

BuildRequires:  mingw32-filesystem >= minimum-version
BuildRequires:  mingw64-filesystem >= minimum-version

and any other BuildRequires that they need.

The minimum-version must be at least 95 or any later version which provides the functionality you need

Build architecture

All packages should have:

BuildArch: noarch

unless they contain Fedora native executables.

Libraries (DLLs)

All libraries must be built as DLLs.

Because of the peculiarity of Windows, DLLs are stored in the %{mingw32_bindir} directory, along with a control file in the %{mingw32_libdir} directory. For example, for a library called foo there would be:

 %{mingw32_bindir}/foo.dll
 %{mingw32_libdir}/foo.dll.a

The foo.dll file is the main library, foo.dll.a is a stub linked to applications so they can find the library at runtime. All of these files are required in those locations in order to link successfully. The .dll may contain a version number although not always (eg. foo-0.dll).

Do not use %{mingw32_bindir}/* or %{mingw32_libdir}/* in %files section

The %files section must list DLLs and import libraries separately. Packages must NOT use %{mingw32_bindir}/* or %{mingw32_libdir}/*

The reason for this is that libtool is very fragile and will give up on building a DLL very easily. Therefore we force the name of the DLL to be listed explicitly in the %files section in order to catch this during RPM builds.

Stripping

Libraries and executables should be stripped. This is done correctly and automatically if the spec file starts with this line:

 %{?mingw_package_header}
Warning.png
%mingw_package_header
The %mingw_package_header macro sets the strip, objdump, and debuginfo generating commands appropriately for windows binaries. Without this line Windows binaries may be corrupted by the automatic tasks that rpm performs on the built binaries.

Debuginfo subpackage

Most binaries contain debugging symbols when the package gets built. To split the debugging symbols to a separate debuginfo package (as is done with native Fedora packages) the spec file must include these lines:

 %{?mingw_package_header}
 [...]
 %{?mingw_debug_package}

The %{?mingw_debug_package} line must be placed after the %description tag. Otherwise spectool and other RPM tools may fail to function

Executables (EXEs)

Most libraries also provide executables. These can include executables which can be used to test or showcase the library in question (for example gtk3-demo.exe in mingw-gtk3). Other examples are helper executables which are used by the library itself internally (for example gspawn-win32-helper.exe in mingw-glib2).

Executables which are required for proper functionality of the libraries must be packaged in the matching mingw32/mingw64 subpackage. All other executables are discouraged, but may be packaged in optional (dependent) subpackages at a packager's discretion.

Files which are already part of native packages

There are various types of files which are simply duplicates of equivalent files found in Fedora native packages. These files should not be packaged in the MinGW package. The following files don't need to be packaged in the MinGW package when their native counterpart already contains them:

  • Man pages (%{mingw32_mandir} / %{mingw64_mandir})
  • Info files (%{mingw32_infodir} / %{mingw64_infodir})
  • Generic documentation (%{mingw32_docdir} / %{mingw64_docdir})
  • Autoconf files (%{mingw32_datadir}/aclocal / %{mingw64_datadir}/aclocal)
  • gtk-doc files (%{mingw32_datadir}/gtk-doc / %{mingw64_datadir}/gtk-doc)

Example Specfile

%{?mingw_package_header}

Name:           mingw-example
Version:        1.0.0
Release:        1%{?dist}
Summary:        MinGW compiled example library

License:        LGPLv2+
URL:            http://fedoraproject.org
Source0:        http://fedoraproject.org/example-%{version}.tar.bz2

BuildArch:      noarch

BuildRequires:  mingw32-filesystem >= 95
BuildRequires:  mingw32-gcc
BuildRequires:  mingw32-binutils
BuildRequires:  mingw32-gettext
BuildRequires:  mingw32-win-iconv
BuildRequires:  mingw32-zlib

BuildRequires:  mingw64-filesystem >= 95
BuildRequires:  mingw64-gcc
BuildRequires:  mingw64-binutils
BuildRequires:  mingw64-gettext
BuildRequires:  mingw64-win-iconv
BuildRequires:  mingw64-zlib


%description
MinGW compiled example library.


# If a package maintainer wishes to bundle static libraries then they
# can be placed in -static subpackages. Otherwise, the -static subpackages
# can be dropped

# Win32
%package -n mingw32-example
Summary:       MinGW compiled example library for the Win32 target

%description -n mingw32-example
MinGW compiled example library for the Win32 target.

%package -n mingw32-example-static
Summary:       Static version of the MinGW Win32 compiled example library
Requires:      mingw32-example = %{version}-%{release}

%description -n mingw32-example-static
Static version of the MinGW Win32 compiled example library.

# Win64
%package -n mingw64-example
Summary:       MinGW compiled example library for the Win64 target

%description -n mingw64-example
MinGW compiled example library for the Win64 target.

%package -n mingw64-example-static
Summary:       Static version of the MinGW Win64 compiled example library
Requires:      mingw64-example = %{version}-%{release}

%description -n mingw64-example-static
Static version of the MinGW Win64 compiled example library.


%{?mingw_debug_package}


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


%build
%mingw_configure --enable-static --enable-shared --enable-foo
%mingw_make %{?_smp_mflags}


%install
%mingw_make install DESTDIR=$RPM_BUILD_ROOT

# Libtool files don't need to be bundled
find $RPM_BUILD_ROOT -name "*.la" -delete

%mingw_find_lang example


# Note: there should be no %%files section for the main package!

# Static subpackages are optional (as mentioned earlier)

# Win32
%files -n mingw32-example -f mingw32-example.lang
%{mingw32_bindir}/libexample-0.dll
%{mingw32_includedir}/example/
%{mingw32_libdir}/libexample.dll.a
%{mingw32_libdir}/pkgconfig/example.pc

%files -n mingw32-example-static
%{mingw32_libdir}/libexample.a

# Win64
%files -n mingw64-example -f mingw64-example.lang
%{mingw64_bindir}/libexample-0.dll
%{mingw64_includedir}/example/
%{mingw64_libdir}/libexample.dll.a
%{mingw64_libdir}/pkgconfig/example.pc

%files -n mingw64-example-static
%{mingw64_libdir}/libexample-0.a


%changelog
* Sun Apr 15 2012 Erik van Pienbroek <epienbro@fedoraproject.org> - 1.0.0-1
- Initial release