From: Leslie Viljoen Date: 2007-06-11T20:06:35+09:00 Subject: Re: Using Rake to build C++ ------=_Part_117391_28407362.1181559995109 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 6/5/07, Magnus Falk wrote: > > I'm making myself a build environment and found this Rake thingy that > seemed just to good to pass upon. But since I don't know any Ruby I'm > struggling a bit. > > I'm making a couple of tasks to compile and link C++ code and it seems > like I've misunderstood the file task somewhat. In the example code > below, the compilation and linking is never run, what am I doing wrong? > > cppTasks.rb: > def compileTask inclDirs, flags > inclDirs = inclDirs.collect { |dir| '-I' + dir } > inclDirs = inclDirs.join(' ') > flags = flags.join(' ') > > SRC_FILES.each do |srcFile| > objFile = File.join(OBJ_DIR, srcFile.pathmap("%f").ext('o')) > file objFile => [srcFile] do > sh "g++ #{inclDirs} #{flags} -c #{srcFile} -o #{objFile}" > end > end > end > > def linkTask libDirs, libs, flags, target > libDirs = libDirs.collect { |dir| '-L' + dir} > libs = libs.collect { |lib| '-l' + (lib[/lib(.+)\./, 1])} > > flags = flags + ((File.extname(target) == '.so') ? ['-shared'] : > ['-c']) > > libDirs = libDirs.join(' ') > libs = libs.join(' ') > flags = flags.join(' ') > > targetFile = File.join(BUILD_DIR, target) > > file targetFile => OBJ_FILES do > objFiles = OBJ_FILES.collect { |objFile| objFile + ' ' } > sh "g++ #{libDirs} #{libs} #{flags} #{objFiles} -o #{targetFile}" > end > end Any luck on your own yet? Take a look at the Rake examples: http://docs.rubyrake.org/read/chapter/1#page3 http://docs.rubyrake.org/read/chapter/9#page31 You need to make TASKs and FILEs, not just functions, although each task and file declaration can call functions. The tutorial is very good and shows a C example. Les -- I always thought Smalltalk would beat Java, I just didn't know it would be called 'Ruby' when it did. -- Kent Beck ------=_Part_117391_28407362.1181559995109--