getting the list of input files of a gcc command line

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

getting the list of input files of a gcc command line

Vincent Lefevre-3
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 <[hidden email]> - 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)
Reply | Threaded
Open this post in threaded view
|

Re: getting the list of input files of a gcc command line

Jonathan Wakely-4
On Wed, 5 Dec 2018 at 16:44, Vincent Lefevre <[hidden email]> 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 '@' ?
Reply | Threaded
Open this post in threaded view
|

Re: getting the list of input files of a gcc command line

Segher Boessenkool
On Wed, Dec 05, 2018 at 06:37:55PM +0000, Jonathan Wakely wrote:
> On Wed, 5 Dec 2018 at 16:44, Vincent Lefevre <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: getting the list of input files of a gcc command line

Jonathan Wakely-4
On Wed, 5 Dec 2018 at 20:43, Segher Boessenkool
<[hidden email]> wrote:

>
> On Wed, Dec 05, 2018 at 06:37:55PM +0000, Jonathan Wakely wrote:
> > On Wed, 5 Dec 2018 at 16:44, Vincent Lefevre <[hidden email]> 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.
Reply | Threaded
Open this post in threaded view
|

Re: getting the list of input files of a gcc command line

Rena
In reply to this post by Vincent Lefevre-3
On Wed, Dec 5, 2018 at 11:44 AM Vincent Lefevre <[hidden email]> 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 <[hidden email]> - 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.
Reply | Threaded
Open this post in threaded view
|

Re: getting the list of input files of a gcc command line

Vincent Lefevre-3
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 <[hidden email]> - 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)
Reply | Threaded
Open this post in threaded view
|

Re: getting the list of input files of a gcc command line

Vincent Lefevre-3
In reply to this post by Jonathan Wakely-4
On 2018-12-05 20:43:43 +0000, Jonathan Wakely wrote:

> On Wed, 5 Dec 2018 at 20:43, Segher Boessenkool
> <[hidden email]> wrote:
> >
> > On Wed, Dec 05, 2018 at 06:37:55PM +0000, Jonathan Wakely wrote:
> > > On Wed, 5 Dec 2018 at 16:44, Vincent Lefevre <[hidden email]> 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 <[hidden email]> - 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)
Reply | Threaded
Open this post in threaded view
|

Re: getting the list of input files of a gcc command line

Florian Weimer-5
In reply to this post by Vincent Lefevre-3
* 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
Reply | Threaded
Open this post in threaded view
|

Re: getting the list of input files of a gcc command line

Segher Boessenkool
In reply to this post by Vincent Lefevre-3
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
> > <[hidden email]> wrote:
> > >
> > > On Wed, Dec 05, 2018 at 06:37:55PM +0000, Jonathan Wakely wrote:
> > > > On Wed, 5 Dec 2018 at 16:44, Vincent Lefevre <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: getting the list of input files of a gcc command line

Vincent Lefevre-3
In reply to this post by Florian Weimer-5
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 <[hidden email]> - 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)
Reply | Threaded
Open this post in threaded view
|

option + argument in 1 or 2 words (was: getting the list of input files of a gcc command line)

Vincent Lefevre-3
In reply to this post by Segher Boessenkool
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 <[hidden email]> - 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)
Reply | Threaded
Open this post in threaded view
|

Re: option + argument in 1 or 2 words (was: getting the list of input files of a gcc command line)

Segher Boessenkool
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