public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* getting the list of input files of a gcc command line
@ 2018-12-05 16:44 Vincent Lefevre
  2018-12-05 18:38 ` Jonathan Wakely
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Vincent Lefevre @ 2018-12-05 16:44 UTC (permalink / raw)
  To: gcc-help

I would like to write a gcc wrapper and get the list of input files
of the gcc command line before executing gcc. As a heuristic, I could
get all the arguments with some extension like .c and .h, but is
there a more reliable way?

The goal is to get a warning if I try to execute gcc while some input
file has not been saved in Emacs (Emacs provides the way to do this,
e.g. by creating a symbolic link .#tst.c when tst.c has not been
saved).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: getting the list of input files of a gcc command line
  2018-12-05 16:44 getting the list of input files of a gcc command line Vincent Lefevre
@ 2018-12-05 18:38 ` Jonathan Wakely
  2018-12-05 20:43   ` Segher Boessenkool
  2018-12-05 22:37 ` Rena
  2018-12-06 11:58 ` Florian Weimer
  2 siblings, 1 reply; 13+ messages in thread
From: Jonathan Wakely @ 2018-12-05 18:38 UTC (permalink / raw)
  To: gcc-help

On Wed, 5 Dec 2018 at 16:44, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
>
> I would like to write a gcc wrapper and get the list of input files
> of the gcc command line before executing gcc. As a heuristic, I could
> get all the arguments with some extension like .c and .h, but is
> there a more reliable way?

Look for any argument that doesn't start with '-' or '@' ?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: getting the list of input files of a gcc command line
  2018-12-05 18:38 ` Jonathan Wakely
@ 2018-12-05 20:43   ` Segher Boessenkool
  2018-12-05 20:44     ` Jonathan Wakely
  0 siblings, 1 reply; 13+ messages in thread
From: Segher Boessenkool @ 2018-12-05 20:43 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

On Wed, Dec 05, 2018 at 06:37:55PM +0000, Jonathan Wakely wrote:
> On Wed, 5 Dec 2018 at 16:44, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
> >
> > I would like to write a gcc wrapper and get the list of input files
> > of the gcc command line before executing gcc. As a heuristic, I could
> > get all the arguments with some extension like .c and .h, but is
> > there a more reliable way?
> 
> Look for any argument that doesn't start with '-' or '@' ?

Some options take a filename as a separate argument.  Like "-o that.o".


Segher

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: getting the list of input files of a gcc command line
  2018-12-05 20:43   ` Segher Boessenkool
@ 2018-12-05 20:44     ` Jonathan Wakely
  2018-12-06  2:26       ` Vincent Lefevre
  0 siblings, 1 reply; 13+ messages in thread
From: Jonathan Wakely @ 2018-12-05 20:44 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-help

On Wed, 5 Dec 2018 at 20:43, Segher Boessenkool
<segher@kernel.crashing.org> wrote:
>
> On Wed, Dec 05, 2018 at 06:37:55PM +0000, Jonathan Wakely wrote:
> > On Wed, 5 Dec 2018 at 16:44, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
> > >
> > > I would like to write a gcc wrapper and get the list of input files
> > > of the gcc command line before executing gcc. As a heuristic, I could
> > > get all the arguments with some extension like .c and .h, but is
> > > there a more reliable way?
> >
> > Look for any argument that doesn't start with '-' or '@' ?
>
> Some options take a filename as a separate argument.  Like "-o that.o".

D'oh, of course.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: getting the list of input files of a gcc command line
  2018-12-05 16:44 getting the list of input files of a gcc command line Vincent Lefevre
  2018-12-05 18:38 ` Jonathan Wakely
