Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Rake - a build system using code written in Ruby

If you're programming in C, C++ or Java, you'll be managing a large number of source files, and using a whole series of commands to build these forward into .o (object) or .class (java class) files, then - in the cases of C and C++ - into executable files.

The make system has been around for as long as I can remember for C (and Fortran and other) builds. It's very clever, but has some curiosities of syntax and its own definition language - and indeed, in the Java world, Apache Ant has been around for quite a while to provide an alternative. And indeed Ant and Make are used extensively for a very wide range of other build tasks these days - far beyond just building or preparing for executable files.

Rake is another build system. It's a Ruby application, and you write a rakefile - the file that describes what depends on what, and how to get from the source to the target of each stage of the process as a piece of Ruby. The rake program, which is written in Ruby, then goes through all the dependencies and builds the code when you run it.

Let's see an example:

  file 'shape.o' => ["shape.c", "shape.h"] do
    sh "gcc -c -o shape.o shape.c"

and that says "if shape.c or shape.h has changed since shape.o was last produced, run the following shell command". It checks the time and date stamps on the various files to see if the work needs to be done and (the clever bit) it will recursively check on the files shape.c and shape.h first to see if they need to be refreshed first, thus provoking a need for shape.o to be refreshed too even if at first glance it's up to date (i.e. newer than either of its dependencies).

By comparison, the same dependency written in a makefile looks like:

shape.o:   shape.c shape.h
            gcc -c -o shape.o shape.cpp

There's a complete rakefile example [here], and the equivalent makefile [here]. The application used in the example is from a recent C++ course ... a whole lot of source files, as it's my worked example of how you would split an application over a series of files with separate header and code files for each class. They are ... shape_main.cpp, square.cpp, square.h, rectangle.cpp, rectangle.h, circle.cpp, circle.h, shape.cpp and shape.h

To run rake, you'll run the rake command at the command line, which runs the ruby program, which in turn pulls in your instructions from the rakefile and does whatever's needed:

munchkin:c5 grahamellis$ rake hereitis
(in /Users/grahamellis/c5)
Compiling shape_main
Compiling shape
Compiling square
Compiling circle
Compiling rectangle
munchkin:c5 grahamellis$ rake hereitis
(in /Users/grahamellis/c5)
munchkin:c5 grahamellis$

So the first time I ran it, all the work had to be done ... the second time, everything was up to date and no compiling of my C++ program was necessary.

Further elements of rake allow you to specify general rules for everything of a particular type, and specify things like "all .h files in a directory" which means you can build up sets of rules with lots of file specified very quickly. And because you have ruby there too, you can write loops and other code to generate a whole lot of elements of your build tree in just a few lines. Although the single source-target example above was shorter in a makefile, typically a rakefile as a whole will be much shorter, and easier to follow too if you knoe Ruby.

Rake is extensively used in Rails. Rails is the Ruby based web framework, and there's a whole range of things such as databases to be setup when you start, refreshed when you update your code and start a fresh set of tests, etc ... and rake is used for these tasks. You'll find that all the standard rake files used by rails when you start using it are there for you, but you may need to get in later. And if - as my customers are doing this week - you're using C++ as a production language and Ruby as your company's scripting standard, it's going to be logical for you to choose rake as your build tool. You can find the rake documentation [here], and about our Ruby courses [here].
(written 2011-02-03, updated 2011-02-10)

Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
R119 - Ruby Miscellany
  [1181] Good Programming practise - where to initialise variables - (2007-05-09)
  [1586] Variable types in Ruby - (2008-03-21)
  [1720] Some Ruby lesser used functions - (2008-07-26)
  [1889] Ruby mixins, modules, require and include - (2008-11-16)
  [1890] MySQL database from Ruby - an example - (2008-11-16)
  [3428] How many days to Christmas? - (2011-09-09)
  [3622] Loading Ruby classes - where does Ruby look? - (2012-02-24)
  [3783] Load path, load and require in Ruby, and a change from 1.8 to 1.9 - (2012-06-24)
  [3799] Ruby Documentation through rdoc - (2012-07-07)

R115 - Using Ruby with Other Languages
  [4676] Running shell (operating system) commands from within Ruby - (2016-05-18)

C051 - C and C based languages - C++ - General
  [2370] C++, Python, and other training - do we use an IDE - (2009-08-21)
  [2504] Learning to program in ... - (2009-11-15)
  [2536] All the Cs ... and Java too - (2009-12-13)
  [2577] Complete teaching example - C++, inheritance, polymorphism - (2010-01-15)
  [2763] Our C and C++ training course are on Open Source platforms - (2010-05-13)
  [2851] Further C++ material - view new or old - (2010-07-04)
  [3052] Getting your C++ program to run - (2010-11-15)
  [3067] Using C and C++ functions in the same program - how to do it - (2010-11-24)
  [3129] Extra courses - C and C++ - (2011-01-12)
  [3250] C++ - how we teach the language and the concepts behind the language - (2011-04-17)
  [3587] C++ Courses - do I get official certification at the end of my Well House course? - (2012-01-20)
  [3809] Dwarf Exception Unwind Info - (2012-07-20)
  [4335] Flexible public courses - residential or commuting, programming newcomer or experienced, C or C++ - (2014-11-30)
  [4355] C++ in 2 days - (2014-12-18)

A509 - Web Application Deployment - Java - Ant build tool
  [694] Ant and Make - (2006-04-22)
  [4708] Scons - a build system in Python - building hello world - (2016-10-29)

Back to
Changing a class later on - Ruby
Previous and next
Horse's mouth home
Forward to
Splitting data reading code from data processing code - Ruby
Some other Articles
Returning multiple values from a function call in various languages - a comparison
Ruby training - some fresh examples for string handling applications
A new monopoly on the ferry to Northern Ireland
Splitting data reading code from data processing code - Ruby
Rake - a build system using code written in Ruby
Changing a class later on - Ruby
Points West to Belfast
Jargon busting
Disassembling Python and Java - previously compiled code
Python dictionaries - mutable and immutable keys and values
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page

This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3155_.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb