diff mbox

[6/6] Makefile: define a default value for CFLAGS

Message ID 20170903121928.24024-6-nicolas.iooss@m4x.org (mailing list archive)
State Not Applicable
Headers show

Commit Message

Nicolas Iooss Sept. 3, 2017, 12:19 p.m. UTC
When building the project with "make DESTDIR=... install", the root
Makefile defines CFLAGS and LDFLAGS without any warning flags ("CFLAGS
+= -I$(DESTDIR)/usr/include" and "LDFLAGS += -L$(DESTDIR)/usr/lib"). As
the Makefiles in subdirectories do not override the flags with warning
flags, the code gets compiled without any enabled warning.

This leads for example to code being introduced which breaks building
libsepol from its directory, while building it from the root Makefile
still works fine.

This issue can be fixed by defining a set of flags in the root Makefile
which are used by all Makefiles in subdirectories. The flags have been
chosen following these principles:
* they are compatible with both clang and gcc,
* they already appear in at least one Makefile, and
* they are not triggered with the current git master version.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 Makefile | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox

Patch

diff --git a/Makefile b/Makefile
index 7701e16252fe..6da7f7b71bdc 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,16 @@  DISTCLEANSUBDIRS=libselinux libsemanage
 ifeq ($(DEBUG),1)
 	export CFLAGS = -g3 -O0 -gdwarf-2 -fno-strict-aliasing -Wall -Wshadow -Werror
 	export LDFLAGS = -g
+else
+	export CFLAGS ?= -O2 -Werror -Wall -Wextra \
+		-Wmissing-format-attribute \
+		-Wmissing-noreturn \
+		-Wpointer-arith \
+		-Wshadow \
+		-Wstrict-prototypes \
+		-Wundef \
+		-Wunused \
+		-Wwrite-strings
 endif
 
 ifneq ($(DESTDIR),)