Chapter 5. Building (compiling) projects with custom Makefiles

Many projects describe how source files have to be compiled (and which files have to be recompiled once a source or header file changes) using Makefiles that are interpreted by the make program (see, for example, GNU make). For simple projects, it is often very easy to set up such a file by hand. Larger projects often integrate their Makefiles with the GNU autotools (autoconf, autoheader, automake). In this section, let us simply assume that you have a Makefile for your project and you want to teach KDevelop how to interact with it.

Note

KDevelop 4.x doesn't know about the GNU autotools at the time this section is written. If your project uses them, you will have to run ./configure or any of the other related commands by hand on a command line. If you want to do this within KDevelop, open the Konsole tool (if necessary add it to the perimeter of the main window using the menu WindowsAdd tool view) that gives you a shell window view and run ./configure from the command line in this view.

The first step is to teach KDevelop about targets in your Makefiles. There are two ways to do that: selecting individual Makefile targets, and choosing a set of targets you may want to build frequently. For both approaches, open the Projects tool by clicking on the Projects button on the perimeter of KDevelop's main window (if you don't have this button see above how to add a tool's button there). The Projects tool window has two parts: the top half — titled Projects — lists all of your projects and let's you expand the underlying directory trees. The bottom half — titled Project Selection — lists a subset of those projects that will be built if you choose the menu item ProjectBuild selection or hit F8; we'll come back to this part below.

Building individual Makefile targets

In the top part of the project view, expand the sub-tree for one project, let's say the one for which you want to run a particular Makefile target. This will give you icons for (i) directories under this project, (ii) files in the top-level directory for this project, (iii) Makefile targets KDevelop can identify. These categories are shown in the picture at right. Note that KDevelop understands Makefile syntax to a certain degree and therefore can offer you targets defined in this Makefile (though this understanding has its limits if targets are composed or implicit).

To build any of the targets listed there, click on it with the right mouse button and select Build. For example, doing this with the clean target will simply execute make clean. You can see this happening in the subwindow titled Build that opens up, showing the command and the output. (This window corresponds to the Build tool, so you can close and later re-open the window using the Build tool button on the perimeter of the main window. It is shown at the bottom right of the picture.)