Conditional include directories

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Conditional include directories

Mike Gran

Hello all,

In a standalone project makefile I want to add a -I directory
parameter to a CFLAGS variable.

On a 32-bit box, I need to add it as
-I/stage2/lib/dbus-1.0/include
 
One a 64-bit box, I need to add it as
-I/stage2/lib64/dbus-1.0/include

There are a bunch of ways to do this, I guess.  I could
check to see if the /stage2/lib64 directory exists.  I could
somehow check if the box is 32-bit or 64-bit.
 
What's easiest (in a readability / maintainability sense)?
 
Thanks,
 
Mike Gran

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Conditional include directories

Basile Starynkevitch
On Mon, Aug 03, 2015 at 04:38:37PM +0000, Mike Gran wrote:

>
> Hello all,
>
> In a standalone project makefile I want to add a -I directory
> parameter to a CFLAGS variable.
>
> On a 32-bit box, I need to add it as
> -I/stage2/lib/dbus-1.0/include
>  
> One a 64-bit box, I need to add it as
> -I/stage2/lib64/dbus-1.0/include
>
> There are a bunch of ways to do this, I guess.


A possible way might be to use pkg-config. Your Dbus library might be
registered in some pkg-config *.pc file.

http://www.freedesktop.org/wiki/Software/pkg-config/

A way of using it in your Makefile:
http://stackoverflow.com/questions/20145132/makefiles-how-can-i-use-them/20146082#20146082

Regards
--
Basile Starynkevitch       http://starynkevitch.net/Basile/
France                     basile at starynkevitch dot net

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

RE: Conditional include directories

Rakesh Sharma-6
One way can be as follows:

## pre-define your library directories based on the output of the "getconf" output format
LIB_32 := /stage2/lib/dbus-1.0/include
LIB_64 := /stage2/lib64/dbus-1.0/include

# then compute the architecture of the machine running gmake
CFLAGS := -I$(LIB_$(strip $(shell getconf LONG_BIT)))

### now you are all set for using the CFLAGS in your build code.
## you may want to incorporate some amount of error checking
# when the `getconf' command delivers output different than either 32 or 64.

# another method could be to invoke the "uname -m" command.



> Date: Mon, 3 Aug 2015 18:56:38 +0200
> From: [hidden email]
> To: [hidden email]
> Subject: Re: Conditional include directories
> CC: [hidden email]
>
> On Mon, Aug 03, 2015 at 04:38:37PM +0000, Mike Gran wrote:
>>
>> Hello all,
>>
>> In a standalone project makefile I want to add a -I directory
>> parameter to a CFLAGS variable.
>>
>> On a 32-bit box, I need to add it as
>> -I/stage2/lib/dbus-1.0/include
>>
>> One a 64-bit box, I need to add it as
>> -I/stage2/lib64/dbus-1.0/include
>>
>> There are a bunch of ways to do this, I guess.
>
>
> A possible way might be to use pkg-config. Your Dbus library might be
> registered in some pkg-config *.pc file.
>
> http://www.freedesktop.org/wiki/Software/pkg-config/
>
> A way of using it in your Makefile:
> http://stackoverflow.com/questions/20145132/makefiles-how-can-i-use-them/20146082#20146082
>
> Regards
> --
> Basile Starynkevitch http://starynkevitch.net/Basile/
> France basile at starynkevitch dot net
>
> _______________________________________________
> Help-make mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-make
     
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Conditional include directories

Stephan Beal-2
In reply to this post by Mike Gran
On Mon, Aug 3, 2015 at 6:38 PM, Mike Gran <[hidden email]> wrote:

> On a 32-bit box, I need to add it as
> -I/stage2/lib/dbus-1.0/include
>
> One a 64-bit box, I need to add it as
> -I/stage2/lib64/dbus-1.0/include
>
> There are a bunch of ways to do this, I guess.  I could
> check to see if the /stage2/lib64 directory exists.  I could
> somehow check if the box is 32-bit or 64-bit.
>
> What's easiest (in a readability / maintainability sense)?



i would think the simplest way is simply to use the first one it finds:

[stephan@host:~/tmp]$ cat foo.make
foodir := $(wildcard /usr/nono /usr/share)
all:
# foodir=$(foodir)
[stephan@host:~/tmp]$ make -f foo.make
# foodir=/usr/share

it's not perfect, but it "should" suffice for your case, i think.

--
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Conditional include directories

Stephan Beal-2
On Tue, Aug 4, 2015 at 1:24 PM, Stephan Beal <[hidden email]>
wrote:

> On Mon, Aug 3, 2015 at 6:38 PM, Mike Gran <[hidden email]> wrote:
>
>> On a 32-bit box, I need to add it as
>> -I/stage2/lib/dbus-1.0/include
>>
>> One a 64-bit box, I need to add it as
>> -I/stage2/lib64/dbus-1.0/include
>>
>> There are a bunch of ways to do this, I guess.  I could
>> check to see if the /stage2/lib64 directory exists.  I could
>> somehow check if the box is 32-bit or 64-bit.
>>
>> What's easiest (in a readability / maintainability sense)?
>
>
>
> i would think the simplest way is simply to use the first one it finds:
>

