「MinGW パッケージガイドライン」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(Kusakata がページ「MinGW PKGBUILD ガイドライン」を「MinGW パッケージガイドライン」に移動しました)
1行目: 1行目:
 
[[Category:パッケージ開発]]
 
[[Category:パッケージ開発]]
[[en:MinGW PKGBUILD Guidelines]]
+
[[en:MinGW package guidelines]]
 
{{Package Guidelines}}
 
{{Package Guidelines}}
   
このページでは、GCC を使って Windows で動作するソフトウェアの [[PKGBUILD|PKGBUILD]] を記述する方法を説明しています。Linux 上で Windows のソフトウェアをビルドする方法は2つあります:
+
このページでは、GCC を使って Windows で動作するソフトウェアの [[PKGBUILD]] を記述する方法を説明しています。Linux 上で Windows のソフトウェアをビルドする方法は2つあります:
   
 
* [http://mingw-w64.sourceforge.net/ Mingw-w64]: secure crt, Vista+ API, DDK (ReactOS), DirectX (WINE) をサポートする32ビットと64ビットのツールチェイン。サポートされている機能の完全なリストと、MinGW.org と違うところについては、[http://sourceforge.net/apps/trac/mingw-w64/wiki/Feature%20list こちら] を見て下さい。Arch の [[公式リポジトリ#.5Bcommunity.5D|[community]]] リポジトリにある {{Pkg|mingw-w64-gcc}} でインストールできます。
 
* [http://mingw-w64.sourceforge.net/ Mingw-w64]: secure crt, Vista+ API, DDK (ReactOS), DirectX (WINE) をサポートする32ビットと64ビットのツールチェイン。サポートされている機能の完全なリストと、MinGW.org と違うところについては、[http://sourceforge.net/apps/trac/mingw-w64/wiki/Feature%20list こちら] を見て下さい。Arch の [[公式リポジトリ#.5Bcommunity.5D|[community]]] リポジトリにある {{Pkg|mingw-w64-gcc}} でインストールできます。
18行目: 18行目:
 
* always use the original {{ic|pkgdesc}} and append {{ic|(mingw-w64)}} to the end of {{ic|pkgdesc}}
 
* always use the original {{ic|pkgdesc}} and append {{ic|(mingw-w64)}} to the end of {{ic|pkgdesc}}
 
* always use and follow the original {{ic|pkgver}} of the official package
 
* always use and follow the original {{ic|pkgver}} of the official package
* always add {{ic|unset LDFLAGS CPPFLAGS}} in front of toolchain configure/Makefile generation sequences
 
 
* always build both 32-bit and 64-bit versions of libraries, unless of course the package can only target, or is meant to only target, 32-bit or 64-bit, or if problems arise building one of the two.
 
* always build both 32-bit and 64-bit versions of libraries, unless of course the package can only target, or is meant to only target, 32-bit or 64-bit, or if problems arise building one of the two.
 
* always put all stuff under the {{Ic|/usr/i686-w64-mingw32}} and {{Ic|/usr/x86_64-w64-mingw32}} prefix
 
* always put all stuff under the {{Ic|/usr/i686-w64-mingw32}} and {{Ic|/usr/x86_64-w64-mingw32}} prefix
25行目: 24行目:
 
* always remove Win32 executables (*.exe) if the intended package is a library ({{ic|<nowiki>rm "$pkgdir"/usr/${_arch}/bin/*.exe</nowiki>}})
 
* always remove Win32 executables (*.exe) if the intended package is a library ({{ic|<nowiki>rm "$pkgdir"/usr/${_arch}/bin/*.exe</nowiki>}})
 
* consider removing unneeded documentation ({{ic|<nowiki>rm -r $pkgdir/usr/i686-w64-mingw32/share/{doc,info,man}</nowiki>}}, {{ic|<nowiki>rm -r $pkgdir/usr/x86_64-w64-mingw32/share/{doc,info,man}</nowiki>}})
 
* consider removing unneeded documentation ({{ic|<nowiki>rm -r $pkgdir/usr/i686-w64-mingw32/share/{doc,info,man}</nowiki>}}, {{ic|<nowiki>rm -r $pkgdir/usr/x86_64-w64-mingw32/share/{doc,info,man}</nowiki>}})
* consider using {{AUR|mingw-w64-pkg-config}} for building with configure scripts
+
* consider using {{AUR|mingw-w64-configure}} for building with configure scripts
 
* consider using {{AUR|mingw-w64-cmake}} for building with CMake
 
* consider using {{AUR|mingw-w64-cmake}} for building with CMake
  +
* consider using compilation flags {{ic|<nowiki>-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4</nowiki>}} (usually named CFLAGS, CXXFLAGS) when no proper build system is provided
 
* consider explicitly stripping symbols with {{ic|${_arch}-strip}} in {{ic|package()}}'s for-loop as demonstrated in the below PKGBUILD examples.
 
* consider explicitly stripping symbols with {{ic|${_arch}-strip}} in {{ic|package()}}'s for-loop as demonstrated in the below PKGBUILD examples.
 
** consider using the `find` command to iterate over {{ic|$pkgdir}} since not all DLLs, static libraries, or executables may reside in their appropriate locations.
 
** consider using the `find` command to iterate over {{ic|$pkgdir}} since not all DLLs, static libraries, or executables may reside in their appropriate locations.
52行目: 52行目:
 
url="http://www.foo.bar"
 
url="http://www.foo.bar"
 
license=('GPL')
 
license=('GPL')
makedepends=('mingw-w64-gcc')
+
makedepends=('mingw-w64-configure')
 
depends=('mingw-w64-crt')
 
depends=('mingw-w64-crt')
 
options=('!strip' '!buildflags' 'staticlibs')
 
options=('!strip' '!buildflags' 'staticlibs')
61行目: 61行目:
   
 
build() {
 
build() {
unset LDFLAGS
 
 
cd "${srcdir}/foo-$pkgver/"
 
cd "${srcdir}/foo-$pkgver/"
 
for _arch in ${_architectures}; do
 
for _arch in ${_architectures}; do
 
mkdir -p build-${_arch} && pushd build-${_arch}
 
mkdir -p build-${_arch} && pushd build-${_arch}
../configure \
+
${_arch}-configure ..
--prefix=/usr/${_arch} \
 
--host=${_arch} --build="$CHOST"
 
 
make
 
make
 
popd
 
popd

2015年12月6日 (日) 19:36時点における版

このページでは、GCC を使って Windows で動作するソフトウェアの PKGBUILD を記述する方法を説明しています。Linux 上で Windows のソフトウェアをビルドする方法は2つあります:

  • Mingw-w64: secure crt, Vista+ API, DDK (ReactOS), DirectX (WINE) をサポートする32ビットと64ビットのツールチェイン。サポートされている機能の完全なリストと、MinGW.org と違うところについては、こちら を見て下さい。Arch の [community] リポジトリにある mingw-w64-gcc でインストールできます。
  • MinGW.org: DirectX を部分的にサポートする32ビットのツールチェイン。スレッドローカルストレージと浮動小数点ライブラリのサポートの実装に長年問題を抱えています。公式リポジトリと AUR からは削除されました。

パッケージの命名規則

mingw-w64 のパッケージには mingw-w64-pkgname という名前を付けて下さい。パッケージの静的なバージョンをビルドする場合は、パッケージの名前に -static を付けます (必要な場合については下を参照)。

パッケージング

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 mingw-w64-crt to depends
  • always add mingw-w64-gcc to makedepends
  • always add !strip, staticlibs and !buildflags to options
  • always use the original pkgdesc and append (mingw-w64) to the end of pkgdesc
  • always use and follow the original pkgver of the official package
  • always build both 32-bit and 64-bit versions of libraries, unless of course the package can only target, or is meant to only target, 32-bit or 64-bit, or if problems arise building one of the two.
  • always put all stuff under the /usr/i686-w64-mingw32 and /usr/x86_64-w64-mingw32 prefix
  • always use any as the architecture
  • always build both shared and static binaries, unless they conflict
  • always remove Win32 executables (*.exe) if the intended package is a library (rm "$pkgdir"/usr/${_arch}/bin/*.exe)
  • consider removing unneeded documentation (rm -r $pkgdir/usr/i686-w64-mingw32/share/{doc,info,man}, rm -r $pkgdir/usr/x86_64-w64-mingw32/share/{doc,info,man})
  • consider using mingw-w64-configureAUR for building with configure scripts
  • consider using mingw-w64-cmakeAUR for building with CMake
  • consider using compilation flags -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 (usually named CFLAGS, CXXFLAGS) when no proper build system is provided
  • consider explicitly stripping symbols with ${_arch}-strip in package()'s for-loop as demonstrated in the below PKGBUILD examples.
    • consider using the `find` command to iterate over $pkgdir since not all DLLs, static libraries, or executables may reside in their appropriate locations.
      • if the binary is a DLL, use ${_arch}-strip --strip-unneeded *.dll
      • if the binary is a static lib, use ${_arch}-strip -g *.a
  • if a package is modular (requires certain build dependencies, but said dependencies are optional to the end user) add these to makedepends and optdepends. Be sure to subtract them from depends if updating an existing package. Example of this in use: mingw-w64-rubyAUR, mingw-w64-allegroAUR
  • if a package installs a $pkgdir/usr/${_arch}/bin/*-config script, symlink it to $pkgdir/usr/bin/${_arch}-*-config
  • if a package uses autoconf, explicitly set --build="$CHOST" for configure to workaround autoconf bug #108405

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

Always try to match the pkgver in your mingw-w64 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 Windows 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. If the corresponding native package is in the AUR, you need not follow this version policy, as many AUR packages are often orphaned or left unmaintained.

サンプル

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

Autotools

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

_architectures="i686-w64-mingw32 x86_64-w64-mingw32"

build() {
  cd "${srcdir}/foo-$pkgver/"
  for _arch in ${_architectures}; do
    mkdir -p build-${_arch} && pushd build-${_arch}
    ${_arch}-configure ..
    make
    popd
  done
}

package() {
  for _arch in ${_architectures}; do
    cd "${srcdir}/foo-$pkgver/build-${_arch}"
    make DESTDIR="${pkgdir}" install
    ${_arch}-strip --strip-unneeded "$pkgdir"/usr/${_arch}/bin/*.dll
    ${_arch}-strip -g "$pkgdir"/usr/${_arch}/lib/*.a
  done
}

CMake

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

_architectures="i686-w64-mingw32 x86_64-w64-mingw32"

build() { 
  unset LDFLAGS
  cd "$srcdir/foo-$pkgver/"
  for _arch in ${_architectures}; do
    mkdir -p build-${_arch} && pushd build-${_arch}
    ${_arch}-cmake \
      -DCMAKE_BUILD_TYPE=Release \
      ..
    make
    popd
  done
}

package() {
  for _arch in ${_architectures}; do
    cd "${srcdir}/foo-$pkgver/build-${_arch}"
    make DESTDIR="${pkgdir}" install
    ${_arch}-strip --strip-unneeded "$pkgdir"/usr/${_arch}/bin/*.dll
    ${_arch}-strip -g "$pkgdir"/usr/${_arch}/lib/*.a
  done
}