Reputation: 201
I'm attempting to migrate a C application I have been working on to use Rake insead of GNU Make. The file tree is something like:
project
├── LICENSE.md
├── Makefile
├── Rakefile
├── README.md
└── src
├── debug.h
├── main.c
├── queue.c
├── queue.h
└── ui
├── ui.c
└── ui.h
I want to build each file in a separate build
directory and generate the dependencies of each .c
file with either gcc
or clang
in a deps directory.
I cannot seem to find any examples of how to write a Rakefile to compile a C project. Does anyone have a link or some advice to help me get started?
EDIT: I have a temporary Rakefile that accomplishes some of the tasks I want it to eventually do. I would like to detect if clang is installed and use clang or gcc.
Here is my current Rakefile https://github.com/Rostepher/spoticli/blob/master/Rakefile
Upvotes: 8
Views: 1516
Reputation: 374
If you're trying to generate a native extension so you can compile a Ruby interface to C code this is a different issue, but I think what you are looking for is how to use mkmf from rake. While you could bare-knuckle a rakefile into acting like make for a C project it 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'll just pass the arguments needed to mkmf and it will generate a makefile for you and run it. The documentation here says it's for building extensions but if you don't write any extension code that's irrelevant and it will just compile your code like a raw makefile would.
As a side note: If you're looking for a more dynamic make tool or a tool to dynamically generate makefiles CMake would be a better option than putting together a hackish rake build.
Upvotes: 0
Reputation: 818
Use Ceedling!
https://github.com/ThrowTheSwitch/Ceedling
It's an automated unit test framework for C, but does a great job of simply building as well. You should be able to get what your looking for by editing a YAML config file, and you'll get Rake tasks for building out-of-the box. Of course you can create your own custom Rake tasks as well.
As a bonus you can create mocks with CMock and automated unit tests with Unity.
It's super easy to install from a gem:
> gem install ceedling
Upvotes: 4