diff options
Diffstat (limited to 'devdocs/gnu_make/file-function.html')
| -rw-r--r-- | devdocs/gnu_make/file-function.html | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/devdocs/gnu_make/file-function.html b/devdocs/gnu_make/file-function.html new file mode 100644 index 00000000..0a8d3c82 --- /dev/null +++ b/devdocs/gnu_make/file-function.html @@ -0,0 +1,18 @@ + <h1 class="section">The file Function</h1> <p>The <code>file</code> function allows the makefile to write to or read from a file. Two modes of writing are supported: overwrite, where the text is written to the beginning of the file and any existing content is lost, and append, where the text is written to the end of the file, preserving the existing content. In both cases the file is created if it does not exist. It is a fatal error if the file cannot be opened for writing, or if the write operation fails. The <code>file</code> function expands to the empty string when writing to a file. </p> <p>When reading from a file, the <code>file</code> function expands to the verbatim contents of the file, except that the final newline (if there is one) will be stripped. Attempting to read from a non-existent file expands to the empty string. </p> <p>The syntax of the <code>file</code> function is: </p> <div class="example"> <pre class="example">$(file <var>op</var> <var>filename</var>[,<var>text</var>]) +</pre> +</div> <p>When the <code>file</code> function is evaluated all its arguments are expanded first, then the file indicated by <var>filename</var> will be opened in the mode described by <var>op</var>. </p> <p>The operator <var>op</var> can be <code>></code> to indicate the file will be overwritten with new content, <code>>></code> to indicate the current contents of the file will be appended to, or <code><</code> to indicate the contents of the file will be read in. The <var>filename</var> specifies the file to be written to or read from. There may optionally be whitespace between the operator and the file name. </p> <p>When reading files, it is an error to provide a <var>text</var> value. </p> <p>When writing files, <var>text</var> will be written to the file. If <var>text</var> does not already end in a newline a final newline will be written (even if <var>text</var> is the empty string). If the <var>text</var> argument is not given at all, nothing will be written. </p> <p>For example, the <code>file</code> function can be useful if your build system has a limited command line size and your recipe runs a command that can accept arguments from a file as well. Many commands use the convention that an argument prefixed with an <code>@</code> specifies a file containing more arguments. Then you might write your recipe in this way: </p> <div class="example"> <pre class="example">program: $(OBJECTS) + $(file >$@.in,$^) + $(CMD) $(CMDFLAGS) @$@.in + @rm $@.in +</pre> +</div> <p>If the command required each argument to be on a separate line of the input file, you might write your recipe like this: </p> <div class="example"> <pre class="example">program: $(OBJECTS) + $(file >$@.in) $(foreach O,$^,$(file >>$@.in,$O)) + $(CMD) $(CMDFLAGS) @$@.in + @rm $@.in +</pre> +</div><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Free Software Foundation, Inc. <br>Licensed under the GNU Free Documentation License.<br> + <a href="https://www.gnu.org/software/make/manual/html_node/File-Function.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/File-Function.html</a> + </p> +</div> |
