KDevelop4/Manual/Building (compiling) projects with custom Makefiles: Difference between revisions

    From KDE UserBase Wiki
    m (add category)
    m (add formatting)
    Line 1: Line 1:
    <languages />
    <translate>
    == Building (compiling) projects with custom Makefiles ==
    == 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, [http://www.gnu.org/software/make/ 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.
    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, [http://www.gnu.org/software/make/ 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|1=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 <code>./configure</code> 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 <menuchoice>Windows > Add tool view</menuchoice>) that gives you a shell window view and run <code>./configure</code> from the command line in this view.}}
    {{Note|1='''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 <code>./configure</code> 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 <menuchoice>Windows -> Add tool view</menuchoice>) that gives you a shell window view and run <code>./configure</code> from the command line in this view.}}


    The first step is to teach KDevelop about targets in your Makefiles. There
    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
    are two ways to do that: selecting individual Makefile targets, and choosing a
    the <menuchoice>Projects</menuchoice> tool by clicking on the <menuchoice>Projects</menuchoice> 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 <menuchoice>Projects</menuchoice> tool window has two parts: the top half &mdash; titled <menuchoice>Projects</menuchoice> &mdash; lists all of your projects and let's you expand the underlying directory trees. The bottom half &mdash; titled <menuchoice>Project Selection</menuchoice> &mdash; lists a subset of those projects that will be built if you choose the menu item <menuchoice>Project -> Build selection</menuchoice> or hit <keycap>F8</keycap>; we'll come back to this part below.
    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
    </translate><span id="Building individual Makefile targets"></span><translate>
    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
    &mdash; titled "Projects" &mdash; lists all of your projects and let's you
    expand the underlying directory trees. The bottom half &mdash; titled "Project
    Selection" &mdash; lists a subset of those projects that will be built if you
    choose the menu item "Project > Build selection" or hit F8; we'll come back to
    this part below.


    === Building individual Makefile targets ===
    === Building individual Makefile targets ===


    In the top part of the project view, expand the sub-tree for one project,
    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).
    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 <i>understands</i> 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).


    [[Image:kdevelop-1a.png|thumb|500px|right]]
    [[Image:kdevelop-1a.png|thumb|500px|right]]


    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.)
    To build any of the targets listed there, click on it with the right mouse button and select <menuchoice>Build</menuchoice>. For example, doing this with the "clean" target will simply execute "make clean". You can see this happening in the subwindow titled <menuchoice>Build</menuchoice> that opens up, showing the command and the output. (This window corresponds to the <menuchoice>Build</menuchoice> tool, so you can close and later re-open the window using the <menuchoice>Build</menuchoice> tool button on the perimeter of the main window. It is shown at the bottom right of the picture.)
     
    </translate><span id="Selecting a collection of Makefile targets for repeated building"></span><translate>


    === Selecting a collection of Makefile targets for repeated building ===
    === Selecting a collection of Makefile targets for repeated building ===


    Right-clicking on individual Makefile targets every time you want to build
    Right-clicking on individual Makefile targets every time you want to build something will quickly get old. Rather, we'd like to have individual targets for one or more of the projects in the session that we can repeatedly build without much mouse work. This is where the concept of "Build target selections" comes in: it is a collection of Makefile targets that are built one-after-the-other whenever you hit the <menuchoice>Build selection</menuchoice> button in the button list at the top, select the <menuchoice>Project -> Build selection</menuchoice> menu item, or
    something will quickly get old. Rather, we'd like to have individual targets
    hit the <keycap>F8</keycap> function key.
    for one or more of the projects in the session that we can repeatedly build
    without much mouse work. This is where the concept of "Build target
    selections" comes in: it is a collection of Makefile targets that are built
    one-after-the-other whenever you hit the "Build selection" button in the
    button list at the top, select the <menuchoice>Project > Build selection</menuchoice> menu item, or
    hit the F8 function key.


    The list of selected Makefile targets is shown in the bottom half of the
    The list of selected Makefile targets is shown in the bottom half of the <menuchoice>Projects</menuchoice> tool view.
    "Projects" tool view.
    By default, the selection contains all projects, but you can change that. For example, if your list of projects contains three projects (a base library L and two applications A and B), but you're currently only working on project A, then you may want to remove project B from the selection by highlighting it in the selection and hitting the red <menuchoice>-</menuchoice> button. Furthermore, you probably want to make sure that the library L is built before  project A by moving entries in the selection up and down using the buttons to the right of the list. You can also get a particular Makefile target into the selection by right-clicking onto it and selecting <menuchoice>Add to buildset</menuchoice>, or just highlighting it and hitting the green <menuchoice>+</menuchoice> button just above the list of selected targets.
    By default, the selection contains all projects, but you can change that. For
    example, if your list of projects contains three projects (a base library L and two applications A and B), but you're currently only working on project A, then you may want to
    remove project B from the selection by highlighting it in the selection and
    hitting the red "-" button. Furthermore, you probably want to make sure that
    the library L is built before  project A by moving entries in
    the selection up and down using the buttons to the right of the list.
    You can also get a particular Makefile target into the selection by
    right-clicking onto it and selecting <menuchoice>Add to buildset</menuchoice>, or just highlighting
    it and hitting the green "+" button just above the list of selected targets.


    KDevelop allows you to configure what to do whenever you build the
    KDevelop allows you to configure what to do whenever you build the selection. To this end, use the menu item <menuchoice>Project -> Open configuration</menuchoice>. There, you can for example select the number of simultaneous
    selection. To this end, use the menu item <menuchoice>Project > Open
    jobs "make" should execute &mdash; if your computer has, say, 8 processor cores, then entering 8 in this field would be a useful choice. In this dialog, the <menuchoice>Default make target</menuchoice> is a Makefile target used for '''all''' targets in the selection.
    configuration</menuchoice>. There, you can for example select the number of simultaneous
     
    jobs "make" should execute &mdash; if your computer has, say, 8 processor
    </translate><span id="What to do with error messages"></span><translate>
    cores, then entering 8 in this field would be a useful choice. In this dialog, the "Default make target" is a Makefile target used
    for '''all''' targets in the selection.


    === What to do with error messages ===
    === What to do with error messages ===


    If the compiler encounters an error message, simply click on the line with the error message and the editor will jump to the line (and if available column) where the error was reported. Depending on the error message, KDevelop may also offer you several possible actions to fix the error, for example by declaring a previously undeclared variable if an unknown symbol was found.
    If the compiler encounters an error message, simply click on the line with the error message and the editor will jump to the line (and if available column) where the error was reported. Depending on the error message, '''KDevelop''' may also offer you several possible actions to fix the error, for example by declaring a previously undeclared variable if an unknown symbol was found.
     
    {{Prevnext2
    | prevpage=Special:MyLanguage/KDevelop4/Manual/Working_with_source_code | nextpage=Special:MyLanguage/KDevelop4/Manual/Running_programs
    | prevtext=Working with source code | nexttext=Running programs
    | index=Special:MyLanguage/KDevelop4/Manual | indextext=Back to menu
    }}


    [[Category:Development]]
    [[Category:Development]]
    </translate>

    Revision as of 15:25, 18 May 2011

    Other languages:

    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 Windows -> Add 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 Project -> Build 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.)

    Selecting a collection of Makefile targets for repeated building

    Right-clicking on individual Makefile targets every time you want to build something will quickly get old. Rather, we'd like to have individual targets for one or more of the projects in the session that we can repeatedly build without much mouse work. This is where the concept of "Build target selections" comes in: it is a collection of Makefile targets that are built one-after-the-other whenever you hit the Build selection button in the button list at the top, select the Project -> Build selection menu item, or hit the F8 function key.

    The list of selected Makefile targets is shown in the bottom half of the Projects tool view. By default, the selection contains all projects, but you can change that. For example, if your list of projects contains three projects (a base library L and two applications A and B), but you're currently only working on project A, then you may want to remove project B from the selection by highlighting it in the selection and hitting the red - button. Furthermore, you probably want to make sure that the library L is built before project A by moving entries in the selection up and down using the buttons to the right of the list. You can also get a particular Makefile target into the selection by right-clicking onto it and selecting Add to buildset, or just highlighting it and hitting the green + button just above the list of selected targets.

    KDevelop allows you to configure what to do whenever you build the selection. To this end, use the menu item Project -> Open configuration. There, you can for example select the number of simultaneous jobs "make" should execute — if your computer has, say, 8 processor cores, then entering 8 in this field would be a useful choice. In this dialog, the Default make target is a Makefile target used for all targets in the selection.

    What to do with error messages

    If the compiler encounters an error message, simply click on the line with the error message and the editor will jump to the line (and if available column) where the error was reported. Depending on the error message, KDevelop may also offer you several possible actions to fix the error, for example by declaring a previously undeclared variable if an unknown symbol was found.