Rake

Using Rake
rake -T    List available tasks for a Rakefile rake -n    Dry run - do nothing but list actions rake -s    Suppress confusing directory messages

Simple Example
task :default => :hello desc "This task prints out a 'hello world' message" task :hello do    puts "hello world" end

Tasks
Tasks are created using this syntax: task :doSomething => :prereq1 A more elaborate example, where 't' is a reference to the task, and the closure may call Rake::Task methods on it: task :doSomething => [:prereq1, :prereq2] do |t| ... # you could call t.name to get 'doSomething' end or

Files
How to create some file file "somefile" do |t| ... t.name end

Rules
Example C++ rule rule '.o' => ['.cpp'] do |t| sh "g++ #{t.source} -c -o #{t.name}" end

Clean and Clobber
require 'rake/clean' CLEAN.include('*.{o,tmp}') CLOBBER.include('myprogram')

Generating Multiple Files
This example includes dependency on a set of files and a directory and removing them when cleaning. require 'rake/clean' require 'find' CLEAN.include 'testFiles' TEMPFILES = (0..9).collect { |x| "testFiles/tempFile#{x}" } directory 'testFiles' task :default => :generate desc "Generate 10 empty files in testFiles/." task :generate => ['testFiles'] + TEMPFILES rule( /testFiles\/tempFile.$/ ) do |t| touch t.name end
 * 1) clean by removing this dir
 * 1) generates an array with 10 'testFiles/tempFile[n]' files
 * 1) create this if needed
 * 1) How to generate a tempFile

LaTeX
require 'rake/clean' task :default => [ 'slides.pdf', :clean ] PUBLISH_TARGET="/home/schmid/web/schmid.dk/htdocs/slides.pdf" FIGURES=FileList['*.svg'] PDF_FIGURES=FIGURES.ext('pdf') file 'slides.pdf' => ['slides.tex', 'preamble.tex', 'Rakefile'] + PDF_FIGURES LATEX_OPTIONS="--quiet" CLEAN.include('*.{aux,snm,toc,nav,out}') CLOBBER.include('slides.pdf', PDF_FIGURES) rule '.pdf' => '.tex' do |t| # rule: object files are made from source files sh "pdflatex #{LATEX_OPTIONS} #{t.source}" sh "pdflatex #{LATEX_OPTIONS} #{t.source}" sh "pdflatex #{LATEX_OPTIONS} #{t.source}" end rule '.pdf' => '.svg' do |t| sh "convert #{t.source} #{t.name}" end rule '.pdf' => '.png' do |t| sh "convert #{t.source} #{t.name}" end
 * 1) DEPENDENCIES ---
 * 1) OPTIONS
 * 1) HOUSECLEANING --
 * 1) COMPILING --
 * 1) GRAPHICS CONVERSION

Doing Different Stuff on Different Hosts
require 'socket' case Socket::gethostname when 'host1' ... else ... end

Subdirectories
task :default do    sh 'cd largeScale && rake' sh 'cd smallArea && rake' end

Rake on Win32
- see Windows Tools page

Quick-Download Rake to Current Dir
wget http://rubyforge.org/frs/download.php/9500/rake-0.7.1.zip unzip -j rake-0.7.1.zip rake-0.7.1/lib/rake.rb rm rake-0.7.1.zip

Using Vim and Rake on Win32
:mak
 * 1) start gvim from msys shell (otherwise rake won't run)
 * 2) run commands: