<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>plusHa &#187; Ruby</title>
	<atom:link href="http://plusha.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://plusha.com</link>
	<description>in the light</description>
	<lastBuildDate>Sat, 31 Dec 2011 01:57:59 +0000</lastBuildDate>
	<language>ko</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='plusha.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>plusHa &#187; Ruby</title>
		<link>http://plusha.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://plusha.com/osd.xml" title="plusHa" />
	<atom:link rel='hub' href='http://plusha.com/?pushpress=hub'/>
		<item>
		<title>gpl backup</title>
		<link>http://plusha.com/2008/11/18/gpl-backup/</link>
		<comments>http://plusha.com/2008/11/18/gpl-backup/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 22:08:33 +0000</pubDate>
		<dc:creator>plusha</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://plusha.wordpress.com/2008/11/18/gpl-backup-utils/</guid>
		<description><![CDATA[Gpl Backup Manager (gplbackup) self document Gpl Backup Manager : backup files matching extensions recursively Usage : gplbackup [cfg filename] Optional parameters : cfg filename    : configuration file(yaml file) name --cfg &#62; gplbackup.yml   : generate sample 'gplbackup.yml' file Configuration file see sample 'gplbackup.yml' file. (use --cfg option) Gpl backup manager는 현재 디렉토리 하위의 디렉토리를 돌아다니며 원하는 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=plusha.com&amp;blog=174108&amp;post=85&amp;subd=plusha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Gpl Backup Manager (gplbackup)</h2>
<h5>self document</h5>
<pre><code>Gpl Backup Manager
    : backup files matching extensions recursively

Usage :
    gplbackup [cfg filename]

Optional parameters :
    cfg filename     : configuration file(yaml file) name
    --cfg &gt; gplbackup.yml
       : generate sample 'gplbackup.yml' file

Configuration file
    see sample 'gplbackup.yml' file. (use --cfg option)</code></pre>
<p>Gpl backup manager는 현재 디렉토리 하위의 디렉토리를 돌아다니며 원하는 확장자의 파일들을 backup해주는 프로그램입니다. 백업할 때에는 (현재 디렉토리에서 상대적인) 디렉토리 구조를 그대로 만들어주며 백업을 합니다. Backup 하고자 하는 디렉토리와 파일 설정은 yml 파일을 이용하여 해줍니다. 예제 yml 파일은<br />
<code>gplbackup --cfg &gt; gplbackup.yml</code><br />
과 같이 생성할 수 있습니다. 이렇게 생기는 yml 파일은 아래와 같습니다. 파일은 YAML 문법을 따르는데, 간단하기 때문에 YAML 문법을 몰라도 아래 파일을 수정하여 사용할 수 있습니다.</p>
<p><strong>Sample <a class="external" title="yml" href="http://en.wikipedia.org/wiki/YAML">yml</a> file</strong></p>
<pre><code># Gpl Backup Manager Configuration File
# Date : 2008.02.21
# Source directories you want to backup
sourceDirectory :
- Documents
- lib

# Extensions of files you want to backup
extensions :
- .f
- .f90
- .c
- .rb
- .sh
- Makefile
- .tex

# A directory name to which the backup files will be copied
targetDirectory : hostname

# Print the copying process (T/F)
verbose : T

# Make "hostnameBak-2008.02.21.tgz" file
# using the targetDirectory (T/F)
makeTarBall : T

# Remove the targetDirectory after backup (T/F)
# - when you want tgz file only
removeBackupDir : F

# Files containing these words in their absolute path
# will be omitted
exclude :
- 'backup'
- 'lib/dms'
- 'lib/UMFPACK'
- 'lib/SU'
- 'lib/seplib'
- '.svn'</code></pre>
<p>예제의 yml 파일에서 #으로 시작하는 부분은 comment입니다.<br />
<code>sourceDirectory :</code><br />
아래에 &#8216;-&#8217;을 긋고 backup하고자 하는 디렉토리 이름을 적습니다. Backup은 하위 디렉토리까지 recursive하게 합니다. &#8216;- .&#8217;과 같이 적으면 현재 디렉토리와  하위 디렉토리의 모든 파일들을 대상으로 backup합니다. 이 때 모든 파일들을 다 backup하는 것이 아니라<br />
<code>extensions :</code><br />
에 해당하는 파일들만 backup합니다. 꼭 확장자가 아니라도<br />
<code>- Makefile</code><br />
과 같이 파일 이름의 끝부분이 같으면 backup합니다. Backup할 때에는 현재 디렉토리 아래에<br />
<code>targetDirectory :</code><br />
에 지정된 디렉토리를 만들고, 그 아래 파일이 들어있는 디렉토리를 만들어 backup합니다. targetDirectory 이름은 현재 hostname을 기준으로 만듭니다.<br />
<code>verbose :<br />
makeTarBall :<br />
removeBackupDir :</code><br />
은 T, F로 표시하고 backup 과정을 화면으로 보여줄지, 디렉토리를 만들어 backup한 후 디렉토리를 tgz 파일로 압축할 것인지, 압축 후 backup 디렉토리를 지울 것인지 지정해줍니다. 압축 파일명은 기본적으로 targetDirectory 이름에 현재 날짜를 더해서 만들어줍니다. 같은 이름의 파일이 존재할 경우 뒤에 숫자를 붙여 새로 만들 파일의 이름을 변경해줍니다.</p>
<p>Backup할 때에는 &#8216;extensions :&#8217;에 맞더라도 절대경로에 &#8216;exclude :&#8217;의 내용이 들어가 있는 파일은 제외합니다.</p>
<h5>Learning by doing</h5>
<p>실행 예를 볼까요? 현재 디렉토리 아래에 gplbackup.yml 파일과 test1, test2, test3 세 개의 디렉토리가 있고, 각각의 디렉토리에는 다음과 같은 파일들이 있습니다.</p>
<pre><code>$ ls -R
.:
gplbackup.yml  test1  test2  test3

./test1:
file1  file2  file2.f90

./test2:
file2.f  file2.f90  file3.f90

./test3:
file1.f90  file2.c
</code></pre>
<p>gplbackup.yml 파일의 내용은 다음과 같습니다.</p>
<pre><code>$ cat gplbackup.yml
# Gpl Backup Manager Configuration File
# Date : 2008.11.18
# Source directories you want to backup
sourceDirectory :
- .

# Extensions of files you want to backup
extensions :
- .f90

# A directory name to which the backup files will be copied
targetDirectory : node480Bak

# Print the copying process (T/F)
verbose : T

# Make "node480Bak-2008.11.18.tgz" file
# using the targetDirectory (T/F)
makeTarBall : T

# Remove the targetDirectory after backup (T/F)
# - when you want tgz file only
removeBackupDir : F

# Files containing these words in their absolute path
# will be omitted
exclude :
- 'test3'
</code></pre>
<p>현재 디렉토리 아래의 모든 디렉토리를 돌며 backup하는데 .f90 파일만 backup하고, 경로에 &#8216;test3&#8242;이라는 문자열이 들어간 파일은 제외합니다. 실행 결과는 다음과 같습니다.</p>
<pre><code>
$ gplbackup gplbackup.yml
in .
cp  ./test2/file2.f90     node480Bak/./test2
cp  ./test2/file3.f90     node480Bak/./test2
cp  ./test1/file2.f90     node480Bak/./test1
3 files are backed up

making tgz ball : node480Bak/
node480Bak/test2/
node480Bak/test2/file2.f90
node480Bak/test2/file3.f90
node480Bak/test1/
node480Bak/test1/file2.f90

node480Bak-20081118.tgz : 207 bytes</code></pre>
<p>현재 디렉토리 밑에 &#8216;node480Bak&#8217; 라는 디렉토리를 만들고(hostname이 &#8216;node480&#8242;입니다) 그 아래에 디렉토리 구조를 유지하며 .f90 파일들을 backup합니다. yml 파일에서 verbose: T 라고 했기 때문에 backup 과정을 화면으로 출력해주고, makeTarBall: T 라고 했기 때문에 backup 디렉토리를 압축하여 node480Bak-20081118.tgz 파일을 만들어줍니다. 또한, 압축 파일의 크기도 보여줍니다.</p>
<p>이 프로그램은 ruby 프로그래밍 언어로 만들었기 때문에 실행하기 위해서는 ruby(version 1.8 이상)가 필요합니다. 개인적으로 상당히 유용하게 쓰고 있는데, 필요하신 분은 <a class="attachment" title="gplbackup" href="http://plusha.springnote.com/pages/838122/attachments/957128">여기</a>에서 받아 쓰세요~^^</p>
<p style="text-align:right;">이 글은 <a href="http://plusha.springnote.com/pages/838122">스프링노트</a>에서 작성되었습니다.</p>
<br /> Tagged: backup, Ruby <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/plusha.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/plusha.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/plusha.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/plusha.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/plusha.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/plusha.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/plusha.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/plusha.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/plusha.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/plusha.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/plusha.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/plusha.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/plusha.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/plusha.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=plusha.com&amp;blog=174108&amp;post=85&amp;subd=plusha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://plusha.com/2008/11/18/gpl-backup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">plusha</media:title>
		</media:content>
	</item>
		<item>
		<title>gpl muting utils</title>
		<link>http://plusha.com/2008/11/06/gpl-muting-utils/</link>
		<comments>http://plusha.com/2008/11/06/gpl-muting-utils/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 22:21:41 +0000</pubDate>
		<dc:creator>plusha</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[muting]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://plusha.wordpress.com/2008/11/06/gpl-muting-utils/</guid>
		<description><![CDATA[Gpl Mute Interpolator(gplMuteintp) self document Gpl Mute Interpolator : read polyg.#### files and interpolate missing numbers Usage : gplMuteintp.rb first=[] last=[] step=[] Required parameters : first    : shot number of the first shotgather last    : shot number of the last shotgather Optional parameter : step=last-first    : shot step Examples 예를 들어, shotgather가 1200번부터 1300번까지 있는데 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=plusha.com&amp;blog=174108&amp;post=31&amp;subd=plusha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Gpl Mute Interpolator(gplMuteintp)</h2>
<h4><span style="font-size:small;">self document</span></h4>
<pre><code>Gpl Mute Interpolator : read polyg.#### files
     and interpolate missing numbers
Usage :
    gplMuteintp.rb first=[] last=[] step=[]
Required parameters :
    first    : shot number of the first shotgather
    last    : shot number of the last shotgather
Optional parameter :
    step=last-first    : shot step</code></pre>
<h4>Examples</h4>
<p>예를 들어, shotgather가 1200번부터 1300번까지 있는데 1200번, 1204번, 1208번, &#8230; , 1300번까지 4개씩 건너 뛰며 xmute script로 Muting을 했다고 합시다.</p>
<p>(이 때 한 shotgather 내에서 muting은 왼쪽에서 오른쪽으로 진행하는 것이 좋습니다.)</p>
<p>그럼 polyg.1200, polyg.1204, polyg.1208, &#8230; , polyg.1300 번까지 polygon 파일들이 생성되었겠죠. 이 파일들이 이 프로그램의 input이 됩니다.</p>
<p>이 프로그램은 앞에서 muting해놓은 polyg.#### 파일들을 interpolation하여 중간중간 비어있는 polyg.1201, polyg.1202, polyg.1203, polyg.1205, &#8230;, polyg.1299 파일들(output)을 생성해내는 프로그램입니다. 이 때의 실행 명령은<br />
<code>gplMuteintp.rb first=1200 last=1300 step=4</code><br />
가 됩니다. 1200번부터 시작하여 4씩 더해가며 이미 존재하는 polyg.#### 파일들로 비어있는 polyg.#### 파일들을 생성해냅니다.</p>
<p>1200번과 1204번을 이용하여 1201~1203번을 interpolation하고,</p>
<p>1204번과 1208번을 이용하여 1205~1207번을 interpolation합니다.</p>
<p>만약 step을 써주지 않으면 first와 last 사이에 있는 모든 파일들을 다 interpolation하여 생성합니다.</p>
<p>Garbage in, garbage out 이라고, 좋은 결과를 얻기 위해서는 muting한 결과가 좋음을 확인하고 써야합니다.</p>
<p>step간격은 자료에 따라 다릅니다. shotgather 모양에 거의 변화가 없는 경우 step을 크게 둘 수 있고, 모양이 불규칙한 경우에는 step을 작게 하거나 전체를 다 직접 muting해야겠죠.</p>
<h2>Gpl Muter(gplMute)</h2>
<h4><span style="font-size:small;">self document</span></h4>
<pre><code>Gpl Muter : mute shotgathers using polyg.#### files
Usage :
    gplMute.rb first=[] last=[] step=[] [optional parameters]
Required parameters :
    first   : shot number of the first shotgather
    last    : shot number of the last shotgather
Optional parameters
    -i              : include all
        if not given, skip [first,last,step]
    step=last-first : shot step
        # skip shotgathers matching [do first,last,step]
    fout=muteshot   : output muted file name
    perc=85         : suximage percent
    hbox=1000       : suximage hbox
    wbox=1270       : suximage wbox
    x1end           : suximage x1end
    d2=1            : suximage d2
    fin             : su file name containing the shot gathers</code></pre>
<h4>Examples</h4>
<p>이 프로그램은 앞에서 interpolation해 놓은 파일들을 가지고 실제 muting을 하여 잘 되었는지 확인하는 프로그램입니다.</p>
<p>shot을 포함한 su 파일은 shot 번호를 기준으로 shots####_####.su 파일들 중에서 자동으로 찾습니다.<br />
<code>gplMute.rb first=1200 last=1300 step=4 x1end=4.5</code><br />
와 같이 실행을 하면 1200번, 1204번, 1208번, &#8230; , 1300번은 건너뛰고(앞에서 이미 확인했으니까요, -i 옵션을 주면 다 포함합니다), 1201번, 1202번, 1203번, 1205번, &#8230; , 1299번까지 interpolation한 polyg.#### 파일들을 이용하여 muting한 결과를 보여줍니다. 결과를 보여준 후에는 확인을 합니다.<br />
<code>ok? [ (y)es or enter | (r)eplace | (n)ot good | (q)uit ]</code><br />
라고 메시지가 나오는데,</p>
<p>muting이 잘 되었을 경우에는 y 또는 그냥 enter를 치면 다음 shot으로 넘어갑니다.</p>
<p>muting 결과가 매우 마음에 들지 않을 때에는 n 을 입력하여 해당 shot을 다시 muting하고 확인하는 과정을 반복합니다.</p>
<p>일부분만 수정하면 될 경우(대부분의 경우) r 을 입력합니다. 이 경우 아래와 같이 muting 되지 않은 shotgather와 polyg.#### curve를 함께 보여줍니다.</p>
<p><img class="attachment" title="mutereplace1.png" src="http://plusha.springnote.com/pages/838194/attachments/368112" alt="mutereplace1.png" /><br />
이 그림에서 수정하고 싶은 부분에 mouse를 찍고 저장하면 해당 위치에 있던 이전 데이터가 새로 muting한 데이터로 바뀌게 됩니다. 새로운 muting 결과를 보여주면 위의 확인과정을 반복합니다.</p>
<h2>Gpl Mute Checker(gplMutecheck)</h2>
<h4>Self Document</h4>
<pre><code>Gpl Mute Checker : check &amp; modify muted shotgathers
Usage :
    gplMutecheck.rb first=[] last=[] [optional parameters]
Required parameters :
    first   : shot number of the first shotgather
    last    : shot number of the last shotgather
Optional parameters
    step=1          : shot step [do first,last,step]
    fout=muteshot   : output muted file name
    perc=85         : suximage percent
    hbox=1000       : suximage hbox
    wbox=1270       : suximage wbox
    x1end           : suximage x1end
    d2=1            : suximage d2
    fin             : su file name
                      containing the shot gathers</code></pre>
<p>이 프로그램은 앞의 gplMute와 거의 같은데 [do first,last,step]에 해당하는 번호의 shotgather만 muting합니다. 처음에 몇 개씩 건너뛰며 muting했던 자료를 확인하기 위해 사용할 수 있겠죠. polygon file이 없을 경우 처음부터 muting을 합니다. 따라서 xmute.sh 스크립트 대신 사용할 수도 있겠죠. 하나의 shot에서 작업하는 동안 다음번 shot 을 suwind로 미리 만들어 놓기 때문에 suwind로 인한 속도 지체 현상이 많이 감소하였습니다. 그럼 su 파일을 쪼갤 필요가 없겠죠?</p>
<p>(실행 파일들은 muting하는 server에 있습니다~^^)</p>
<p style="text-align:right;">이 글은 <a href="http://plusha.springnote.com/pages/838194">스프링노트</a>에서 작성되었습니다.</p>
<br /> Tagged: muting, Ruby <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/plusha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/plusha.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/plusha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/plusha.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/plusha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/plusha.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/plusha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/plusha.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/plusha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/plusha.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/plusha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/plusha.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/plusha.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/plusha.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=plusha.com&amp;blog=174108&amp;post=31&amp;subd=plusha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://plusha.com/2008/11/06/gpl-muting-utils/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">plusha</media:title>
		</media:content>

		<media:content url="http://plusha.springnote.com/pages/838194/attachments/368112" medium="image">
			<media:title type="html">mutereplace1.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Rakefile basic</title>
		<link>http://plusha.com/2008/05/20/rakefile-basic/</link>
		<comments>http://plusha.com/2008/05/20/rakefile-basic/#comments</comments>
		<pubDate>Tue, 20 May 2008 12:06:21 +0000</pubDate>
		<dc:creator>plusha</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Makefile]]></category>
		<category><![CDATA[Rakefile]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://plusha.wordpress.com/?p=13</guid>
		<description><![CDATA[Rakefile은 Makefile과 비슷한 역할을 하는, Ruby script입니다. 따라서 Ruby라는 언어의 강력한 기능들을 그대로 가져다 쓸 수 있다는 장점이 있습니다. 단, Ruby를 알아야 제대로 사용할 수 있겠죠. Makefile을 make라는 명령어로 실행하듯이, Rakefile은 rake라는 명령어로 실행합니다. Rakefile 작성법을 Makefile 작성법과 비교하며 살펴보도록 하겠습니다. Makefile의 기본적인 작성법은 Target: Dependency list [Tab] Command 였죠. Rakefile도 유사합니다. 단, Ruby syntax를 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=plusha.com&amp;blog=174108&amp;post=13&amp;subd=plusha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Rakefile은 Makefile과 비슷한 역할을 하는, Ruby script입니다. 따라서 Ruby라는 언어의 강력한 기능들을 그대로 가져다 쓸 수 있다는 장점이 있습니다. 단, Ruby를 알아야 제대로 사용할 수 있겠죠. Makefile을 make라는 명령어로 실행하듯이, Rakefile은 rake라는 명령어로 실행합니다. Rakefile 작성법을 Makefile 작성법과 비교하며 살펴보도록 하겠습니다. Makefile의 기본적인 작성법은<br />
<code>Target: Dependency list<br />
[Tab] Command<br />
</code><br />
였죠. Rakefile도 유사합니다. 단, Ruby syntax를 사용하죠. 기본적인 작성법은 다음과 같습니다.<br />
<code>task :name = [:prereq1, :prereq2] do<br />
    Command<br />
end<br />
</code><br />
Makefile에서 Target에 해당하는 것이 Rakefile의 task입니다. 잘 살펴보면 task라는 함수명과 Hash, Block 두 개의 argument로 이루어진 구조라는 것을 알 수 있습니다. Hash의 key는 target이 되고 value는 prerequisites (dependency list)가 됩니다. Block은 실행해야 할 명령들로 이루어집니다. 특별히 compile하는 경우와 같이 파일을 작성하는 task의 경우에는<br />
<code>file "name" = ["prereq1", "prereq2"] do<br />
    Command<br />
end<br />
</code><br />
와 같이 file task를 사용합니다. Command 부분에서 &#8216;name&#8217; 또는 dependency list (prereq1, prereq2, &#8230; )를 사용하고 싶을 때는<br />
<code>file "name" = ["prereq1", "prereq2"] do |t|<br />
sh "f77 -o #{t.name} #{t.prerequisites.join(' ')}"<br />
end<br />
</code><br />
과 같이 사용하여 <code>f77 -o name prereq1 prereq2</code>와 같은 결과를 얻을 수도 있습니다.</p>
<p>그럼 <a href="http://plusha.com/2008/05/08/makefile-basic/">앞에서 만들었던 Makefile</a>과 같은 기능을 하는 Rakefile을 만들어 비교해 보겠습니다. 앞에서 만들었던 Makefile은 다음과 같고,</p>
<pre><tt><code><span style="color:#000000;">01:</span> <em><span style="color:#9a1900;"># target: dependency list</span></em>
<span style="color:#000000;">02:</span> <em><span style="color:#9a1900;"># [tab] command</span></em>
<span style="color:#000000;">03:</span> <span style="color:#009900;">F77=</span>gfortran
<span style="color:#000000;">04:</span>
<span style="color:#000000;">05:</span> <span style="color:#990000;">all:</span> main
<span style="color:#000000;">06:</span>
<span style="color:#000000;">07:</span> <span style="color:#990000;">main:</span> main.o sub1.o sub2.o
<span style="color:#000000;">08:</span>         <span style="color:#009900;">$(F77)</span> -O<span style="color:#993399;">2</span> -o main main.o sub1.o sub2.o
<span style="color:#000000;">09:</span> <span style="color:#990000;">main.o:</span> main.f
<span style="color:#000000;">10:</span>         <span style="color:#009900;">$(F77)</span> -O<span style="color:#993399;">2</span> -c main.f
<span style="color:#000000;">11:</span> <span style="color:#990000;">sub1.o:</span> sub1.f
<span style="color:#000000;">12:</span>         <span style="color:#009900;">$(F77)</span> -O<span style="color:#993399;">2</span> -c sub1.f
<span style="color:#000000;">13:</span> <span style="color:#990000;">sub2.o:</span> sub2.f
<span style="color:#000000;">14:</span>         <span style="color:#009900;">$(F77)</span> -O<span style="color:#993399;">2</span> -c sub2.f
<span style="color:#000000;">15:</span> <span style="color:#990000;">clean:</span>
<span style="color:#000000;">16:</span>         rm main main.o sub1.o sub2.o</code>
</tt></pre>
<p>이에 해당하는 Rakefile은 다음과 같습니다.</p>
<p><pre class="brush: ruby;">
f90='gfortran'

task :default =&gt; ['main.e']
file 'main.e' =&gt; ['main.o','sub1.o','sub2.o'] do |t|
    sh &quot;#{f90} -o #{t.name} main.o sub1.o sub2.o&quot;
end

file 'main.o' =&gt; ['main.f'] do
    sh &quot;#{f90} -c main.f&quot;
end
file 'sub1.o' =&gt; ['sub1.f'] do
    sh &quot;#{f90} -c sub1.f&quot;
end
file 'sub2.o' =&gt; ['sub2.f'] do
    sh &quot;#{f90} -c sub2.f&quot;
end

require 'rake/clean'
CLEAN.include('*.o')
CLOBBER.include('main.e')
</pre></p>
<p><code>task :default</code> 부분은 Makefile에서 all 이라는 target을 지정해서 사용했던 것과 같은 역할을 합니다. 단, Rakefile에서는 default task가 맨 처음에 나올 필요가 없습니다. 파일 내 아무데나 나와도 잘 인식합니다. 중간 부분은 Makefile과 매우 유사하므로 특별한 설명이 필요 없겠죠? 뒤에 있는 clean task는 rake에 이미 지정되어 있는 task입니다. 사용하기 위해서는 &#8216;rake/clean&#8217;을 불러옵니다. <code>rake clean</code>을 실행하면 CLEAN에 포함된 파일들을 지워주고 <code>rake clobber</code>를 실행하면 CLOBBER와 CLEAN에 지정된 파일들을 모두 지워줍니다. 위에서 볼 수 있는 것처럼, 최종 결과 파일만 CLOBBER에 포함시키고 중간에 생성되는 파일들은 CLEAN에 포함시키면 편리하게 사용할 수 있습니다.</p>
<p>Makefile에서는 확장자법칙을 이용해 편리하게 compile할 수 있었죠? Rakefile에도 같은 기능이 있습니다. 비교해볼까요?</p>
<pre><tt><code><span style="color:#000000;">01:</span> <em><span style="color:#9a1900;"># $^ : dependency list</span></em>
<span style="color:#000000;">02:</span> <em><span style="color:#9a1900;"># $@ : target</span></em>
<span style="color:#000000;">03:</span>
<span style="color:#000000;">04:</span> <span style="color:#009900;">F77=</span>ifort
<span style="color:#000000;">05:</span> <span style="color:#009900;">FFLAG=</span>-assume byterecl -O<span style="color:#993399;">2</span>
<span style="color:#000000;">06:</span> <span style="color:#009900;">TARGET=</span>main
<span style="color:#000000;">07:</span> <span style="color:#009900;">OBJECTS=</span>main.o sub1.o sub2.o
<span style="color:#000000;">08:</span>
<span style="color:#000000;">09:</span> <span style="color:#990000;">all:</span> <span style="color:#009900;">$(TARGET)</span>
<span style="color:#000000;">10:</span>
<span style="color:#000000;">11:</span> <span style="color:#009900;">$(TARGET)</span><span style="color:#990000;">:</span> <span style="color:#009900;">$(OBJECTS)</span>
<span style="color:#000000;">12:</span>         <span style="color:#009900;">$(F77)</span> -o <span style="color:#009900;">$@</span> <span style="color:#009900;">$^</span>
<span style="color:#000000;">13:</span>
<span style="color:#000000;">14:</span> <strong><span style="color:#000080;">.SUFFIXES:</span></strong> .o .f
<span style="color:#000000;">15:</span> <span style="color:#990000;">%</span>.o<span style="color:#990000;">:</span> <span style="color:#990000;">%</span>.f
<span style="color:#000000;">16:</span>         <span style="color:#009900;">$(F77)</span> <span style="color:#009900;">${FFLAG}</span> -c <span style="color:#009900;">$^</span>
<span style="color:#000000;">17:</span>
<span style="color:#000000;">18:</span> <span style="color:#990000;">clean:</span>
<span style="color:#000000;">19:</span>         rm <span style="color:#009900;">$(TARGET)</span> <span style="color:#009900;">$(OBJECTS)</span></code>
</tt></pre>
<p><pre class="brush: ruby;">
F90='ifort'
FFLAG='-assume byterecl -O2'
TARGET='main.e'
SRC=FileList['*.f']
OBJ=SRC.ext('o')

task :default =&gt; TARGET
file TARGET =&gt; OBJ do
    sh &quot;#{F90} -o #{TARGET} #{OBJ}&quot;
end
rule '.o' =&gt; '.f' do |t|
    sh &quot;#{F90} #{FFLAG} -c #{t.source}&quot;
end

require 'rake/clean'
CLEAN.include('*.o')
CLOBBER.include('main.e')
</pre></p>
<p>Rakefile에서는 rule이라는 함수가 Makefile의 확장자법칙과 같은 역할을 합니다. FileList 명령은 glob pattern (여기서는 &#8216;*.f&#8217;)을 받아들여서 해당하는 파일들의 목록을 만들어주고, FileList 객체의 ext method는 목록에 있는 파일들의 확장자를 원하는 확장자로 바꿔서 새로운 FileList를 만들어줍니다. 앞에서 dependency list를 불러올 때 <code>t.prerequisites.join(' ')</code>이라고 사용했었는데 여기서는 <code>t.source</code>라고 사용했습니다. 앞의 방법은 전체 dependency list를 문자열로 만들어주고(&#8216; &#8216;을 이용하여 각각을 합치죠), 뒤의 방법은 dependency list의 첫 번 째 항목만 문자열로 만들어줍니다. 위의 예에서는 dependency list에 &#8216;.o&#8217;에 해당하는 &#8216;.f&#8217; 파일 하나만 있으니까 <code>t.source</code>라고 사용해도 무관하겠죠?</p>
<p>Makefile에 없고 Rakefile에만 있는 기능 중 하나로, task에 설명을 달 수 있는 기능이 있습니다. task 또는 file task 바로 윗 줄에<br />
<code>desc "description"</code><br />
이라고 설명을 추가해주면 <code>rake -T</code>라고 실행했을 때 설명과 함께 task 목록을 보여줍니다. Rakefile을 직접 보지 않고도 안에 무슨 task가 있는지 확인할 수 있는 유용한 기능이죠^^</p>
<p>더 자세한 내용은 다음의 site들을 참고하세요.<br />
<a href="http://rake.rubyforge.org/">http://rake.rubyforge.org/</a><br />
<a href="http://docs.rubyrake.org/">http://docs.rubyrake.org/</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/plusha.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/plusha.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/plusha.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/plusha.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/plusha.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/plusha.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/plusha.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/plusha.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/plusha.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/plusha.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/plusha.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/plusha.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/plusha.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/plusha.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/plusha.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/plusha.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=plusha.com&amp;blog=174108&amp;post=13&amp;subd=plusha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://plusha.com/2008/05/20/rakefile-basic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">plusha</media:title>
		</media:content>
	</item>
		<item>
		<title>Custom Rake Applications</title>
		<link>http://plusha.com/2006/06/03/custom-rake-applications/</link>
		<comments>http://plusha.com/2006/06/03/custom-rake-applications/#comments</comments>
		<pubDate>Sat, 03 Jun 2006 06:04:48 +0000</pubDate>
		<dc:creator>plusha</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Rakefile]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://plusha.wordpress.com/?p=9</guid>
		<description><![CDATA[Reference Rake를 Rakefile을 이용하여 실행하지 않고 library로 사용하는 방법입니다.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=plusha.com&amp;blog=174108&amp;post=9&amp;subd=plusha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.onestepback.org/index.cgi/Tech/Rake/CustomRakeApplications.blog.red">Reference</a></p>
<p>Rake를 Rakefile을 이용하여 실행하지 않고 library로 사용하는 방법입니다.</p>
<p><pre class="brush: ruby;">
#!/usr/bin/env ruby

#gem 'rake', '&gt;= 0.7.3'
require 'rake'

Rake.application.init('server')

### (write a Rakefile here)

Rake.application.top_level
</pre></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/plusha.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/plusha.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/plusha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/plusha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/plusha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/plusha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/plusha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/plusha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/plusha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/plusha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/plusha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/plusha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/plusha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/plusha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/plusha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/plusha.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=plusha.com&amp;blog=174108&amp;post=9&amp;subd=plusha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://plusha.com/2006/06/03/custom-rake-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">plusha</media:title>
		</media:content>
	</item>
	</channel>
</rss>
