TamaMcGlinn
TamaMcGlinn

Reputation: 3238

Can gprbuild be configured to output gnatprep preprocessed sources?

I have a gpr project which uses gnatprep to preprocess source files. But now I have a tool which needs the already preprocessed source files. I know that I can hunt down each source file and run it through gnatprep:

find . -type f -iname '*.ad[sb]' -exec gnatprep -DSymbol=value {} {}.prep \;

But I'd like to leverage the project file to find the right source files and pass them through. My project file also defines the various symbol values to use, which I would have to add to the command above. Is it possible through some parameter in the .gpr file? E.g.

   for Object_Dir use 'obj';
   for Preprocessed_Sources_Dir use 'wow_that_was_easy';

Upvotes: 3

Views: 551

Answers (1)

egilhh
egilhh

Reputation: 6430

You can tell the compiler to leave the preprocessed sources in the Object_Dir with the -gnateG option, like so, in the project file:

   package Compiler is
      for Default_Switches ("Ada") use ("-gnateDFoo=""Bar""", "-gnateG" );
   end Compiler;

The preprocessed source will then be named <original_filename>.prep, for example foo.adb -> foo.adb.prep

Edit:

For your followup-question, you'd have to put the preprocessor options in a separate file, for example prep.def:

* -u -c -DFoo="Bar"

or, if you want to specify options per file:

"foo.adb" -u -c -DFoo="Bar"

And then tell the compiler to use that file with the gnatep= option:

package Compiler is
   for Default_Switches ("Ada") use ("-gnateG", "-gnatep=" & Foo'Project_Dir & "prep.def" );
end Compiler;

Upvotes: 5

Related Questions