MAKESTYLE(1)

NAME
makestyle - print violations of Makefile guidelines

SYNOPSIS
makestyle [-vishp] filenames

DESCRIPTION

makestyle finds violations of a selected set of Makefile guidelines documented in "Makefile Standards and Guidelines". It issues messages for three types of checks:

•   Violations of guidelines which must be fixed. (Default)

•   Violations of guidelines which, when fixed, help create coherent makefiles. (-p option)

•   Possible violations of guidelines. These type of violations are difficult to catch in a programmatic way and human interpretation is required as the algorithms are complex to implement. (-h option)

OUTPUT
The script outputs violations of guidelines, one violation to a line. Because of the difference in the types of inputs available to the utility during the first and the second pass, the utility prints messages of two different types. During the first pass it prints line numbers along with the error message but during the second pass it only prints warning messages.

OVERVIEW
The script uses two pass algorithm to analyze the Makefile. The first pass does static analysis of the Makefile. The second pass invokes make with -DD option to create a file which contains all the included files where some of the variables and targets are resolved. This file is then parsed to detect redefinitions of macros or suffix rules. The design of the utility ensures that no target from the makefile is actually built during "make -DD" and hence no target dependencies are modified.

The script will exit with an error message during second pass if the makefile contains errors that prevent successful invocation of make.

The categories of violations of the guidelines, based on their importance and complexity in identifying them programmatically, is as follows:

    1. Regular checks
    2. Picky checks
    3. Heuristic checks

These guidelines are further divided depending on whether the check is made during the first or the second pass.

  Regular Checks

This is the default mode of the utility. The list of checks made is as follows.

First pass checks:

    •   Keyword, copyright and pathname identifiers should be included, where a pathname identifier is the name of the makefile with respect to the path from the base of the source.

    •   No command should be used without macro reference. i.e. make instead of $(MAKE).

    •   Whenever a cd to another directory is done, pwd should follow.

    •   -I and -D should not be specified in CFLAGS macro but only in CPPFLAGS macro.

    •   -L should appear only in LDFLAGS macro.

    •   Install target should have no actions.

    •   INS.dir and INS.file should be used instead of install command.

    •   sccs command should not be explicitly used.

    •   Variables like PRINTER, ENV which are commonly used should not be used in makefile.

    •   Absolute path should not be used.

    •   Dynamic macro $< should appear only in the actions of percent and suffix rules. It should not appear in an actions list of a regular target.

    •   Pattern replacement statements should not be used as targets.

    •   Operator += should be surrounded by white space unlike "=".

    •   INC macro should not be used as in AT&T makefiles.

    •   Target .KEEP_STATE should be included in each makefile.

    •   Target all, when present, should be the first regular target.

    •   A statement should not begin with space characters.

    •   No statement should have more than 80 characters.

Second pass checks:

    •   Makefile.lib should be included if a library is being built.

  Picky checks

This mode is invoked by -p option of the utility. Messages of this type would be issued for violations of following guidelines. When enabled it helps create better than acceptable type of makefile.

First pass checks:

    •   Makefile should not use wildcards. i.e. rm -rf *.o

  Heuristic checks

This mode is invoked by -h option of the utility. These checks point out POSSIBLE violations of makefile guidelines. The messages have to be analyzed to determine whether they are indeed violations. The guidelines are as follows.

First pass checks:

    •   The install target should have the dependencies in terms of ROOT instead of actual path.

    •   Target all should be included in each makefile.

Second pass checks:

    •   Predefined suffix rules should be used wherever possible.

    •   Predefined macros should be used wherever possible.

USAGE
makestyle has following options.

    -v  verbose.

    -i  Check included files for duplicate definitions of macros and suffix rules.

    -s  Skip second pass.

    -h  Perform heuristic checks that are sometimes wrong.

    -p  Perform some of the more picky checks.

The typical invocation of the script would be as follows:

    example% makestyle path/of/Makefile

To catch maximum number of violations, heuristic checks and picky checks should be made. The usage in that situation would be:

    example% makestyle -h -p path/of/Makefile

  Clean Up

makestyle cleans up all the intermediate files it creates in /tmp. When errors in the makefile result in failure of make, the output of the most recent failed run is left in /tmp for possible future analysis.

DOCUMENTS

"Makefile Standards and Guidelines"
    /shared/ON/general_docs/make_std.txt

EXIT CODES

0   makestyle could run successfully.

1   makestyle failed due to an erroneous input or error condition encountered while running make.