{"id":272,"date":"2010-09-01T09:29:27","date_gmt":"2010-09-01T14:29:27","guid":{"rendered":"http:\/\/hoolihan.net\/blog-tim\/?p=272"},"modified":"2010-09-03T08:42:48","modified_gmt":"2010-09-03T13:42:48","slug":"rake-breathing-new-life-to-building-old-projects","status":"publish","type":"post","link":"http:\/\/hoolihan.net\/blog-tim\/2010\/09\/01\/rake-breathing-new-life-to-building-old-projects\/","title":{"rendered":"Rake Breathing New Life to Building Old Projects"},"content":{"rendered":"<p>I&#8217;ve seen lots of examples of rake (the ruby make replacement) being used as a build tool in non-ruby projects.  Many of these are still modern platforms, like .Net.  For example, <a href=\"http:\/\/structuremap.github.com\">StructureMap<\/a> builds with rake.  But I&#8217;ve found that even on older platforms, the power of having a full programming language in your build tool is useful.<\/p>\n<p>Recently, I was working through examples in <a href=\"http:\/\/www.amazon.com\/gp\/product\/0139798099?ie=UTF8&#038;tag=timhoosblo-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0139798099\"><em>Thinking in C++<\/em><\/a><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.assoc-amazon.com\/e\/ir?t=timhoosblo-20&#038;l=as2&#038;o=1&#038;a=0139798099\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" \/>, and there is the need to build many small one file examples.  I started writing a Makefile to simplify this, and decided to try rake instead.  <\/p>\n<p>The power of a programming language brings a lot to table when doing repetitive tasks.  Check out the following Rakefile which generates a build, run, and clean method for each file listed in an array.  And there are aggregate methods which will run or clean all.<\/p>\n<pre>\r\n<code>exe_name = [\"hello\",\"c_in_cpp\",\"file\",\"vector\"]\r\n\r\nexe_name.each do |f|\r\n  desc \"clean #{f}\"\r\n  task \"clean_#{f}\".to_sym do\r\n    sh \"rm -rf #{f} #{f}.o\"\r\n  end\r\n\r\n  desc \"build #{f}\"\r\n  task \"build_#{f}\".to_sym =&gt; \"clean_#{f}\" do\r\n    sh \"g++ #{f}.cpp -o #{f}\"\r\n  end\r\n\r\n  desc \"run #{f}\"\r\n  task \"run_#{f}\".to_sym =&gt; \"build_#{f}\" do\r\n    sh \".\/#{f} 2&gt; error.log\"\r\n  end\r\nend\r\n\r\ndesc \"run all\"\r\ntask :default =&gt; exe_name.collect{|f| \"run_#{f}\"}\r\n\r\ndesc \"clean all\"\r\ntask :clean =&gt; exe_name.collect{|f| \"clean_#{f}\"}<\/code>\r\n<\/pre>\n<p>If any of the above is unclear, and you want to see the output, do the following:  copy and paste that code into a file named &#8220;Rakefile&#8221;.  Run &#8220;rake -T&#8221; to lists all available tasks.  You won&#8217;t be able to actually run the tasks, unless you have the appropriate cpp files in the directory (ie &#8220;rake run_hello&#8221; requires hello.cpp).  <\/p>\n<p>If you want to learn a build tool, and know ruby, or want to learn ruby rather than some specialized build language with no other uses, give rake a shot.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve seen lots of examples of rake (the ruby make replacement) being used as a build tool in non-ruby projects. Many of these are still modern platforms, like .Net. For example, StructureMap builds with rake. But I&#8217;ve found that even on older platforms, the power of having a full programming language in your build tool [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[105,69,272,113,271],"class_list":["post-272","post","type-post","status-publish","format-standard","hentry","category-programming","tag-c","tag-linkedin","tag-programming","tag-rake","tag-ruby"],"_links":{"self":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts\/272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/comments?post=272"}],"version-history":[{"count":0,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts\/272\/revisions"}],"wp:attachment":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/media?parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/categories?post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/tags?post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}