17
17

More than 3 years have passed since last update.

M1 MacでのCrossOver Wine 20.0.2のソースコードのビルドと実行

Last updated at Posted at 2020-12-28

CrossOver版Wine

WindowsアプリケーションをLinuxやmacOS上で動作させることができるWine というソフトがあります。また、Wineの主要な開発者が関わっているCodeWeavers社が商用版のWineに相当するCrossOverを開発しています。

32bitアプリケーション非対応になったmacOS Catalina以降でも32bit Windowsアプリケーションを実行できるWineは2020年12月28日時点ではCrossOverのみです。llvm/clangベースの特別なコンパイラを使って64bit環境で32bitバイナリを実行する仕組みであるwine32on64を実現しています。

WineはGPLなので、WineをベースとするCrossOverもこちらでソースコードを公開しています。M1 Mac Big SurのRosetta2環境でCrossOver 20.0.2をビルド・実行してみたので開発者の方に向けて手順を解説します。

ビルド環境構築

基本的に~/Download/以下で作業しています。

$ cd ~/Downloads

(20201229追記) 最初にCommand line tools for Xcodeをインストールしてください。
こちらが参考になります。

Rosetta2でx86_64用のhomebrewをインストールしてください。
例えばこちらが参考になります。

homebrewでcmake、bison、flex、mingw-w64、pkgconfig、freetypeをインストールしbisonやflexにパスを通します。

$ brew install cmake bison flex mingw-w64 pkgconfig freetype
$ export PATH="/usr/local/opt/flex/bin:/usr/local/opt/bison/bin:$PATH"
$ export LDFLAGS="-L/usr/local/opt/flex/lib -L/usr/local/opt/bison/lib"
$ export CPPFLAGS="-I/usr/local/opt/flex/include"

CrossOverのソースのダウンロード

CrossOver 20.0.0のみにwine32on64に必要なllvm/clangが入っているようなので、20.0.020.0.2の両方をダウンロードし展開してください。

$ tar xvf crossover-sources-20.0.0.tar
$ mv sources/ sources-20.0.0
$ tar xvf crossover-sources-20.0.2.tar
$ mv sources/ sources-20.0.2

必要な修正

まず、wine/include/distversion.hが抜けています。

/* ---------------------------------------------------------------
*   distversion.c
*
* Copyright 2013, CodeWeavers, Inc.
*
* Information from DISTVERSION which needs to find
* its way into the wine tree.
* --------------------------------------------------------------- */

#define WINDEBUG_WHAT_HAPPENED_MESSAGE "This can be caused by a problem in the program or a deficiency in Wine. You may want to check <a href=\"http://www.codeweavers.com/compatibility/\">http://www.codeweavers.com/compatibility/</a> for tips about running this application."

#define WINDEBUG_USER_SUGGESTION_MESSAGE "If this problem is not present under Windows and has not been reported yet, you can save the detailed information to a file using the \"Save As\" button, then <a href=\"http://www.codeweavers.com/support/tickets/enter/\">file a bug report</a> and attach that file to the report."

現時点でbrewでインストールされるgccは10ですが、CrossOver 20.0.2はgcc10未対応なので次のパッチも必要です。
- https://www.winehq.org/pipermail/wine-cvs/2020-June/145081.html)
- https://source.winehq.org/git/wine.git/commitdiff/cc7f698b8245a48669d248569e7589ff824f2c70)
- https://source.winehq.org/git/wine.git/commitdiff/ea032bb7f8daddfe308f86f52c54db5f657b658a
- https://source.winehq.org/git/wine.git/commitdiff/1d785798605c01dcfc8a2f9f6ecc24bc21351029
- https://source.winehq.org/git/wine.git/commitdiff/4a91eb362666b3af549c48b95e093051756628e0
- https://source.winehq.org/git/wine.git/commitdiff/da21c305164c3e585e29e20242afc5a31f91989f
- https://source.winehq.org/git/wine.git/commitdiff/bc51c5d589de709e1d393b58b0cc5985c78061ac
- https://source.winehq.org/git/wine.git/commitdiff/44e69405adcdc98d6b0777e6c0acb2697d776ef8