@ 2018-12-05 22:37 ` Rena
  2018-12-06  2:15   ` Vincent Lefevre
  2018-12-06 11:58 ` Florian Weimer
  2 siblings, 1 reply; 13+ messages in thread
From: Rena @ 2018-12-05 22:37 UTC (permalink / raw)
  To: gcc-help

On Wed, Dec 5, 2018 at 11:44 AM Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
>
> I would like to write a gcc wrapper and get the list of input files
> of the gcc command line before executing gcc. As a heuristic, I could
> get all the arguments with some extension like .c and .h, but is
> there a more reliable way?
>
> The goal is to get a warning if I try to execute gcc while some input
> file has not been saved in Emacs (Emacs provides the way to do this,
> e.g. by creating a symbolic link .#tst.c when tst.c has not been
> saved).
>
> --
> Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Perhaps you can do it the other way around: make a script/macro that
saves all open files, then runs gcc.

-- 
Sent from my Game Boy.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: getting the list of input files of a gcc command line
  2018-12-05 22:37 ` Rena
@ 2018-12-06  2:15   ` Vincent Lefevre
  0 siblings, 0 replies; 13+ messages in thread
From: Vincent Lefevre @ 2018-12-06  2:15 UTC (permalink / raw)
  To: gcc-help

On 2018-12-05 17:38:31 -0500, Rena wrote:
> Perhaps you can do it the other way around: make a script/macro that
> saves all open files, then runs gcc.

I don't think that's possible to save them like that (and I certainly
don't want to force a save). What could be possible would be to have
a daemon that tracks the unsaved files (thanks to inotify), and the
wrapper could warn unconditionally if there is any open file (a bit
complex, but that would eliminate any false negative).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: getting the list of input files of a gcc command line
  2018-12-05 20:44     ` Jonathan Wakely
@ 2018-12-06  2:26       ` Vincent Lefevre
  2018-12-06 15:54         ` Segher Boessenkool
  0 siblings, 1 reply; 13+ messages in thread
From: Vincent Lefevre @ 2018-12-06  2:26 UTC (permalink / raw)
  To: gcc-help

On 2018-12-05 20:43:43 +0000, Jonathan Wakely wrote:
> On Wed, 5 Dec 2018 at 20:43, Segher Boessenkool
> <segher@kernel.crashing.org> wrote:
> >
> > On Wed, Dec 05, 2018 at 06:37:55PM +0000, Jonathan Wakely wrote:
> > > On Wed, 5 Dec 2018 at 16:44, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
> > > >
> > > > I would like to write a gcc wrapper and get the list of input files
> > > > of the gcc command line before executing gcc. As a heuristic, I could
> > > > get all the arguments with some extension like .c and .h, but is
> > > > there a more reliable way?
> > >
> > > Look for any argument that doesn't start with '-' or '@' ?
> >
> > Some options take a filename as a separate argument.  Like "-o that.o".
> 
> D'oh, of course.

However, I probably wouldn't miss any input file, because all of them
are actually full arguments (i.e. nothing like -Idir for files). If
the wrapper considers other files like in "-o that.o", this is not an
issue, because it is unlikely that such files have been opened in a
text editor, and directories are not an issue either since one can
easily skip them.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: getting the list of input files of a gcc command line
  2018-12-05 16:44 getting the list of input files of a gcc command line Vincent Lefevre
  2018-12-05 18:38 ` Jonathan Wakely
  2018-12-05 22:37 ` Rena
@ 2018-12-06 11:58 ` Florian Weimer
  2018-12-06 16:37   ` Vincent Lefevre
  2 siblings, 1 reply; 13+ messages in thread
From: Florian Weimer @ 2018-12-06 11:58 UTC (permalink / raw)
  To: gcc-help

* Vincent Lefevre:

> The goal is to get a warning if I try to execute gcc while some input
> file has not been saved in Emacs (Emacs provides the way to do this,
> e.g. by creating a symbolic link .#tst.c when tst.c has not been
> saved).

The makefile dependency generation options provide this information.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: getting the list of input files of a gcc command line
  2018-12-06  2:26       ` Vincent Lefevre
@ 2018-12-06 15:54         ` Segher Boessenkool
  2018-12-06 16:47           ` option + argument in 1 or 2 words (was: getting the list of input files of a gcc command line) Vincent Lefevre
  2018-12-06 17:28           ` getting the list of input files of a gcc command line Segher Boessenkool
  0 siblings, 2 replies; 13+ messages in thread
