I em in neede for a possibility to check within a .gpr file which operating system is runnung. Is there a way to do that? So I can use the same project file without changing the .gpr file when compiling a program on different OS'ses.
On Thursday, June 18, 2020 at 1:33:20 PM UTC+2, ldries46 wrote:
> I em in neede for a possibility to check within a .gpr file which
> operating system is runnung. Is there a way to do that? So I can use the
> same project file without changing the .gpr file when compiling a
> program on different OS'ses.
Can't you define a scenario variable and set it on the command line? Then it's only the command line that differs between the two builds.
Regards,
Mark L
On 18/06/2020 13:32, ldries46 wrote: > I em in neede for a possibility to check within a .gpr file which > operating system is runnung. Is there a way to do that? So I can use the > same project file without changing the .gpr file when compiling a > program on different OS'ses. Well, it is a sad story. Actually there is Project'Target which should give you Linux-esque triplet containing architecture and OS. [Isn't it obvious that you need three fields for two things?] Unfortunately it does not work. Sometimes (most of the times?) it is empty. And even if it worked GRP has no means to split a triplet into parts because it has no string indexing. So you will end up with a long case like: Target_Triplet := Project'Target; case Target_Triplet is when "aarch64-linux-gnu" => when "arm-linux" => when "arm-linux-gnueabi" => when "arm-linux-gnueabihf" => when "x86_64-apple-darwin" => when "x86_64-freebsd" => and so on. So you will be better on with a scenario variable. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
Den 2020-06-18 kl. 13:32, skrev ldries46:
> I em in neede for a possibility to check within a .gpr file which
> operating system is runnung. Is there a way to do that? So I can use the
> same project file without changing the .gpr file when compiling a
> program on different OS'ses.
As others have replied you can use scenario variables.
And they are passed from commandline.
But gprbuild looks for variables passed in with -X like -XVARIBLE=Value
however if that is not found it will look for that name amomg the
environent variables
so I create env vars for current os/arch/db in the os
and test on every combination needed
db_libs := ();
case db is
when Oracle => db_libs := db_lib1;
when Postgresql => db_libs := db_lib2;
when sqlserver => db_libs := db_lib3;
end case
other_libs := ():
case os_arch is
when AIX_PPC => other_libs := lib1;
when Linux_x64 => other_libs := lib2;
when Linux_arm => other_libs := lib3;
when Win_64 => other_libs := lib4;
end case
and so on
the use db_libs and other-libs elsewhere in the gprfile
--
Björn
At this point I found within my environment variables on Windows:
OS=Windows_NT so I created the following in my .gpr file (I have not
yest looked in Linux, perhaps I shoud add OS=Linux there)
type OS_Kind is
("Windows_NT", "Linux");
OS : OS_Kind := external("OS", "Windows_NT");
case OS is
when "Windows_NT" =>
for Object_Dir use "./build";
for Exec_Dir use ".";
when "Linux" =>
for Object_Dir use "./build";
for Exec_Dir use ".";
for Casing use "mixedcase";
end case;
The problem now is the casing, that seems not to be available on
Windows. In Linux it looks like I need it because the standard there is
"lowercase" Is there an overall .gpr file that all project use in which
I can add or change that ?
Op 18-6-2020 om 13:32 schreef ldries46:
> I em in neede for a possibility to check within a .gpr file which
> operating system is runnung. Is there a way to do that? So I can use
> the same project file without changing the .gpr file when compiling a
> program on different OS'ses.
In the mean time still found the solution. Casing should be in a package
which makes an extra case neccesary.
Op 19-6-2020 om 10:01 schreef ldries46:
> At this point I found within my environment variables on Windows:
> OS=Windows_NT so I created the following in my .gpr file (I have not
> yest looked in Linux, perhaps I shoud add OS=Linux there)
>
> type OS_Kind is
> ("Windows_NT", "Linux");
> OS : OS_Kind := external("OS", "Windows_NT");
>
> case OS is
> when "Windows_NT" =>
> for Object_Dir use "./build";
> for Exec_Dir use ".";
> when "Linux" =>
> for Object_Dir use "./build";
> for Exec_Dir use ".";
> for Casing use "mixedcase";
> end case;
>
> The problem now is the casing, that seems not to be available on
> Windows. In Linux it looks like I need it because the standard there
> is "lowercase" Is there an overall .gpr file that all project use in
> which I can add or change that ?
>
>
> Op 18-6-2020 om 13:32 schreef ldries46:
>> I em in neede for a possibility to check within a .gpr file which
>> operating system is runnung. Is there a way to do that? So I can use
>> the same project file without changing the .gpr file when compiling
>> a program on different OS'ses.
>
On Friday, June 19, 2020 at 10:01:59 AM UTC+2, ldries46 wrote:
> At this point I found within my environment variables on Windows:
> OS=Windows_NT so I created the following in my .gpr file (I have not
> yest looked in Linux, perhaps I shoud add OS=Linux there)
>
> type OS_Kind is
> ("Windows_NT", "Linux");
> OS : OS_Kind := external("OS", "Windows_NT");
>
> case OS is
> when "Windows_NT" =>
> for Object_Dir use "./build";
> for Exec_Dir use ".";
> when "Linux" =>
> for Object_Dir use "./build";
> for Exec_Dir use ".";
> for Casing use "mixedcase";
> end case;
>
> The problem now is the casing, that seems not to be available on
> Windows. In Linux it looks like I need it because the standard there is
> "lowercase" Is there an overall .gpr file that all project use in which
> I can add or change that ?
Casing of what? Do you e.g. have directories with mixed casing?
It seems that your Object_Dir and Exec_Dir are the same on the two platforms. Do you have file names with mixed case?
Regards,
Mark L
Mark Lorenzen <mark.lorenzen@gmail.com> writes:
> Casing of what? Do you e.g. have directories with mixed casing?
>
> It seems that your Object_Dir and Exec_Dir are the same on the two
> platforms. Do you have file names with mixed case?
Casing is an attribute of package Naming.
It doesn't matter on Windows (or macOS), but it seems to me that if your
compiler is GNAT you might as well go with the flow and make all your
Ada source file names lower case! Not really that hard a mindset to get
into.
ldries46 <bertus.dries@planet.nl> writes: > I em in neede for a possibility to check within a .gpr file which > operating system is runnung. Is there a way to do that? So I can use > the same project file without changing the .gpr file when compiling a > program on different OS'ses. Alire settled on this[1] in an aggregate project after some heartsearching: Host_OS := external ("OS", "default"); -- On Windows an OS environment variable is defined, we can use it to -- determine if we are compiling on Windows. -- -- On macOS, the nearest equivalent is OSTYPE; however this is -- e.g. "darwin18", so not useful here. Set "macOS" by hand. -- ALIRE_OS is used in alire_common.gpr. -- GNATCOLL_OS is used in gnatcoll.gpr. case Host_OS is when "Windows_NT" => for External ("ALIRE_OS") use "windows"; for External ("GNATCOLL_OS") use "windows"; when "macOS" => for External ("ALIRE_OS") use "osx"; for External ("GNATCOLL_OS") use "osx"; when others => for External ("ALIRE_OS") use "unix"; for External ("GNATCOLL_OS") use "unix"; end case; but I've had a lot of trouble with aggregate projects (I don't think I've grasped what the use cases are). As I remember, it was package Builder that was the issue. [1] https://github.com/alire-project/alire/blob/master/alr_env.gpr#L22
Op 19-6-2020 om 18:29 schreef Simon Wright:
> Mark Lorenzen <mark.lorenzen@gmail.com> writes:
>
>> Casing of what? Do you e.g. have directories with mixed casing?
>>
>> It seems that your Object_Dir and Exec_Dir are the same on the two
>> platforms. Do you have file names with mixed case?
> Casing is an attribute of package Naming.
>
> It doesn't matter on Windows (or macOS), but it seems to me that if your
> compiler is GNAT you might as well go with the flow and make all your
> Ada source file names lower case! Not really that hard a mindset to get
> into.
I didn't correctly understood the way how to use Casing. That is needed
to be in the package Naming. In the meantime I have corrected that and
now I it works correctly.
No I want to use filenames with a mixed casing because I find then
easier to read or to recognize.
For instance using a file name of "Name_Main_CB" is better to recognize
(in my opinion) as "name_main_cb" as the file in which the package of
the Callbacks of the Initiation part of the main program is written.
At the moment I originally posted this point I didn't realized that the
standard on Windows is "\" and on Linux "/" although Windows recognizes
both. But let us be strict.