help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Maintaining PATH while running make with sudo


From: Peter Johnson
Subject: Re: Maintaining PATH while running make with sudo
Date: Mon, 1 Mar 2010 13:51:42 -0800

Steve,

Something I like to do is to set the PATH in the Makefile rather than relying 
on a PATH to be set from the user environment. This allows me to set the 
version of the tool in the Makefile and then not have users using the wrong 
version of the tool.

So I can say something like

COMPILER_VERSION = 1.3
COMPILER_ROOT = /tools/compiler/${COMPILER_VERSION}
COMPILER_INCLUDE = ${COMPILER_ROOT}/include
COMPILER_BIN = ${COMPILER_ROOT}/bin
COMPILER_LIB = ${COMPILER_ROOT}/lib

CC = PATH=${COMPILER_BIN}:${PATH} gcc

Then when I use ${CC} in a rule I get the compiler I want. If I change 
COMPILER_VERSION to test a new compiler version, the whole flow changes at 
once. That way you don't have to keep paths in two separate places, and you are 
sure that everyone is using the same version.

-Pete

On Mar 1, 2010, at 1:31 PM, Steve Deiters wrote:

> I had thought make was changing my PATH under root for some reason, but
> it is actually just the root login modifying it.  I am trying to keep a
> path to my compiler when I run make with sudo so I can run 'sudo make
> install', but my compiler is a cross compiler in a non-standard
> location.
> 
> It seems this is not a make issue though.  Now I just need to find the
> right startup script to put my path in for sudo access.
> 
> Thanks.
> 
> 
>> -----Original Message-----
>> From: John Calcote [mailto:address@hidden 
>> Sent: Monday, March 01, 2010 3:07 PM
>> To: Steve Deiters
>> Cc: address@hidden
>> Subject: Re: Maintaining PATH while running make with sudo
>> 
>> Hi Steve,
>> 
>> I this what you're talking about:
>> 
>> $ sudo -s
>> root's password:
>> # echo $PATH
>> /usr/sbin:/bin:/usr/bin:/sbin
>> # make
>> /usr/sbin:/bin:/usr/bin:/sbin
>> #
>> # cat Makefile
>> all:
>>         @echo $(PATH)
>> #
>> # make --version
>> GNU Make 3.81
>> Copyright (C) 2006  Free Software Foundation, Inc.
>> This is free software; see the source for copying conditions.
>> There is NO warranty; not even for MERCHANTABILITY or FITNESS 
>> FOR A PARTICULAR PURPOSE.
>> 
>> This program built for x86_64-unknown-linux-gnu
>> 
>> Seems to work for me on my 64-bit opensuse 11.2 box.
>> 
>> John
>> 
>> On 3/1/2010 1:52 PM, Steve Deiters wrote:
>>> It seems make is setting a default PATH variable when I run 
>> with sudo.
>>> If I run a root shell with 'sudo -s' followed by 'echo 
>> $PATH', I see 
>>> the correct PATH.  However, while in the root shell if I run the 
>>> simple
>>> Makefile:
>>> 
>>> 
>>> ----Makefile----
>>> 
>>> all:
>>>     @echo $(PATH)
>>> 
>>> ----------------
>>> 
>>> it will not give me the same as the result from the echo.
>>> 
>>> 
>>> I am running Make 3.81, sudo 1.6.9p10, on Ubuntu 2.6.24-25-server 
>>> kernel.
>>> 
>>> Thanks.
>>> 
>>> 
>>> 
>>> _______________________________________________
>>> Help-make mailing list
>>> address@hidden
>>> http://lists.gnu.org/mailman/listinfo/help-make
>>> 
>>> 
>> 
>> 
> 
> 
> _______________________________________________
> Help-make mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-make





reply via email to

[Prev in Thread] Current Thread [Next in Thread]