From: Segher Boessenkool @ 2018-12-06 15:54 UTC (permalink / raw)
  To: gcc-help

On Thu, Dec 06, 2018 at 03:26:20AM +0100, Vincent Lefevre wrote:
> On 2018-12-05 20:43:43 +0000, Jonathan Wakely wrote:
> > On Wed, 5 Dec 2018 at 20:43, Segher Boessenkool
> > <segher@kernel.crashing.org> wrote:
> > >
> > > On Wed, Dec 05, 2018 at 06:37:55PM +0000, Jonathan Wakely wrote:
> > > > On Wed, 5 Dec 2018 at 16:44, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
> > > > >
> > > > > I would like to write a gcc wrapper and get the list of input files
> > > > > of the gcc command line before executing gcc. As a heuristic, I could
> > > > > get all the arguments with some extension like .c and .h, but is
> > > > > there a more reliable way?
> > > >
> > > > Look for any argument that doesn't start with '-' or '@' ?
> > >
> > > Some options take a filename as a separate argument.  Like "-o that.o".
> > 
> > D'oh, of course.
> 
> However, I probably wouldn't miss any input file, because all of them
> are actually full arguments (i.e. nothing like -Idir for files). If
> the wrapper considers other files like in "-o that.o", this is not an
> issue, because it is unlikely that such files have been opened in a
> text editor, and directories are not an issue either since one can
> easily skip them.

It won't miss any input files from people who didn't write weird command
lines.  But, for example, you can do "gcc a.c -includea.h" (note no space
after the -include), and that works.


Segher

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: getting the list of input files of a gcc command line
  2018-12-06 11:58 ` Florian Weimer
@ 2018-12-06 16:37   ` Vincent Lefevre
  0 siblings, 0 replies; 13+ messages in thread
From: Vincent Lefevre @ 2018-12-06 16:37 UTC (permalink / raw)
  To: gcc-help

On 2018-12-06 12:58:35 +0100, Florian Weimer wrote:
> * Vincent Lefevre:
> 
> > The goal is to get a warning if I try to execute gcc while some input
> > file has not been saved in Emacs (Emacs provides the way to do this,
> > e.g. by creating a symbolic link .#tst.c when tst.c has not been
> > saved).
> 
> The makefile dependency generation options provide this information.

Good idea. This is even better. However, the parsing of the
command line would be more difficult, and in particular, it
may be difficult to decide what to do when such options are
already used (for a different purpose).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* option + argument in 1 or 2 words (was: getting the list of input files of a gcc command line)
  2018-12-06 15:54         ` Segher Boessenkool
@ 2018-12-06 16:47           ` Vincent Lefevre
  2018-12-07 23:09             ` Segher Boessenkool
  2018-12-06 17:28           ` getting the list of input files of a gcc command line Segher Boessenkool
  1 sibling, 1 reply; 13+ messages in thread
From: Vincent Lefevre @ 2018-12-06 16:47 UTC (permalink / raw)
  To: gcc-help

On 2018-12-06 09:54:00 -0600, Segher Boessenkool wrote:
> On Thu, Dec 06, 2018 at 03:26:20AM +0100, Vincent Lefevre wrote:
> > However, I probably wouldn't miss any input file, because all of them
> > are actually full arguments (i.e. nothing like -Idir for files). If
> > the wrapper considers other files like in "-o that.o", this is not an
> > issue, because it is unlikely that such files have been opened in a
> > text editor, and directories are not an issue either since one can
> > easily skip them.
> 
> It won't miss any input files from people who didn't write weird command
> lines.  But, for example, you can do "gcc a.c -includea.h" (note no space
> after the -include), and that works.

Isn't this a bug? I thought that this was allowed only with options
with a single letter, like -I.

BTW, the man page is not consistent, e.g.

       -I dir

but

       -Ldir

and even both:

       -llibrary
       -l library

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: getting the list of input files of a gcc command line
  2018-12-06 15:54         ` Segher Boessenkool
  2018-12-06 16:47           ` option + argument in 1 or 2 words (was: getting the list of input files of a gcc command line) Vincent Lefevre
