Difference between revisions of "MinGW package guidelines"

From ArchWiki
Jump to: navigation, search
(Package Naming)
Line 6: Line 6:
  
 
== Package Naming ==
 
== Package Naming ==
Since there are mingw32 as well as mingw-w64, it is important to properly name your packages. A package for mingw32 might be named {{Ic|mingw32-''pkgname''}} while a package for mingw-w64 should be named {{Ic|mingw-w64-''pkgname''}}. The following parts of the guide focuses on mingw32 as it is a lot more popular than mingw-w64.
+
Since there are mingw32 as well as mingw-w64, it is important to properly name your packages. A package for mingw32 might be named {{Ic|mingw32-''pkgname''}} while a package for mingw-w64 should be named {{Ic|mingw-w64-''pkgname''}}. The following parts of the guide focuses on mingw32, which only provides tools to compile for Windows 32-bit.
  
 
== Packaging ==
 
== Packaging ==

Revision as of 11:59, 30 May 2012

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Template:Package Guidelines

Writing PKGBUILDs for software running in MinGW environment.

Package Naming

Since there are mingw32 as well as mingw-w64, it is important to properly name your packages. A package for mingw32 might be named mingw32-pkgname while a package for mingw-w64 should be named mingw-w64-pkgname. The following parts of the guide focuses on mingw32, which only provides tools to compile for Windows 32-bit.

Packaging

Packaging for cross platform packages can be fairly tricky as there are many different build systems and low-level quirks. Take a note of the following things though:

  • always add mingw32-runtime to depends
  • always add mingw32-gcc to makedepends
  • always add !strip and !buildflags to options
  • always use the original pkgdesc and append (mingw32) to the end of pkgdesc
  • always use and follow the original pkgver of the official package
  • always add unset LDFLAGS in front of toolchain configure/Makefile generation sequences
  • always put all stuff under the /usr/i486-mingw32 prefix
  • always use any as the architecture
  • consider using !libtool in options if you get .la files in $pkgdir

As mentioned above, the files should all be installed into /usr/i486-mingw32. Specifically, all .dll files should be put into /usr/i486-mingw32/bin as they are dynamic libraries needed at runtime. Their corresponding .dll.a files should go into /usr/i486-mingw32/lib. Please delete any unnecessary documentation and perhaps other files from /usr/share. Cross-compilations packages aren't meant for the user but only for the compiler and as such you should try to make them as small as possible.

Always try to match the pkgver in your mingw packages to the pkgver of the corresponding regular packages in the official Arch Linux repos (not the testing repos). This ensures that the cross-compiled software works exactly the same way on mingw without any unexpected bugs. If packages in Arch are out-of-date, there usually is a good reason and you should still follow the Arch version instead of using the most recent upstream release.

Examples

The following examples will try to cover some of the most common conventions and build systems.

Plain Makefile

# Maintainer: yourname <yourmail>
pkgname=mingw32-foo
pkgver=1.0
pkgrel=1
pkgdesc="Foo bar (mingw32)"
arch=('any')
url="http://www.foo.bar"
license=('GPL')
makedepends=('mingw32-gcc')
depends=('mingw32-runtime')
options=('!strip' '!buildflags')
source=("http://www.foo.bar/foobar.tar.gz")
md5sums=('4736ac4f34fd9a41fa0197eac23bbc24')

build() {
  cd "${srcdir}/foobar"

  unset LDFLAGS

  sed "s|LOCAL = /usr/local|LOCAL = ${pkgdir}/usr/i486-mingw32|g" -i Makefile
  sed "s|CXX = gcc|CXX = i486-mingw32-gcc|g" -i Makefile
  sed "s|CXXFLAGS = |CXXFLAGS = -fPIC |g" -i Makefile

  # or with setconf instead of sed (add 'setconf' to makedepends)
  #setconf Makefile LOCAL "$pkgdir/usr/i486-mingw32"
  #setconf Makefile CXX i486-mingw32-gcc
  #setconf Makefile CXXFLAGS -fPIC

  make
}

package() {
  cd "${srcdir}/foobar"

  mkdir -p ${pkgdir}/usr/i486-mingw32/{lib,include}
  make install
  chmod 644 ${pkgdir}/usr/i486-mingw32/lib/libfoo.a
  i486-mingw32-ranlib ${pkgdir}/usr/i486-mingw32/lib/libfoo.a
}

Autotools

# Maintainer: yourname <yourmail>
pkgname=mingw32-foo
pkgver=1.0
pkgrel=1
pkgdesc="Foo bar (mingw32)"
arch=('any')
url="http://www.foo.bar"
license=('GPL')
makedepends=('mingw32-gcc')
depends=('mingw32-runtime')
options=('!strip' '!buildflags')
source=("http://www.foo.bar/foobar.tar.gz")
md5sums=('4736ac4f34fd9a41fa0197eac23bbc24')

build() {
  cd "${srcdir}/foobar"

  unset LDFLAGS

  ./configure --prefix=/usr/i486-mingw32 --host=i486-mingw32
  make
}

package() {
  cd "${srcdir}/foobar"

  make DESTDIR=${pkgdir} install
}

CMake

# Maintainer: yourname <yourmail>
pkgname=mingw32-foo
pkgver=1.0
pkgrel=1
pkgdesc="Foo bar (mingw32)"
arch=('any')
url="http://www.foo.bar"
license=('GPL')
makedepends=('mingw32-gcc' 'cmake')
depends=('mingw32-runtime')
options=('!strip' '!buildflags')
source=("http://www.foo.bar/foobar.tar.gz"
        "cmake-toolchain.cmake")
md5sums=('4736ac4f34fd9a41fa0197eac23bbc24'
         'dd2b2db48187dff84050fe191d309d81')

build() {
  cd "${srcdir}/foobar"
 
  unset LDFLAGS

  mkdir build && cd build
  cmake .. \
    -DCMAKE_INSTALL_PREFIX=/usr/i486-mingw32/ \
    -DCMAKE_TOOLCHAIN_FILE=${srcdir}/cmake-toolchain.cmake
  make
}

package() {
  cd "${srcdir}/foobar"

  cd build
  make DESTDIR=${pkgdir} install
}

In this case, the toolchain is specified externally in cmake-toolchain.cmake:

cmake-toolchain.cmake
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)

# which compilers to use for C and C++
SET(CMAKE_C_COMPILER i486-mingw32-gcc)
SET(CMAKE_CXX_COMPILER i486-mingw32-g++)
SET(CMAKE_RC_COMPILER i486-mingw32-windres)

# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /usr/i486-mingw32)

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search 
# programs in the host environment
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)