[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9. Compilation/Build

This chapter describes how to compile files, build executables and run them. Most capabilities can be accessed through the Build menu item, or through the Build and Run contextual menu items, as described in the following section.

When compiler messages are detected by GPS, an entry is added in the Locations tree, allowing you to easily navigate through the compiler messages (see 2.8 The Locations Tree), or even to automatically correct some errors or warnings (see 13.3 Code Fixing).

9.1 The Build Menu  
9.2 Integrating existing build procedures with the GPS build system  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.1 The Build Menu

The build menu gives access to capabilities related to checking, parsing and compiling files, as well as creating and running executables.

Check Syntax
Check the syntax of the current source file. Display an error message in the Messages window if no file is currently selected.

Compile File
Compile the current file. Display an error message in the Messages window if no file is selected.

If errors or warnings occur during the compilation, the corresponding locations will appear in the Locations Tree. If the corresponding Preference is set, the source lines will be highlighted in the editors (see 15.1 The Preferences Dialog). To remove the highlighting on these lines, remove the files from the Locations Tree.

Make
main
For each main source file defined in your top level project, an entry is listed to build (compile, bind, link) this source file. Similarly the Build contextual menu accessible from a project entity contains the same entries.

Project
Build all source files defined in your top level project.

<current file>
Consider the currently selected file as a main file, and build it.

Custom...
Display a text entry where you can enter any external command. This menu is very useful when you already have existing build scripts, make files, ... and want to invoke them from GPS.

Recompute C/C++ Xref info
Recompute the cross-reference information for C and C++ source files. See section 6.1 Support for Cross-References.

Run
main
For each main source file defined in your top level project, an entry is listed to run the executable associated with this main file. Running an application will first open a dialog where you can specify command line arguments to your application, if needed. You can also specify whether the application should be run within GPS (the default), or using an external terminal.

When running an application from GPS, a new execution window is added in the bottom area where input and output of the application is handled. This window is never closed automatically, even when the application terminates, so that you can still have access to the application's output. If you explicitly close an execution window while an application is still running, a dialog window will be displayed to confirm whether the application should be terminated.

When using an external terminal, GPS launches an external terminal utility that will take care of the execution and input/output of your application. This external utility can be configured in the preferences dialog (Helpers->Execute command).

Similarly, the Run contextual menu accessible from a project entity contains the same entries.

Custom...
Similar to the entry above, except that you can run any arbitrary executable.

Interrupt
Interrupt the current compilation or build.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.2 Integrating existing build procedures with the GPS build system

Note that this capability is not fully supported yet.

Since the multi-language build system provided by GPS is based on makefiles, it is possible to integrate existing build scripts and makefiles. In the following section, we will call such projects that integrate with existing build procedures a foreign project.

You first need to provide your own Makefile.<project> file, that will provide stubs to the real build commands.

Then to tell GPS that it should not generate automatically the makefile corresponding to a given project, set the read-only attribute on the makefile, e.g under Unix:

 
$ chmod -w Makefile.<project>

or under Windows:

 
> attrib +r Makefile.<project>

This way when saving the project, GPS knows that the existing makefile should not be overridden.

Depending on your project, you will need to define some or all of the following targets in the makefile stub:

internal-build
This is the main rule, used for building all the files for a foreign project.

internal-clean
This is an optional rule, used to clean the temporary files, e.g. the object files generated during the build.

SRC_DIRS
Blank separated list of source directories.

LDFLAGS
Linker options (e.g. libraries or objects to link with).

DEPS_PROJECTS
List of projects (foreign or non foreign) that this project depends upon.

For example, suppose we have a foreign project called Foo, with an existing makefile, here is how Makefile.foo would look like:

 
ifeq ($(FOO_PROJECT),)
FOO_PROJECT=True

ifeq ($(BASE_DIR),)
   BASE_DIR=$(shell pwd)
   FOO_ROOT=True

# Redirect clean to the real clean rule
   internal-clean:
        $(MAKE) clean

# Ditto for the build rule
   internal-build:
        $(MAKE) build
endif

FOO_BASE_DIR := $(BASE_DIR)

# Add our source directories to the default search path
# so that other projects can reference our include files
FOO_SRC_DIRS = $(FOO_BASE_DIR)/include $(FOO_BASE_DIR)/include2
SRC_DIRS += $(FOO_SRC_DIRS)

# Add <build>/libfoo.a, built by the internal-build rule above, to the
# list of libraries to link with
LDFLAGS += $(FOO_BASE_DIR)/<build>/libfoo.a

ifneq ($(FOO_ROOT),True)
   DEPS_PROJECTS += $(FOO_BASE_DIR)/foo
endif

endif


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Mail Server on November, 9 2003 using texi2html