LoginSignup
15
15

More than 5 years have passed since last update.

mac で spdylay の build もしくは homebrew と pkg-config

Last updated at Posted at 2013-01-27

spdylay のビルド

SPDY の開発で必ずお世話になる spdylay

ubuntu ではほぼドキュメント通りにやっただけで一発で通った spdylay のビルドを、
mac で入れようとして盛大にハマったのでメモ。

原因は自分の pkg-config 周りの知識が無かったのが問題。

たぶん mac の brew で zlib とか、 libxml2 を入れた時の pkg-config を使ったビルドは、
総じて以下のようなことをググると思うけど、案外出るようで出なかった。
brew 使わずソースからこれらをビルドしている人には関係ないと思う。

まず、必要なライブラリ をかき集める。
自分が必要だったのは以下。

$brew install cunit libxml2 libtool autoconf automake openssl

openssl, libxml2 あたりは古かったのでアップグレード目的。

これで揃うが、ビルドをすると色々エラーが出る。

zlib 周り

zlib はまず下をやってから入れる。

$brew tap homebrew/dupes
$brew install zlib
==> Downloading http://zlib.net/zlib-1.2.7.tar.gz
######################################################################## 100.0%
==> Patching
patching file configure
==> ./configure --prefix=/usr/local/Cellar/zlib/1.2.7
==> make install
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/zlib/lib
        CPPFLAGS: -I/usr/local/opt/zlib/include

        ==> Summary
        /usr/local/Cellar/zlib/1.2.7: 9 files, 384K, built in 10 seconds

書いてある通り、 zlib はシステムの中を荒らさないように /usr/local にはリンクしない。
ちなみにこれをせずに spdylay のビルドをすると、 autoconf あたりでいかが出る。

checking for ZLIB... no
configure: error: Package requirements (zlib >= 1.2.3) were not met:

No package 'zlib' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ZLIB_CFLAGS
and ZLIB_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

なので、zlib をビルドに使いたい場合は、以下の方法がある。

  • 自己責任で /usr/local に置いたりとかする。
  • コメントに出てるように LDFLAGS や CPPFLAGS を毎回セットする。
  • pkg-config に認識させてしまう。

pkg-config は環境ごとのライブラリがどこにあるのかを探すためのツール。
spdylay もビルド時に、そのマシンのライブラリをどっから取ってくるのかを pkg-config で調べている。
brew で入れた zlib には pkgconfig 用のファイルがあったので、楽そうだからそれを使った。

自分の環境では

/usr/local/Cellar/zlib/1.2.7/lib/pkgconfig/zlib.pc がそれにあたる。

これを以下に置けば良い。

/usr/lib/pkgconfig

怖いから古いのは .old とかして置いておいて、 slink した。

sudo mv  /usr/lib/pkgconfig/zlib.pc /usr/lib/pkgconfig/zlib.pc.old
sudo ln -s /usr/local/Cellar/zlib/1.2.7/lib/pkgconfig/zlib.pc /usr/lib/pkgconfig

libxml2 周り

configure のフェーズで以下の warning が出ている。

checking for libxml - version >= 2.7.7... 
*** An old version of libxml (2.7.3) was found.
*** You need a version of libxml newer than 2.7.7. The latest version of
*** libxml is always available from ftp://ftp.xmlsoft.org.
***
*** If you have already installed a sufficiently new version, this error
*** probably means that the wrong copy of the xml2-config shell script is
*** being found. The easiest way to fix this is to remove the old version
*** of LIBXML, but you can also set the XML2_CONFIG environment to point to the
*** correct copy of xml2-config. (In this case, you will have to
*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf
*** so that the correct libraries are found at run-time))
no

libxml2 も古いのが認識されている。
さっきと同じ方法で pkg-conifg で解決しないかと思ったけど、
libxml2-2.0.pc を slink しても結果が変わらない。

やはり xml2-config を変えないとだめっぽい。
brew で入れた方には /usr/local/Cellar/libxml2/2.8.0/bin/xml2-config があるので、
これに置き換えればいけそうだけど、ちょっと影響が怖いので、ここはオプションで指定した。

./configure --with-xml-prefix=/usr/local/Cellar/libxml2/2.8.0

openssl 周り

次に configure の最後に出る結果を見ると

    Version:        0.3.8-DEV shared 5:0:0
    Host type:      x86_64-apple-darwin11.4.2
    Install prefix: /usr/local
    (snip) 
    OpenSSL:        no
    (cont)

ということで OpenSSL が認識されていない。多分これでビルドすると spdycat コマンドがビルドされない。

--with-openssl あるかと思ったけど、取れないっぽい。
さっきの pkg-config の方法ならすぐ戻せるしということで、同じく openssl も置き換えた。

$ sudo mv /usr/lib/pkgconfig/openssl.pc /usr/lib/pkgconfig/openssl.pc.old
$ sudo ln -s /usr/local/Cellar/openssl/1.0.1c/lib/pkgconfig/openssl.pc /usr/lib/pkgconfig 

まとめ

  • zlib, openssl, xmllib2 を brew で入れる
  • pkg-config に認識させる
  • ./configure --with-xml-prefix=/usr/local/Cellar/libxml2/2.8.0

みんな、 pck-config + brew ってどうしてるんだろう?
それとも src からビルドしてるんだろうか。

15
15
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
15
15