また、dlls/winecoreaudio.drv/authorization.mのCoreAudio_request_capture_authorizationでコンパイラのclang-8が落ちるのを回避する修正や,
dlls/winemac.drv/cocoa_event.mの107行目の
NSParameterAssertでコンパイル時にエラーが出ることへの修正や、—without-vulkanなのにdlls/winvulkan/でエラーが出るのを修正する必要があります。

authorization.mはHAVE_AVFOUNDATION_AVFOUNDATION_Hを未定義とした雑な修正で、NSParameterAssertはコメントアウトする雑な修正ですが、以上の内容を統合したbuild20201227.patchを用意したのでこれをダウンロードして当ててください。

$ cd sources-20.0.2
$ patch -p1 < ../build20201227.patch

llvmとclangのビルド

wine32on64用のllvm/clangをビルドしてパスを通します。ビルドにかなり時間がかかります。

llvm

$ cd ../sources-20.0.0

$ cd clang/llvm
$ mkdir build
$ cd build
$ cmake ../
$ make
$ cd bin
$ export PATH="$(pwd):$PATH"
$ cd ../../../..

clang

$ cd clang/clang
$ mkdir build
$ cd build
$ cmake ../
$ make
$ cd bin
$ export PATH="$(pwd):$PATH"
$ cd ../../../..

CrossOver Wineのビルド

Windows 32bitアプリと64bitアプリの実行環境を共存できるようにするためには、最初にwine64をビルドした後、wine64のビルド環境を参照するオプション(--with-wine64)を指定してwine32on64をビルドする必要があります。

/usr/local/crossover-20.0.2にインストールするようにしていますが、別なディレクトリでも問題ないはずです。

こちらもビルドにかなり時間がかかります。

wine64

$ cd ../sources-20.0.2

$ cd wine
$ export PATH="$(pwd):$PATH"
$ export MACOSX_DEPLOYMENT_TARGET=10.14

$ mkdir build64
$ cd build64

$ CC="clang" CXX="clang++" MACOSX_DEPLOYMENT_TARGET=10.14 ../configure --enable-win64 --disable-winedbg --without-x --without-vulkan --disable-mscms --prefix=/usr/local/crossover-20.0.2

$ make

$ sudo mkdir /usr/local/crossover-20.0.2
$ sudo chown "$USER":admin /usr/local/crossover-20.0.2
$ make install

$ cd ..

wine32on64

$ cd ..

$ mkdir build32
$ cd build32

$ CC="clang" CXX="clang++" MACOSX_DEPLOYMENT_TARGET=10.14 ../configure --enable-win32on64 --with-wine64=../build64 --disable-winedbg --without-x --without-vulkan --disable-mscms --prefix=/usr/local/crossover-20.0.2

$ make

$ make install

wineの実行とwinetricks等の実行環境構築

最初にwine64を実行しないと~/.wine/を32bit64bit両対応にならないはずなので、wine64を先に実行してください。その後はWindows 32bitバイナリならばwine32on64を使い、Windows 64bitバイナリならばwine64を使ってください。

7zipのx86版とx64版が正常に動作することは確認しています。

winecfg

$ export PATH=/usr/local/crossover-20.0.2/bin:$PATH
$ wine64 winecfg

winetricks

winetricksをダウンロードしてください。

$ ./winetricks

日本語フォントを入れるならば

$ ./winetricks fonts fakejapanese

Mono

monoが必要な場合はこちらよりダウンロードして

$ wine32on64 msiexec /i wine-mono-5.1.1-x86.msi

(.netアプリはwine32on64でないと起動しないようです)

問題点

windowsアプリ終了後wineが落ちたようなエラーが出ます。

参考ページ

次のページを参考にビルドしました。
- https://gist.github.com/Alex4386/4cce275760367e9f5e90e2553d655309
- https://gist.github.com/sarimarton/471e9ff8046cc746f6ecb8340f942647
- https://wiki.winehq.org/Building_Wine

おまけ

homebrew経由でもインストール可能なビルド済みCrossOver 19.0.2がこちらにあるようです。
https://github.com/Gcenx/homebrew-wine

17
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
17