はじめに
一眼レフをPCで制御したいとき便利なのが、gphoto2。
各メーカーの一眼レフSDKを取り込んでいて共通のコマンドで、一元的に制御できる
gphoto2はlibgphoto2のCLIフロントエンドとして駆動する。このgphoto2を他のアプリケーションから叩いて使うことも可能だ。
本記事では、libgphoto2を直接叩くことを目標に、前段階としてlibgphoto2関連ライブラリをFrameworkにまとめ、Xcodeに放り込むだけで使えるようにビルドした。
Githubに便利そうなプロジェクトがあったので以下を使う。
https://github.com/lnxbil/GPhoto2.framework
ちなみに各環境によってインストールしてあるツールによってインストールするべきツールが異なるので、成功するまでの手順をエラー含めて記載している都合上、冗長な記事となっているが、ご容赦いただきたい。
また私は別環境で2回ほどセットアップを試しているが、環境の違いで多少出てくるエラーも変わっているようだ。
構築手順
https://github.com/lnxbil/GPhoto2.framework
を、適当なディレクトリにチェックアウトしておく
構築環境は以下の通り
- macOS 10.12.5
- Xcode 8.3.3
- homebrewをインストール済み
現時点の最新バージョン(2.5.14)で構築しておきたいので、Gphoto2.frameworkディレクトリ下のconfigを編集する
- PKGCONFIG=0.29.1
+ PKGCONFIG=0.29.2
- LIBGPHOTO=2_5_11
+ LIBGPHOTO=2_5_14
Gphoto2.frameworkのREADMEに従い、
wgetとnasmをインストールする。
brew update
brew install wget nasm
また、ビルド時に/Library/Frameworks/Gphoto2.framework
内に各種ライブラリを放り込むようなので、以下コマンドで書き込み可能なディレクトリを作っておく。(これがそのままFrameworkとして機能するようになる)
sudo mkdir -m 777 -p /Library/Frameworks/GPhoto2.framework
ここまでが、READMEにかかれている手順なので、いったんビルドする。
./build.sh
Build Process of the GPhoto2.framework
https://github.com/lnxbil/GPhoto2.framework
+ Checking permissions on /Library/Frameworks/GPhoto2.framework
+ Download and extracting files
+ Start building at Tue Aug 1 04:27:38 JST 2017 with 16 threads
- Building libtool-2.4.6
- Building pkg-config-0.29.2
An error occured
...(省略)...
configure: error: Either a previously installed pkg-config or
"glib-2.0 >= 2.16" could not be found. Please set GLIB_CFLAGS
and GLIB_LIBS to the correct values or pass --with-internal-glib
to configure to use the bundled copy.
glibのバージョンが古いようなので、インストールする。
brew info glibで調べると2.52.3が入るようなので、インストールして再度ビルドする
brew install glib
./build.sh
Build Process of the GPhoto2.framework
https://github.com/lnxbil/GPhoto2.framework
+ Checking permissions on /Library/Frameworks/GPhoto2.framework
+ Download and extracting files
+ Start building at Tue Aug 1 04:33:41 JST 2017 with 16 threads
- Building libtool-2.4.6
- Building pkg-config-0.29.2
- Building libusb-1.0.21
- Building libusb-compat-0.1-0.1.6-rc2
An error occured
...(省略)...
./build.sh: line 172: autoreconf: command not found
Running './configure --prefix=/Library/Frameworks/GPhoto2.framework/prefix --enable-shared --disable-iconv --enable-osx-universal-binary --disable-nls '
./build.sh: line 175: ./configure: No such file or directory
再度エラーで止まる。
autoreconf コマンドが足りないらしい。
automake に含まれるコマンドなので、インストールして再度ビルドする。
brew install automake
./build.sh
Build Process of the GPhoto2.framework
https://github.com/lnxbil/GPhoto2.framework
+ Checking permissions on /Library/Frameworks/GPhoto2.framework
+ Download and extracting files
+ Start building at Tue Aug 1 04:45:27 JST 2017 with 16 threads
- Building libtool-2.4.6
- Building pkg-config-0.29.2
- Building libusb-1.0.21
- Building libusb-compat-0.1-0.1.6-rc2
An error occured
...(省略)...
configure: error: cannot find install-sh, install.sh, or shtool in "." "./.." "./../.."
さっきよりは進んでるようだが、エラーだ。
見当がつかないのでエラー文で検索すると、別のプロジェクトでこんなissueが見つかった
- autoconf
- automake
- gettext
- libtool
これらが必要らしい。libtoolはビルドに含まれてるはずなので、gettextのみ追加してみるが、特に変化なし。issueを読み進めると、PATH指定に問題がありそうなので、.bash_profileに次の行を追加する
export PATH=$PATH:$(brew --prefix gettext)/bin
追加した上で、Gphoto2.framework/download/を削除したのち、再度./build.sh
で、このエラーは回避できた。
最後まで実行完了すると以下のような表示となる。
Build Process of the GPhoto2.framework
https://github.com/lnxbil/GPhoto2.framework
+ Checking permissions on /Library/Frameworks/GPhoto2.framework
+ Download and extracting files
+ Start building at Tue Aug 1 05:29:27 JST 2017 with 16 threads
- Building libtool-2.4.6
- Building pkg-config-0.29.2
- Building libusb-1.0.21
- Building libusb-compat-0.1-0.1.6-rc2
- Building libjpeg-turbo-1.5.1
- Building libgphoto2-libgphoto2-2_5_11-release
+ Finished building at Tue Aug 1 05:31:42 JST 2017
+ Cleaning up framework directory
+ Linking headers
+ Building Apple Framework infrastructure
example を実行できることを確認できれば作業完了となる
