Bug 31588 - gfortran should be able to output Makefile dependencies with -M* options
Summary: gfortran should be able to output Makefile dependencies with -M* options
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: ---
Assignee: Daniel Franke
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-16 10:21 UTC by Francois-Xavier Coudert
Modified: 2010-06-13 16:07 UTC (History)
9 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-05-25 22:55:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2007-04-16 10:21:24 UTC
gcc has various -M options to create Makefile dependencies for automatic dependency tracking, which is very nice for compilation of large projects. gfortran should be able to do the same. Here are examples with g95:

$ cat a.f90 
module foo
  integer, parameter :: bar = 42
end module foo
$ g95 -M a.f90     
a.o foo.mod: a.f90
$ cat a.F90
include "foo.inc"

module foo
  integer, parameter :: bar = 42
end module foo
$ g95 -M a.F90
a.o foo.mod: a.F90 foo.inc
Comment 1 Daniel Franke 2007-04-16 11:02:46 UTC
FX, +5 karma for this proposal :)
How about USE association? For example

$> cat a.f90
module a
[...]
end module

$> cat b.f90
[...]
USE a
[...]

$> gfortran -M a.f90
a.o a.mod: a.f90

$> gfortran -M b.f90
b.o: a.mod b.f90

(Don't have g95 to check its output)
Comment 2 Francois-Xavier Coudert 2007-04-16 11:06:39 UTC
(In reply to comment #1)
> How about USE association?

That's also part of the plan.
Comment 3 Tobias Burnus 2007-04-16 15:28:24 UTC
What about
  include "foo.f90"
and
#include "bar.f90"
(g95 handles both)

And what about
  include "z.f90"
where "z.f90" is foo/z.f90 and is found via
gfortran -Jfoo ?
(g95 does not handle this and writes: b.o b.mod: b.F90 z.f90)
Comment 4 Bernhard Reutner-Fischer 2007-06-04 17:20:10 UTC
fx, are you still working on this?

yet another reason why "-M" as an alias for -J should be dropped and instead proper -M dependency handling should be added is this:

$ echo end > foo.f90 && gfortran -o main  foo.f90 -v -M
Segmentation fault

i.e. it isn't user-safe with 4.1.2, 4.2.0 and trunk.
Comment 5 Francois-Xavier Coudert 2007-06-04 17:39:47 UTC
(In reply to comment #4)
> fx, are you still working on this?

Not actively. It's probably not so hard, though: read the file, like we do with -fsyntax-only mode, and parse #file headers.

> yet another reason why "-M" as an alias for -J should be dropped and instead
> proper -M dependency handling should be added is this:
> 
> $ echo end > foo.f90 && gfortran -o main  foo.f90 -v -M
> Segmentation fault

That's another one. File a new PR (it's probably a simple check that's missing in gfc_handle_module_path_options()).
Comment 6 rep.dot.nop@gmail.com 2007-06-04 20:50:20 UTC
Subject: Re:  gfortran should be able to output Makefile dependencies with -M* options

On Mon, Jun 04, 2007 at 05:39:48PM -0000, fxcoudert at gcc dot gnu dot org wrote:
>
>
>------- Comment #5 from fxcoudert at gcc dot gnu dot org  2007-06-04 17:39 -------
>(In reply to comment #4)
>> fx, are you still working on this?
>
>Not actively. It's probably not so hard, though: read the file, like we do with
>-fsyntax-only mode, and parse #file headers.

Yes, without looking i was thinking about for each file, populate a list
of provides/needs mods and emit them when a file is done.

>> yet another reason why "-M" as an alias for -J should be dropped and instead
>> proper -M dependency handling should be added is this:
>> 
>> $ echo end > foo.f90 && gfortran -o main  foo.f90 -v -M
>> Segmentation fault
>
>That's another one. File a new PR (it's probably a simple check that's missing
>in gfc_handle_module_path_options()).

I did not look whether it is calling strlen on NULL or another spot in
the option handling, but i will not look at the current meaning of -M,
so please feel free to file this if you think it's worth noting it.
Thanks,
Comment 7 Thomas Koenig 2007-10-06 21:36:25 UTC
For once, the segfault is in the
gfortran driver, not the f951 binary.

Backtrace, plus some more debug info:

$ gdb ~/bin/gfortran 
GNU gdb 6.6.90.20070912-debian
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
Using host libthread_db library "/lib/i686/cmov/libthread_db.so.1".
(gdb)  r foo.f90 -v -M
Starting program: /home/ig25/bin/gfortran foo.f90 -v -M

Program received signal SIGSEGV, Segmentation fault.
0xb7e23513 in strlen () from /lib/i686/cmov/libc.so.6
(gdb) bt
#0  0xb7e23513 in strlen () from /lib/i686/cmov/libc.so.6
#1  0x08056b56 in lang_specific_driver (in_argc=0xbfde2b08, in_argv=0xbfde2b04, in_added_libraries=0x8079b94)
    at ../../../gcc/trunk/gcc/fortran/gfortranspec.c:431
#2  0x0804f910 in process_command (argc=4, argv=0x807e938) at ../../../gcc/trunk/gcc/gcc.c:3581
#3  0x0805364e in main (argc=4, argv=0xbfde2c54) at ../../../gcc/trunk/gcc/gcc.c:6244
(gdb) up
#1  0x08056b56 in lang_specific_driver (in_argc=0xbfde2b08, in_argv=0xbfde2b04, in_added_libraries=0x8079b94)
    at ../../../gcc/trunk/gcc/fortran/gfortranspec.c:431
431                   p = XNEWVEC (char, strlen (argv[i + 1]) + 2);
(gdb) p i   
$1 = 4
(gdb) p argv[0]
$2 = 0xbfde47c5 "/home/ig25/bin/gfortran"
(gdb) p argv[1]
$3 = 0xbfde47dd "foo.f90"
(gdb) p argv[2]
$4 = 0xbfde47e5 "-v"
(gdb) p argv[3]
$5 = 0xbfde47e8 "-M"
(gdb) p argv[4]
$6 = 0x0

Comment 8 Daniel Franke 2008-01-30 22:22:48 UTC
> Not actively. It's probably not so hard, though: read the file, like we 
> do with -fsyntax-only mode, and parse #file headers.

FX, I'm lost here. The flag_syntax_only is not used anywhere in the fortran directory, but only in places like gcc/toplev.c(compile_file) to, as I understand it, e.g. avoid code generation. As I see it, gfortran never knows it does syntax checking only?!

What exactly do you mean by "#file headers"? Preprocessor include directives as
`#include "foo.inc"`?

Last but not least: did you intend to use the mkdeps-interface of libcpp or to craft something on your own?
Comment 9 Francois-Xavier Coudert 2008-01-31 00:26:04 UTC
(In reply to comment #8)
> As I see it, gfortran never knows it does syntax checking only?!

Exactly. 

> What exactly do you mean by "#file headers"? Preprocessor include directives as
> `#include "foo.inc"`?

Yes. These are some of the dependencies, but not all. Fortran include directives are others (probably not too hard to handle), modules are yet another one.

> Last but not least: did you intend to use the mkdeps-interface of libcpp or to
> craft something on your own?

gfortran doesn't use libcpp, but it probably should. There's a PR about that, and I tried to make the switch at some point (I was still a newcomer to gfortran development at that time, so probably somewhere around 4.1/4.2), but didn't succeed.
Comment 10 Andrew Pinski 2008-03-26 03:32:59 UTC
Subject: Bug 31588

Author: pinskia
Date: Wed Mar 26 03:32:13 2008
New Revision: 133541

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133541
Log:
2008-03-25  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR target/31588
        * config/rs6000/rs6000-c.c (rs6000_builtin_type_compatible): Handle
        error_mark_node's.

2008-03-25  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR target/31588
        * g++.dg/ext/altivec-15.C: New testcase.


Added:
    trunk/gcc/testsuite/g++.dg/ext/altivec-15.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/rs6000/rs6000-c.c
    trunk/gcc/testsuite/ChangeLog

Comment 11 Andrew Pinski 2008-03-26 03:35:37 UTC
Ignore comment #10, I entered the wrong number, it should have been 31558.
Comment 12 Daniel Franke 2010-05-03 18:09:35 UTC
*** Bug 43954 has been marked as a duplicate of this bug. ***
Comment 13 Daniel Franke 2010-06-12 21:06:13 UTC
Would it be ok to require '-cpp' with '-M' or shall '-M' work without explicit preprocessing enabled? In the latter case, would it be ok to enable preprocessing implicitly?
Comment 14 Daniel Franke 2010-06-12 21:46:09 UTC
(In reply to comment #13)
> Would it be ok to require '-cpp' with '-M' or shall '-M' work without explicit
> preprocessing enabled? In the latter case, would it be ok to enable
> preprocessing implicitly?

"Passing -M to the driver implies -E" - so much for that.
Comment 15 Daniel Franke 2010-06-13 16:05:35 UTC
Subject: Bug 31588

Author: dfranke
Date: Sun Jun 13 16:05:01 2010
New Revision: 160684

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160684
Log:
2010-06-13  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/31588
	PR fortran/43954
	* gfortranspec.c (lang_specific_driver): Removed deprecation
	warning for -M.
	* lang.opt: Add options -M, -MM, -MD, -MMD, -MF, -MG, -MP, -MT, -MQ.
	* lang-specs.h (CPP_FORWARD_OPTIONS): Add -M* options.
	* cpp.h (gfc_cpp_makedep): New.
	(gfc_cpp_add_dep): New.
	(gfc_cpp_add_target): New.
	* cpp.c (gfc_cpp_option): Add deps* members.
	(gfc_cpp_makedep): New.
	(gfc_cpp_add_dep): New.
	(gfc_cpp_add_target): New.
	(gfc_cpp_init_options): Initialize new options.
	(gfc_cpp_handle_option): Handle new options.
	(gfc_cpp_post_options): Map new options to libcpp-options.
	(gfc_cpp_init): Handle deferred -MQ and -MT options.
	(gfc_cpp_done): If requested, write dependencies to file.
	* module.c (gfc_dump_module): Add a module filename as target.
	* scanner.c (open_included_file): New parameter system; add the
	included file as dependency.
	(gfc_open_included_file): Add the included file as dependency.
	(gfc_open_intrinsic_module): Likewise.
	* invoke.texi: Removed deprecation warning for -M.
	* gfortran.texi: Removed Makefile-dependencies project.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/cpp.c
    trunk/gcc/fortran/cpp.h
    trunk/gcc/fortran/gfortran.texi
    trunk/gcc/fortran/gfortranspec.c
    trunk/gcc/fortran/invoke.texi
    trunk/gcc/fortran/lang-specs.h
    trunk/gcc/fortran/lang.opt
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/scanner.c

Comment 16 Daniel Franke 2010-06-13 16:07:36 UTC
Fixed in trunk. See PR44526 for a follow-up request for libcpp.
Closing.
Comment 17 Jerry DeLisle 2010-08-07 16:52:13 UTC
Subject: Bug 31588

Author: jvdelisle
Date: Sat Aug  7 16:51:55 2010
New Revision: 162980

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162980
Log:
2010-08-07  Daniel Franke  <franke.daniel@gmail.com>

	2010-06-13  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/31588
	PR fortran/43954
	Backport from mainline:
	* gfortranspec.c (lang_specific_driver): Removed deprecation
	warning for -M.
	* lang.opt: Add options -M, -MM, -MD, -MMD, -MF, -MG, -MP, -MT, -MQ.
	* lang-specs.h (CPP_FORWARD_OPTIONS): Add -M* options.
	* cpp.h (gfc_cpp_makedep): New.
	(gfc_cpp_add_dep): New.
	(gfc_cpp_add_target): New.
	* cpp.c (gfc_cpp_option): Add deps* members.
	(gfc_cpp_makedep): New.
	(gfc_cpp_add_dep): New.
	(gfc_cpp_add_target): New.
	(gfc_cpp_init_options): Initialize new options.
	(gfc_cpp_handle_option): Handle new options.
	(gfc_cpp_post_options): Map new options to libcpp-options.
	(gfc_cpp_init): Handle deferred -MQ and -MT options.
	(gfc_cpp_done): If requested, write dependencies to file.
	* module.c (gfc_dump_module): Add a module filename as target.
	* scanner.c (open_included_file): New parameter system; add the
	included file as dependency.
	(gfc_open_included_file): Add the included file as dependency.
	(gfc_open_intrinsic_module): Likewise.
	* invoke.texi: Removed deprecation warning for -M.
	* gfortran.texi: Removed Makefile-dependencies project.

Modified:
    branches/gcc-4_5-branch/gcc/fortran/ChangeLog
    branches/gcc-4_5-branch/gcc/fortran/cpp.c
    branches/gcc-4_5-branch/gcc/fortran/cpp.h
    branches/gcc-4_5-branch/gcc/fortran/gfortran.texi
    branches/gcc-4_5-branch/gcc/fortran/gfortranspec.c
    branches/gcc-4_5-branch/gcc/fortran/invoke.texi
    branches/gcc-4_5-branch/gcc/fortran/lang-specs.h
    branches/gcc-4_5-branch/gcc/fortran/lang.opt
    branches/gcc-4_5-branch/gcc/fortran/module.c
    branches/gcc-4_5-branch/gcc/fortran/scanner.c

Comment 18 Jerry DeLisle 2010-08-08 01:59:34 UTC
Subject: Bug 31588

Author: jvdelisle
Date: Sun Aug  8 01:59:15 2010
New Revision: 162990

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162990
Log:
2010-08-07  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/31588
	PR fortran/43954
	Backport from mainline:
	* gfortranspec.c (lang_specific_driver): Removed deprecation
	warning for -M.
	* lang.opt: Add options -M, -MM, -MD, -MMD, -MF, -MG, -MP, -MT, -MQ.
	* lang-specs.h (CPP_FORWARD_OPTIONS): Add -M* options.
	* cpp.h (gfc_cpp_makedep): New.
	(gfc_cpp_add_dep): New.
	(gfc_cpp_add_target): New.
	* cpp.c (gfc_cpp_option): Add deps* members.
	(gfc_cpp_makedep): New.
	(gfc_cpp_add_dep): New.
	(gfc_cpp_add_target): New.
	(gfc_cpp_init_options): Initialize new options.
	(gfc_cpp_handle_option): Handle new options.
	(gfc_cpp_post_options): Map new options to libcpp-options.
	(gfc_cpp_init): Handle deferred -MQ and -MT options.
	(gfc_cpp_done): If requested, write dependencies to file.
	* module.c (gfc_dump_module): Add a module filename as target.
	* scanner.c (open_included_file): New parameter system; add the
	included file as dependency.
	(gfc_open_included_file): Add the included file as dependency.
	(gfc_open_intrinsic_module): Likewise.
	* invoke.texi: Removed deprecation warning for -M.
	* gfortran.texi: Removed Makefile-dependencies project.

Modified:
    branches/gcc-4_4-branch/gcc/fortran/ChangeLog
    branches/gcc-4_4-branch/gcc/fortran/cpp.c
    branches/gcc-4_4-branch/gcc/fortran/cpp.h
    branches/gcc-4_4-branch/gcc/fortran/gfortran.texi
    branches/gcc-4_4-branch/gcc/fortran/gfortranspec.c
    branches/gcc-4_4-branch/gcc/fortran/invoke.texi
    branches/gcc-4_4-branch/gcc/fortran/lang-specs.h
    branches/gcc-4_4-branch/gcc/fortran/lang.opt
    branches/gcc-4_4-branch/gcc/fortran/module.c
    branches/gcc-4_4-branch/gcc/fortran/scanner.c