This is the mail archive of the
mailing list for the GCC project.
Re: How to compare two text files? Using sed, cmp, diff, tr?
- From: Kevin <kth at srv dot net>
- To: Georg-Johann Lay <avr at gjlay dot de>, gcc at gcc dot gnu dot org
- Date: Sat, 26 May 2012 09:03:16 -0600
- Subject: Re: How to compare two text files? Using sed, cmp, diff, tr?
- References: <4FC0AA16.email@example.com>
Georg-Johann Lay wrote:
The avr backend auto-generates parts of GCC's texi documentation,
namely the supported -mmcu= options, which are about 200.
To generate the texi a small C program is used to print the texi
to stdout, and that output is then compared against the already
If the output is the same like in that file, nothing happens.
If the output differs from that file, the user (someone building the
avr compiler) is nagged to update the existing documentation so that
the documentation says in sync with the compiler.
The part of t-avr reads:
$(RUN_GEN) $< | sed -e 's:\r::g' > avr-mmcu.texi
@if cmp -s $(srcdir)/doc/avr-mmcu.texi avr-mmcu.texi; then \
$(STAMP) $@; \
echo >&2 ; \
echo "***" >&2 ; \
echo "*** Verify that you have permission to grant a" >&2 ; \
echo "*** GFDL license for all new text in" >&2 ; \
echo "*** avr-mmcu.texi,then copy it to
$(srcdir)/doc/avr-mmcu.texi" >&2 ; \
echo "***" >&2 ; \
The problem is comparing the new texi file avr-mmcu.texi against the
already existing $(srcdir)/doc/avr-mmcu.texi and factor out different
line endings that depend on the build system like LF vs. CRLF.
What is the best way to do such a comparison on text level without
getting a complaint if the original texi was built on linux and the
user builds the compiler under, say, windows?
How to cope with different line endings in that case?
Instead of trying to cope with different line endings on the
generated files, wouldn't it be better to modify the C program
to output the desired line ending format in the first place?
Instead of just writing a \n in text mode, output \n\r in binary
mode (if you want DOS format), or just \n (for unix format).
I'd think changing the line ending format on a file should be
considered a problem, as the distributed files could end up
in numerous formats, making nobody really happy.