cco: Integrating Orion in the makefile

Orion's functionality is an extension and improvement of the checks performed by compilers. Hence, a natural place to invoke Orion is from the makefile. Including the Orion checks in the makefile not only automates the analysis, but it will also avoid unnecessary checks in case source files have not changed since the last build. The cco command (for cc + Orion) is provided especially for use in makefiles, and is meant to replace whatever command is used to invoke the compiler. cco still does the compilation, but in addition it performs an analysis by orion. Leaving the compilation in place ensures that the original tasks of the makefile are not altered, as this might derail the build process.

On every file given in its argument list, cco first calls a compiler. Which compiler is called, is specified through the -@cc option for C compilers and the -@cxx option for C++ compilers. Furthermore, the options to be provided to these compiler are given as strings (enclosed in double quotes), using resp. the -@cflags and -@cxxflags options of cco.

After having compiled a file, cco then analyzes it by calling orion. It does so with the remaining options, i.e. after dropping the -@cc, -@cxx, -@cflags, and -@cxxflags options. cco automatically sets the -@append option to orion, so that the reports are appended to ORION.report; any previously existing version of that file may have to be removed manually in this case. orion needs to parse the file again, for which it depends internally on (the front end of) gcc. Therefore, these remaining options need to be understood by gcc.

For example, suppose that originally, the compiler used in the makefile is /usr/bin/cc, as follows:

CC = /usr/bin/cc
CFLAGS = -I /home/elmo/include -fullwarn -dollar -O3

foo.o: foo.c
        $(CC) $(CFLAGS) foo.c

An adapted makefile that does compile-time analysis using Orion might look as follows:

CC = $(ORIONDIR)/bin/cco
ORIG_CFLAGS = -I /home/elmo/include -fullwarn -dollar -O3
CFLAGS = -I /home/elmo/include -fdollars-in-identifiers   # orion preproc. options
AFLAGS = -@precision 5 -@exitfn bailout                   # orion analysis options

foo.o: foo.c
        $(CC) -@cc /usr/bin/cc -@cflags "$(ORIG_CFLAGS)" $(CFLAGS) $(AFLAGS) foo.c

The command to compile, specified in the variable CC, has been replaced by our version of cco. The option -@cc /usr/bin/cc tells cco that it has to use /usr/bin/cc to do the compilation, while -@cflags "$(ORIG_CFLAGS)" specifies the options to be passed along when calling /usr/bin/cc. These are the options that were given in the original makefile, in the variable CFLAGS; they are now enclosed in double quotes so that cco knows where they end. In contrast, the options specified in CFLAGS are the ones that orion itself uses when parsing foo.c. Note that they partly overlap with the options given in ORIG_CFLAGS. The include path is kept as orion needs it in order to preprocess the file. Also the option -dollar is needed to parse the file, however since orion's parser (the front-end of gcc) is not compatible with cc at this point, it has been converted to the gcc option -fdollars-in-identifiers. The -fullwarn option has been left out because orion's parser need not repeat the work of cc in producing warnings. The -O3 option has been dropped because it is not relevant to the parsing. Finally, the analysis-specific options, that cco passes to orion, are listed in AFLAGS (-@exitfn bailout tells Orion to treat bailout as the name of a function that does not return; see the User's Guide).

Further remarks on cco

The compiler to be used defaults (i.e. when no -@cc is given) to gcc. The options passed to the compiler default (when no -@cflags is given) to the compilation options (not including the analysis options starting with -@) given to cco itself. E.g., if the part -@cflags "$(ORIG_CFLAGS)" would have been omitted from the rule above then the command to compile would be (the expansion of) /usr/bin/cc $(CFLAGS) (which would be wrong because cc does not recognize the -fdollars-in-identifiers option; in practice it will usually be the case that -@cflags is present when -@cc is).

When the file arguments given to cco contain both C and C++ files, then cco will use the C++ compiler (i.e. the one indicated by the -@cxx option if present or else g++) for the compilation step of each of the files.

The particularities of the version of make in effect should be kept in mind when editing makefiles. For example, GNU make uses default rules to make object files: if no explicit rule is given, then a .o file is made by running the command $(CC) -c $(CPPFLAGS) $(CFLAGS) on the corresponding .c file, and similarly $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) is used in case of C++ files. Also note that depending on the version of make, the syntax of the above example may be different. E.g., in some makes the double quotes might have to be escaped.

cco ignores object (.o) files, so it is no problem if the original compiler is also used to link files.

All options to orion are also understood by cco, with the exception of -@project, because the use in a makefile should eliminate the need for that. In addition to orion, the -@compile-only option tells cco to only do the compilation, while -@analyze-only tells it to only do analysis.