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

提供: ArchWiki
ナビゲーションに移動 検索に移動
(3人の利用者による、間の6版が非表示)
1行目: 1行目:
 
[[Category:パッケージ開発]]
 
[[Category:パッケージ開発]]
 
[[en:MinGW package guidelines]]
 
[[en:MinGW package guidelines]]
  +
[[pt:MinGW package guidelines]]
 
{{Package Guidelines}}
 
{{Package Guidelines}}
   
 
このページでは、GCC を使って Windows で動作するソフトウェアの [[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}} でインストールできます。
+
* [https://mingw-w64.org mingw-w64]: secure crt, Vista+ API, DDK (ReactOS), DirectX ([[Wine]]) をサポートする32ビットと64ビットのツールチェイン。サポートされている機能の完全なリストと、MinGW.org と違うところについては、[https://sourceforge.net/p/mingw-w64/wiki2/Feature%20list/ こちら] を見て下さい。{{Pkg|mingw-w64-gcc}} パッケージでインストールできます。
* [http://www.mingw.org/ MinGW.org]: DirectX を部分的にサポートする32ビットのツールチェイン。スレッドローカルストレージと浮動小数点ライブラリのサポートの実装に長年問題を抱えています。公式リポジトリと AUR からは削除されました。
+
* [http://www.mingw.org/ MinGW]: DirectX を部分的にサポートする32ビットのツールチェイン。スレッドローカルストレージと浮動小数点ライブラリのサポートの実装に長年問題を抱えています。公式リポジトリと AUR からは削除されました。
   
 
== パッケージの命名規則 ==
 
== パッケージの命名規則 ==
  +
 
mingw-w64 のパッケージには {{Ic|mingw-w64-''pkgname''}} という名前を付けて下さい。パッケージの静的なバージョンをビルドする場合は、パッケージの名前に {{ic|-static}} を付けます (必要な場合については下を参照)。
 
mingw-w64 のパッケージには {{Ic|mingw-w64-''pkgname''}} という名前を付けて下さい。パッケージの静的なバージョンをビルドする場合は、パッケージの名前に {{ic|-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 {{Pkg|mingw-w64-crt}} to {{ic|depends}}
 
  +
* {{ic|depends}} に常に {{Pkg|mingw-w64-crt}} を追加する (依存している他のパッケージが明示的に依存している場合は除く)。
* always add {{Pkg|mingw-w64-gcc}} to {{ic|makedepends}}
 
  +
* {{ic|makedepends}} に常に {{Pkg|mingw-w64-gcc}} を追加する ({{AUR|mingw-w64-configure}} や {{AUR|mingw-w64-cmake}} を使用する場合は除く)。
* always add {{ic|!strip}}, {{ic|staticlibs}} and {{ic|!buildflags}} to {{ic|options }}
 
* always use the original {{ic|pkgdesc}} and append {{ic|(mingw-w64)}} to the end of {{ic|pkgdesc}}
+
* {{ic|options}} に常に {{ic|!strip}}, {{ic|staticlibs}}, {{ic|!buildflags}} を追加する。
  +
* オリジナルの {{ic|pkgdesc}} を常に使い、{{ic|pkgdesc}} の末尾に {{ic|(mingw-w64)}} と追記する。
* always use and follow the original {{ic|pkgver}} of the official package
 
  +
* 公式パッケージのオリジナルの {{ic|pkgver}} を常に使用・追従する。
* 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.
 
  +
* ライブラリの32ビット版と64ビット版の両方を常にビルドする。
* always put all stuff under the {{Ic|/usr/i686-w64-mingw32}} and {{Ic|/usr/x86_64-w64-mingw32}} prefix
 
  +
* 全てのファイルを常に {{Ic|/usr/i686-w64-mingw32}} と {{Ic|/usr/x86_64-w64-mingw32}} プリフィックスの下に配置する。
* always use {{ic|any}} as the architecture
 
  +
* アーキテクチャは必ず {{ic|any}} を使う (ビルド環境で実行する必要がある実行ファイルを含む場合は除く)。
* always build both shared and static binaries, unless they conflict
 
  +
* 衝突が発生しないかぎり、共有・静的バイナリの両方をビルドする。
* 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>}})
+
* 不必要なドキュメントは削除する ({{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-configure}} for building with configure scripts
+
* configure スクリプトでビルドするときは {{AUR|mingw-w64-configure}} を使用する。
* consider using {{AUR|mingw-w64-cmake}} for building with CMake
+
* CMake でビルドするときは {{AUR|mingw-w64-cmake}} を使用する。
  +
* Meson でビルドするときは {{AUR|mingw-w64-meson}} を使用する。
* 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
 
  +
* configure スクリプトなどを使わず直接書かれた Makefile を用いてビルドするときは {{AUR|mingw-w64-make}} を使用する。
* consider explicitly stripping symbols with {{ic|${_arch}-strip}} in {{ic|package()}}'s for-loop as demonstrated in the below PKGBUILD examples.
 
  +
* QMake でビルドするときは {{AUR|mingw-w64-qt5-base}} を使用する。
** consider using the `find` command to iterate over {{ic|$pkgdir}} since not all DLLs, static libraries, or executables may reside in their appropriate locations.
 
  +
* 下の PKGBUILD のサンプルでしているように {{ic|package()}} の for ループで {{ic|${_arch}-strip}} を使ってシンボルを除去する。
*** if the binary is a DLL, use {{ic|${_arch}-strip --strip-unneeded *.dll}}
 
  +
** DLL や静的ライブラリ、実行ファイルが適切な場所に収まるまで {{ic|$pkgdir}} で繰り返し [[find]] コマンドを実行すると良いでしょう。
*** if the binary is a static lib, use {{ic|${_arch}-strip -g *.a}}
 
  +
*** バイナリが DLL の場合、{{ic|${_arch}-strip --strip-unneeded *.dll}} を使用する。
* if a package is modular (requires certain build dependencies, but said dependencies are optional to the end user) add these to {{ic|makedepends}} and {{ic|optdepends}}. Be sure to subtract them from {{ic|depends}} if updating an existing package. Example of this in use: {{AUR|mingw-w64-ruby}}, {{AUR|mingw-w64-allegro}}
 
  +
*** バイナリが静的ライブラリの場合、{{ic|${_arch}-strip -g *.a}} を使用する。
* if a package installs a {{ic|$pkgdir/usr/${_arch}/bin/*-config}} script, symlink it to {{ic|$pkgdir/usr/bin/${_arch}-*-config}}
 
  +
* if a package is modular (requires certain build dependencies, but said dependencies are optional to the end user) add these to {{ic|makedepends}} and {{ic|optdepends}}. Be sure to subtract them from {{ic|depends}} if updating an existing package. Example of this in use: {{AUR|mingw-w64-ruby}}{{Broken package link|パッケージが存在しません}}, {{AUR|mingw-w64-allegro}}
* if a package uses autoconf, explicitly set {{ic|1=--build="$CHOST"}} for {{ic|configure}} to workaround [//savannah.gnu.org/support/?108405 autoconf bug #108405]
 
  +
* パッケージが {{ic|$pkgdir/usr/${_arch}/bin/*-config}} スクリプトをインストールする場合、{{ic|$pkgdir/usr/bin/${_arch}-*-config}} にシンボリックリンクを作成する。
  +
* パッケージが autoconf を使用する場合、[https://savannah.gnu.org/support/?108405 autoconf bug #108405] を避けるために {{ic|configure}} で明示的に {{ic|1=--build="$CHOST"}} を設定するか {{AUR|mingw-w64-configure}} を使用する。
   
 
As mentioned above, the files should all be installed into {{Ic|/usr/i686-w64-mingw32}} and {{Ic|/usr/x86_64-w64-mingw32}}. Specifically, all DLLs should be put into {{Ic|/usr/*-w64-mingw32/bin}} as they are dynamic libraries needed at runtime. Their corresponding {{Ic|.dll.a}} files should go into {{Ic|/usr/*-w64-mingw32/lib}}. Please delete any unnecessary documentation and perhaps other files from {{Ic|/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.
 
As mentioned above, the files should all be installed into {{Ic|/usr/i686-w64-mingw32}} and {{Ic|/usr/x86_64-w64-mingw32}}. Specifically, all DLLs should be put into {{Ic|/usr/*-w64-mingw32/bin}} as they are dynamic libraries needed at runtime. Their corresponding {{Ic|.dll.a}} files should go into {{Ic|/usr/*-w64-mingw32/lib}}. Please delete any unnecessary documentation and perhaps other files from {{Ic|/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.
40行目: 44行目:
   
 
== サンプル ==
 
== サンプル ==
  +
以下の例は一般的な決まり事やビルド環境をカバーしています。
The following examples will try to cover some of the most common conventions and build systems.
 
   
 
=== Autotools ===
 
=== Autotools ===
 
{{bc|<nowiki>
 
{{bc|<nowiki>
# Maintainer: yourname <yourmail>
 
 
pkgname=mingw-w64-foo
 
pkgname=mingw-w64-foo
 
pkgver=1.0
 
pkgver=1.0
56行目: 59行目:
 
options=('!strip' '!buildflags' 'staticlibs')
 
options=('!strip' '!buildflags' 'staticlibs')
 
source=("http://www.foo.bar/foobar.tar.gz")
 
source=("http://www.foo.bar/foobar.tar.gz")
  +
sha256sums=('8f32d4617390d1c2d16f26a27ab60d97807b35440d45891fa340fc2648b04406')
md5sums=('4736ac4f34fd9a41fa0197eac23bbc24')
 
   
 
_architectures="i686-w64-mingw32 x86_64-w64-mingw32"
 
_architectures="i686-w64-mingw32 x86_64-w64-mingw32"
82行目: 85行目:
 
=== CMake ===
 
=== CMake ===
 
{{bc|<nowiki>
 
{{bc|<nowiki>
# Maintainer: yourname <yourmail>
 
 
pkgname=mingw-w64-foo
 
pkgname=mingw-w64-foo
 
pkgver=1.0
 
pkgver=1.0
94行目: 96行目:
 
options=('!strip' '!buildflags' 'staticlibs')
 
options=('!strip' '!buildflags' 'staticlibs')
 
source=("http://www.foo.bar/foobar.tar.gz")
 
source=("http://www.foo.bar/foobar.tar.gz")
  +
sha256sums=('8f32d4617390d1c2d16f26a27ab60d97807b35440d45891fa340fc2648b04406')
md5sums=('4736ac4f34fd9a41fa0197eac23bbc24')
 
   
 
_architectures="i686-w64-mingw32 x86_64-w64-mingw32"
 
_architectures="i686-w64-mingw32 x86_64-w64-mingw32"
   
 
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}
${_arch}-cmake \
+
${_arch}-cmake ..
-DCMAKE_BUILD_TYPE=Release \
 
..
 
 
make
 
make
 
popd
 
popd

2020年10月15日 (木) 23:11時点における版

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

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

パッケージの命名規則

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

パッケージング

多数のビルド環境が存在し低水準な問題に溢れているためクロスプラットフォームパッケージの作成は非常に困難です。以下の事柄に注意してください:

  • depends に常に mingw-w64-crt を追加する (依存している他のパッケージが明示的に依存している場合は除く)。
  • makedepends に常に mingw-w64-gcc を追加する (mingw-w64-configureAURmingw-w64-cmakeAUR を使用する場合は除く)。
  • options に常に !strip, staticlibs, !buildflags を追加する。
  • オリジナルの pkgdesc を常に使い、pkgdesc の末尾に (mingw-w64) と追記する。
  • 公式パッケージのオリジナルの pkgver を常に使用・追従する。
  • ライブラリの32ビット版と64ビット版の両方を常にビルドする。
  • 全てのファイルを常に /usr/i686-w64-mingw32/usr/x86_64-w64-mingw32 プリフィックスの下に配置する。
  • アーキテクチャは必ず any を使う (ビルド環境で実行する必要がある実行ファイルを含む場合は除く)。
  • 衝突が発生しないかぎり、共有・静的バイナリの両方をビルドする。
  • 不必要なドキュメントは削除する (rm -r $pkgdir/usr/i686-w64-mingw32/share/{doc,info,man}, rm -r $pkgdir/usr/x86_64-w64-mingw32/share/{doc,info,man})。
  • configure スクリプトでビルドするときは mingw-w64-configureAUR を使用する。
  • CMake でビルドするときは mingw-w64-cmakeAUR を使用する。
  • Meson でビルドするときは mingw-w64-mesonAUR を使用する。
  • configure スクリプトなどを使わず直接書かれた Makefile を用いてビルドするときは mingw-w64-makeAUR を使用する。
  • QMake でビルドするときは mingw-w64-qt5-baseAUR を使用する。
  • 下の PKGBUILD のサンプルでしているように package() の for ループで ${_arch}-strip を使ってシンボルを除去する。
    • DLL や静的ライブラリ、実行ファイルが適切な場所に収まるまで $pkgdir で繰り返し find コマンドを実行すると良いでしょう。
      • バイナリが DLL の場合、${_arch}-strip --strip-unneeded *.dll を使用する。
      • バイナリが静的ライブラリの場合、${_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
  • パッケージが $pkgdir/usr/${_arch}/bin/*-config スクリプトをインストールする場合、$pkgdir/usr/bin/${_arch}-*-config にシンボリックリンクを作成する。
  • パッケージが autoconf を使用する場合、autoconf bug #108405 を避けるために configure で明示的に --build="$CHOST" を設定するか mingw-w64-configureAUR を使用する。

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.

サンプル

以下の例は一般的な決まり事やビルド環境をカバーしています。

Autotools

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")
sha256sums=('8f32d4617390d1c2d16f26a27ab60d97807b35440d45891fa340fc2648b04406')

_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

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")
sha256sums=('8f32d4617390d1c2d16f26a27ab60d97807b35440d45891fa340fc2648b04406')

_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}-cmake ..
    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
}