• Articles
  • Ceedling Book
  • Eclipse Toolkit
  • About
Menu

ElectronVector - Test-First Embedded Software

Better embedded software
  • Articles
  • Ceedling Book
  • Eclipse Toolkit
  • About

Get your free guide: How to use Ceedling for embedded test-driven development

Rake: An Alternative to Make for Embedded C Applications

January 9, 2015

Make has been traditionally been used for building embedded applications written in C. However Make has its issues. For example, it suffers from heavy reliance upon the host environment, arcane syntax and mysterious bugs due to whitespace issues.

Rake is a powerful and capable alternative, and I recommend you consider it for future projects. It's standardized, available on many platforms and backed by the full power of a real programming language.

Rake is used as the build system for the Ruby programming language. As part of the Ruby on Rails framework, Ruby is used by a large community of developers. With such a large development community, support and reference materials are easy to come by.

Rake uses Ruby syntax. Coming from C, the syntax takes a little bit to get used to, but it's well worth it in my opinion.

Although Rake is heavily linked to Ruby, it's language-agnostic as far as the target build is concerned. You can use it to build essentially any type of application, provided you point it to the correct tools. This includes cross-compiling toolchains for embedded targets as well.

Rake is available with Ruby on most major platforms, including Linux, OSX and Windows. Since it runs under Ruby, it does not rely on the host environment for simple operations like file or directory manipulation. These operations are built directly in Ruby and make Rakefiles platform independent.

Installation

Rake is included in Ruby installations 1.9 and later. To install Ruby, follow the directions for your platform here:

https://www.ruby-lang.org/en/documentation/installation/

Generally, use a package manager for Linux or OS X and use RubyInstaller for Windows.

After installation you'll want to make sure that the Ruby binaries are in your path.

Getting Started

Rake works on Rakefiles, which consists of tasks (like Make targets) with specifed dependencies.

Here's a simple Rakefile:

task :default do
    puts "Hello World"
end

This file defines a single task -- the "default" task -- which simply prints some text using puts. The default task is the task run when no task argument is provided to Rake at the command line.

$ rake
Hello World

We can add another task, and make the default task depend on this new task:

task :newtask do
    puts "Hi"
end

task :default => :newtask do
    puts "Hello World"
end

When we run the default task, newtask is run first.

$ rake
Hi
Hello World

We can also run the new task individually.

$ rake newtask
Hi

References

For more information, check out the official Rake documentation. Also there are several really good Rake tutorials online:

  • Virtuous Code - Rake Part 1: Files and Rules
  • Jason Seifer - Rake Tutorial
  • StuartEllis.eu - Using Rake to Automate Tasks
← Using Rake to Build a Simple C Application
Matt Chernoksy

Matt Chernosky


book-3d.png

Need more help with Ceedling?

A Field Manual for Ceedling is filled with examples for how to write tests (and create mocks) for your embedded software.

Get the Book

Add unit tests to your current project with Ceedling

Try embedded TDD right now with Ceedling

Mocking embedded hardware interfaces with Ceedling and CMock

CMock vs FFF -- A comparison of mocking frameworks


Don't miss a post!

Sign up here and I'll keep you in the loop.

ElectronVector