スキップしてメイン コンテンツに移動

MacPorts の GHC が macOS Sierra でビルドできない件の回避策 (i.e. MacPorts のパッチの当て方)

多分じきに修正されて腐る内容だが、MacPorts の port にパッチする方法としてまとめておく。

会社を辞めたので久方ぶりにブログを書こうと思い、pandoc をインストールしようとしたところ GHC のビルドがコケた。 ログをみると GetTime.c というファイルのコンパイルに失敗している。MacPorts の Trac を検索してみると果たして既知の問題だった。「Haskell 処理系とそれに依存する全パッケージがインストールできない」問題が四ヶ月前に報告されていまだに直っていないという大らかさ。

幸いチケット内にパッチが提案されていたのでこれを適用してことなきを得た。

まずローカルに GHC の port をコピーし、MacPorts の ports tree として登録する:

$ sudo -i
Password:
# mkdir -p /usr/local/ports/lang/ && cd /usr/local/ports/lang/
# cp -r $(port dir ghc) ./
# cd ghc && port lint

# cp /opt/local/etc/macports/sources.conf{,.orig}
# vi /opt/local/etc/macports/sources.conf  # 作成したディレクトリをデフォルトの ports tree の前に追記する
# diff -u /opt/local/etc/macports/sources.conf{.orig,}
--- /opt/local/etc/macports/sources.conf.orig   2017-02-10 14:10:00.000000000 +0900
+++ /opt/local/etc/macports/sources.conf        2017-02-10 14:11:04.000000000 +0900
@@ -29,4 +29,5 @@
 # sites, etc.), the primary MacPorts source must always be tagged
 # "[default]", even if switched from the default "rsync://" URL.

+file:///usr/local/ports
 rsync://rsync.macports.org/release/tarballs/ports.tar [default]

# cd /usr/local/ports && portindex

これで ghc をインストールする際は /usr/local/ports 以下にあるソースが使われるようになった。port dir ghc コマンドを実行すると /usr/local/ports/lang/ghc と表示されるはずである。

続いてパッチを配置して Portfile を書き換える:

# curl -Lo $(port dir ghc)/files/patch-Fix-GetTime.c-on-Darwin-with-clock_gettime.diff https://trac.macports.org/raw-attachment/ticket/52582/patch-Fix-GetTime.c-on-Darwin-with-clock_gettime.diff
# cp $(port file ghc){,.orig}
# port edit ghc  # Portfile を編集する専用コマンド。要するに vi /usr/local/ports/lang/ghc/Portfile
# diff -u $(port file ghc){.orig,}
--- /usr/local/ports/lang/ghc/Portfile.orig     2017-02-10 14:24:42.000000000 +0900
+++ /usr/local/ports/lang/ghc/Portfile  2017-02-10 14:40:40.000000000 +0900
@@ -56,7 +56,8 @@

 patchfiles      patch-configure-workaround-bsdsed-incompatibility.diff \
                 patch-configure-disable-docs.diff \
-                patch-unix_lib_osx_sandbox_compatibility.diff
+                patch-unix_lib_osx_sandbox_compatibility.diff \
+                patch-Fix-GetTime.c-on-Darwin-with-clock_gettime.diff

 livecheck.type  none
 test.run        yes

これで改変は終わり。一般的にパッチで済む変更は port dir 以下の files ディレクトリにパッチを置いて Portfile を書き換えるだけで良い。

あとはビルドできるか試して実際にインストールするだけ。異様に時間がかかるのは GHC が巨大だからであってパッチが悪いわけではない:

# port clean ghc
# port build ghc  # この間に昼食に行って仮眠してその後コーヒーを入れるなどする
--->  Computing dependencies for ghc
--->  Fetching distfiles for ghc
--->  Verifying checksums for ghc
--->  Extracting ghc
--->  Applying patches to ghc
--->  Configuring ghc
--->  Building ghc
...
# port install ghc

この記事は Markdown で書いているので、これが公開されているということは筆者が pandoc をインストールできたということである。

参考

コメント