comp.lang.ada
 help / color / mirror / Atom feed
From: Chrono <pablittto@gmail.com>
Subject: Re: Conditional Compilation in Ada
Date: Mon, 29 Jun 2009 05:01:35 -0700 (PDT)
Date: 2009-06-29T05:01:35-07:00	[thread overview]
Message-ID: <942d7aa6-a93b-45a3-b250-9398e2754af7@y17g2000yqn.googlegroups.com> (raw)
In-Reply-To: 768c8117-d8af-4a04-b27e-2e74b69c1e8b@y17g2000yqn.googlegroups.com

Yes, I mean a GPS scenario. In my case it is a bit difficult to put
files in a different folder for each scenario, due to I need to lead
with a some thousands of files project. I used to have a solution with
included a prepost compilation, a script launched before the unit
compilation which turned up some part of the code to a commented one,
so in "real" compilation, that part would not be compilated. I have a
feeling that GPS has some way to do this without external scripts, a
more ellegant solution, maybe using some compilation directives.
My last implementation included some like this:

package body My_Package is
  procedure Calculate_Data (My_Variable : out Some_Type) is
  begin
    --# if TARGET
    MY_Variable = 1;
    --# end If TARGET

    --# if HOST
    MY_Variable = 2;
    --# end If HOST
  end Calculate_Data;
end My_Package;

so I just discover a way to set two environments, e.g., TARGET and
HOST, and compile each one according to the GPS scenario chosen.

On 29 jun, 08:42, sjw <simon.j.wri...@mac.com> wrote:
> On Jun 29, 12:10 pm, Pablo <pablit...@gmail.com> wrote:
>
> > Hi, does someone know how to make conditional compilation in Ada with
> > Scenarios? Say, I need to hide from compilation a part of an Ada code
> > in some Scenario mode.
>
> When you say 'scenario' do you mean a GPS scenario? If not, you will
> have to tell us more...
>
> The normal way of dealing with this problem is to put the alternate
> codes in different directories and adjust the compiler's source path
> to pick up the appropriate file.
>
> package body Target is
>    ..
>    function Get_Position (At_Time : Time) return Position is separate;
>    ..
>

> then (with GNAT) the separate body will be target-get_position.adb. If
> your scenarios are Real and Simulated, make subdirectories Real/ and
> Simulated/ and place an appropriate implementation in each. Your GPR
> might then look like
>
>    type Environment is ("Real", "Simulated");
>    Env : Environment := external ("ENVIRONMENT");
>    case Env is
>       when "Real" => Env_Path = "Real";
>       when "Simulated" => Env_Path = "Simulated";
>    end case;
>    for Source_Dirs use ..... & Env_Path;
>
> (I haven't tested this particular example ...)




  reply	other threads:[~2009-06-29 12:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-29 11:10 Conditional Compilation in Ada Pablo
2009-06-29 11:42 ` sjw
2009-06-29 12:01   ` Chrono [this message]
2009-06-29 12:30     ` Dmitry A. Kazakov
2009-06-29 12:15   ` sjw
2009-06-29 18:00     ` Chrono
2009-06-29 20:02       ` sjw
2009-06-30 10:41         ` Chrono
2009-06-29 20:13       ` Robert A Duff
2009-06-30 15:39 ` Per Sandberg
2009-06-30 17:03   ` Chrono
2009-06-30 20:09   ` sjw
2009-06-30 20:15   ` sjw
2009-07-01 16:20     ` Per Sandberg
2009-07-01  0:18 ` anon
replies disabled

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