comp.lang.ada
 help / color / mirror / Atom feed
* Including C source in GNAT project for building library
@ 2008-01-24  5:27 Simon Wright
  2008-01-24  5:54 ` Per Sandberg
  2008-01-24  6:05 ` Simon Wright
  0 siblings, 2 replies; 4+ messages in thread
From: Simon Wright @ 2008-01-24  5:27 UTC (permalink / raw)


This relates to building TASH as a library (static, libtash.a) using
GNAT Project, as in GNAT-GPL-2007.

As well as Ada source, this library needs two C-sourced units to act
as wrappers for macros in the Tcl/Tk header files.

I can do this by hand (obviously only for a static library) by doing
this after gnatmake has done its part:

   gcc -c -g -O2 -I/usr/include tclmacro.c
   gcc -c -g -O2 -I/usr/include tkmacro.c
   ar -r lib/libtash.a tclmacro.o tkmacro.o
   ranlib lib/libtash.a

but can't help feeling there should be a way to tell gnatmake to do
this!

So far I have

with "../tash_options";

project Build_Tash_Library is

  for Library_Name use "tash";
  for Languages use ("Ada","C");
  for Library_Interface use
    (
     "cargv",
     "chelper",
     "tash.arrays",
     "tash.file",
     "tash.file_io",
     "tash.float_arrays",
     "tash.float_lists",
     "tash.floats",
     "tash.integer_arrays",
     "tash.integer_lists",
     "tash.integers",
     "tash.lists",
     "tash.platform",
     "tash.regexp",
     "tash.strings",
     "tash.system",
     "tash",
     "tcl.ada",
     "tcl.tk.ada",
     "tcl.tk",
     "tcl"
     );
  for Source_Files use
    (
     "tclmacro.c",
     "tkmacro.c",
     "cargv.adb",
     "cargv.ads",
     "chelper.adb",
     "chelper.ads",
     "tash-arrays.adb",
     "tash-arrays.ads",
     "tash-file.adb",
     "tash-file.ads",
     "tash-file_io.adb",
     "tash-file_io.ads",
     "tash-float_arrays.ads",
     "tash-float_lists.ads",
     "tash-floats.adb",
     "tash-floats.ads",
     "tash-integer_arrays.ads",
     "tash-integer_lists.ads",
     "tash-integers.adb",
     "tash-integers.ads",
     "tash-lists.adb",
     "tash-lists.ads",
     "tash-platform.adb",
     "tash-platform.ads",
     "tash-regexp.adb",
     "tash-regexp.ads",
     "tash-strings.adb",
     "tash-strings.ads",
     "tash-system.adb",
     "tash-system.ads",
     "tash.adb",
     "tash.ads",
     "tcl-ada.adb",
     "tcl-ada.ads",
     "tcl-tk-ada.adb",
     "tcl-tk-ada.ads",
     "tcl-tk.adb",
     "tcl-tk.ads",
     "tcl.adb",
     "tcl.ads"
    );
  for Object_Dir use ".build_lib";
  for Library_Kind use "static";
  for Library_Src_Dir use "lib";
  for Library_Dir use "lib";

  package IDE is
     for Compiler_Command ("ada") use "gnatmake";
     for Gnatlist use "gnatls";
     for VCS_Kind use "CVS";
  end IDE;

  package Builder is
     for Default_Switches ("ada") use ("-m", "-g");
  end Builder;

  package Compiler is
     for Default_Switches ("ada") use Tash_Options.Compiler_Options;
     for Default_Switches ("C") use ("-c", "-g", "-O2", "-I/usr/include");
  end Compiler;

end Build_Tash_Library;




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Including C source in GNAT project for building library
  2008-01-24  5:27 Including C source in GNAT project for building library Simon Wright
