絖綛 N@i.jp  昨日:00035641
 今日:00016286
 総計:00506249
keywords
管理者専用
  Post   Add link   Control Panel 































新しいトピック
最新:04/16 19:55


新しいコメント
最新:07/28 16:47






管理人へMAIL

プライバシーポリシー

IRKit Ruby Gemのインストール

ちょっと強行突破になりました


 いよいよ IRKit Ruby Gem のインストールです。パッケージ名は irkitです。本来インストールは簡単で、

$ sudo gem install irkit

だけで依存パッケージまで含めてインストールされるはずなのですが、ウチの Mac mini G4, MacOS X 10.4.11 Tiger では dnssdパッケージのインストールで以下のようなエラーになってしまいました。

Fetching: dnssd-3.0.1.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing dnssd:
	ERROR: Failed to build gem native extension.

    /usr/local/bin/ruby -r ./siteconf20150614-17952-nnmwgr.rb extconf.rb
checking for dns_sd.h... yes
checking for main() in -ldnssd... no
checking for main() in -ldns_sd... no
checking for main() in -lmdns... no
checking for main() in -lSystem... yes
checking for htons in arpa/inet.h... yes
checking for ntohs in arpa/inet.h... yes
checking for iphlpapi.h... no
checking for if_indextoname() in sys/types.h,sys/socket.h,net/if.h... yes
checking for if_nametoindex() in sys/types.h,sys/socket.h,net/if.h... yes
checking for struct sockaddr_in in netinet/in.h... yes
checking for struct sockaddr_in.sin_len in netinet/in.h... yes

checking for missing avahi features
checking for DNSServiceGetProperty() in dns_sd.h... no
checking for DNSServiceGetAddrInfo() in dns_sd.h... no
checking for kDNSServiceFlagsForce() in dns_sd.h... no
checking for kDNSServiceFlagsNonBrowsable() in dns_sd.h... no
checking for kDNSServiceFlagsReturnIntermediates() in dns_sd.h... no
checking for kDNSServiceFlagsShareConnection() in dns_sd.h... no
checking for kDNSServiceErr_BadSig() in dns_sd.h... no

checking for ruby features
checking for ruby/encoding.h... yes

creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling dnssd.c
compiling errors.c
compiling flags.c
compiling record.c
compiling service.c
service.c: In function 'dnssd_service_resolve':
service.c:634: warning: passing argument 7 of 'DNSServiceResolve' from incompatible pointer type
service.c: In function 'Init_DNSSD_Service':
service.c:680: error: 'kDNSServiceMaxServiceName' undeclared (first use in this function)
service.c:680: error: (Each undeclared identifier is reported only once
service.c:680: error: for each function it appears in.)
make: *** [service.o] Error 1

make failed, exit code 2

 dnssdは Apple の Bonjour機能をRubyから使用するためのパッケージですね。irkitパッケージは IRKit本体を見付けるために Bonjour機能を使用するので dnssdパッケージと依存関係があり、この dnssdがインストールできなければ irkitをインストールすることができません。

 エラーの内容を見ると 'kDNSServiceMaxServiceName' が未定義であることが原因のようです。Appleは Bonjourを mDNSresponder という名前のオープンソースとして配布していますので、これをダウンロードして 'kDNSServiceMaxServiceName' が何処にどのように定義されているのか調べてみました。すると "dns_sd.h" というヘッダファイル内で

#define kDNSServiceMaxServiceName 64

という具合に定数マクロとして定義されていました。一方 MacOS X 10.4.11 Tiger の "/usr/include/dns_sd.h" にはこの定数マクロの定義がありませんでした。どうやら Tigerの "/usr/include/dns_sd.h" は少し古い物みたい。そこで、"/usr/include/dns_sd.h" に定義を書き加えてみました。230行め付近に、

/* Maximum length, in bytes, of a service name represented as a */
/* literal C-String, including the terminating NULL at the end. */

#define kDNSServiceMaxServiceName 64

/* Maximum length, in bytes, of a domain name represented as an escaped C-String */
/* including the final trailing dot, and the C-String terminating NULL at the end */

#define kDNSServiceMaxDomainName 1005

と書き加えて(赤字の部分。コメント部分は別に無くても構わないんですけどね。)、dnssdパッケージをインストールさせてみます。

$ export MACOSX_DEPLOYMENT_TARGET=10.4
$ sudo gem install dnssd
Building native extensions.  This could take a while...
Successfully installed dnssd-3.0.1
Parsing documentation for dnssd-3.0.1
Installing ri documentation for dnssd-3.0.1
Done installing documentation for dnssd after 3 seconds
1 gem installed

突破!(ここでも MACOSX_DEPLOYMENT_TARGET環境変数の定義が必要な事に注意。)あとは最初に書いたように irkitをインストールするだけ。無事にインストールが完了すると、irkitという便利なコマンドが使えるようになります。使用方法は irkitとだけ入力する、または --helpオプションを指定すると以下のような簡単なヘルプが表示されます。

$ export LANG=ja_JP.UTF-8
$ irkit
IRKit v0.0.9
      https://github.com/shokai/ruby-irkit

options:
 -get (-read)    get IR Data
 -post (-write)  post IR Data
 -delete         delete IR Data
 -rename         rename IR Data -to NEWNAME
 -show           print IR Data
 -list           show list of IR Data and Devices
 -address        IRKit IP Address
 -device         use Internet API
 -device:add     save clientkey and deviceid for Internet API
 -device:delete  delete clientkey and deviceid
 -device:show    print clientkey and deviceid
 -version (-v)   show version
 -help (-h)      show help

e.g.
 % irkit --get  tv_on
 % irkit --post tv_on
 % irkit --post tv_on --address 192.168.0.123
 % irkit --show tv_on
 % irkit --delete tv_on
 % irkit --rename tv_on -to newname
 % irkit --device:add myhouse
 % irkit --post tv_on --device myhouse
 % irkit --device:delete myhouse

基本的な使用方法は --getオプションで IRKitが最後に受信した信号を保存し、--postオプションで保存した信号を IRKitから発信するというわけね。保存先のファイルは "~/.irkit.json" という不可視ファイルです。

 因に MacOS X 10.9.5 Marvericks には ruby Ver.2.0.0 が入っており、IRKit Ruby Gemもこんな苦労することもなく、最初に書いた方法で簡単にインストールできます。(MACOSX_DEPLOYMENT_TARGET環境変数の定義も必要ありませんでした。)


< 過去の記事 [ 6月の 全てのカテゴリ リスト ] 新しい記事 >

2015 calendar
6月
123456
78910111213
14151617181920
21222324252627
282930


掲示板
最新:08/15 17:19


GsBlog was developed by GUSTAV, Copyright(C) 2003, Web Application Factory All Rights Reserved.