Assume 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 "with"s
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.
Diagrammatically:
/common debug.gpr release.gpr pack.ads pack.adb proc.adb /common/debug {-g, -gnata, -gnato, -gnatE} proc.ali, proc.o pack.ali, pack.o /common/release {-O2} proc.ali, proc.o pack.ali, pack.o
Here are the project files:
project Debug is for Object_Dir use "debug"; for Main use ("proc"); package Builder is for Default_Switches ("Ada") use ("-g"); 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, and the proc
executable also in /common/debug, 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.