<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>taichino.com &#187; 技術</title>
	<atom:link href="http://taichino.com/category/engineer-life/feed" rel="self" type="application/rss+xml" />
	<link>http://taichino.com</link>
	<description>永遠のネバーランド</description>
	<lastBuildDate>Sat, 04 Sep 2010 16:20:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>.emacsを整理した</title>
		<link>http://taichino.com/engineer-life/1894</link>
		<comments>http://taichino.com/engineer-life/1894#comments</comments>
		<pubDate>Sun, 29 Aug 2010 08:06:52 +0000</pubDate>
		<dc:creator>taichino</dc:creator>
				<category><![CDATA[emacs]]></category>
		<category><![CDATA[技術]]></category>

		<guid isPermaLink="false">http://taichino.com/?p=1894</guid>
		<description><![CDATA[本当は去年の年末に行うはずだった.emacsの整理ですが、中々着手できず放置してました。しかし先日「Emacsテクニックバイブル」が発売され、この絶好のタイミングを逃せば、またいつになるか分からなかったので、重い腰を上げて以下を目標に整理してみました。

 .emacsを分割して整理する
 リポジトリ管理下に置いて適宜改善できるようにする
 最近のEmacs事情に少しキャッチアップする


まず.emacsを分割して、使ってない箇所を消してみました。分割自体は、かなりいい加減です。init-loaderを使うのが常套手段のようですが手元で動かないので、それぞれのファイルを手動でロードしています。課題はbase.elにまだ設定が集中していることです。かといって分割しすぎても管理が大変なので難しいところですね。

;; ロードパス
&#40;add-to-list 'load-path &#34;~/.emacs.d&#34;&#41;
&#40;add-to-list 'load-path &#34;~/.emacs.d/lisp&#34;&#41;
&#40;add-to-list 'load-path &#34;~/.emacs.d/lisp/apel&#34;&#41;
&#40;add-to-list 'load-path &#34;~/.emacs.d/lisp/emu&#34;&#41;
&#40;add-to-list 'load-path &#34;~/.emacs.d/lisp/howm&#34;&#41;
&#160;
;; 実行パス
&#40;add-to-list 'exec-path &#34;/usr/local/bin&#34;&#41;
&#40;add-to-list 'exec-path &#34;/opt/local/bin&#34;&#41;
&#160;
;; auto-install
&#40;require 'auto-install&#41;
&#40;add-to-list 'load-path auto-install-directory&#41;
&#40;auto-install-update-emacswiki-package-name t&#41;
&#40;auto-install-compatibility-setup&#41;
&#160;
;; 基本設定
&#40;load &#34;init/base.el&#34;&#41;
&#160;
;; 表示、window関連の設定
&#40;load &#34;init/display.el&#34;&#41;
&#160;
;; global-set-key
&#40;load &#34;init/keybind.el&#34;&#41;
&#160;
;; howm/org
&#40;load &#34;init/memo.el&#34;&#41;
&#160;
;; 各種プログラミング用メジャーモード
&#40;load &#34;init/programming.el&#34;&#41;
&#160;
;; 自分で追加した関数など
&#40;load &#34;init/self.el&#34;&#41;

設定ファイル一式をgithubにあげて管理する事にしました。プライベートリポジトリだと、ついつい汚くなるので駄目でした。本当は.emacs.d以下すべてを置いておきたいですけど、リポジトリが公開状態なので良いのかどうなのか。ちょっと様子見です。
今回の整理での気分的に大きな収穫は以下です。Carbonが素晴らしいと触れ回っていたのですが、しれっとCocoa Emacsに乗り換えてしまいました。

magit: gitをemacsから使えるようになった
Cocoa Emacs: magitを導入するためにCarbonから乗り換えた
org-modeをhowmのメジャーモードで使うようにした
moccur-edit: occurの検索結果を直接編集して元のバッファに反映させる
sequential-command: C-a, C-eがパワーアップ

まだ改善の余地だらけですが、とにかくも整理して管理下に置いたので、ようやく.emacsも自分も育てていける感じになって、大変気分がいいです。
]]></description>
			<content:encoded><![CDATA[<p>本当は去年の年末に行うはずだった.emacsの整理ですが、中々着手できず放置してました。しかし先日「<a href="http://www.amazon.co.jp/gp/product/4774143278?ie=UTF8&#038;tag=creatorsland-22&#038;linkCode=as2&#038;camp=247&#038;creative=1211&#038;creativeASIN=4774143278">Emacsテクニックバイブル</a><img src="http://www.assoc-amazon.jp/e/ir?t=creatorsland-22&#038;l=as2&#038;o=9&#038;a=4774143278" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />」が発売され、この絶好のタイミングを逃せば、またいつになるか分からなかったので、重い腰を上げて以下を目標に整理してみました。</p>
<ul>
<li> .emacsを分割して整理する</li>
<li> リポジトリ管理下に置いて適宜改善できるようにする</li>
<li> 最近のEmacs事情に少しキャッチアップする</li>
</ul>
<p><span id="more-1894"></span></p>
<p>まず.emacsを分割して、使ってない箇所を消してみました。分割自体は、かなりいい加減です。init-loaderを使うのが常套手段のようですが手元で動かないので、それぞれのファイルを手動でロードしています。課題はbase.elにまだ設定が集中していることです。かといって分割しすぎても管理が大変なので難しいところですね。</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; ロードパス</span>
<span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'load-path <span style="color: #ff0000;">&quot;~/.emacs.d&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'load-path <span style="color: #ff0000;">&quot;~/.emacs.d/lisp&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'load-path <span style="color: #ff0000;">&quot;~/.emacs.d/lisp/apel&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'load-path <span style="color: #ff0000;">&quot;~/.emacs.d/lisp/emu&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'load-path <span style="color: #ff0000;">&quot;~/.emacs.d/lisp/howm&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; 実行パス</span>
<span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'exec-path <span style="color: #ff0000;">&quot;/usr/local/bin&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'exec-path <span style="color: #ff0000;">&quot;/opt/local/bin&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; auto-install</span>
<span style="color: #66cc66;">&#40;</span>require 'auto-install<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'load-path auto-install-directory<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>auto-install-update-emacswiki-package-<span style="color: #b1b100;">name</span> t<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>auto-install-compatibility-setup<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; 基本設定</span>
<span style="color: #66cc66;">&#40;</span>load <span style="color: #ff0000;">&quot;init/base.el&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; 表示、window関連の設定</span>
<span style="color: #66cc66;">&#40;</span>load <span style="color: #ff0000;">&quot;init/display.el&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; global-set-key</span>
<span style="color: #66cc66;">&#40;</span>load <span style="color: #ff0000;">&quot;init/keybind.el&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; howm/org</span>
<span style="color: #66cc66;">&#40;</span>load <span style="color: #ff0000;">&quot;init/memo.el&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; 各種プログラミング用メジャーモード</span>
<span style="color: #66cc66;">&#40;</span>load <span style="color: #ff0000;">&quot;init/programming.el&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; 自分で追加した関数など</span>
<span style="color: #66cc66;">&#40;</span>load <span style="color: #ff0000;">&quot;init/self.el&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>設定ファイル一式を<a href="http://github.com/taichino/emacs_config">github</a>にあげて管理する事にしました。プライベートリポジトリだと、ついつい汚くなるので駄目でした。本当は.emacs.d以下すべてを置いておきたいですけど、リポジトリが公開状態なので良いのかどうなのか。ちょっと様子見です。</p>
<p>今回の整理での気分的に大きな収穫は以下です。Carbonが素晴らしいと触れ回っていたのですが、しれっとCocoa Emacsに乗り換えてしまいました。</p>
<ul>
<li><strong>magit</strong>: gitをemacsから使えるようになった</li>
<li><strong>Cocoa Emacs</strong>: magitを導入するためにCarbonから乗り換えた</li>
<li><strong>org-mode</strong>をhowmのメジャーモードで使うようにした</li>
<li><strong>moccur-edit</strong>: occurの検索結果を直接編集して元のバッファに反映させる</li>
<li><strong>sequential-command</strong>: C-a, C-eがパワーアップ</li>
</ul>
<p>まだ改善の余地だらけですが、とにかくも整理して管理下に置いたので、ようやく.emacsも自分も育てていける感じになって、大変気分がいいです。</p>
]]></content:encoded>
			<wfw:commentRss>http://taichino.com/engineer-life/1894/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>何故かAppleScriptが動かない時はactivateしたら良いよという話</title>
		<link>http://taichino.com/memo/1843</link>
		<comments>http://taichino.com/memo/1843#comments</comments>
		<pubDate>Thu, 08 Jul 2010 23:46:26 +0000</pubDate>
		<dc:creator>taichino</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[メモ]]></category>
		<category><![CDATA[技術]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[Mail.app]]></category>
		<category><![CDATA[reply]]></category>

		<guid isPermaLink="false">http://taichino.com/?p=1843</guid>
		<description><![CDATA[覚えたばかりのAppleScriptが動かなくて、ハマり倒したのでメモしておきます。まず動かなかったのは以下のコードで、やろうとしてるのは一番新しい送信ボックス中のメールに返信する形で新しいメールを作って件名と本文に適当な文字列を設定すると言うことです。単純ですね。

on run
  tell application &#34;Mail&#34;
       set last_msg to the first message of sent mailbox
       set reply_msg to reply last_msg with opening window
       tell reply_msg
            set [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://taichino.com/engineer-life/mac/1834">覚えたばかりのAppleScript</a>が動かなくて、ハマり倒したのでメモしておきます。まず動かなかったのは以下のコードで、やろうとしてるのは一番新しい送信ボックス中のメールに返信する形で新しいメールを作って件名と本文に適当な文字列を設定すると言うことです。単純ですね。</p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #0066ff;">run</span>
  <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Mail&quot;</span>
       <span style="color: #ff0033; font-weight: bold;">set</span> last_msg <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> <span style="color: #ff0033;">first</span> message <span style="color: #ff0033; font-weight: bold;">of</span> sent mailbox
       <span style="color: #ff0033; font-weight: bold;">set</span> reply_msg <span style="color: #ff0033; font-weight: bold;">to</span> reply last_msg <span style="color: #ff0033; font-weight: bold;">with</span> opening <span style="color: #0066ff;">window</span>
       <span style="color: #ff0033; font-weight: bold;">tell</span> reply_msg
            <span style="color: #ff0033; font-weight: bold;">set</span> subject <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;replied&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #0066ff;">content</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;this is replied message&quot;</span>
       <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
  <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #0066ff;">run</span></pre></div></div>

<p>パッと見は動きそうなのですが、実行するとsubjectの設定でAppleEvent handler failedという謎のエラーが出ます。replyではなくて新しくメールを作った場合は動作するので、さっぱり原因が予想できず自己解決できませんでした。</p>
<p><span id="more-1843"></span></p>
<p>そこで<a href="http://stackoverflow.com/questions/3173361/py-appscript-how-to-configure-mail-created-by-reply">stackoverflowに質問</a>すると、OSX 10.5.xのMail.appはバギーだからOSX 10.6.xにした方が良いよと言われたので、なるほどと思い従ってみたのですが今度はcontentのセットがエラーは出ないものの失敗します。SnowLeopardでも駄目やんと言うと、本家のapplescript-usersに聞いてくれと言われたので再度質問してみると、<a href="http://piyocast.com/as/archives/1370">Piyomaruさんにdelayを使うと良いよ</a>と教えてもらいました。コード的には以下になりまして、これはばっちり動作します。要は各処理がちゃんとブロッキングされていないので、sleepして調節するべしと言う事です。ただ動くのですが、これAppleScriptマジかよと疑いたくなる内容ですね。</p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #0066ff;">run</span>
  <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Mail&quot;</span>
       <span style="color: #ff0033; font-weight: bold;">set</span> last_msg <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> <span style="color: #ff0033;">first</span> message <span style="color: #ff0033; font-weight: bold;">of</span> sent mailbox
       <span style="color: #ff0033; font-weight: bold;">set</span> reply_msg <span style="color: #ff0033; font-weight: bold;">to</span> reply last_msg <span style="color: #ff0033; font-weight: bold;">with</span> opening <span style="color: #0066ff;">window</span>
	   delay <span style="color: #000000;">2.0</span>
       <span style="color: #ff0033; font-weight: bold;">tell</span> reply_msg
            <span style="color: #ff0033; font-weight: bold;">set</span> subject <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;replied&quot;</span>
			delay <span style="color: #000000;">1.0</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #0066ff;">content</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;this is replied message&quot;</span>
       <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
  <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #0066ff;">run</span></pre></div></div>

<p>マシンのスペックによってこの程度のスクリプトが動いたり動かなかったりするのかと思って萎えていたのですが、<a href="http://twitter.com/semweb">@semweb</a>さんとの会話でactivateしたら動くんじゃね？と言うことになりまして試してみるとこれがばっちり動作しました。結果のコードは以下になりまして、処理前にactivateを入れているだけです。</p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #0066ff;">run</span>
  <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Mail&quot;</span>
  	   <span style="color: #0066ff;">activate</span>
       <span style="color: #ff0033; font-weight: bold;">set</span> last_msg <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> <span style="color: #ff0033;">first</span> message <span style="color: #ff0033; font-weight: bold;">of</span> sent mailbox
       <span style="color: #ff0033; font-weight: bold;">set</span> reply_msg <span style="color: #ff0033; font-weight: bold;">to</span> reply last_msg <span style="color: #ff0033; font-weight: bold;">with</span> opening <span style="color: #0066ff;">window</span>
       <span style="color: #ff0033; font-weight: bold;">tell</span> reply_msg
            <span style="color: #ff0033; font-weight: bold;">set</span> subject <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;replied&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #0066ff;">content</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;this is replied message&quot;</span>
       <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
  <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #0066ff;">run</span></pre></div></div>

<p>Cocoaを理解していないので正確な事は分からないのですが、バックグラウンドで走っているプロセス上の処理が、ごにょごにょされた結果スクリプトの各行がブロッキングじゃ無くなるとかそういう雰囲気です。なんとなくこれはMail.appに限らない話だと思われるので、AppleScriptが何故か動かない時はとりあえずactivateしておけば良いと思います。これはpy-appscript等のラッパーを使っていても同様です。</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> appscript <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
mailapp = app<span style="color: black;">&#40;</span><span style="color: #483d8b;">'Mail'</span><span style="color: black;">&#41;</span>
mailapp.<span style="color: black;">activate</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
msg = mailapp.<span style="color: black;">sent_mailbox</span>.<span style="color: black;">messages</span>.<span style="color: black;">first</span>
reply_msg = mailapp.<span style="color: black;">reply</span><span style="color: black;">&#40;</span>msg, opening_window=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
&nbsp;
reply_msg.<span style="color: black;">subject</span>.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'replied message'</span><span style="color: black;">&#41;</span>
reply_msg.<span style="color: black;">content</span>.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'some content'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>「activateを1行入れる」にたどり着くまでに結局1週間かかりまして、もっと問題解決プロセスを高速化しないとあっという間に死にそうだなぁというこの頃です。</p>
]]></content:encoded>
			<wfw:commentRss>http://taichino.com/memo/1843/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello AppleScript World</title>
		<link>http://taichino.com/engineer-life/mac/1834</link>
		<comments>http://taichino.com/engineer-life/mac/1834#comments</comments>
		<pubDate>Fri, 02 Jul 2010 17:01:32 +0000</pubDate>
		<dc:creator>taichino</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[appscript]]></category>

		<guid isPermaLink="false">http://taichino.com/?p=1834</guid>
		<description><![CDATA[最近ではデザイナさんもAppleScriptを使いこなすようで、プログラマの自分がまったく理解してないのはどうかと言うことでかじってみる事にしました。まぁ日常的に使ってるのはTerminalとEmacsとYoruFukuroだけなので、個人的にはあんまり使う機会が無いかもなのですが、ひょっとするとXcode周辺で役に立つかもしれないという甘い期待を抱いています。

中々とっかかりが掴めなかったのですが、とりあえずコードを見るのが早いかと思います。以下のスクリプトはMail.appからテストメールを送るというものです。構文自体はあまり見慣れないですが、ちょっとゆっくり見れば難しくはありません。

on run
    -- Mail.appに対するブロック
	tell application &#34;Mail&#34;
	    -- 送信メールオブジェクトを作成
		set newMessage to make new outgoing message   
&#160;
		-- 送信するメールオブジェクトに対するブロック
		tell newMessage
			set subject to makeSubject&#40;&#41; of me   -- 件名の設定
			set content to &#34;applescript&#34;         -- 本文の設定
		end tell
&#160;
		-- 宛先を指定
		make new to recipient at the end [...]]]></description>
			<content:encoded><![CDATA[<p>最近ではデザイナさんもAppleScriptを使いこなすようで、プログラマの自分がまったく理解してないのはどうかと言うことでかじってみる事にしました。まぁ日常的に使ってるのはTerminalとEmacsとYoruFukuroだけなので、個人的にはあんまり使う機会が無いかもなのですが、ひょっとするとXcode周辺で役に立つかもしれないという甘い期待を抱いています。</p>
<p><span id="more-1834"></span></p>
<p>中々とっかかりが掴めなかったのですが、とりあえずコードを見るのが早いかと思います。以下のスクリプトはMail.appからテストメールを送るというものです。構文自体はあまり見慣れないですが、ちょっとゆっくり見れば難しくはありません。</p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #0066ff;">run</span>
    <span style="color: #808080; font-style: italic;">-- Mail.appに対するブロック</span>
	<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Mail&quot;</span>
	    <span style="color: #808080; font-style: italic;">-- 送信メールオブジェクトを作成</span>
		<span style="color: #ff0033; font-weight: bold;">set</span> newMessage <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">make</span> <span style="color: #0066ff;">new</span> outgoing message   
&nbsp;
		<span style="color: #808080; font-style: italic;">-- 送信するメールオブジェクトに対するブロック</span>
		<span style="color: #ff0033; font-weight: bold;">tell</span> newMessage
			<span style="color: #ff0033; font-weight: bold;">set</span> subject <span style="color: #ff0033; font-weight: bold;">to</span> makeSubject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">me</span>   <span style="color: #808080; font-style: italic;">-- 件名の設定</span>
			<span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #0066ff;">content</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;applescript&quot;</span>         <span style="color: #808080; font-style: italic;">-- 本文の設定</span>
		<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">-- 宛先を指定</span>
		<span style="color: #0066ff;">make</span> <span style="color: #0066ff;">new</span> <span style="color: #ff0033; font-weight: bold;">to</span> recipient at <span style="color: #ff0033;">the</span> <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #ff0033; font-weight: bold;">to</span> recipients <span style="color: #ff0033; font-weight: bold;">of</span> newMessage <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">properties</span> <span style="color: #000000;">&#123;</span>address:<span style="color: #009900;">&quot;taichino@gmail.com&quot;</span><span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">-- 送信</span>
		send newMessage
	<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #0066ff;">run</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> makeSubject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
   <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #009900;">&quot;hello&quot;</span>
<span style="color: #ff0033; font-weight: bold;">end</span> makeSubject</pre></div></div>

<p>見た感じで大体予想はつきますがon runのブロックがmain関数の様なもので、on makeSubjectのブロックがサブルーチンです。run内の処理の流れは、大抵以下の様になるかと思います。</p>
<ol>
<li>アプリケーションを指定 (今回はMail)</li>
<li>操作したいオブジェクトを作るか取得するかして準備する(今回はメールオブジェクト)</li>
<li>準備したオブジェクトを弄って結果を反映する(今回はメールにタイトル等を設定して送信)</li>
</ol>
<p>コードは処理をスコープごとに綺麗に分離できますし、あまりプログラムを理解していなくても雰囲気は掴めますね。またアプリケーションごとにどのような処理やオブジェクトが使用可能かを調べる為にスクリプトエディタのヘルプを利用します。スクリプトエディタを起動して⌘+Shift+Oでリファレンスが開きますので一度目を通しておくと良さそうです。</p>
<p>さて、もちろんiTuneやらXcodeやらをスクリプトから弄れたら嬉しいのですが、日常的にAppleScriptを書くのは辛そうです。個人的な見解ですがAppleScriptはShell Scriptよりも貧弱で、PythonやPerl等とは比べるべくもありません。調べていると色々不満が出てきたのですが、僕は標準入出力にアクセスできない時点で覚える気が無くなりました。Script Editorに強く依存しているのも辛いところです。閉鎖的な設計が非常に残念です。</p>
<p>とは言っても各アプリケーションに用意されたインターフェースは割と強力なので諦めるのはもったいないということで、何とかならないかと思って調べていると<a href="http://appscript.sourceforge.net/py-appscript/index.html">py-appscript</a>というビンゴなPythonモジュールが見つかりました。これはAppleScriptをPythonから操作する為のラッパーモジュールです。詳細は省きますが、このモジュールを使うと上記スクリプトを、以下のように書き換える事が出来ます。</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> appscript <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
mail = app<span style="color: black;">&#40;</span><span style="color: #483d8b;">'Mail'</span><span style="color: black;">&#41;</span>
msg = mail.<span style="color: black;">make</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">new</span>=k.<span style="color: black;">outgoing_message</span><span style="color: black;">&#41;</span>
msg.<span style="color: black;">subject</span>.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hello&quot;</span><span style="color: black;">&#41;</span>,
msg.<span style="color: black;">content</span>.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;appscript&quot;</span><span style="color: black;">&#41;</span>
msg.<span style="color: black;">to_recipients</span>.<span style="color: black;">end</span>.<span style="color: black;">make</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">new</span>=k.<span style="color: black;">to_recipient</span>, with_properties=<span style="color: black;">&#123;</span><span style="color: #483d8b;">'address'</span>:<span style="color: #483d8b;">'taichino@gmail.com'</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
msg.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>使い慣れたPythonでしかもかなり楽にAppleScriptを叩けています。これで基本的な処理はPythonでやりながら、必要な分だけアプリに投げると言うスクリプトが書けます。これなら覚えて損は無いでしょうという感じになりましたね。徐々にmacスキルを上げる為にもPython経由でAppleScript叩いていきたいと思います。ちなみにPythonの他にruby, objcにもそれぞれラッパーが存在しているようですので、得意なものを使えば良さそうです。</p>
<p><strong>2010.7.2 9:00 追記</strong><br />
上記py-appscriptを使ったコードは一つずつプロパティを設定していますが、make関数で一気に設定することも出来ます。こちらの方が見通しがいいですね。</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> appscript <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
mail = app<span style="color: black;">&#40;</span><span style="color: #483d8b;">'Mail'</span><span style="color: black;">&#41;</span>
msg = mail.<span style="color: black;">make</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">new</span>=k.<span style="color: black;">outgoing_message</span>,
                with_properties=<span style="color: black;">&#123;</span>k.<span style="color: black;">subject</span>:<span style="color: #483d8b;">&quot;hello&quot;</span>,
                                 k.<span style="color: black;">content</span>:<span style="color: #483d8b;">'appscript'</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
msg.<span style="color: black;">to_recipients</span>.<span style="color: black;">end</span>.<span style="color: black;">make</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">new</span>=k.<span style="color: black;">to_recipient</span>, with_properties=<span style="color: black;">&#123;</span><span style="color: #483d8b;">'address'</span>:<span style="color: #483d8b;">'taichino@gmail.com'</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
msg.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>あと大した話ではないですが、メール送信はやっぱり目で確認して自分でMail.appの送信ボタンを押したいという方はsendの代わりにvisibleプロパティをsetすれば作成した内容が反映されたメールペインが表示されます。</p>
]]></content:encoded>
			<wfw:commentRss>http://taichino.com/engineer-life/mac/1834/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPadでJailbreakメモ</title>
		<link>http://taichino.com/memo/1823</link>
		<comments>http://taichino.com/memo/1823#comments</comments>
		<pubDate>Sat, 19 Jun 2010 04:16:34 +0000</pubDate>
		<dc:creator>taichino</dc:creator>
				<category><![CDATA[メモ]]></category>
		<category><![CDATA[技術]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[jailbreak]]></category>

		<guid isPermaLink="false">http://taichino.com/?p=1823</guid>
		<description><![CDATA[iPadでJailbreakしてみました。コードをビルドするところまでの手順をメモしておきます。僕の環境はOSX Leopard + iPad(iPhoneOS 3.2)です。それ以外の環境では動作確認はしてません。
あとお約束ですが、JailbreakするとiPadが壊れるリスクがあるので自己責任でお願いしますね。また作業前にiPadのバックアップをとってから行うことをオススメします。

1. Jailbreak
さて早速Jailbreakします。ココからSpirit.appをダウンロードし、iPadを繋いだ状態で実行するとJailbreakボタンが出てくるのでポチリます。以上でJailbreak完了です。今や数秒でJailbreakできる時代になりましたね。iPadにCydiaというアプリがインストールされていたら成功しています。CydiaはAppStoreの野良アプリ版で、このアプリから色々なツールをインストールする事になります。
2. シェルログインの準備
CydiaはAPTのGUIフロントエンドでよく出来ているのですが、CUIの方が使い易いのでシェルログインして作業する為の準備をします。Cydiaから以下のパッケージをインストールしましょう。適当に検索すれば見つかります。

OpenSSH
APT
 Vi IMproved (vim)

これでiPadにSSHでログインして作業する準備が整いました。
3. mobileユーザで作業する為の準備
早速ログインしてみます。iPadのIPは「設定」=&#62;「Wi-Fi」で繋いでるネットワークを選択したら見れます。デフォルトでrootとmobileというユーザが作成されていて、どちらもパスワードがalpineになっているので変更します。またrootで作業し続けるのは非常に怖いのでmobileユーザで作業する為にsudoを入れて、その後はmobileユーザで作業します。

your_pc$ ssh ipad_ip -l root
$ passwd
$ passwd mobile
$ apt-get install sudo
$ apt-get install coreutils
$ vim /etc/sudoers  # mobileユーザをsudoersに追加

3. mobileユーザでビルド環境を整える
さてmobileユーザでsudoが使えるようになったのでユーザをスイッチしてビルド環境を整えていきます。普段最初から入っているライブラリやヘッダファイルが入ってないので苦労しました。

$ su - mobile
$ sudo apt-get install zsh
$ sudo apt-get install wget
$ wget http://apt.saurik.com/debs/libgcc_4.2-20080410-1-6_iphoneos-arm.deb
$ sudo dpkg -i libgcc_4.2-20080410-1-6_iphoneos-arm.deb
$ sudo apt-get install iphone-gcc
$ sudo apt-get install make
$ [...]]]></description>
			<content:encoded><![CDATA[<p>iPadでJailbreakしてみました。コードをビルドするところまでの手順をメモしておきます。僕の環境はOSX Leopard + iPad(iPhoneOS 3.2)です。それ以外の環境では動作確認はしてません。<br />
あとお約束ですが、<span style="color: #ff0000;"><strong>JailbreakするとiPadが壊れるリスクがあるので自己責任でお願いしますね。</strong></span>また作業前にiPadのバックアップをとってから行うことをオススメします。</p>
<p><span id="more-1823"></span></p>
<p><strong>1. Jailbreak</strong><br />
さて早速Jailbreakします。<a href="http://spiritjb.com/">ココ</a>からSpirit.appをダウンロードし、iPadを繋いだ状態で実行するとJailbreakボタンが出てくるのでポチリます。以上でJailbreak完了です。今や数秒でJailbreakできる時代になりましたね。iPadにCydiaというアプリがインストールされていたら成功しています。CydiaはAppStoreの野良アプリ版で、このアプリから色々なツールをインストールする事になります。</p>
<p><strong>2. シェルログインの準備</strong><br />
CydiaはAPTのGUIフロントエンドでよく出来ているのですが、CUIの方が使い易いのでシェルログインして作業する為の準備をします。Cydiaから以下のパッケージをインストールしましょう。適当に検索すれば見つかります。</p>
<ul>
<li>OpenSSH</li>
<li>APT</li>
<li> Vi IMproved (vim)</li>
</ul>
<p>これでiPadにSSHでログインして作業する準備が整いました。</p>
<p><strong>3. mobileユーザで作業する為の準備</strong><br />
早速ログインしてみます。iPadのIPは「設定」=&gt;「Wi-Fi」で繋いでるネットワークを選択したら見れます。デフォルトでrootとmobileというユーザが作成されていて、どちらもパスワードがalpineになっているので変更します。またrootで作業し続けるのは非常に怖いのでmobileユーザで作業する為にsudoを入れて、その後はmobileユーザで作業します。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">your_pc$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> ipad_ip <span style="color: #660033;">-l</span> root
$ <span style="color: #c20cb9; font-weight: bold;">passwd</span>
$ <span style="color: #c20cb9; font-weight: bold;">passwd</span> mobile
$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span>
$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> coreutils
$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>sudoers  <span style="color: #666666; font-style: italic;"># mobileユーザをsudoersに追加</span></pre></div></div>

<p><strong>3. mobileユーザでビルド環境を整える</strong><br />
さてmobileユーザでsudoが使えるようになったのでユーザをスイッチしてビルド環境を整えていきます。普段最初から入っているライブラリやヘッダファイルが入ってないので苦労しました。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">su</span> - mobile
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">zsh</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">wget</span>
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>apt.saurik.com<span style="color: #000000; font-weight: bold;">/</span>debs<span style="color: #000000; font-weight: bold;">/</span>libgcc_4.2-<span style="color: #000000;">20080410</span>-<span style="color: #000000;">1</span>-<span style="color: #000000;">6</span>_iphoneos-arm.deb
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> libgcc_4.2-<span style="color: #000000;">20080410</span>-<span style="color: #000000;">1</span>-<span style="color: #000000;">6</span>_iphoneos-arm.deb
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> iphone-gcc
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">make</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ldid
$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>toolchain
$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>toolchain
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> zxvf ~<span style="color: #000000; font-weight: bold;">/</span>sys32.tgz  <span style="color: #666666; font-style: italic;"># 予めhttp://www.2shared.com/file/wx3Kc7RW/sys32.htmlからsys32.tgzをダウンロードしておく</span></pre></div></div>

<p>これで一応ビルド環境が整いました。テストの為HelloWorldを書いておきます。</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* hello.c */</span>
<span style="color: #339933;">#include ＜stdio.h＞</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hello iPad World!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>上記コードをインクルードファイルとライブラリのパスに注意してビルドして実行してみます。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-I</span><span style="color: #ff0000;">&quot;/var/toolchain/sys32/usr/include&quot;</span> <span style="color: #660033;">-L</span><span style="color: #ff0000;">&quot;/var/toolchain/sys32/usr/lib/&quot;</span> hello.c <span style="color: #660033;">-o</span> hello
$ .<span style="color: #000000; font-weight: bold;">/</span>hello
Hello iPad World<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<p>うまく実行されていますね。後は大抵は普通のunixマシンとして扱えるので好きにして下さい。個人的には取りあえずemacsをインストールしてみようかと思っています。あと下記ページのTabBarSampleのMakefileが色々と参考になります。</p>
<p><strong>参考ページ様</strong><br />
<a href="http://iphonesdkdev.blogspot.com/2010/06/iphone-gcc-for-sdk-32-ipad.html">http://iphonesdkdev.blogspot.com/2010/06/iphone-gcc-for-sdk-32-ipad.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://taichino.com/memo/1823/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello Autotools World</title>
		<link>http://taichino.com/engineer-life/1763</link>
		<comments>http://taichino.com/engineer-life/1763#comments</comments>
		<pubDate>Thu, 13 May 2010 14:04:25 +0000</pubDate>
		<dc:creator>taichino</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[技術]]></category>

		<guid isPermaLink="false">http://taichino.com/?p=1763</guid>
		<description><![CDATA[名前とぼんやりとした役割や機能だけは知ってるけど、腰が引けて使えないという状態だったautomakeやautoconfですが、覚える必要が出てきたので概要だけでも把握しようという事で調べてみました。出てくるツールや中間ファイルの種類が多いので、まずは図を書いて整理してみました。


パッと見は複雑で見て見ぬ振りをしたくなる図ですが、よく見ると自分で作成・編集する必要があるのは、オレンジの項目だけなので、ソースコードを除くとconfigure.acとMakefile.amの2つだけです。これなら何とか覚え始めようという気になりますね。
実際に図の手順を実行しながら追ってみますが、その前に手元のAutotoolsのバージョンを確認します。バージョンが違うと上手く動かないかもしれません。

$ autoconf --version
autoconf &#40;GNU Autoconf&#41; 2.61
# 残りの出力は省略
$ automake --version
automake &#40;GNU automake&#41; 1.10
# 残りの出力は省略

今回のビルド対象のソースコードは以下になります。単純ですがまぁ練習なのでこれくらいにしておきましょう。

$ tree -a
`-- src
    &#124;-- hello.cpp
    &#124;-- hello.h
    `-- main.cpp

まずはMakefile.amを作成します。Makefile.amにはビルド対象のソースコードやリンク情報を記述します。このファイルはディレクトリごとに作成する必要があるので注意して下さい。

$ vim Makefile.am
$ cat Makefile.am
SUBDIRS = src
&#160;
$ vim src/Makefile.am
$ cat src/Makefile.am
bin_PROGRAMS = hello
hello_SOURCES = hello.cpp hello.h main.cpp
&#160;
$ tree -a
&#124;-- Makefile.am
`-- src
    &#124;-- [...]]]></description>
			<content:encoded><![CDATA[<p>名前とぼんやりとした役割や機能だけは知ってるけど、腰が引けて使えないという状態だったautomakeやautoconfですが、覚える必要が出てきたので概要だけでも把握しようという事で調べてみました。出てくるツールや中間ファイルの種類が多いので、まずは図を書いて整理してみました。</p>
<p><a href="http://taichino.com/wp-content/uploads/2010/05/autotools-5.png"><img src="http://taichino.com/wp-content/uploads/2010/05/autotools-5-300x214.png" alt="Autotoolsのフローチャート" title="autotools" width="300" height="214" class="alignnone size-medium wp-image-1770" /></a></p>
<p><span id="more-1763"></span></p>
<p>パッと見は複雑で見て見ぬ振りをしたくなる図ですが、よく見ると自分で作成・編集する必要があるのは、オレンジの項目だけなので、ソースコードを除くとconfigure.acとMakefile.amの2つだけです。これなら何とか覚え始めようという気になりますね。</p>
<p>実際に図の手順を実行しながら追ってみますが、その前に手元のAutotoolsのバージョンを確認します。バージョンが違うと上手く動かないかもしれません。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">autoconf</span> <span style="color: #660033;">--version</span>
<span style="color: #c20cb9; font-weight: bold;">autoconf</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>GNU Autoconf<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">2.61</span>
<span style="color: #666666; font-style: italic;"># 残りの出力は省略</span>
$ <span style="color: #c20cb9; font-weight: bold;">automake</span> <span style="color: #660033;">--version</span>
<span style="color: #c20cb9; font-weight: bold;">automake</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>GNU <span style="color: #c20cb9; font-weight: bold;">automake</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1.10</span>
<span style="color: #666666; font-style: italic;"># 残りの出力は省略</span></pre></div></div>

<p>今回のビルド対象のソースコードは以下になります。単純ですがまぁ練習なのでこれくらいにしておきましょう。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">tree</span> <span style="color: #660033;">-a</span>
<span style="color: #000000; font-weight: bold;">`</span>-- src
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.cpp
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.h
    <span style="color: #000000; font-weight: bold;">`</span>-- main.cpp</pre></div></div>

<p>まずはMakefile.amを作成します。Makefile.amにはビルド対象のソースコードやリンク情報を記述します。このファイルはディレクトリごとに作成する必要があるので注意して下さい。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> Makefile.am
$ <span style="color: #c20cb9; font-weight: bold;">cat</span> Makefile.am
SUBDIRS = src
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">vim</span> src<span style="color: #000000; font-weight: bold;">/</span>Makefile.am
$ <span style="color: #c20cb9; font-weight: bold;">cat</span> src<span style="color: #000000; font-weight: bold;">/</span>Makefile.am
bin_PROGRAMS = hello
hello_SOURCES = hello.cpp hello.h main.cpp
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">tree</span> <span style="color: #660033;">-a</span>
<span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
<span style="color: #000000; font-weight: bold;">`</span>-- src
    <span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.cpp
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.h
    <span style="color: #000000; font-weight: bold;">`</span>-- main.cpp</pre></div></div>

<p>次にconfigureスクリプトを作成するまでのプロセスを実行してみます。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ autoscan    <span style="color: #666666; font-style: italic;"># configure.scanを生成</span>
$ <span style="color: #c20cb9; font-weight: bold;">tree</span> <span style="color: #660033;">-a</span>
<span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
<span style="color: #000000; font-weight: bold;">|</span>-- autoscan.log
<span style="color: #000000; font-weight: bold;">|</span>-- configure.scan
<span style="color: #000000; font-weight: bold;">`</span>-- src
    <span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.cpp
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.h
    <span style="color: #000000; font-weight: bold;">`</span>-- main.cpp
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">mv</span> configure.scan configure.ac
$ <span style="color: #c20cb9; font-weight: bold;">vim</span> configure.ac   <span style="color: #666666; font-style: italic;"># 内容は後述</span>
$ <span style="color: #c20cb9; font-weight: bold;">tree</span> <span style="color: #660033;">-a</span>
<span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
<span style="color: #000000; font-weight: bold;">|</span>-- autoscan.log
<span style="color: #000000; font-weight: bold;">|</span>-- configure.ac
<span style="color: #000000; font-weight: bold;">`</span>-- src
    <span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.cpp
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.h
    <span style="color: #000000; font-weight: bold;">`</span>-- main.cpp
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">aclocal</span>    <span style="color: #666666; font-style: italic;"># aclocal.m4を生成</span>
$ <span style="color: #c20cb9; font-weight: bold;">tree</span> <span style="color: #660033;">-a</span>
<span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
<span style="color: #000000; font-weight: bold;">|</span>-- aclocal.m4
<span style="color: #000000; font-weight: bold;">|</span>-- autom4te.cache
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- output.0
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- requests
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">`</span>-- traces.0
<span style="color: #000000; font-weight: bold;">|</span>-- autoscan.log
<span style="color: #000000; font-weight: bold;">|</span>-- configure.ac
<span style="color: #000000; font-weight: bold;">`</span>-- src
    <span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.cpp
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.h
    <span style="color: #000000; font-weight: bold;">`</span>-- main.cpp
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">autoconf</span>     <span style="color: #666666; font-style: italic;"># configureスクリプトを生成</span>
$ <span style="color: #c20cb9; font-weight: bold;">tree</span> <span style="color: #660033;">-a</span>
<span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
<span style="color: #000000; font-weight: bold;">|</span>-- aclocal.m4
<span style="color: #000000; font-weight: bold;">|</span>-- autom4te.cache
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- output.0
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- output.1
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- requests
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- traces.0
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">`</span>-- traces.1
<span style="color: #000000; font-weight: bold;">|</span>-- autoscan.log
<span style="color: #000000; font-weight: bold;">|</span>-- configure
<span style="color: #000000; font-weight: bold;">|</span>-- configure.ac
<span style="color: #000000; font-weight: bold;">`</span>-- src
    <span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.cpp
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.h
    <span style="color: #000000; font-weight: bold;">`</span>-- main.cpp</pre></div></div>

<p>長い道のりを経て無事にconfigureスクリプトが生成されました。途中で編集したconfigure.acの内容は以下になります。エラーが発生する場合はAC_PREREQの値を確認しましょう。インストールされているautoconfパッケージよりも新しいバージョンが指定されているとエラーで先に進めません。僕もosx上でハマりました。linuxだと多分大丈夫だと思います。</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
&nbsp;
AC_PREREQ(2.61)
AC_INIT(hello, 1.0, taichino@gmail.com)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/hello.cpp])
AC_CONFIG_HEADER([config.h])
&nbsp;
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
&nbsp;
# Checks for libraries.
&nbsp;
# Checks for header files.
&nbsp;
# Checks for typedefs, structures, and compiler characteristics.
&nbsp;
# Checks for library functions.
&nbsp;
AC_CONFIG_FILES([Makefile
                 src/Makefile])
AC_OUTPUT</pre></div></div>

<p>さて生成されたconfigureを早速実行したいわけですが、これを実行する為にはまだ準備が必要です。実行したい気持ちをぐっと抑えてconfig.h.inとMakefile.inを作成しましょう。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">autoheader</span>    <span style="color: #666666; font-style: italic;"># config.h.inを生成</span>
$ <span style="color: #c20cb9; font-weight: bold;">tree</span> <span style="color: #660033;">-a</span>
<span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
<span style="color: #000000; font-weight: bold;">|</span>-- aclocal.m4
<span style="color: #000000; font-weight: bold;">|</span>-- autom4te.cache
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- output.0
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- output.1
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- requests
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- traces.0
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">`</span>-- traces.1
<span style="color: #000000; font-weight: bold;">|</span>-- autoscan.log
<span style="color: #000000; font-weight: bold;">|</span>-- config.h.in
<span style="color: #000000; font-weight: bold;">|</span>-- configure
<span style="color: #000000; font-weight: bold;">|</span>-- configure.ac
<span style="color: #000000; font-weight: bold;">`</span>-- src
    <span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.cpp
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.h
    <span style="color: #000000; font-weight: bold;">`</span>-- main.cpp
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">touch</span> NEWS README AUTHORS ChangeLog
$ <span style="color: #c20cb9; font-weight: bold;">tree</span> <span style="color: #660033;">-a</span>
<span style="color: #000000; font-weight: bold;">|</span>-- AUTHORS
<span style="color: #000000; font-weight: bold;">|</span>-- ChangeLog
<span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
<span style="color: #000000; font-weight: bold;">|</span>-- NEWS
<span style="color: #000000; font-weight: bold;">|</span>-- README
<span style="color: #000000; font-weight: bold;">|</span>-- aclocal.m4
<span style="color: #000000; font-weight: bold;">|</span>-- autom4te.cache
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- output.0
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- output.1
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- requests
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- traces.0
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">`</span>-- traces.1
<span style="color: #000000; font-weight: bold;">|</span>-- autoscan.log
<span style="color: #000000; font-weight: bold;">|</span>-- config.h.in
<span style="color: #000000; font-weight: bold;">|</span>-- configure
<span style="color: #000000; font-weight: bold;">|</span>-- configure.ac
<span style="color: #000000; font-weight: bold;">`</span>-- src
    <span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.cpp
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.h
    <span style="color: #000000; font-weight: bold;">`</span>-- main.cpp
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">automake</span> <span style="color: #660033;">--add-missing</span> <span style="color: #660033;">--copy</span>    <span style="color: #666666; font-style: italic;"># Makefile.inを生成</span>
<span style="color: #666666; font-style: italic;"># ブログに貼付けると表示が乱れるので出力は省略</span>
$ <span style="color: #c20cb9; font-weight: bold;">tree</span> <span style="color: #660033;">-a</span>
<span style="color: #000000; font-weight: bold;">|</span>-- AUTHORS
<span style="color: #000000; font-weight: bold;">|</span>-- COPYING
<span style="color: #000000; font-weight: bold;">|</span>-- ChangeLog
<span style="color: #000000; font-weight: bold;">|</span>-- INSTALL
<span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
<span style="color: #000000; font-weight: bold;">|</span>-- Makefile.in
<span style="color: #000000; font-weight: bold;">|</span>-- NEWS
<span style="color: #000000; font-weight: bold;">|</span>-- README
<span style="color: #000000; font-weight: bold;">|</span>-- aclocal.m4
<span style="color: #000000; font-weight: bold;">|</span>-- autom4te.cache
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- output.0
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- output.1
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- requests
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- traces.0
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">`</span>-- traces.1
<span style="color: #000000; font-weight: bold;">|</span>-- autoscan.log
<span style="color: #000000; font-weight: bold;">|</span>-- config.h.in
<span style="color: #000000; font-weight: bold;">|</span>-- configure
<span style="color: #000000; font-weight: bold;">|</span>-- configure.ac
<span style="color: #000000; font-weight: bold;">|</span>-- depcomp
<span style="color: #000000; font-weight: bold;">|</span>-- install-sh
<span style="color: #000000; font-weight: bold;">|</span>-- missing
<span style="color: #000000; font-weight: bold;">`</span>-- src
    <span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
    <span style="color: #000000; font-weight: bold;">|</span>-- Makefile.in
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.cpp
    <span style="color: #000000; font-weight: bold;">|</span>-- hello.h
    <span style="color: #000000; font-weight: bold;">`</span>-- main.cpp</pre></div></div>

<p>図には書いていませんがautomakeを実行するには予めNEWS README AUTHORS ChangeLogが作成されている必要があります。これはGNUの推奨するパッケージ構成なのですが、ここでは空ファイルを作成してお茶を濁しています。さてこれで漸くconfigureを実行する準備が整いました。早速実行してみましょう。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>configure
checking <span style="color: #000000; font-weight: bold;">for</span> a BSD-compatible install... <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-c</span>
checking whether build environment is sane... <span style="color: #c20cb9; font-weight: bold;">yes</span>
checking <span style="color: #000000; font-weight: bold;">for</span> a thread-safe <span style="color: #c20cb9; font-weight: bold;">mkdir</span> -p... .<span style="color: #000000; font-weight: bold;">/</span>install-sh <span style="color: #660033;">-c</span> <span style="color: #660033;">-d</span>
checking <span style="color: #000000; font-weight: bold;">for</span> gawk... <span style="color: #c20cb9; font-weight: bold;">gawk</span>
checking whether <span style="color: #c20cb9; font-weight: bold;">make</span> sets $<span style="color: #7a0874; font-weight: bold;">&#40;</span>MAKE<span style="color: #7a0874; font-weight: bold;">&#41;</span>... <span style="color: #c20cb9; font-weight: bold;">yes</span>
checking <span style="color: #000000; font-weight: bold;">for</span> g++... <span style="color: #c20cb9; font-weight: bold;">g++</span>
checking <span style="color: #000000; font-weight: bold;">for</span> C++ compiler default output <span style="color: #c20cb9; font-weight: bold;">file</span> name... a.out
checking whether the C++ compiler works... <span style="color: #c20cb9; font-weight: bold;">yes</span>
checking whether we are cross compiling... no
checking <span style="color: #000000; font-weight: bold;">for</span> suffix of executables...
checking <span style="color: #000000; font-weight: bold;">for</span> suffix of object files... o
checking whether we are using the GNU C++ compiler... <span style="color: #c20cb9; font-weight: bold;">yes</span>
checking whether <span style="color: #c20cb9; font-weight: bold;">g++</span> accepts -g... <span style="color: #c20cb9; font-weight: bold;">yes</span>
checking <span style="color: #000000; font-weight: bold;">for</span> style of include used by make... GNU
checking dependency style of g++... gcc3
checking <span style="color: #000000; font-weight: bold;">for</span> gcc... <span style="color: #c20cb9; font-weight: bold;">gcc</span>
checking whether we are using the GNU C compiler... <span style="color: #c20cb9; font-weight: bold;">yes</span>
checking whether <span style="color: #c20cb9; font-weight: bold;">gcc</span> accepts -g... <span style="color: #c20cb9; font-weight: bold;">yes</span>
checking <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">gcc</span> option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
configure: creating .<span style="color: #000000; font-weight: bold;">/</span>config.status
config.status: creating Makefile
config.status: creating src<span style="color: #000000; font-weight: bold;">/</span>Makefile
config.status: creating config.h
config.status: executing depfiles commands
$ <span style="color: #c20cb9; font-weight: bold;">tree</span> <span style="color: #660033;">-a</span>
<span style="color: #000000; font-weight: bold;">|</span>-- AUTHORS
<span style="color: #000000; font-weight: bold;">|</span>-- COPYING
<span style="color: #000000; font-weight: bold;">|</span>-- ChangeLog
<span style="color: #000000; font-weight: bold;">|</span>-- INSTALL
<span style="color: #000000; font-weight: bold;">|</span>-- Makefile        <span style="color: #666666; font-style: italic;"># Makefileができてる！</span>
<span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
<span style="color: #000000; font-weight: bold;">|</span>-- Makefile.in
<span style="color: #000000; font-weight: bold;">|</span>-- NEWS
<span style="color: #000000; font-weight: bold;">|</span>-- README
<span style="color: #000000; font-weight: bold;">|</span>-- aclocal.m4
<span style="color: #000000; font-weight: bold;">|</span>-- autom4te.cache
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- output.0
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- output.1
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- requests
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- traces.0
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">`</span>-- traces.1
<span style="color: #000000; font-weight: bold;">|</span>-- autoscan.log
<span style="color: #000000; font-weight: bold;">|</span>-- config.h
<span style="color: #000000; font-weight: bold;">|</span>-- config.h.in
<span style="color: #000000; font-weight: bold;">|</span>-- config.log
<span style="color: #000000; font-weight: bold;">|</span>-- config.status
<span style="color: #000000; font-weight: bold;">|</span>-- configure
<span style="color: #000000; font-weight: bold;">|</span>-- configure.ac
<span style="color: #000000; font-weight: bold;">|</span>-- depcomp
<span style="color: #000000; font-weight: bold;">|</span>-- install-sh
<span style="color: #000000; font-weight: bold;">|</span>-- missing
<span style="color: #000000; font-weight: bold;">|</span>-- src
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- .deps
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- hello.Po
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">`</span>-- main.Po
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- Makefile
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- Makefile.am
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- Makefile.in
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- hello.cpp
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- hello.h
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">`</span>-- main.cpp
<span style="color: #000000; font-weight: bold;">`</span>-- stamp-h1</pre></div></div>

<p>おなじみの出力の後にMakefileが作成されましたね。以上でだいたいAutotoolsの作業手順を追う事が出来ました。もうちょっと調べた事を書こうと思ってたのですが、長くなったので割愛します。infoにやたらと詳しいドキュメントが準備されているので、ちらっと読んでみると理解が進むかもしれません。</p>
<p>あと本質とは関係ないですけど、.acがAutoConf、.amがAutoMake、.inはconfigureの入力ファイルだと言うのを覚えれば見通しが良くなるかもしれません。</p>
]]></content:encoded>
			<wfw:commentRss>http://taichino.com/engineer-life/1763/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
