gcc -MG output incorrect for non-existent files in sub-directories
Gwyn Judd
b.judd@xtra.co.nz
Sun Jan 2 02:33:00 GMT 2000
>From the documentation for the -MG option:
"-MG Treat missing header files as generated files and assume they live
in the same directory as the source file."
So if you imagine a file in a subdirectory which includes a non-existent
file the output of gcc -MG should predict that it will be generated in
the same sub-directory. However this is not the case. Imagine the
following directory structure:
.
|-- Makefile
|-- depend.sh
`-- main
|-- lex.l
|-- lex.c
|-- main.c
|-- module.mk
`-- parse.y
In this particular case, "main/lex.c" is generated from "main/lex.l". It
includes the file "main/parse.h" which is generated from "main/parse.y".
If we run the command "gcc -MM -MG main/lex.c" we get the output:
[gwyn@thislove:/home/sources/bas]$ gcc -MM -MG main/lex.c
lex.o: main/lex.c parse.h
This causes make to look for the file "parse.h" in the root directory
rather than in the "main" directory where it will be generated
eventually. However if we create the file "main/parse.h" and run the
command again we get:
[gwyn@thislove:/home/sources/bas]$ gcc -MM -MG main/lex.c
lex.o: main/lex.c main/parse.h
Which is more the expected output. I see no point in the current
behaviour, it is just as reasonable to expect a generated file to be
created in the same directory as the file that includes it as it is to
expect it to be in the root directory (or any other directory) so I am
presuming this is a bug (especially as it seems to contradict the
documentation).
--
Gwyn Judd (b.judd@xtra.co.nz)
You will remember something that you should not have forgotten.
More information about the Gcc-bugs
mailing list