@ 2008-01-24  5:54 ` Per Sandberg
  2008-01-24  8:33   ` Simon Wright
  2008-01-24  6:05 ` Simon Wright
  1 sibling, 1 reply; 4+ messages in thread
From: Per Sandberg @ 2008-01-24  5:54 UTC (permalink / raw)


Simon,
The project file looks ok to me but gnatmake only accepts Ada so you 
need to use gprmake to use other languages.

/Per

Simon Wright wrote:
> This relates to building TASH as a library (static, libtash.a) using
> GNAT Project, as in GNAT-GPL-2007.
> 
> As well as Ada source, this library needs two C-sourced units to act
> as wrappers for macros in the Tcl/Tk header files.
> 
> I can do this by hand (obviously only for a static library) by doing
> this after gnatmake has done its part:
> 
>    gcc -c -g -O2 -I/usr/include tclmacro.c
>    gcc -c -g -O2 -I/usr/include tkmacro.c
>    ar -r lib/libtash.a tclmacro.o tkmacro.o
>    ranlib lib/libtash.a
> 
> but can't help feeling there should be a way to tell gnatmake to do
> this!
> 
> So far I have
> 
> with "../tash_options";
> 
> project Build_Tash_Library is
> 
>   for Library_Name use "tash";
>   for Languages use ("Ada","C");
>   for Library_Interface use
>     (
>      "cargv",
>      "chelper",
>      "tash.arrays",
>      "tash.file",
>      "tash.file_io",
>      "tash.float_arrays",
>      "tash.float_lists",
>      "tash.floats",
>      "tash.integer_arrays",
>      "tash.integer_lists",
>      "tash.integers",
>      "tash.lists",
>      "tash.platform",
>      "tash.regexp",
>      "tash.strings",
>      "tash.system",
>      "tash",
>      "tcl.ada",
>      "tcl.tk.ada",
>      "tcl.tk",
>      "tcl"
>      );
>   for Source_Files use
>     (
>      "tclmacro.c",
>      "tkmacro.c",
>      "cargv.adb",
>      "cargv.ads",
>      "chelper.adb",
>      "chelper.ads",
>      "tash-arrays.adb",
>      "tash-arrays.ads",
>      "tash-file.adb",
>      "tash-file.ads",
>      "tash-file_io.adb",
>      "tash-file_io.ads",
>      "tash-float_arrays.ads",
>      "tash-float_lists.ads",
>      "tash-floats.adb",
>      "tash-floats.ads",
>      "tash-integer_arrays.ads",
>      "tash-integer_lists.ads",
>      "tash-integers.adb",
>      "tash-integers.ads",
>      "tash-lists.adb",
>      "tash-lists.ads",
>      "tash-platform.adb",
>      "tash-platform.ads",
>      "tash-regexp.adb",
>      "tash-regexp.ads",
>      "tash-strings.adb",
>      "tash-strings.ads",
>      "tash-system.adb",
>      "tash-system.ads",
>      "tash.adb",
>      "tash.ads",
>      "tcl-ada.adb",
>      "tcl-ada.ads",
>      "tcl-tk-ada.adb",
>      "tcl-tk-ada.ads",
>      "tcl-tk.adb",
>      "tcl-tk.ads",
>      "tcl.adb",
>      "tcl.ads"
>     );
>   for Object_Dir use ".build_lib";
>   for Library_Kind use "static";
>   for Library_Src_Dir use "lib";
>   for Library_Dir use "lib";
> 
>   package IDE is
>      for Compiler_Command ("ada") use "gnatmake";
>      for Gnatlist use "gnatls";
>      for VCS_Kind use "CVS";
>   end IDE;
> 
>   package Builder is
>      for Default_Switches ("ada") use ("-m", "-g");
>   end Builder;
> 
>   package Compiler is
>      for Default_Switches ("ada") use Tash_Options.Compiler_Options;
>      for Default_Switches ("C") use ("-c", "-g", "-O2", "-I/usr/include");
>   end Compiler;
> 
> end Build_Tash_Library;
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Including C source in GNAT project for building library
  2008-01-24  5:27 Including C source in GNAT project for building library Simon Wright
  2008-01-24  5:54 ` Per Sandberg
@ 2008-01-24  6:05 ` Simon Wright
  1 sibling, 0 replies; 4+ messages in thread
From: Simon Wright @ 2008-01-24  6:05 UTC (permalink / raw)


Simon Wright <simon.j.wright@mac.com> writes:

> As well as Ada source, this library needs two C-sourced units to act
> as wrappers for macros in the Tcl/Tk header files.
>
> I can do this by hand (obviously only for a static library) by doing
> this after gnatmake has done its part:
>
>    gcc -c -g -O2 -I/usr/include tclmacro.c
>    gcc -c -g -O2 -I/usr/include tkmacro.c
>    ar -r lib/libtash.a tclmacro.o tkmacro.o
>    ranlib lib/libtash.a
>
> but can't help feeling there should be a way to tell gnatmake to do
> this!

OK, this seems to work:

   gprmake -P build_tash_library.gpr
   gnatmake -P build_tash_library.gpr

because gnatmake includes all the objects it finds in the object
directory in the resulting library.

Is this The Way?



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Including C source in GNAT project for building library
  2008-01-24  5:54 ` Per Sandberg
@ 2008-01-24  8:33   ` Simon Wright
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Wright @ 2008-01-24  8:33 UTC (permalink / raw)


Per Sandberg <per.sandberg@bredband.net> writes:

> The project file looks ok to me but gnatmake only accepts Ada so you
> need to use gprmake to use other languages.

Got it, thanks.

The next problem (may only be a Darwin thing) is that I was trying to
construct a static standalone library.

It looks as though a client gnatmake may manage to work out the
required elaboration but may not compute the library dependencies
right: eg, if the main program doesn't use tasking and neither do the
used parts of the library, things appear to work; but if the used
parts of the library use tasking, the binder leaves out libgnarl (I
only have .a, didn't build .dynlib).

I'm not even sure that elaboration is OK, because when I added -largs
-lgnarl it linked but I got a segv at runtime.

Workround: don't try to build a standalone static library! (ie, leave
out the Library_Interface attribute). This does mean copying the
source files to an include directory (can be the same as the object
directory).

Good to see the -p switch for {gnat,gpr}make (create required output
directories if needed).



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-01-24  8:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-24  5:27 Including C source in GNAT project for building library Simon Wright
2008-01-24  5:54 ` Per Sandberg
2008-01-24  8:33   ` Simon Wright
2008-01-24  6:05 ` Simon Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox