tilde expansion not working in makefiles
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > tilde expansion not working in makefiles




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    tilde expansion not working in makefiles  
Simon Elliott


Report This Message To A Moderator Edit/Delete Message


 
02-14-06 12:49 PM

INCLUDE = -I~/mylibs

CFLAGS= -g -Wall $(INCLUDE)

$(OBJDIR)/%.o : %.cpp
$(COMPILE.cpp) $< $(CFLAGS) -MMD -o $@


The tilde's aren't being expanded to the current home directory. The
GNU mkae manual suggests that they should be. Any suggestions why this
isn't working?

--
Simon Elliott    http://www.ctsn.co.uk





[ Post a follow-up to this message ]



    Re: tilde expansion not working in makefiles  
Robert Harris


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-14-06 12:50 PM

Simon Elliott wrote:
> INCLUDE = -I~/mylibs
>
> CFLAGS= -g -Wall $(INCLUDE)
>
> $(OBJDIR)/%.o : %.cpp
> 	$(COMPILE.cpp) $< $(CFLAGS) -MMD -o $@
>
>
> The tilde's aren't being expanded to the current home directory. The
> GNU mkae manual suggests that they should be. Any suggestions why this
> isn't working?

make won't substitute the tilde in the command but your shell should do.
What happens if you just type:

g++ xx.cpp -g -Wall -I~/mylibs -MMD -o xx

(substituting a plausible file name for xx)

Robert





[ Post a follow-up to this message ]



    Re: tilde expansion not working in makefiles  
Paul D. Smith


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-14-06 12:50 PM

%% "Simon Elliott" <Simon at ctsn.co.uk> writes:

se> INCLUDE = -I~/mylibs
se> CFLAGS= -g -Wall $(INCLUDE)

se> $(OBJDIR)/%.o : %.cpp
se> 	$(COMPILE.cpp) $< $(CFLAGS) -MMD -o $@

se> The tilde's aren't being expanded to the current home
se> directory. The GNU mkae manual suggests that they should be. Any
se> suggestions why this isn't working?

The GNU make manual says:

>    The character `~' at the beginning of a file name also has special
> significance.  If alone, or followed by a slash, it represents your home
> directory.  For example `~/bin' expands to `/home/you/bin'.

Your use of the tilde, "-I~/mylibs", is not at the beginning of the
word: it's in the middle.  Thus it isn't eligible for tilde expansion.

You need to write "-I ~/mylibs".  Even that isn't a guarantee (see
below).  I suggest you just write "-I$(HOME)/mylibs" instead (although
of course, having a makefile depend on the content of your home
directory is just asking for trouble in general).


The GNU make manual also says:

>    Wildcard expansion happens automatically in targets, in
> prerequisites, and in commands (where the shell does the expansion).
> In other contexts, wildcard expansion happens only if you request it
> explicitly with the `wildcard' function.

I think this should be more clear, that not all shells do
tilde-expansion and thus expansion in commands is not guaranteed.

--
----------------------------------------------------------------------------
---
Paul D. Smith <psmith@gnu.org>          Find some GNU make tips at:
http://www.gnu.org                      http://make.paulandlesley.org
"Please remain calm...I may be mad, but I am a professional." --Mad Scientis
t





[ Post a follow-up to this message ]



    Re: tilde expansion not working in makefiles  
Nils O. Selåsdal


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-14-06 10:54 PM

Robert Harris wrote:
> Simon Elliott wrote: 
>
> make won't substitute the tilde in the command but your shell should do.
> What happens if you just type:
>
> g++ xx.cpp -g -Wall -I~/mylibs -MMD -o xx
>
> (substituting a plausible file name for xx)
It shouldn't work here either. The tilde isn't the beginning
of a token the shell will interpret as a filename.

g++ xx.cpp -g -Wall -I ~/mylibs -MMD -o xx
should work.





[ Post a follow-up to this message ]



    Re: tilde expansion not working in makefiles  
Simon Elliott


Report This Message To A Moderator Edit/Delete Message


 
02-14-06 10:54 PM

On 14/02/2006, Robert Harris wrote:

> make won't substitute the tilde in the command but your shell should
> do. What happens if you just type:
>
> g++ xx.cpp -g -Wall -I~/mylibs -MMD -o xx
>
> (substituting a plausible file name for xx)

The above doesn't get expanded but this does:

g++ xx.cpp -g -Wall -I ~/mylibs -MMD -o xx

It seems the space before the tilde is critical

--
Simon Elliott    http://www.ctsn.co.uk





[ Post a follow-up to this message ]



    Re: tilde expansion not working in makefiles  
Simon Elliott


Report This Message To A Moderator Edit/Delete Message


 
02-14-06 10:54 PM

On 14/02/2006, Paul D. Smith wrote:

> The GNU make manual says:
> 
>
> Your use of the tilde, "-I~/mylibs", is not at the beginning of the
> word: it's in the middle.  Thus it isn't eligible for tilde expansion.

What was confusing me was the statement "The character `~' at the
beginning of a file name". In my example, the tilde was at the
beginning of the file name, but was not the beginning of a token.

