comp.lang.ada
 help / color / mirror / Atom feed
* conditionnal compilation
@ 2009-05-13 20:08 guerrier.cachalot
  2009-05-13 21:51 ` Jeffrey R. Carter
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: guerrier.cachalot @ 2009-05-13 20:08 UTC (permalink / raw)


Hi my friends
Now that I know Ada has not built'in support for conditional
compilation such a full-featured preprocessor, I would like know what
should I use instead ?
I precise I'm just a little beginner who doesn't want to compile
anything .
What really happend when I specify "--no-ssl" at some Ada-written
program compilation ?



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

* Re: conditionnal compilation
  2009-05-13 20:08 conditionnal compilation guerrier.cachalot
@ 2009-05-13 21:51 ` Jeffrey R. Carter
  2009-05-14  3:06 ` Hibou57 (Yannick Duchêne)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Jeffrey R. Carter @ 2009-05-13 21:51 UTC (permalink / raw)


guerrier.cachalot@gmail.com wrote:
> Now that I know Ada has not built'in support for conditional
> compilation such a full-featured preprocessor, I would like know what
> should I use instead ?

Conditional compilation and preprocessing was deliberately left out of Ada, 
because it leads to unreadable code. But if you want to create unreadable code, 
you can always use your favorite preprocessor.

Conditional compilation is usually used to deal with target variations. The Ada 
approach to this is to hide the target-specific things in a package body, and 
provide different bodies for different targets.

-- 
Jeff Carter
"We'll make Rock Ridge think it's a chicken
that got caught in a tractor's nuts!"
Blazing Saddles
87



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

* Re: conditionnal compilation
  2009-05-13 20:08 conditionnal compilation guerrier.cachalot
  2009-05-13 21:51 ` Jeffrey R. Carter
@ 2009-05-14  3:06 ` Hibou57 (Yannick Duchêne)
  2009-05-14  3:20 ` anon
  2009-05-14  4:20 ` Per Sandberg
  3 siblings, 0 replies; 6+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2009-05-14  3:06 UTC (permalink / raw)


On 13 mai, 22:08, guerrier.cacha...@gmail.com wrote:
> Hi my friends
> Now that I know Ada has not built'in support for conditional
> compilation such a full-featured preprocessor, I would like know what
> should I use instead ?
> I precise I'm just a little beginner who doesn't want to compile
> anything .
> What really happend when I specify "--no-ssl" at some Ada-written
> program compilation ?

Same as Jeffrey, with another thing : for flavoured and option driven
code, you may also write a little program (in Ada, you can, or a shell
script) which will produce an automatically generated code for a
package which will contains all flavoured variations. This may be
driven my a make file. This little program may be build during the
build process of the overall application.



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

* Re: conditionnal compilation
  2009-05-13 20:08 conditionnal compilation guerrier.cachalot
  2009-05-13 21:51 ` Jeffrey R. Carter
  2009-05-14  3:06 ` Hibou57 (Yannick Duchêne)
@ 2009-05-14  3:20 ` anon
  2009-05-14  4:20 ` Per Sandberg
  3 siblings, 0 replies; 6+ messages in thread
From: anon @ 2009-05-14  3:20 UTC (permalink / raw)


An easy way is to use a common specification file and provide multi-body 
files.

An example:
    spec:
       Package_ABC.ads  -- contains common prototype of routines
    body"
       Package_ABC_Linux.adb       -- routines written for Linux
       Package_ABC_Windows.adb     -- routines written for Windows
       Package_ABC_Linux_x64.adb   -- routines written for Linux x86_64
       ...

Then use a batch or script file to check and verify target then rename the 
correct body file to Package_ABC.adb.  Compile Package_ABC.adb and use 
package in your program.



In <4259b442-6772-4527-989a-b20e1641b8d0@g20g2000vba.googlegroups.com>, guerrier.cachalot@gmail.com writes:
>Hi my friends
>Now that I know Ada has not built'in support for conditional
>compilation such a full-featured preprocessor, I would like know what
>should I use instead ?
>I precise I'm just a little beginner who doesn't want to compile
>anything .
>What really happend when I specify "--no-ssl" at some Ada-written
>program compilation ?




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

* Re: conditionnal compilation
  2009-05-13 20:08 conditionnal compilation guerrier.cachalot
                   ` (2 preceding siblings ...)
  2009-05-14  3:20 ` anon
@ 2009-05-14  4:20 ` Per Sandberg
  2009-05-14  7:17   ` guerrier.cachalot
  3 siblings, 1 reply; 6+ messages in thread
From: Per Sandberg @ 2009-05-14  4:20 UTC (permalink / raw)


More on the above them when using GNAT project files:

When the number of target specific files is moderate:
--------------------------------------------------------------------
project my is
   -- Both the spec and body of My_Unit is target specific
   -- But i would recommend to keep the target specific parts
   --  as isolated as possible.
   type OS_Type is ("Windows_NT","Linux");
   OS : OS_Type := external("OS","Linux");
   package Naming is
     case OS is
       when "Linux" =>
          for Implementation("My.Unit") use "my-unit__Linux.adb";
          for Specification ("My.Unit") use "my-unit__Linux.ads";
       when "Windows_NT" =>
          for Implementation("My.Unit") use "my-unit__Win32.adb";
          for Specification ("My.Unit") use "my-unit__Win32.ads";
     end case;
   end Naming;
end my;
---------------------------------------------------------------------

When the number of target specific files is a bit larger:
--------------------------------------------------------------------
project my is
   -- The target specific files are kept in separate directories.
   type OS_Type is ("Windows_NT","Linux");
   OS : OS_Type := external("OS","Linux");
   for Source_Dirs use ("src");
     case OS is
       when "Linux" =>
          For Source_Dirs use project'Source_Dirs & ("src/Linux");
       when "Windows_NT" =>
          For Source_Dirs use project'Source_Dirs & ("src/Win32");
     end case;
end my;
--------------------------------------------------------------------

I would advice to one of the above schema's since they keep things 
understandable and try to stay with the first since Ada is usually is 
very portable.

But if conditional compilation is a requirement (in my opinion a very 
stupid one and this one is very compiler specific) you could read about 
it in:
  The GNAT users guide chapters:
    16. Preprocessing Using gnatprep
    3.2.17 Integrated Preprocessing	
The chapter references may not be 100% correct but anyway.

/Project files are an engineers best friend.
/Per


guerrier.cachalot@gmail.com wrote:
> Hi my friends
> Now that I know Ada has not built'in support for conditional
> compilation such a full-featured preprocessor, I would like know what
> should I use instead ?
> I precise I'm just a little beginner who doesn't want to compile
> anything .
> What really happend when I specify "--no-ssl" at some Ada-written
> program compilation ?



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

* Re: conditionnal compilation
  2009-05-14  4:20 ` Per Sandberg
@ 2009-05-14  7:17   ` guerrier.cachalot
  0 siblings, 0 replies; 6+ messages in thread
From: guerrier.cachalot @ 2009-05-14  7:17 UTC (permalink / raw)


Thank you very much.
I'm surprised by the help's speed here, God save comp.lang.ada !



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

end of thread, other threads:[~2009-05-14  7:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-13 20:08 conditionnal compilation guerrier.cachalot
2009-05-13 21:51 ` Jeffrey R. Carter
2009-05-14  3:06 ` Hibou57 (Yannick Duchêne)
2009-05-14  3:20 ` anon
2009-05-14  4:20 ` Per Sandberg
2009-05-14  7:17   ` guerrier.cachalot

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