Shell command to compile C in Gprbuild

351 Views Asked by At

Using GtkAda, I'm trying to use the resource API to include the Glade file directly inside my code.

For this, we can generate C code from a set of resources using glib-compile-resources which can then be linked to the Ada code.

The problem is that this C code requires Gtk includes which we usually get from the pkg-config command under Linux such as

gcc -c -x c `pkg-config --cflags gio-2.0` myglade.gresource.c

I'd like to know how to provide the same kind of information in a GPRBuild project file.

FYI, I already tried to use the pkg-config command inside the compiler package for C language without any success. Of course, I managed to build by hand but that's a bit long :)

2

There are 2 best solutions below

2
On BEST ANSWER

This might work for you:

project Config_Demo is
   Pkg_Config := external_as_list ("PKG_CONFIG", " ");
   package Compiler is
      --  only this file needs the extra switches
      for Switches ("myglade.gresource.c") use Pkg_Config;
   end Compiler;
end Config_Demo;

and then

gprbuild -P config_demo -XPKG_CONFIG="`pkg-config -cflags gio-2.0`"
1
On

Your best bet will be to do what GtkAda does: Look at its shared.gpr.in file, it uses the token @GTK_LIBS_GPR@ which will be replaced by the configure script, giving a usable shared.gpr.

Thing is, you need to issue the pkg-config call and build your gpr file from the result somehow. GPRBuild is not equipped to do this for you and process the result. If you're comfortable with GNU autotools, you can look further at how GtkAda achieves it:

GTK_LIBS_GPR is set in aclocal.m4 using a macro that converts the C-style flags to a GPR array. The value comes from GTK_LIBS which is queried here via pkg-config.

If you're not comfortable with GNU autotools, you can write your configure script using basic shell commandos, a scripting language like Python or with whatever other tool you're comfortable with.