> You need to write "-I ~/mylibs".  Even that isn't a guarantee (see
> below).  I suggest you just write "-I$(HOME)/mylibs" instead

Thanks - this works as expected.

> (although
> of course, having a makefile depend on the content of your home
> directory is just asking for trouble in general).

Fair comment. I want to set up a source tree where developers can work
on their bits, but where the same makefiles will work when it all comes
together. In the past I've done this by giving the project its own
login for the production code, so that there's always a home directory.
Individual developers can copy a subset or all of the project to their
own space and the makefiles still allow them to buld their bits.

I expect there are other (better?) ways of skinning this cat.

> The GNU make manual also says:
> 
>
> I think this should be more clear, that not all shells do
> tilde-expansion and thus expansion in commands is not guaranteed.

Yes. In my initial google search for a solution, the most common cause
of tilde not working was that the shell didn't support it.


--
Simon Elliott    http://www.ctsn.co.uk





[ Post a follow-up to this message ]



    Re: tilde expansion not working in makefiles  
Paul D. Smith


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-14-06 10:54 PM

%% "Simon Elliott" <Simon at ctsn.co.uk> writes:
[vbcol=seagreen] 
[vbcol=seagreen] 

se> What was confusing me was the statement "The character `~' at the
se> beginning of a file name". In my example, the tilde was at the
se> beginning of the file name, but was not the beginning of a token.

Yes.  I looked at the documentation but it's difficult to come up with a
better comment, other than pointing out a bunch of special cases.  This
section of the manual is really talking about targets and prerequisites,
where a word == a file name; there's no ambiguity there.

It's only later on that the manual mentions tildes in commands.  I
reworked that section slightly to make it more obvious that tildes in
commands are handled according to the shell and shell expansion rules.

--
----------------------------------------------------------------------------
---
Paul D. Smith <psmith@gnu.org>          Find some GNU make tips at:
http://www.gnu.org                      http://make.paulandlesley.org
"Please remain calm...I may be mad, but I am a professional." --Mad Scientis
t





[ Post a follow-up to this message ]



    Re: tilde expansion not working in makefiles  
Simon Elliott


Report This Message To A Moderator Edit/Delete Message


 
02-18-06 03:40 AM

On 14/02/2006, Paul D. Smith wrote:

> Yes.  I looked at the documentation but it's difficult to come up
> with a better comment, other than pointing out a bunch of special
> cases.  This section of the manual is really talking about targets
> and prerequisites, where a word == a file name; there's no ambiguity
> there.
>
> It's only later on that the manual mentions tildes in commands.  I
> reworked that section slightly to make it more obvious that tildes in
> commands are handled according to the shell and shell expansion rules.

It's good that something positive has come out of my misunderstanding!
Thanks again for your helpful response to my queries.


--
Simon Elliott    http://www.ctsn.co.uk





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:54 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register