comp.lang.ada
 help / color / mirror / Atom feed
* Building a minimal-source-code Ada library with GNAT
@ 2002-03-08  5:45 Michael Card
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Card @ 2002-03-08  5:45 UTC (permalink / raw)


Hello CLA-

I am trying to do something with GNAT 3.14 that I have not done before
and I am hoping someone out there has done this and can point me in the
right direction. Google searches for this info have proved fruitless.

What I am trying to do is build a GNAT Ada library that contains all of
the .o and .ali files for a re-usable software component and as little
of the re-usable component's source code as possible. What I did to
build the library was to compile all of the source code and then delete
the .adb (body) files that a user would not need to see from the
directory containing the GNAT Ada library. The code is something like
this:

top_level_pkg.ads -- root pkg user withs in
top_level_pkg.adb -- root pkg body, deleted user doesn't need it
top_level_pkg-public_generic_child_1.ads -- spec of generic child user
will need to instantiate
top_level_pkg-public_generic_child_1.adb -- body of generic child 1
top_level_pkg-public_generic_child_2.ads -- another generic for user
top_level_pkg-public_generic_child_2.adb -- body of generic child 2
top_level_pkg-private_child_1.ads -- spec of private pkg, included
because bodies of public generics with this in
top_level_pkg-private_child_1.adb -- deleted, user doesn't need it
top_level_pkg-private_child_2.ads -- 2nd private pkg withed in by
bodies of public generic child pkgs
top_level_pkg-private_child_2.adb -- deleted, user doesn't need it

The code is compiled simply like this:

foreach f (*.ad{s,b})
   gcc -c $f
end

and the un-needed .adb files are deleted.

The idea is to expose only the code you want the user to see, hiding
the rest of the source and providing only .ali and .o files for the
removed .adb files. Since none of the bodies removed are necessary for
a user to compile against the library, it seems like this should work.

When I try a gnatmake against such a library, however, the compilation
goes fine but the gnatbind fails in an interesting way. It gives errors
like this:

error: filename.adb needs to be recompiled

The interesting thing is that filename.adb may be one of the removed
files, but I built a library leaving in the files it complained about
and still got this error. For the gnatmake, I used the -A<path to Ada
library> option to point to these Ada libraries, as it looked like this
was what I should use. For example:

gnatmake -g -gnatE my_application -A/path_to_library
-A/path_to_library_2 -largs -lsocket -lnsl

Again, the compilation goes fine even with these .adb files removed, th
eproblem is in gnatbind. I also tried using the -x and -t options on
gnatbind but got the same error:

gnatmake -g -gnatE my_application -A/path_to_library
-A/path_to_library_2 -largs -lsocket -lnsl -bargs -x -t

Has anyone else ever tried this? I assume it must be possible to
release a library in GNAT without providing ALL of the source code, but
I cannot figure out how to do this. Any guidanace would be much
appreciated!

Thanks,

Mike



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

