Rake to create a C application

I am trying to port the C application I was working on to use Rake insead GNU Make. The file tree looks something like this:

project β”œβ”€β”€ LICENSE.md β”œβ”€β”€ Makefile β”œβ”€β”€ Rakefile β”œβ”€β”€ README.md └── src β”œβ”€β”€ debug.h β”œβ”€β”€ main.c β”œβ”€β”€ queue.c β”œβ”€β”€ queue.h └── ui β”œβ”€β”€ ui.c └── ui.h 

I want to create each file in a separate build directory and generate dependencies of each .c file using gcc or clang in the deps folder.

I can't find examples of how to write a Rakefile to compile a C project. Does anyone have a link or some tips to help me get started?

EDIT: I have a temporary Rakefile that performs some of the tasks I want to end up doing this. I would like to determine if clang is installed and use clang or gcc.

Here is my current Rakefile https://github.com/Rostepher/spoticli/blob/master/Rakefile

+8
c ruby rake
source share
2 answers

Use Ceedling!

https://github.com/ThrowTheSwitch/Ceedling

This is an automated unit test framework for C, but also an excellent job in simple construction. You should be able to get what you are looking for by editing the YAML configuration file, and you will get Rake tasks to build the finished product. Of course, you can create your own Rake tasks.

As a bonus, you can create mocks with CMock and automatic unit tests with Unity.

It is very easy to install in gem:

> gem install ceedling

+3
source share

If you are trying to create your own extension so that you can compile the Ruby interface for C code, this is another problem, but I think you're looking for how to use mkmf from rake. While you could strip the rakefile to do as you would for a C project, there would be a lot of extra effort that tools like mkmf have already done for you. Take a look at: http://ruby-doc.org/stdlib-2.0.0/libdoc/mkmf/rdoc/MakeMakefile.html

Basically you just pass the arguments needed for mkmf and it will generate a makefile for you and run it. The documentation here says that it is designed to create extensions, but if you don’t write any additional code that is irrelevant, and it just compiles your code, as in a raw makefile.

As a side note: if you are looking for a more dynamic creation tool or a tool for dynamically creating makefiles, CMake would be a better option than building a hacked rake assembly.

0
source share

All Articles