@ 2018-12-06 17:28           ` Segher Boessenkool
  1 sibling, 0 replies; 13+ messages in thread
From: Segher Boessenkool @ 2018-12-06 17:28 UTC (permalink / raw)
  To: gcc-help

On Thu, Dec 06, 2018 at 03:26:20AM +0100, Vincent Lefevre wrote:
> On 2018-12-05 20:43:43 +0000, Jonathan Wakely wrote:
> > On Wed, 5 Dec 2018 at 20:43, Segher Boessenkool
> > <segher@kernel.crashing.org> wrote:
> > >
> > > On Wed, Dec 05, 2018 at 06:37:55PM +0000, Jonathan Wakely wrote:
> > > > On Wed, 5 Dec 2018 at 16:44, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
> > > > >
> > > > > I would like to write a gcc wrapper and get the list of input files
> > > > > of the gcc command line before executing gcc. As a heuristic, I could
> > > > > get all the arguments with some extension like .c and .h, but is
> > > > > there a more reliable way?
> > > >
> > > > Look for any argument that doesn't start with '-' or '@' ?
> > >
> > > Some options take a filename as a separate argument.  Like "-o that.o".
> > 
> > D'oh, of course.
> 
> However, I probably wouldn't miss any input file, because all of them
> are actually full arguments (i.e. nothing like -Idir for files). If
> the wrapper considers other files like in "-o that.o", this is not an
> issue, because it is unlikely that such files have been opened in a
> text editor, and directories are not an issue either since one can
> easily skip them.

It won't miss any input files from people who didn't write weird command
lines.  But, for example, you can do "gcc a.c -includea.h" (note no space
after the -include), and that works.


Segher

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: option + argument in 1 or 2 words (was: getting the list of input files of a gcc command line)
  2018-12-06 16:47           ` option + argument in 1 or 2 words (was: getting the list of input files of a gcc command line) Vincent Lefevre
@ 2018-12-07 23:09             ` Segher Boessenkool
  0 siblings, 0 replies; 13+ messages in thread
From: Segher Boessenkool @ 2018-12-07 23:09 UTC (permalink / raw)
  To: gcc-help

On Thu, Dec 06, 2018 at 05:47:10PM +0100, Vincent Lefevre wrote:
> On 2018-12-06 09:54:00 -0600, Segher Boessenkool wrote:
> > On Thu, Dec 06, 2018 at 03:26:20AM +0100, Vincent Lefevre wrote:
> > > However, I probably wouldn't miss any input file, because all of them
> > > are actually full arguments (i.e. nothing like -Idir for files). If
> > > the wrapper considers other files like in "-o that.o", this is not an
> > > issue, because it is unlikely that such files have been opened in a
> > > text editor, and directories are not an issue either since one can
> > > easily skip them.
> > 
> > It won't miss any input files from people who didn't write weird command
> > lines.  But, for example, you can do "gcc a.c -includea.h" (note no space
> > after the -include), and that works.
> 
> Isn't this a bug? I thought that this was allowed only with options
> with a single letter, like -I.

But is this a bug that is worth fixing?  No doubt people use it
(unknowingly), given how old this is.  Shouldn't be done in stage 3,
in any case.


Segher

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2018-12-06 17:28 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-05 16:44 getting the list of input files of a gcc command line Vincent Lefevre
2018-12-05 18:38 ` Jonathan Wakely
2018-12-05 20:43   ` Segher Boessenkool
2018-12-05 20:44     ` Jonathan Wakely
2018-12-06  2:26       ` Vincent Lefevre
2018-12-06 15:54         ` Segher Boessenkool
2018-12-06 16:47           ` option + argument in 1 or 2 words (was: getting the list of input files of a gcc command line) Vincent Lefevre
2018-12-07 23:09             ` Segher Boessenkool
2018-12-06 17:28           ` getting the list of input files of a gcc command line Segher Boessenkool
2018-12-05 22:37 ` Rena
2018-12-06  2:15   ` Vincent Lefevre
2018-12-06 11:58 ` Florian Weimer
2018-12-06 16:37   ` Vincent Lefevre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).