3

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';
TamaMcGlinn
  • 2,840
  • 23
  • 34

1 Answers1

5

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;
egilhh
  • 6,464
  • 1
  • 18
  • 19
  • I also want to pass `gnatprep -c` to leave removed sections as comments. But `-gnatec` or `-gnateC` does not work; is there any way to pass gnatprep flags from the gpr file? – TamaMcGlinn Dec 09 '20 at 08:46
  • Thank you, that works. Note it is also possible to keep the `-gnateDFoo=Bar` in the gprfile, having only the -c option in prep.def – TamaMcGlinn Dec 09 '20 at 09:40