LinuxCommandLibrary

gnatprep

Preprocesses Ada code for conditional compilation

TLDR

Use symbol definitions from a file

$ gnatprep [source_file] [target_file] [definitions_file]
copy

Specify symbol values in the command-line
$ gnatprep -D[name]=[value] [source_file] [target_file]
copy

SYNOPSIS

gnatprep [options] input_file [output_file]

PARAMETERS

-c file
    Specifies a configuration file that contains characteristic definitions to be used by gnatprep.

-C
    Prevents case conversion of identifiers found within the input Ada source code.

-Dcharacteristic
    Defines a specific characteristic as true, enabling conditional compilation branches dependent on this characteristic.

-e
    Enables processing of non-Ada files, treating them line by line for conditional compilation directives.

-g
    Generates dependency information, which is useful for build systems like gprbuild to track preprocessor dependencies.

-h, --help
    Displays help information about the command and its options, then exits.

-k
    Keeps any intermediate files that are generated during the preprocessing operation.

-l
    Lists all defined characteristics and their current values, providing insight into the preprocessing environment.

-o file
    Specifies the file where the preprocessed output will be written. If this option is omitted, output is directed to standard output.

-r
    Generates a template for a configuration file, outputting it to standard output, which can be useful for setting up new projects.

-s
    Searches for characteristics in standard system configuration files in addition to user-specified ones.

-u
    Disables case conversion during processing (similar to -C).

-v
    Enables verbose output, showing detailed progress and information about the preprocessing steps.

-V, --version
    Displays the version information of gnatprep and then exits.

-w
    Suppresses warning messages that might otherwise be issued during the preprocessing phase.

-x
    Treats any undefined characteristics as false, rather than assuming them to be true by default.

DESCRIPTION

gnatprep is a utility from the GNAT toolchain designed to preprocess Ada source files. Its primary function is to handle conditional compilation based on "characteristics" defined by the system, specific configurations, or explicitly provided parameters. It interprets special pragmas like pragma System_Specific and pragma Configuration_Specific, allowing different sections of code to be included or excluded during compilation based on the target environment or build settings. This mechanism is crucial for developing portable Ada code that adapts seamlessly to various platforms or custom configurations, significantly enhancing code reuse and maintainability across diverse projects. The preprocessor can read input from standard source files and direct its processed output to a specified file or to standard output.

CAVEATS

gnatprep is primarily designed for Ada source files. While the -e option allows processing of other file types, unexpected behavior may occur if conditional compilation pragmas are not formatted in a way that gnatprep can interpret correctly.
The effectiveness of conditional compilation heavily relies on the accurate definition of characteristics through configuration files or command-line arguments; incorrect definitions can lead to unintended code segments being included or excluded.
Over-reliance on conditional compilation can sometimes complicate code readability and debugging, making it essential to use this feature judiciously.

HISTORY

gnatprep is an integral component of the GNAT (GNU Ada Translator) toolchain, which was initially developed by AdaCore (formerly ACT-Europe) and is now part of the GNU Project. Its development has consistently paralleled the evolution of the Ada language and the GNAT compiler itself, providing a crucial mechanism for handling platform-specific code and configuration management within Ada projects. It has remained a stable and essential utility within the GNAT ecosystem for many years, adapting to new Ada standards and evolving build system requirements.

SEE ALSO

gnatmake(1), gprbuild(1), gnat(1), gcc(1)

Copied to clipboard