Next: , Up: Examples of Project Files


11.2.1 Common Sources with Different Switches and Directories

Suppose that the Ada source files pack.ads, pack.adb, and proc.adb are in the /common directory. The file proc.adb contains an Ada main subprogram Proc that withs package Pack. We want to compile these source files under two sets of switches:

The GNAT project files shown below, respectively debug.gpr and release.gpr in the /common directory, achieve these effects.

Schematically:

     /common
       debug.gpr
       release.gpr
       pack.ads
       pack.adb
       proc.adb
     /common/debug
       proc.ali, proc.o
       pack.ali, pack.o
     /common/release
       proc.ali, proc.o
       pack.ali, pack.o

Here are the corresponding project files:

     project Debug is
       for Object_Dir use "debug";
       for Main use ("proc");
     
       package Builder is
         for Default_Switches ("Ada")
             use ("-g");
         for Executable ("proc.adb") use "proc1";
       end Builder;
     
       package Compiler is
         for Default_Switches ("Ada")
            use ("-fstack-check",
                 "-gnata",
                 "-gnato",
                 "-gnatE");
       end Compiler;
     end Debug;
     project Release is
       for Object_Dir use "release";
       for Exec_Dir use ".";
       for Main use ("proc");
     
       package Compiler is
         for Default_Switches ("Ada")
             use ("-O2");
       end Compiler;
     end Release;

The name of the project defined by debug.gpr is "Debug" (case insensitive), and analogously the project defined by release.gpr is "Release". For consistency the file should have the same name as the project, and the project file's extension should be "gpr". These conventions are not required, but a warning is issued if they are not followed.

If the current directory is /temp, then the command

     gnatmake -P/common/debug.gpr

generates object and ALI files in /common/debug, as well as the proc1 executable, using the switch settings defined in the project file.

Likewise, the command

     gnatmake -P/common/release.gpr

generates object and ALI files in /common/release, and the proc executable in /common, using the switch settings from the project file.