From Schmid.wiki
Jump to: navigation, search

Sample Rakefile

# Options
OUTPUT_DIR      = "/some/dir"

COMPILE_OPTIONS = '-g'
INCLUDE_DIRS = FileList["somewhere/include"]
LINK_OPTIONS    = 
LIBRARY_OPTIONS = "-Lsomewhere -lsomelib"

# Dependencies
file 'something.o'        => ['something.cpp', 'something.h']
file 'test-something.o'   => ['test-something.cpp']
file 'test-something.exe' => ['test-something.o', 'something.o']

COMMON_OBJECTS = FileList['something.o']

# Tasks
desc 'Build everything.'
task :default => [:tests]
task :tests   => ['test-something.exe']

# Compiling
INCLUDE_OPTIONS = INCLUDE_DIRS.collect do |i| "-I" + i end
rule '.o' => '.cpp' do |target| # rule: object files are made from source files
    sh "g++ #{INCLUDE_OPTIONS} #{COMPILE_OPTIONS} -c -o #{target.name} #{target.source}"
end

rule '.exe' => '.o' do |target|
    sh "g++ -o #{target.name} #{LINK_OPTIONS} #{LIBRARY_OPTIONS} #{target.sources} #{COMMON_OBJECTS}"
    cp target.name, OUTPUT_DIR
end

ctags Support

change:

task :default => [..., :ctags]

add:

# Tags
task :ctags   => 'tags'
CTAGS           = 'c:/bin/ctags'
# which dirs should be scanned recursively by ctags apart from the current:
TAG_DIRS        = INCLUDE_DIRS + ['/path/to/gcc/include/dir']

file 'tags' => 'tags.library' do
    sh "cp tags.library tags"
    sh "#{CTAGS} -a tags -R --c++-kinds=+p --fields=+iaS --extra=+q *.cpp"
end
file 'tags.library' do
    sh "#{CTAGS} -f tags.library -R --c++-kinds=+p --fields=+iaS --extra=+q #{TAG_DIRS}"
end

cscope Support

change:

task :default => [..., :cscope]

add:

# CScope
task :cscope => 'cscope.out'
CSCOPE = 'c:/bin/cscope'
file 'cscope' do
   sh "find -name "*.cpp" -or -name "*.h">cscope.file"
   sh "#{CSCOPE} -b"
end

doxygen support

change:

task :default => [..., :doxygen]

add:

# doxygen
task :doxygen => 'html/index.html'
file 'html/index.html' => FileList['*.cpp', '*.h', 'doxygen.cfg'] do
    sh "doxygen doxygen.cfg"
end