High-level Build with gprbuild (with examples)
1: Building a project
gprbuild
Motivation:
Building a project is the most basic use case of the gprbuild
command. It allows you to compile and link all the source files in a project, producing the corresponding executables.
Explanation:
This command assumes that there is only one *.gpr
(GNAT project) file in the current directory. It will search for this file and build the project based on its contents.
Example Output:
Compiling main.adb
Linking main.exe
Build completed successfully.
2: Building a specific project file
gprbuild -Pproject_name
Motivation:
In a scenario where there are multiple *.gpr
files in the current directory, it is necessary to specify the exact project file that needs to be built. This command allows you to build a specific project file by providing its name.
Explanation:
The -P
option is used to specify the project name (without the .gpr
extension). The gprbuild
command will locate and build the specified project file.
Example Output:
Compiling main.adb
Linking main.exe
Build completed successfully.
3: Cleaning up the build workspace
gprclean
Motivation:
During development, the build workspace may accumulate temporary files and directories that are no longer needed. The gprclean
command allows you to clean up this workspace, removing all the generated files.
Explanation:
The gprclean
command performs a clean-up of the build workspace associated with the current project. It deletes temporary build files, object files, and any other generated artifacts.
Example Output:
Cleaning workspace...
Workspace cleaned successfully.
4: Installing compiled binaries
gprinstall --prefix path/to/installation/dir
Motivation:
After building a project, you might want to install the compiled binaries into a specific directory. The gprinstall
command provides a convenient way to install the built executables, libraries, and other artifacts.
Explanation:
The --prefix
option is used to specify the installation directory. This directory will be the root directory under which the compiled binaries will be installed.
Example Output:
Installing main.exe to /path/to/installation/dir/bin
Installation completed successfully.
Note: The gprinstall
command can install multiple files and directories depending on the project configuration.