ada_answers_gem_logo_fourth

Gem #159 : GPRinstall - Part 2

Let's get started...

In the first installment we described how to install a library project. It's also possible to install a standard project. In that case the spec files and corresponding objects are installed. This is not very different from the library case described in the first part.

But gprinstall can also handle application projects. That is, a project with one or multiple mains specified. In such cases we do not want to install sources, just the executables built as part of the project. Consider this project:

project Prj is

   for Mains use ("mytool.adb");

   ...

end Prj;

To install only mytool (or mytool.exe on Windows platforms), gprinstall's "usage" mode can be set:

$ gprinstall -p --mode=usage prj.gpr

The default mode is "dev" (for development), which is the most common mode to use when installing a library. In development mode we need the specs forming the API of the library. In usage mode, gprinstall will copy the executable mytool to the "bin" directory under the install prefix.

The default prefix is where the compiler is installed. It's possible to change this with the --prefix option:

$ gprinstall -p --prefix=/opt/myapps --mode=usage prj.gpr

All default values can be changed. For example, the default executable directory is "bin" which can be changed with the --exec-subdir option:

$ gprinstall -p --prefix=/opt/myapps --exec-subdir=tools --mode=usage prj.gpr

With this last command, the mytool executable will be installed in the /opt/myapps/tools directory.

Up to now we have only seen ways to install the build artifacts of the project. What if documentation also needs to be installed?

Again gprinstall can take care of that: the Artifacts project attribute can be used to describe items to be installed that are not part of the project build. This attribute must be placed in the Install package of the project:

project Prj is

   for Mains use ("mytool.adb");

   package Install is
      for Artifacts ("doc") use ("doc/README", "doc/VERSION");
      for Artifacts ("share/examples") use ("examples/*");
   end Install;

   ...

end Prj;

So, using this command:

$ gprinstall -p --prefix=/opt/myapps --mode=usage prj.gpr

will install the executable mytool as above, but it will also copy the files doc/README and doc/VERSION to the /opt/myapps/doc directory, and all directories for the examples will be copied into /opt/myapps/examples.

That's all there is to it! Wait, no, in fact... we can now remove further messing around with makefiles!

Pascal Obry
EDF R&D