|
Home > Archive > Unix Programming > February 2006 > tilde expansion not working in makefiles
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
tilde expansion not working in makefiles
|
|
| Simon Elliott 2006-02-14, 7:49 am |
| 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
| |
| Robert Harris 2006-02-14, 7:50 am |
| 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
| |
| Paul D. Smith 2006-02-14, 7:50 am |
| %% "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 Scientist
| |
| Nils O. Selåsdal 2006-02-14, 5: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.
| |
| Simon Elliott 2006-02-14, 5: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
| |
| Simon Elliott 2006-02-14, 5: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
| |
| Paul D. Smith 2006-02-14, 5: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 Scientist
| |
| Simon Elliott 2006-02-17, 10:40 pm |
| 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
|
|
|
|
|