Step 2 - Add Targets to Makefile Approach

If you're using make to build your software, the makefiles contain information about source files and their associated preprocessor flags. The Add Targets to Makefile approach leverages this info by using the already existing definitions. It does this by adds a set of targets to your makefiles. It thus requires that you use makefiles to build your software. Under this approach, the new makefile targets in turn invoke the actual Imagix 4D analyzer.

The makefile already contains makefile macros that list which source files to compile, which include directories to search for header files, and what macro definitions to use when compiling the code. The targets added by Imagix 4D build on these existing macros. You will probably need to edit the Imagix 4D related targets (step 2g).

At the time that the targets are added to the makefile, settings from the Options tab of the Data Sources dialog are included in the makefile settings. To change these options later, you'll need to modify the makefile, rather than simply make changes in the Options tab, before regenerating the project data.

Note: While this approach offers some advantages in on-going production use of Imagix 4D, it is not recommended for initial evaluation of the tool, as it requires knowledge and modification of your makefiles, and is generally much more difficult to get started with than the alternatives. If you're using a make system, it's likely that the Extract from Makelog approach would be much easier to apply and result in equal precision.

Before starting

In the Add Targets to Makefile approach, Imagix 4D actually invokes your makefile with the command make (nmake under Windows). If you normally invoke make with a different invocation, such as gmake or clearmake, you'll need to configure Imagix 4D accordingly. You'll need to change the make name field in the Data Collection section of the Options dialog (File > Options > Data Collection > Adding Targets to Makefile). Under Windows, you may also need to use the dialog to specify the path to the make (or nmake) executable, if the path is not already in your PATH environment variable.

In addition, you can customize the templates used for adding the targets. The templates, along with instructions, are found in ../imagix/user/mk_trgts.

2a. Specify that you're adding a new data source

Open the Data Sources dialog (Project > Data Sources). To specify that you wish to add a new data source into the project rather than modify the settings for an existing data source, choose `+ new data source' under the Data Sources selector on the left side of the dialog. As this is a new project, and there are no existing data sources to modify, this is indeed the only choice available.

2b. Select the adding targets to makefile approach

For the rest of step 5, you'll be working on the right side of the Data Sources dialog. At the top, select [Source Files][Make Based][Add Targets into Makefile] in the menubutton labeled `Select Data Source Type'.

2c. Specify the name of your makefile

In the Makefile field of the Makefile tab, enter the full path/file name of your makefile.

Note: Imagix 4D will modify the makefile you specify. You may not want to modify your actual makefile at this point. If so, create a new file, perhaps called imagix.mak, in the same directory as your regular makefile. Edit the first line of imagix.mak to read something like:

include /path/name/of/real_makefile
Use include and not #include. Then, in the Makefile field, enter the full path/file name of imagix.mak.

2d. Specify the base name of the targets that Imagix 4D will add to your makefile

Normally, you can leave the Make Target field as `imagix', but if you already have a target named imagix in your makefile, you'll need to change the field to an unused name.

2e. Select your compiler configuration file

In the Compiler & Target combobox, select the compiler configuration file that you set up in step 1. If you haven't yet configured a compiler configuration file for the compiler and target platform of your software, strongly consider doing so now. The alternative is to select `other'. If you select `other', you'll need to specify the implicit flags in the makefile (IMAGIX_FLAGS).

2f. Open the makefile for editing

Leave `Edit makefile' checked, and click Add Data Source at the bottom of the dialog. Doing so will cause Imagix 4D to add data collection targets to the makefile, and open the makefile for editing.

2g. Modify the specific Imagix 4D targets

There's a section in the makefile where five specific makefile macros have been defined. Assuming that you specified imagix for the base target name, the first three of these makefile macros are IMAGIX_SRCDIR, IMAGIX_MAKEFILE, and IMAGIX_PROJDIR. You can ignore these definitions - they are automatically generated by Imagix 4D, and are there for the purpose of replicating the makefile in other locations (see step 7).

Again assuming the target is named imagix, the other two are IMAGIX_SOURCES and IMAGIX_FLAGS. These need to be modified.


Modify the IMAGIX_SOURCES macro so that it expands out to a list of the source files you want to load.

Search the regular makefile for a list of sources. These may be listed as a series of source files, such as `SRCS = foo1.c foo2.c foo3.c', or may instead be represented by a series of objects files, such as `OBJS = foo1.o foo2.o foo3.o'.

If source files are listed, define IMAGIX_SOURCES to be equal to the macro which lists the sources. For example, if the sources are defined as above, modify the IMAGIX_SOURCES line to read `IMAGIX_SOURCES = $(SRCS)'.

If object files are listed instead, modify the IMAGIX_SOURCES to evaluate out to the related source files. For example, if the object files are named OBJS, and their related source files use a .cc suffix, change the IMAGIX_SOURCES line to read `IMAGIX_SOURCES = $(OBJS:.o.=cc)'.


Modify the IMAGIX_FLAGS macro so that it expands out to all the -I, -D and -U flags explicitly passed to your compiler.

Search the regular makefile for where the -I, -D and -U flags are defined. Often, the -I flags may be collected in a different macro than the -D flags. For example, you might have one macro, named perhaps INCLUDES, which contains all the -I flags. You may have another macro, named perhaps CCFLAGS, which contains all the -D flags (use of -U flags is rare).

The IMAGIX_FLAGS line is also used to specify which compiler configuration file to process, and can be used for passing any other options to the Imagix 4D analyzer.

In this example, modify IMAGIX_FLAGS to be something like `IMAGIX_FLAGS = -inc/path/to/compiler/configuration/ $(INCLUDES) $(CCFLAGS)'. If you chose `other' as your configuration file (step 5e), the -inc option won't appear here, and you'll need to also specify the compiler's implicit flags on this line instead (see step 3a).

2h. Start the analysis process

At this point you're ready to invoke the analyzer. However, analyzing your code often turns up errors in how you have specified your -I, -D and -U flags. You may find it preferable to load just a subset of your code first. If so, comment out the IMAGIX_SOURCES line (with a #), and create a new line, such as `IMAGIX_SOURCES = foo1.c'.

When you're ready to analyze your code, save the changes you just made to the makefile (File > Save). Close the makefile. Then close the information window. This causes the analysis process to begin.