help-make
[Top][All Lists]
Advanced

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

Re: What is the difference between > and >> in a makefile.


From: givemecode
Subject: Re: What is the difference between > and >> in a makefile.
Date: Mon, 28 Mar 2011 12:59:57 -0700 (PDT)



givemecode wrote:
> 
> I modified a for loop in a makefile that looked like this:
> 
>       @for f in $(DRV_GEN_HEADER) ; do echo "#include \""$$f"\"" >> $@ ; done
> 
> which puts the output of echo into a new file I sepcified.
> 
> changed to this:
> 
>        @for f in $(INCLUDE_DIR)/%.h); do \
>          echo "#include \""$$f"\""; \
>         done > '$@'
> 
> which does the same thing but the writing is done after the loop completes
> (I think). Can someone please explain the difference and why it works?
> 
> 


I think I accidentally deleted Stephan's original reply to this:

Functionally there is little difference, except that the first approach
opens the file twice (once in write/truncate mode and once in write/append
mode), which means twice as many points for an i/o error. The second
approach only opens the output once and streams the data to it as the data
is generated (or when the file descriptor is flushed, to be more precise).
You can test this by creating a for loop which exits with an error after
(e.g.) 3 loops. The output generated before the error will still be
redirected (it is not buffered until completion of the loop/scope
construct).

One trick to get around having to use a combination of >/>> is to use a
scope:

{
   echo hi
   echo world
   cat /etc/hosts
} > myfile
-- 
View this message in context: 
http://old.nabble.com/What-is-the-difference-between-%3E-and-%3E%3E-in-a-makefile.-tp31260849p31261692.html
Sent from the Gnu - Make - Help mailing list archive at Nabble.com.




reply via email to

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