User-Defined Builder Commands

GNATbench uses a project-specific makefile to associate the various builder commands with their tool-specific invocations. The makefile is created for each project based on the compiler specified by the user when creating the project. This makefile is used only to invoke the commands and does not use any additional 'make' utility capabilities such as defining dependencies between files and makefile targets. All such settings are specified by the GNAT project file that is also created by the wizards (or imported) and specified by the low level commands as an argument.

For example, here is a sample makefile generated by the new-project wizards. The user chose "gnatmake" from the list of project builders and the wizard did the rest.

sample basic makefile

All the project settings are specified in the project file passed via the "-P" switch rather than by the makefile. Arguably, GNATbench does not, therefore, require a makefile and the corresponding make utility. There are two primary reasons that GNATbench uses this approach.

The first reason GNATbench uses a makefile is so that developers of high-integrity applications can use a script to build their executables. A script is a means to demonstrate repeatable executable image construction, a typical requirement in that application domain. These developers can simply reference the makefile as part of their demonstration.

The second reason GNATbench uses a makefile is so that project-specific user-defined commands can be specified and invoked. These commands might be required, for example, to do some extra setup not known to the GNAT or foreign compiler.

Defining Commands

As noted earlier, the project-specific makefile and GNAT project file work together to define the effective command, although the GNAT project file should do most of the work. You can use as much of the 'make' tool capabilities as you feel appropriate, and thus perhaps put less in the GNAT project file, but doing so will reduce interoperability with GPS. GPS is also conceptually based on GNAT project files and in general the two IDE's can share GNAT project files without much difficulty.

Makefile Additions

You add a new makefile target and associated tool invocation to an existing makefile in order to create a user-defined command. In the following figure, we have added a command that assembles a small file written in assembly language. This new command (makefile target) is named "setup" and appears at the end of the makefile.

sample makefile with user-defined command

We could have used the 'make' dependency capability to have this command executed automatically when necessary, but in this simple example the user will invoke the command when first building the project.

Project File Additions

The GNAT project file might also require additions in order to accomodate the new user-defined builder command. Whether or not any change is required will depend on the details of the new command. We don't need any additions for the sake of the example "setup" command.

Invoking User-Defined Commands

The "Build Target In Project..." command allows you to invoke the low-level commands defined by the makefile targets. Issuing the command via the contextual menu brings up a dialog box listing all these targets. Each target has descriptive text explaining what it does, for your convenience. For example, the following figure illustrates the dialog box you would see for a project without any user-defined commands:

makefile target selection dialog box

Simply click on the name of the target to select the corresponding command and then press Build to invoke it. The steps and any messages will be displayed in the project-specific console.