2

I am unable to understand the following piece of code from Contiki-os' native platform's makefile.

NM       ?= nm
OBJCOPY  ?= objcopy
STRIP    ?= strip
ifdef WERROR
CFLAGSWERROR=-Werror -pedantic -std=c99 -Werror
endif
CFLAGSNO = -Wall -g -I/usr/local/include $(CFLAGSWERROR)
CFLAGS  += $(CFLAGSNO) -O

Source: https://github.com/contiki-os/contiki/blob/master/cpu/native/Makefile.native#L13-20

It is not the variable assignments that i do not understand, my questions is what is 'WERROR' and how is it related to 'CFLAGS' and what is NM refer to? CC refers to compiler, LD to linker.

It would be great if someone could help me.

DarthSpeedious
  • 965
  • 1
  • 13
  • 25
  • What do you exactly not understand? Maybe http://stackoverflow.com/questions/448910/makefile-variable-assignment helps. – FPK Jun 04 '15 at 08:53
  • It is not the variable assignments, my questions is what is 'WERROR' and how is it related to 'CFLAGS' and what is NM refer to? CC refers to compiler, LD to linker. – DarthSpeedious Jun 04 '15 at 08:57

1 Answers1

1

If WERROR is defined, the make file add options to the compilation, so that warnings are treated as errors. Presumably, something at some point will define WERROR=1 triggering this stricter build. CFLAGS will be used in the rule that compiles source code into object code.

From: http://www.chemie.fu-berlin.de/chemnet/use/info/make/make_7.html

Compiling C programs:

n.o is made automatically from n.c with a recipe of the form ‘$(CC) $(CPPFLAGS) $(CFLAGS) -c’.

Austin France
  • 2,381
  • 4
  • 25
  • 37
  • What does this: `CFLAGSWERROR=-Werror -pedantic -std=c99 -Werror` do? – DarthSpeedious Jun 04 '15 at 09:34
  • You would have to check the compiler reference for specifics, but presumably -Werror is telling the compiler to treat warnings as errors. -pedantic telling it to be pedantic, -std=c99 is telling it to compile to the c99 standard, and the extra -Werror probably a mistake. Those flags get expanded into CFLAGSNO if they are defined, which in turn is expanded into CFLAGS which is used in the default compile rule performed by make. – Austin France Jun 05 '15 at 10:47