Created
November 25, 2010 10:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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