Re: [PATCH v2] gdbserver: Suffix generated C files with -generated

Simon Marchi
2017-03-31T18:46:52Z

On 2017-03-31 11:40, Simon Marchi wrote:
> On 2017-03-31 11:12, Pedro Alves wrote:
>> On 03/31/2017 03:55 PM, Simon Marchi wrote:
>>> From: Simon Marchi <simon.marchi@polymtl.ca>
>>>
>>> I noticed that there were some missing files in gdbserver's gitignore
>>> (some generated register format .c files). Of course the easy fix
>>> would
>>> be to add those files to .gitignore, but I think we can do a better
>>> job,
>>> so that we don't have to worry about adding generated files to
>>> .gitignore or the clean Makefile target.
>>>
>>> I suggest naming all generated source files -generated.c. This way,
>>> we
>>> can use a single rule in .gitignore and do a "rm -f *-generated.c" to
>>> clean them up.
>>>
>>> New in v2:
>>>
>>> - Don't rename version.o and xml-builtin.o
>>>
>>> gdb/gdbserver/ChangeLog:
>>>
>>> * .gitignore: Remove generated files, replace with wildcard.
>>> * (clean): Replace removal of generated files with wildcard.
>>> (version.c): Replace with...
>>> (version-generated.c): ...this.
>>> (xml-builtin.c): Replace with...
>>> (xml-builtin-generated.c): ...this.
>>> (%-ipa.o: %-generated.c, %.o: %-generated.c): New rules.
>>> (%.c: *regformats*): Replace with...
>>> (%-generated.c: *regformats*): ...this.
>>
>> OK.
>
> Thanks, pushed.

Note that when updating past this commit and rebuilding, or in general
hopping back and forth between branches that have this commit and
branches that don't and rebuilding, you may stumble on errors like:

make: *** No rule to make target `version.c', needed by `version.o'.
Stop.

It's the same issue some people had when environ.c was moved to
common/environ.c, and it will happen every time we move a source file.
The reason is the leftover dependency file in .deps, containing
something like:

version.o: version.c

These files are automatically generated by gcc and state all the files
that went into creating version.o during the last build. That rule
states that version.c should exist when for version.o to be built, and
that version.o should be rebuilt if version.c is more recent. But
version.c was moved and no longer exists, hence the error.

One thing I see we could do to mitigate the problem is clear the .deps
directory when doing a "make clean". After all, when doing a clean, all
objects are deleted and are going to be rebuilt, so we don't care about
the dependencies anymore. So if somebody stumbles on that problem,
there's a chance they'll try to clean and build again, which would fix
the problem.

Do you have any better idea?

Simon