this time with the missing piece (use only the first entry):

[stephan@host:~/tmp]$ cat foo.make
foodir := $(wildcard /usr/nono /usr/share /usr/lib)
bardir := $(word 1,$(foodir))
all:
# foodir=$(foodir)
# bardir=$(bardir)
[stephan@host:~/tmp]$ make -f foo.make
# foodir=/usr/share /usr/lib
# bardir=/usr/share


--
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Conditional include directories

Reinier Post
In reply to this post by Stephan Beal-2
On Tue Aug  4 13:24:51 2015, [hidden email] (Stephan Beal) wrote:
> On Mon, Aug 3, 2015 at 6:38 PM, Mike Gran <[hidden email]> wrote:
>
> > On a 32-bit box, I need to add it as
> > -I/stage2/lib/dbus-1.0/include
> >
> > One a 64-bit box, I need to add it as
> > -I/stage2/lib64/dbus-1.0/include

[...]

> i would think the simplest way is simply to use the first one it finds:

I wouldn't do this - a system may have both.

--
Reinier

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Conditional include directories

Reinier Post
In reply to this post by Rakesh Sharma-6
On Tue Aug  4 04:03:32 2015, [hidden email] (Rakesh Sharma) wrote:

> One way can be as follows:
>
> ## pre-define your library directories based on the output of the "getconf" output format
> LIB_32 := /stage2/lib/dbus-1.0/include
> LIB_64 := /stage2/lib64/dbus-1.0/include
>
> # then compute the architecture of the machine running gmake
> CFLAGS := -I$(LIB_$(strip $(shell getconf LONG_BIT)))
>
> ### now you are all set for using the CFLAGS in your build code.
> ## you may want to incorporate some amount of error checking
> # when the `getconf' command delivers output different than either 32 or 64.
>
> # another method could be to invoke the "uname -m" command.

How portable is this software supposed to be?

uname exists on all the Unixy systems I've used;
I'm not sure about getconf, but I notice it exists on Cygwin.

--
Reinier Post
TU Eindhoven

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

RE: Conditional include directories

Rakesh Sharma-6

Actually, it is getconf which is used for maximum portability.
The POSIX manual has more on that.  It's a little-known but
quite a useful tool in the shell toolbox.

--Rakesh

----------------------------------------

> Date: Tue, 4 Aug 2015 13:49:06 +0200
> From: [hidden email]
> To: [hidden email]
> Subject: Re: Conditional include directories
>
> On Tue Aug 4 04:03:32 2015, [hidden email] (Rakesh Sharma) wrote:
>> One way can be as follows:
>>
>> ## pre-define your library directories based on the output of the "getconf" output format
>> LIB_32 := /stage2/lib/dbus-1.0/include
>> LIB_64 := /stage2/lib64/dbus-1.0/include
>>
>> # then compute the architecture of the machine running gmake
>> CFLAGS := -I$(LIB_$(strip $(shell getconf LONG_BIT)))
>>
>> ### now you are all set for using the CFLAGS in your build code.
>> ## you may want to incorporate some amount of error checking
>> # when the `getconf' command delivers output different than either 32 or 64.
>>
>> # another method could be to invoke the "uname -m" command.
>
> How portable is this software supposed to be?
>
> uname exists on all the Unixy systems I've used;
> I'm not sure about getconf, but I notice it exists on Cygwin.
>
> --
> Reinier Post
> TU Eindhoven
>
> _______________________________________________
> Help-make mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-make
     
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Conditional include directories

Stephan Beal-3
In reply to this post by Reinier Post
A 32-bit system is unlikely to have the 64-bit libs. If that's a risk, then
yeah, my proposal is broken, but i have never seen such a system (in which
case put the 64s first in the list of dirs to check).

----- stephan
Sent from a mobile device, possibly from bed. Please excuse brevity and
typos.
On Aug 4, 2015 1:45 PM, "Reinier Post" <[hidden email]> wrote:

> On Tue Aug  4 13:24:51 2015, [hidden email] (Stephan Beal)
> wrote:
> > On Mon, Aug 3, 2015 at 6:38 PM, Mike Gran <[hidden email]> wrote:
> >
> > > On a 32-bit box, I need to add it as
> > > -I/stage2/lib/dbus-1.0/include
> > >
> > > One a 64-bit box, I need to add it as
> > > -I/stage2/lib64/dbus-1.0/include
>
> [...]
>
> > i would think the simplest way is simply to use the first one it finds:
>
> I wouldn't do this - a system may have both.
>
> --
> Reinier
>
> _______________________________________________
> Help-make mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-make
>
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Conditional include directories

Mike Gran
In reply to this post by Rakesh Sharma-6
On Tuesday, August 4, 2015 4:03 AM, Rakesh Sharma <[hidden email]> wrote:


>
>
>One way can be as follows: ## pre-define your library directories based on the output of the "getconf" output format


Thanks.  I like this idea.

I've never heard of getconf, but I checked its output on the two build VMs.
It does return "32" and "64" on the 32-bit box and 64-bit box respectively.
That is easier than parsing uname, for sure.

Thanks everyone for the other suggestions.

-Mike

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make