bugmake - Bugs: bug #35384, Request for a...


bug #35384: Request for a "writefile" function

Submitted by:  None
Submitted on:  Fri 27 Jan 2012 04:08:51 PM UTC  
Severity:  3 - Normal Item Group:  Enhancement
Status:  Duplicate Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  3.82 Operating System:  None
Fixed Release:  None Triage Status:  None

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Sun 29 Jan 2012 06:14:51 PM UTC, comment #6:

See bug #35147

Paul D. Smith <psmith>
Project Administrator
Sun 29 Jan 2012 04:15:46 AM UTC, comment #5:

Yes, it's a duplicate. We can close this one.

If there's anything I can do for 35147 let me know. My work maintains large make-based builds and I don't know how many times we've run into the "argument list too long" issue, usually shortly before an important deadline. Numeric limits are nasty.


John Coiner <jcoiner>
Sun 29 Jan 2012 03:19:42 AM UTC, comment #4:

I don't see a way to mark it formally but note that this proposal is very much the same as #35147. There was also a long thread on the bug-make mailing list quite recently (late 2011?) discussing proposals in detail, and more or less coming to agreement.

David Boyce <boyski>
Sat 28 Jan 2012 12:07:57 AM UTC, comment #3:

Oops, the message board ate the formatting of the patch in comment #2.

It's also attached as a file, that one should be OK.

John Coiner <jcoiner>
Sat 28 Jan 2012 12:06:25 AM UTC, comment #2:

diff -u -r make-3.82/doc/make.texi make-3.82-mine/doc/make.texi
--- make-3.82/doc/make.texi 2010-07-19 03:10:54.000000000 -0400
+++ make-3.82-mine/doc/make.texi 2012-01-27 10:39:02.221433328 -0500
@@ -7694,6 +7694,32 @@
This function does nothing more than print its (expanded) argument(s)
to standard output. No makefile name or line number is added. The
result of the expansion of this function is the empty string.
+@item $(writefile @var{file}, @var{text}@dots{})
+@findex writefile
+@cindex printing messages
+This function prints its (expanded) @var{text} argument(s)
+into @var{file}. No makefile name or line number is added. The
+result of the expansion of this function is the empty string.
+This is useful if you need to pass the value of a Make variable
+through to a program, and the value is either too large to fit
+on a command line due to OS limits, or it contains shell control
+characters that you would need to escape if you passed the value
+as a command line argument.
+For example,
+KLINGON_NOVEL = Heghlu'meH QaQ jajvam! ... and so on for 100,000 words.
+translate :
+ $(writefile novel.klingon.txt, $(KLINGON_NOVEL)) \
+ translate.pl -in novel.klingon.txt -out novel.english.txt
+@end example
@end table

@node Running, Implicit Rules, Functions, Top
diff -u -r make-3.82/function.c make-3.82-mine/function.c
--- make-3.82/function.c 2010-07-12 21:20:39.000000000 -0400
+++ make-3.82-mine/function.c 2012-01-27 10:11:10.701434083 -0500
@@ -1117,6 +1117,42 @@
return o;

+ write text into a file
+static char *
+func_writefile (char o, char *argv, const char *funcname)
+ char **argvp;
+ char msg, p;
+ int len;
+ /* The arguments will be broken on commas. Rather than create yet
+ another special case where function arguments aren't broken up,
+ just create a format string that puts them back together. */
+ for (len=0, argvp=argv+1; *argvp != 0; ++argvp)
+ len += strlen (*argvp) + 2;
+ p = msg = alloca (len + 1);
+ for (argvp=argv+1; argvp[1] != 0; ++argvp)
+ {
+ strcpy (p, *argvp);
+ p += strlen (*argvp);
+ *(p++) = ',';
+ *(p++) = ' ';
+ }
+ strcpy (p, *argvp);
+ FILE fp = fopen( argv, "w" );
+ if( fp == NULL )
+ fatal (reading_file, "writefile: unable to open '%s'", *argv );
+ fprintf( fp, "%s", msg );
+ fclose( fp );
+ /* The writefile function expands to the empty string. */
+ return o;

chop argv[0] into words, and sort them.
@@ -2125,6 +2161,7 @@
{ STRING_SIZE_TUPLE("info"), 0, 1, 1, func_error},
{ STRING_SIZE_TUPLE("error"), 0, 1, 1, func_error},
{ STRING_SIZE_TUPLE("warning"), 0, 1, 1, func_error},
+ { STRING_SIZE_TUPLE("writefile"), 2, 2, 1, func_writefile},
{ STRING_SIZE_TUPLE("if"), 2, 3, 0, func_if},
{ STRING_SIZE_TUPLE("or"), 1, 0, 0, func_or},
{ STRING_SIZE_TUPLE("and"), 1, 0, 0, func_and},

John Coiner <jcoiner>
Fri 27 Jan 2012 04:17:53 PM UTC, comment #1:

ps. I am the submitter of this, I did not intend to submit anonymously.

John Coiner <jcoiner>
Fri 27 Jan 2012 04:08:51 PM UTC, original submission:

This patch adds a "writefile" function. This is similar to the existing "info" function, except that it writes to a file.

This is useful when you have a Make variable whose value is larger than the OS-imposed limit on the maximum size of a command line, and you need to pass this value to a target. While there are workarounds, they are either slow or don't work in the general case. For example:



The "writefile" function also avoids another problem with passing arbitrary strings through as command-line arguments: it avoids the need to escape shell control characters.

The patch is against 3.82. Please apply it. It's small, it's localized, and it helps Make scale to large build environments.



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #24906:  patch added by None (3KiB - application/octet-stream)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by boyski (Posted a comment)
  • -email is unavailable- added by jcoiner
  • -email is unavailable- added by jcoiner (Posted a comment)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    Sun 29 Jan 2012 06:14:51 PM UTC psmith StatusNone => Duplicate
        Open/ClosedOpen => Closed
    Fri 27 Jan 2012 11:46:40 PM UTC jcoiner Carbon-Copy- => Added -email is unavailable-
    Fri 27 Jan 2012 04:08:51 PM UTC None Attached File- => Added patch, #24906

    Back to the top

    Powered by Savane 3.3