@file response file support for make, revised
This patch is a revision of my previous patch adding @file support to GNU make, as discussed at http://lists.gnu.org/archive/html/bug-make/2006-09/msg8.html and http://savannah.gnu.org/patch/?5809. This version will use @file with temporary files created by make to pass down options to sub-makes, as requested in that patch tracker issue. It uses the same approach as in GCC: a temporary @file is created to pass down options iff an @file was used on the original make's command line (or in its MAKEFLAGS, so further levels of recursive make work OK). It is inevitably rather more complicated than the previous version of the patch. 2007-09-27 Joseph Myers [EMAIL PROTECTED] * argv.c: New. From libiberty. * Makefile.am (make_SOURCES): Add argv.c. * doc/make.texi: Update. * main.c (write_env_switches, at_file_supplied, open_tmpfile_default, struct tmpfile_list, tmpfiles, open_tmpfile_record, remove_tmpfile, remove_tmpfiles, env_switches_to_array, process_env_switches, write_env_switches_callback): New. (main): Call expandargv. If @FILE is used, use it for passing down options and variables to sub-makes. Use open_tmpfile_default. Call remove_tmpfiles. Use remove_tmpfile. (decode_env_switches): Use env_switches_to_array. (define_makeflags): If @FILE is used, use it for passing down options to sub-makes. Allow for temporary file name ending with '-'. (die): Call remove_tmpfiles. * make.h (buildargv, freeargv, dupargv, writeargv, expandargv): Declare. diff -rupN make.orig/Makefile.am make/Makefile.am --- make.orig/Makefile.am 2007-07-04 19:35:16.0 + +++ make/Makefile.am2007-09-27 14:48:32.0 + @@ -40,8 +40,8 @@ else endif -make_SOURCES = ar.c arscan.c commands.c default.c dir.c expand.c file.c \ - function.c getopt.c getopt1.c implicit.c job.c main.c \ +make_SOURCES = ar.c argv.c arscan.c commands.c default.c dir.c expand.c \ + file.c function.c getopt.c getopt1.c implicit.c job.c main.c \ misc.c read.c remake.c $(remote) rule.c signame.c \ strcache.c variable.c version.c vpath.c hash.c diff -rupN make.orig/argv.c make/argv.c --- make.orig/argv.c1970-01-01 00:00:00.0 + +++ make/argv.c 2007-09-27 21:28:37.0 + @@ -0,0 +1,511 @@ +/* Create and destroy argument vectors (argv's) + Copyright (C) 1992, 2001, 2005, 2006, 2007 Free Software Foundation, Inc. + Written by Fred Fish @ Cygnus Support + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +Boston, MA 02110-1301, USA. */ + + +/* Create and destroy argument vectors. An argument vector is simply an +array of string pointers, terminated by a NULL pointer. */ + +#include make.h + +/* Routines imported from standard C runtime libraries. */ + +#include stddef.h +#include string.h +#include stdlib.h +#include stdio.h + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef EOS +#define EOS '\0' +#endif + +#define INITIAL_MAXARGC 8 /* Number of args + NULL in initial argv */ + +#define ISBLANK(c) ((c) == ' ' || (c) == '\t') +#define ISSPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' \ +|| (c) == '\r' || (c) == '\f' || (c) == '\v') + +/* + [EMAIL PROTECTED] Extension char** dupargv (char [EMAIL PROTECTED]) + +Duplicate an argument vector. Simply scans through @var{vector}, +duplicating each argument until the terminating @code{NULL} is found. +Returns a pointer to the argument vector if successful. Returns [EMAIL PROTECTED] if there is insufficient memory to complete building the +argument vector. + [EMAIL PROTECTED] deftypefn + +*/ + +char ** +dupargv (char **argv) +{ + int argc; + char **copy; + + if (argv == NULL) +return NULL; + + /* the vector */ + for (argc = 0; argv[argc] != NULL; argc++); + copy = (char **) malloc ((argc + 1) * sizeof (char *)); + if (copy == NULL) +return NULL; + + /* the strings */ + for (argc = 0; argv[argc] != NULL; argc++) +{ + int len = strlen (argv[argc]); + copy[argc] = (char *) malloc (len + 1); + if (copy[argc] == NULL) + { + freeargv (copy); +
Re: @file response file support for make
On Mon, 19 Mar 2007, Paul Smith wrote: This seems like a very useful additional feature. Can you please add this patch to the Savannah project for GNU make, so we don't lose track of it? https://savannah.gnu.org/patch/?func=additemgroup=make Now done. https://savannah.gnu.org/patch/index.php?5809 -- Joseph S. Myers [EMAIL PROTECTED] ___ Bug-make mailing list Bug-make@gnu.org http://lists.gnu.org/mailman/listinfo/bug-make
Re: @file response file support for make
On Mon, 2007-03-19 at 15:36 +, Joseph S. Myers wrote: Now done. Great; thanks! -- --- Paul D. Smith [EMAIL PROTECTED] 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 ___ Bug-make mailing list Bug-make@gnu.org http://lists.gnu.org/mailman/listinfo/bug-make
RE: Ping Re: @file response file support for make
On 18 March 2007 20:49, Joseph S. Myers wrote: Ping. Any views on this patch or the principle of this feature http://lists.gnu.org/archive/html/bug-make/2006-09/msg8.html? I think it's eminently sensible. The @-file is increasingly a standard convention. cheers, DaveK -- Can't think of a witty .sigline today ___ Bug-make mailing list Bug-make@gnu.org http://lists.gnu.org/mailman/listinfo/bug-make
Re: @file response file support for make
On Thu, 2006-09-07 at 20:49 +, Joseph S. Myers wrote: There is a de facto standard solution to this problem, which is that a command line argument of the form @file causes arguments to be read from file (a response file) if it exists. (If file doesn't exist, @file is taken literally as an ordinary command-line argument.) This feature is supported by GCC and GNU binutils, for example; I think it originated on Windows, but it is useful everywhere with any command line limit. This seems like a very useful additional feature. Can you please add this patch to the Savannah project for GNU make, so we don't lose track of it? https://savannah.gnu.org/patch/?func=additemgroup=make Thanks for your work on this! -- --- Paul D. Smith [EMAIL PROTECTED] 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 ___ Bug-make mailing list Bug-make@gnu.org http://lists.gnu.org/mailman/listinfo/bug-make
@file response file support for make
Sometimes you wish to invoke a program with too many or too long arguments to fit in ARG_MAX. For example, I have a case where a script wishes to invoke make with many -o options. There is a de facto standard solution to this problem, which is that a command line argument of the form @file causes arguments to be read from file (a response file) if it exists. (If file doesn't exist, @file is taken literally as an ordinary command-line argument.) This feature is supported by GCC and GNU binutils, for example; I think it originated on Windows, but it is useful everywhere with any command line limit. I'd like to have this feature in GNU make. The patch below is my current implementation of it for CVS HEAD make. argv.c, the main part of the implementation, is taken from GNU libiberty as used by GCC and binutils to implement this feature, with a minimum of changes to be usable without the rest of libiberty. The documentation is also taken from libiberty. 2006-09-07 Joseph Myers [EMAIL PROTECTED] * argv.c: New. From libiberty. * Makefile.am (make_SOURCES): Add argv.c. * doc/make.texi: Update. * main.c (main): Call expandargv. * make.h (buildargv, freeargv, dupargv, expandargv): Declare. diff -rupN make.orig/Makefile.am make/Makefile.am --- make.orig/Makefile.am 2006-04-07 01:43:44.0 + +++ make/Makefile.am2006-09-07 20:23:20.0 + @@ -39,8 +39,8 @@ else endif -make_SOURCES = ar.c arscan.c commands.c default.c dir.c expand.c file.c \ - function.c getopt.c getopt1.c implicit.c job.c main.c \ +make_SOURCES = ar.c argv.c arscan.c commands.c default.c dir.c expand.c \ + file.c function.c getopt.c getopt1.c implicit.c job.c main.c \ misc.c read.c remake.c $(remote) rule.c signame.c \ strcache.c variable.c version.c vpath.c hash.c diff -rupN make.orig/argv.c make/argv.c --- make.orig/argv.c1970-01-01 00:00:00.0 + +++ make/argv.c 2006-09-07 20:23:20.0 + @@ -0,0 +1,456 @@ +/* Create and destroy argument vectors (argv's) + Copyright (C) 1992, 2001, 2005, 2006 Free Software Foundation, Inc. + Written by Fred Fish @ Cygnus Support + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +Boston, MA 02110-1301, USA. */ + + +/* Create and destroy argument vectors. An argument vector is simply an +array of string pointers, terminated by a NULL pointer. */ + +#include make.h + +/* Routines imported from standard C runtime libraries. */ + +#include stddef.h +#include string.h +#include stdlib.h +#include stdio.h + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef EOS +#define EOS '\0' +#endif + +#define INITIAL_MAXARGC 8 /* Number of args + NULL in initial argv */ + +#define ISBLANK(c) ((c) == ' ' || (c) == '\t') +#define ISSPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' \ +|| (c) == '\r' || (c) == '\f' || (c) == '\v') + +/* + [EMAIL PROTECTED] Extension char** dupargv (char [EMAIL PROTECTED]) + +Duplicate an argument vector. Simply scans through @var{vector}, +duplicating each argument until the terminating @code{NULL} is found. +Returns a pointer to the argument vector if successful. Returns [EMAIL PROTECTED] if there is insufficient memory to complete building the +argument vector. + [EMAIL PROTECTED] deftypefn + +*/ + +char ** +dupargv (char **argv) +{ + int argc; + char **copy; + + if (argv == NULL) +return NULL; + + /* the vector */ + for (argc = 0; argv[argc] != NULL; argc++); + copy = (char **) malloc ((argc + 1) * sizeof (char *)); + if (copy == NULL) +return NULL; + + /* the strings */ + for (argc = 0; argv[argc] != NULL; argc++) +{ + int len = strlen (argv[argc]); + copy[argc] = (char *) malloc (len + 1); + if (copy[argc] == NULL) + { + freeargv (copy); + return NULL; + } + strcpy (copy[argc], argv[argc]); +} + copy[argc] = NULL; + return copy; +} + +/* + [EMAIL PROTECTED] Extension void freeargv (char [EMAIL PROTECTED]) + +Free an argument vector that was built using @code{buildargv}. Simply +scans through @var{vector}, freeing the memory for each argument until +the terminating @code{NULL} is found, and