Solaris 上で h2o をビルドしてみようとしたところ、
libyrmcds のビルドで sys/endian.h がないと怒られる。
deps/libyrmcds で make を実行すると以下のようになる。
$ make gcc -Wall -Wconversion -gdwarf-3 -O2 -D_GNU_SOURCE -c -o send.o send.c In file included from send.c:4:0: portability.h:33:26: fatal error: sys/endian.h: No such file or directory # include <sys/endian.h> ^ compilation terminated. make: *** [send.o] Error 1
portability.h を見ると、
#if defined(__APPLE__) # include <libkern/OSByteOrder.h> # define htobe16(x) OSSwapHostToBigInt16(x) # define htole16(x) OSSwapHostToLittleInt16(x) # define be16toh(x) OSSwapBigToHostInt16(x) # define le16toh(x) OSSwapLittleToHostInt16(x) # define htobe32(x) OSSwapHostToBigInt32(x) # define htole32(x) OSSwapHostToLittleInt32(x) # define be32toh(x) OSSwapBigToHostInt32(x) # define le32toh(x) OSSwapLittleToHostInt32(x) # define htobe64(x) OSSwapHostToBigInt64(x) # define htole64(x) OSSwapHostToLittleInt64(x) # define be64toh(x) OSSwapBigToHostInt64(x) # define le64toh(x) OSSwapLittleToHostInt64(x) #elif defined(__linux__) # include <endian.h> #else // *BSD # include <sys/endian.h> #endif
のように、OS 毎に読み込むファイルを切替えているので、
ここに Solaris 対応のものを書けばよさそう。
ということでググると、以下が見つかった。
- Development of PowerDNS - endian.h patch for SunOS (Solaris)
http://comments.gmane.org/gmane.network.dns.powerdns.devel/1172
これによると、
- defined(sun) で Solaris かチェック
- sys/isa_defs.h を include
すればよいようなので、以下のように書き換え。
$ git diff diff --git a/deps/libyrmcds/portability.h b/deps/libyrmcds/portability.h index 06e9265..e49dc30 100644 --- a/deps/libyrmcds/portability.h +++ b/deps/libyrmcds/portability.h @@ -29,6 +29,8 @@ # define le64toh(x) OSSwapLittleToHostInt64(x) #elif defined(__linux__) # include <endian.h> +#elif defined(sun) +# include <sys/isa_defs.h> #else // *BSD # include <sys/endian.h> #endif
これで、ファイルが見つからないと怒られることはなくなったが、
link 時に symbol (be16toh, be32toh, be64toh, htobe32, htobe16, htobe64) が見つからない
というエラーになる。
portability.h を見ると、'#if defined(__APPLE__)' の中で定義されているので、
Solaris でも同様に '#elif defined(sun)' の中で定義すればよさそう。
今回、symbol が見つからないのは big endian 関連なので、
ntohs や htons で network byte order (big endian) と host byte order の変換をすればいいらしい。
ということで、'#elif defined(sun)' の中に以下を追記。
# define htobe16(x) htons(x) # define be16toh(x) ntohs(x) # define htobe32(x) htonl(x) # define be32toh(x) ntohl(x) # define htobe64(x) htonll(x) # define be64toh(x) ntohll(x)
これで、symbol が見つからないと怒られることもなくなった。