Nokia Networks Home

Nokia nmake Product Builder

Quick Links

Related Products

Dynamic Dependency Scan

Feature Description

The capability to determine the implicit dependencies between files, typically between source and header files. Built-in rules are provided for scanning many languages (C, C++, Fortran, ESQL/C, nroff/troff, and others). Users can define new scan strategies for other languages.

Impact

Productivity

Build Accuracy

Consequence of Not Having the Feature

Examples

The following files are used in this example. a.c include a.h, which includes b.h, which includes c.h, which includes stdio.h.

/*** ./Makefile  ****/
.SOURCE.h : include0 include1 include2 include3 include4 include5
abc :: a.c 
/*** ./a.c ***/
#include "a.h"
int main() {
    printf("abc\n");
    return(0);
}
/*** include1/a.h ***/
#include "b.h"
/*** include2/b.h ***/
#include "c.h"
/*** include3/c.h ***/
#include <stdio.h>

The first example illustrates that nmake scans the source code, locates the necessary include files and constructs the proper -I list for the compile line. Note that the -I flags are not hard-coded in the makefile, the .SOURCE.h special atom tells nmake where to search for include files.

$ nmake
+ cc -O -Iinclude1 -Iinclude2 -Iinclude3 -I- -c a.c
+ cc -O -o abc a.o

If one of the include files is updated nmake will recompile the target. We will use the nmake -e option to get an explanation of why it is recompiling. This shows nmake is tracking changes to the include files without listing them in the makefile.

$ touch include2/b.h

$ nmake -e
include2/b.h [Aug 21 13:38:18 2003] has changed [Aug 21 13:37:45 2003]
. [Aug 21 13:38:13 2003] has changed [Aug 21 13:38:08 2003]
+ cc -O -Iinclude1 -Iinclude2 -Iinclude3 -I- -c a.c
+ cc -O -o abc a.o

We can add another header file and it will be picked up automatically with no makefile change. c.h now includes d.h which is in the include4 directory.

/*** c.h ***/
#include <stdio.h>
#include "d.h"
$ nmake -e
include3/c.h [Aug 21 14:07:02 2003] has changed [Aug 21 14:06:32 2003]
include3/c.h prerequisite include4/d.h added or re-ordered
include4/d.h [Aug 21 14:05:17 2003] has no previous state
. [Aug 21 14:06:50 2003] has changed [Aug 21 14:06:45 2003]
+ cc -O -Iinclude1 -Iinclude2 -Iinclude3 -Iinclude4 -I- -c a.c
+ cc -O -o abc a.o

Finally, instead of compiling the target we will use a different makefile to show a list of the implicit include files. $(!) is an automatic variable which expands to all the explicit and implicit file prerequisites of the current target. This illustrates exactly which prerequisite header files nmake found by scanning the code. Notice even the system include files are tracked.

/*** ./Makefile ***/
.SOURCE.h : include0 include1 include2 include3 include4 include5

abc : a.c
        : $(!)
$ nmake
+ : a.c include1/a.h include2/b.h include3/c.h include4/d.h /usr/inclu
de/stdio.h /usr/include/sys/va_list.h /usr/include/sys/feature_tests.h

Example using standard make tool

The following uses the standard make tool to build the same code. Notice the makefile is much more complicated and verbose.

First we'll build without the additional d.h include file.

##### ./makefile #####
CFLAGS = -O -Iinclude1 -Iinclude2 -Iinclude3 -Iinclude4

abc : a.o 
        cc $(CFLAGS) -o abc a.o

a.o : a.c include1/a.h include2/b.h include3/c.h \
        /usr/include/stdio.h /usr/include/sys/va_list.h \
        /usr/include/sys/feature_tests.h
$ make
cc -O -Iinclude1 -Iinclude2 -Iinclude3 -Iinclude4  -c  a.c
cc -O -Iinclude1 -Iinclude2 -Iinclude3 -Iinclude4 -o abc a.o

$ touch include2/b.h

$ make
cc -O -Iinclude1 -Iinclude2 -Iinclude3  -c  a.c
cc -O -Iinclude1 -Iinclude2 -Iinclude3 -o abc a.o

When d.h is added the makefile is out-of-date.

$ make
cc -O -Iinclude1 -Iinclude2 -Iinclude3 -Iinclude4  -c  a.c
cc -O -Iinclude1 -Iinclude2 -Iinclude3 -Iinclude4 -o abc a.o

$ touch include4/d.h  

$ make
`abc' is up to date.

Oops, let's update the makefile.

##### ./makefile #####
CFLAGS = -O -Iinclude1 -Iinclude2 -Iinclude3 -Iinclude4

abc : a.o 
        cc $(CFLAGS) -o abc a.o

a.o : a.c include1/a.h include2/b.h include3/c.h include4/d.h \
        /usr/include/stdio.h /usr/include/sys/va_list.h \
        /usr/include/sys/feature_tests.h
$ make
cc -O -Iinclude1 -Iinclude2 -Iinclude3 -Iinclude4  -c  a.c
cc -O -Iinclude1 -Iinclude2 -Iinclude3 -Iinclude4 -o abc a.o

$ touch include4/d.h

$ make
cc -O -Iinclude1 -Iinclude2 -Iinclude3 -Iinclude4  -c  a.c
cc -O -Iinclude1 -Iinclude2 -Iinclude3 -Iinclude4 -o abc a.o
Last Update: Tuesday,16-Aug-2016 16:51:31 EDT