* Re: Building a minimal-source-code Ada library with GNAT
@ 2002-03-08  7:52 Christoph Grein
  2002-03-09  2:24 ` Michael Card
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Grein @ 2002-03-08  7:52 UTC (permalink / raw)


> and still got this error. For the gnatmake, I used the -A<path to Ada
> library> option to point to these Ada libraries, as it looked like this
> was what I should use. For example:
> 
> gnatmake -g -gnatE my_application -A/path_to_library
> -A/path_to_library_2 -largs -lsocket -lnsl

See the "Search Paths and the Run-Time Library (RTL)" section in Gnat UG. The correct 
switch is -Idir. Also make the ALI files read only.



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

* Re: Building a minimal-source-code Ada library with GNAT
  2002-03-08  7:52 Christoph Grein
@ 2002-03-09  2:24 ` Michael Card
  2002-03-09 15:45   ` Wes Groleau
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Card @ 2002-03-09  2:24 UTC (permalink / raw)


Chris-

Thanks for the suggestions. The use of -I vs -A didn't change anything
for me, but I did figure out how to do this. 

As it turns out, the crucial step I was missing was that my .o and .ali
files had to be created as the resulting of LINKING one or more
applications that used the top-level packages. So, the steps I followed
were:

1. I ran gnatmake a few times to build several applications, so that as
a result all of the top-level packages would be used (i.e. all of the
top-level public generics would be instantiated), i.e.

gnatmake -g -gnatE my_application -I /path_to_my_app_source
-I/path_to_lib1_source -I/path_to_lib2_source -largs -lsocket -lnsl

gnatmake -g -gnatE my_application_2 -I /path_to_my_app_source
-I/path_to_lib1_source -I/path_to_lib2_source -largs -lsocket -lnsl

2. Next, I created subdirectories to hold the .o files and the .ali
files that would be put into the Ada libraries

3. I moved the .o and .ali files into their respective subdirectories.
I did as you suggested and did a chmod 444 to make the .ali files
read-only.

4. I created an object archive of all of the .o files in the library
subdirectories using ar, then deleted the .o files. The archives had
the usual naming convention, i.e. lib<Adalib_name>.a

5. I used cp -p to copy the necessary .ads and .adb files into the
library subdirectories, leaving out the source code that was not needed
for compilation that I wanted to "hide" from users of the libraries

6. After doing these things, I cleaned (rm *.*) the directory where I
initially build the applications, and I was able to build and run them
successfully using my new GNAT Ada libraries like this:

gnatmake -g -gnatE my_application -I /path_to_my_app_source
-I/path_to_Adalib_1 -I/path_to_Adalib_2 -L/path_to_Adalib_1
-L/path_to_Adalib_2 -largs -lsocket -lnsl -lAdalib1_name -lAdalib2_name

- Mike

In article <mailman.1015573982.10301.comp.lang.ada@ada.eu.org>,
Christoph Grein <christoph.grein@eurocopter.com> wrote:

> > and still got this error. For the gnatmake, I used the -A<path to Ada
> > library> option to point to these Ada libraries, as it looked like this
> > was what I should use. For example:
> > 
> > gnatmake -g -gnatE my_application -A/path_to_library
> > -A/path_to_library_2 -largs -lsocket -lnsl
> 
> See the "Search Paths and the Run-Time Library (RTL)" section in Gnat UG. The
> correct 
> switch is -Idir. Also make the ALI files read only.



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

* Re: Building a minimal-source-code Ada library with GNAT
  2002-03-09  2:24 ` Michael Card
@ 2002-03-09 15:45   ` Wes Groleau
  2002-03-10  2:28     ` Michael Card
  0 siblings, 1 reply; 5+ messages in thread
From: Wes Groleau @ 2002-03-09 15:45 UTC (permalink / raw)



> 1. I ran gnatmake a few times to build several applications, so that as
> a result all of the top-level packages would be used (i.e. all of the
> top-level public generics would be instantiated), i.e.

Couldn't you just make one "dummy app" that withs ALL of your APIs
and does nothing else?

-- 
Wes Groleau
http://freepages.rootsweb.com/~wgroleau



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

* Re: Building a minimal-source-code Ada library with GNAT
  2002-03-09 15:45   ` Wes Groleau
@ 2002-03-10  2:28     ` Michael Card
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Card @ 2002-03-10  2:28 UTC (permalink / raw)


In article <3C8A2E34.AFD31B2D@despammed.com>, Wes Groleau
<wesgroleau@despammed.com> wrote:

> > 1. I ran gnatmake a few times to build several applications, so that as
> > a result all of the top-level packages would be used (i.e. all of the
> > top-level public generics would be instantiated), i.e.
> 
> Couldn't you just make one "dummy app" that withs ALL of your APIs
> and does nothing else?

Yes, but I already had real apps. Also, I *think* you have to actually
instantiate the generics once but I could be wrong sbout that

- Mike



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

end of thread, other threads:[~2002-03-10  2:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-08  5:45 Building a minimal-source-code Ada library with GNAT Michael Card
  -- strict thread matches above, loose matches on Subject: below --
2002-03-08  7:52 Christoph Grein
2002-03-09  2:24 ` Michael Card
2002-03-09 15:45   ` Wes Groleau
2002-03-10  2:28     ` Michael Card

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