ビルドするもの多すぎてもうダメポになってきたので ccache を入れる。
ccache は MacPorts 版を使ってたけど最近 /opt/local
そのものを入れ替えたりすることもあるので /usr/local
に自前でインストールすることにした。
http://ccache.samba.org/download.html からソースをダウンロードするか Git のリポジトリをコピーしてくる。今後も ccache は使うので Git 版を使うことにした。Git 版は configure が無いので先に autogen.sh
を実行する。
$ git clone git://git.samba.org/ccache.git
$ cd ccache
$ ./autogen.sh
CPPFLAGS
とか LDFLAGS
をセットしてビルド。
$ ./configure
$ make
$ make install
MacPorts 版はここでさよならする。
$ sudo port uninstall ccache
~/.ccache
が MacPorts によって作成されたもので権限が違うので一度削除する。
$ sudo rm -rf ~/.ccache
ccache -s
でステータスを確認する。設定ファイル ~/.ccache/ccache.conf
が作成される。
$ ccache -s cache directory /Users/***/.ccache primary config /Users/***/.ccache/ccache.conf secondary config (readonly) /usr/local/etc/ccache.conf cache hit (direct) 0 cache hit (preprocessed) 0 cache miss 0 files in cache 0 cache size 0.0 kB max cache size 5.0 GB
5GB はちょっと多い気がするので MacPorts 版のときと同じ 2GB にしておく。
~/.ccache/ccache.conf
max_size = 2.0G
設定可能な値は ccache -p
で確認できる。
$ ccache -p
圧縮の設定もできるらしい。
(default) base_dir = (default) cache_dir = /Users/***/.ccache (default) cache_dir_levels = 2 (default) compiler = (default) compiler_check = mtime (default) compression = false (default) compression_level = 6 (default) cpp_extension = (default) direct_mode = true (default) disable = false (default) extra_files_to_hash = (default) hard_link = false (default) hash_dir = false (default) log_file = (default) max_files = 0 (/Users/***/.ccache/ccache.conf) max_size = 2.0G (default) path = (default) prefix_command = (default) read_only = false (default) recache = false (default) run_second_cpp = false (default) sloppiness = (default) stats = true (default) temporary_dir = (default) umask = (default) unify = false
ccache を使うには ccache の引数にコンパイラ名もしくはパスを与えるか、各コンパイラの名前で ccache へのシンボリックリンクを作成する。ちょっと面倒だけど問題が少ないのは恐らく前者。後者は公式ドキュメントに例が記載されてる。
ln -s ccache /usr/local/bin/gcc ln -s ccache /usr/local/bin/g++ ln -s ccache /usr/local/bin/cc ln -s ccache /usr/local/bin/c++
MacPorts 版では /opt/local/libexec/ccache
以下にシンボリックリンクを作成し、PATH
で /opt/local/libexec/ccache
を優先するようになってた。同じ名前のコンパイラが存在したら困るから当たり前か。
$ ls /opt/local/libexec/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 c++ -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 c++-3.3 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 c++-4.0 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 c++-4.2 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 c++3 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 cc -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 g++ -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 g++-3.3 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 g++-4.0 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 g++-4.2 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 g++2 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 g++3 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 gcc -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 gcc-3.3 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 gcc-4.0 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 gcc-4.2 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 gcc2 -> /opt/local/bin/ccache lrwxr-xr-x 1 root admin 21 1 29 19:17 gcc3 -> /opt/local/bin/ccache
ところで ccache の安全性ってどうなんだろうね。