Skip to content

Instantly share code, notes, and snippets.

@nazgob
Created November 25, 2010 10:22
Show Gist options
  • Save nazgob/715170 to your computer and use it in GitHub Desktop.
Save nazgob/715170 to your computer and use it in GitHub Desktop.
sample Rakefile for building c++ project / inc lib / .rb extension just for GH to color stuff
require 'rake/clean'
PROG = "foo"
LIBNAME = PROG
LIBFILE = "lib#{LIBNAME}.a"
SRC = FileList['**/*.cpp']
OBJDIR = 'obj'
OBJ = SRC.collect { |fn| File.join(OBJDIR, File.basename(fn).ext('o')) }
CLEAN.include(OBJ, OBJDIR, LIBFILE)
CLOBBER.include(PROG)
task :default => [:build, :run]
task :build => [PROG]
task :run => [PROG] do
sh "./#{PROG}"
end
file PROG => [LIBFILE] do
sh "g++ -o #{PROG} -L . -l#{LIBNAME}"
end
file LIBFILE => OBJ do
sh "ar cr #{LIBFILE} #{OBJ}"
sh "ranlib #{LIBFILE}"
end
directory OBJDIR
rule '.o' => lambda{ |objfile| find_source(objfile) } do |t|
Task[OBJDIR].invoke
sh "g++ -c -o #{t.name} #{t.source}"
end
def find_source(objfile)
base = File.basename(objfile, '.o')
SRC.find { |s| File.basename(s, '.cpp') == base }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment