WinAVR 20040720 #warning not printed

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hallo,

using WinAVR with the supplied sample-Makefile I do not get output from #warning any longer. The "no newline at end of file"-warning is also not shown any longer. Maybe others too. #error is ok: prints message and breaks .

I could track down this issue to the -Wp options in the makefile-call of the avr-gcc-frontend which seem to be a "new method" to determine the dependencies. The warnings are printed when using a sample-makefile from a previous WinAVR-release or calling avr-gcc from the command-line/windows-"shell" with minimal options. From reading the gcc-man-page I could not find out why the "new method" disabled the output of #warning.

Since I use something like #warning "Compiling for mega32-testplatform xyz" quite often I reverted to the older WinAVR-makefile-"template". #warning is used in the avr-libc (use avr/io.h not io.h...) and other "third-party-libraries" too so this issue should be fixed.

Martin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I understand your question correctly, it sounds like you need to modify your Makefile to change the warning level to -Wall (part of the CFLAGS or compiler options). This will then turn on all warnings. This is something I generally do since, even though a program may compile okay, warnings are a good indicator that I might not be doing what I want or think I'm doing.

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for the proposal, Dave. But as far as I did understand the sample-Makefile the -Wall option is activated.

Some Parts for the WinAVR 20040720 Sample-Makefile:

...
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS) $(CINCS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
...
# Compiler flags to generate dependency files.
GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
...
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
...
# Compile: create object files from C source files.
%.o : %.c
	@echo
	@echo $(MSG_COMPILING) $<
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
...

Makefile-output shows that the avr-gcc gets called with -Wall and some warnings are also shown during the compile-run. But no output from " #warning". If the options defined in $(GENDEPFLAGS) are not given the compiler-frontend (so automatic dependencies do not work and longer) #warning-text gets printed.
Martin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mjthomas wrote:

Makefile-output shows that the avr-gcc gets called with -Wall and some warnings are also shown during the compile-run. But no output from " #warning". If the options defined in $(GENDEPFLAGS) are not given the compiler-frontend (so automatic dependencies do not work and longer) #warning-text gets printed.
Martin

Hi Martin!

Yup, I've confirmed this.

Would you be willing to fill out a bug report on the WinAVR site?:
http://sourceforge.net/tracker/?atid=520074&group_id=68108&func=browse

When Jörg takes a look at this, maybe he'll have an idea about this as it affects MFile too.

Eric

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I've found out why this is hapenning. In the makefile the flags to generate dependency information are:

Quote:

GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d

The GCC manual says this about -M in passing it to the preprocessor (see the bolded part below):

Quote:

`-M'
Instead of outputting the result of preprocessing, output a rule
suitable for `make' describing the dependencies of the main source
file. The preprocessor outputs one `make' rule containing the
object file name for that source file, a colon, and the names of
all the included files, including those coming from `-include' or
`-imacros' command line options.

Unless specified explicitly (with `-MT' or `-MQ'), the object file
name consists of the basename of the source file with any suffix
replaced with object file suffix. If there are many included
files then the rule is split into several lines using `\'-newline.
The rule has no commands.

This option does not suppress the preprocessor's debug output,
such as `-dM'. To avoid mixing such debug output with the
dependency rules you should explicitly specify the dependency
output file with `-MF', or use an environment variable like
`DEPENDENCIES_OUTPUT' (*note Environment Variables::). Debug
output will still be sent to the regular output stream as normal.

Passing `-M' to the driver implies `-E', and suppresses warnings
with an implicit `-w'
.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok I have something for everybody to try out. Change the GENDEPFLAGS line in the makefile to:

GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d

And let me know what you think.

Note: You may want to "make clean" before "make all" when you change this line.

Thanks
Eric

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, that definitely enables warnings. I'm now being informed that there are no newlines at the end of any of my source files?

David

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is normal and typical for GCC.

So go the end of your files and hit :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you very much Eric! I will try your DEP-option-settings.
Beside of the missing #warning-Functionality I really missed the usual "no linefeed" warning ;-)
Martin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

EW wrote:
That is normal and typical for GCC.

And IIRC it's because the C Standard specifies that a .c file should end in a newline.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

More specifically, even though C is basically a free-form language
(unlike e. g. FORTRAN, for those old farts who still know it ;-), the
C preprocessing step is standardized to operate on lines of input.
While this might appear surprising at first, look at a typical
preprocessor statement like

#define foo bar

Here, any later occurence of `foo' will be replaced by `bar '. The
macro replacement will always be everything up to the end of the input
line (the initial whitespace between the macro name and `bar' is not
part of the replacement though). Thus, the preprocessing basically
operates on input lines. For that reason, the standard mandates that
the input consists of lines. Since by definition, a line is ended by
an end-of-line sequence (like on Unix, or on MS-DOS),
any C source file must eventually end up with (at least) one
end-of-line sequence. If you've got an editor that doesn't warn you
when you store a text file without an EOL sequence in the last line,
well, you'll get that compiler warning. (In theory, the input file
does not adhere to the C standard in that case.)

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.