«

»

Août 29

Robotics 101 : Makefile Survival guide

In the last tutorial we mentioned the other files present in a basic project, let’s take a closer look on one of them : the Makefile.

This tutorial is going to be a short one, as only what you need to build your project will be explained. Nevertheless the Makefile is a really powerful tool and i highly encourage you to learn more about it.

Discover the Makefile :

As you may have noticed, you did not compile your files one at a time, but used the $ make shell command, you may have wondered how the compiler knew what to do with only one command. In facts this $ make command simply tells the compiler to look in the Makefile what do to.

Now open the Makefile, you should see something like this :
makefile1
As you can see, there are a LOOOOT of options, we are only going to cover how to add files, change the c compiler options and specify the location of ChibiOS.

Add a file to compile :

makefile2

Find the part about CSRC, and simply add the path to the other .c files you want to compile. In order to keep on adding files in an other line, simply end the previous one with « \ ».

Change the c compiler options :

makeile4

In order to add/change/delete teh C compiler options, simply change what is written after USE_COPT.

ChibiOS’ location :

makefile3

When you first installed everything, i had you change something in the Makefile remember ? What you did there was simply telling gcc where to find chibiOS sources. Now if you want to change it simply state the path (relative or absolute) to your new chibiOS emplacement.
Note that it is considered a good practice to state the relative path and put every thing in the same folder so that everyone can compile it without specifying a new absolute path.

You may also notice the link to a file named board.mk, it is an other Makefile (yes you can have makefiles in makefiles in makefiles in … if you want), this one is used for the board files, the one that describe your board ans pin use (we will see it in a next part of the tutorial).

And that’s it, you know enough of the Makefile to improve your projects by having more .c files and compiler options (c99 instead of c89 for example…).

Now do something really important : go get an other beer ! You deserve it 🙂

Felix