From 924c0eb6ac80186297769e5d41065831b2903573 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Sat, 2 Jun 2012 11:18:28 +0000 Subject: [PATCH] Add C_FLAGS, CPP_FLAGS and ASM_FLAGS variables to the build system BUILD module to allow for language-specific compiler/assembler flags. --- BuildTests/ModuleTest/makefile.test | 11 +++++++---- LUFA/Build/lufa.build.in | 22 ++++++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/BuildTests/ModuleTest/makefile.test b/BuildTests/ModuleTest/makefile.test index 94004b8b3a..b3307f8970 100644 --- a/BuildTests/ModuleTest/makefile.test +++ b/BuildTests/ModuleTest/makefile.test @@ -27,8 +27,9 @@ TARGET = Test SRC = $(TARGET)_C.c $(TARGET)_CPP.cpp Dummy.S $(LUFA_SRC_USB) LUFA_PATH = ../../LUFA/ -CC_FLAGS = -Wextra -#CC_FLAGS += -Werror # FIXME +# Generic C/C++ compiler flags +CC_FLAGS = -Wextra +CC_FLAGS += -Werror CC_FLAGS += -Wformat=2 CC_FLAGS += -Winit-self CC_FLAGS += -Wswitch-enum @@ -38,11 +39,9 @@ CC_FLAGS += -Wpointer-arith CC_FLAGS += -Wcast-align CC_FLAGS += -Wwrite-strings CC_FLAGS += -Wlogical-op -CC_FLAGS += -Wmissing-parameter-type CC_FLAGS += -Wmissing-declarations CC_FLAGS += -Wmissing-field-initializers CC_FLAGS += -Wmissing-format-attribute -CC_FLAGS += -Wnested-externs CC_FLAGS += -Woverlength-strings # Only enable rendundant declaration warnings for AVR8 target (FIXME) @@ -50,6 +49,10 @@ ifeq ($(ARCH), AVR8) CC_FLAGS += -Wredundant-decls endif +# C compiler only flags +C_FLAGS += -Wmissing-parameter-type +C_FLAGS += -Wnested-externs + # Potential additional warnings to enable in the future (FIXME) #CC_FLAGS += -Wswitch-default #CC_FLAGS += -Wc++-compat diff --git a/LUFA/Build/lufa.build.in b/LUFA/Build/lufa.build.in index be14a6fdc6..d9d6b9fe54 100644 --- a/LUFA/Build/lufa.build.in +++ b/LUFA/Build/lufa.build.in @@ -42,7 +42,11 @@ LUFA_BUILD_TARGETS += size checksource all elf hex clean # C_STANDARD - C Language Standard to use # CPP_STANDARD - C++ Language Standard to use # F_CPU - Speed of the CPU, in Hz -# CC_FLAGS - Flags to pass to the compiler +# C_FLAGS - Flags to pass to the C compiler only +# CPP_FLAGS - Flags to pass to the C++ compiler only +# ASM_FLAGS - Flags to pass to the assembler only +# CC_FLAGS - Common flags to pass to the C/C++ compiler and +# assembler # LD_FLAGS - Flags to pass to the linker # # ----------------------------------------------------------------------------- @@ -83,6 +87,10 @@ OPTIMIZATION ?= s F_CPU ?= C_STANDARD ?= gnu99 CPP_STANDARD ?= gnu++98 +C_FLAGS ?= +CPP_FLAGS ?= +ASM_FLAGS ?= +CC_FLAGS ?= # Convert input source file list to differentiate them by type C_SOURCE = $(filter %.c, $(SRC)) @@ -105,14 +113,16 @@ else ifeq ($(ARCH), UC3) else $(error Unsupported architecture.) endif -CC_FLAGS += -fno-strict-aliasing -funsigned-char -funsigned-bitfields -ffunction-sections -CC_FLAGS += -Wall -Wstrict-prototypes +CC_FLAGS += -Wall -fno-strict-aliasing -funsigned-char -funsigned-bitfields -ffunction-sections CC_FLAGS += -I. -I$(LUFA_PATH)/.. CC_FLAGS += -DARCH=ARCH_$(ARCH) -DBOARD=BOARD_$(BOARD) -DF_USB=$(F_USB)UL ifneq ($(F_CPU),) CC_FLAGS += -DF_CPU=$(F_CPU)UL endif +# Additional language specific compiler flags +C_FLAGS += -Wstrict-prototypes + # Create a list of flags to pass to the linker LD_FLAGS += -Wl,-Map=$(TARGET).map,--cref -Wl,--gc-sections -lm ifneq ($(F_CPU), UC3) @@ -162,15 +172,15 @@ lss: $(TARGET).lss %.o: %.c @echo $(MSG_COMPILE_CMD) Compiling C file \"$^\" - $(CROSS)gcc -c $(CC_FLAGS) -O$(OPTIMIZATION) -std=$(C_STANDARD) $< -o $@ + $(CROSS)gcc -c $(CC_FLAGS) $(C_FLAGS) -O$(OPTIMIZATION) -std=$(C_STANDARD) $< -o $@ %.o: %.cpp @echo $(MSG_COMPILE_CMD) Compiling C++ file \"$^\" - $(CROSS)gcc -c $(CC_FLAGS) -O$(OPTIMIZATION) -std=$(CPP_STANDARD) -x c++ $< -o $@ + $(CROSS)gcc -c $(CC_FLAGS) $(CPP_FLAGS) -O$(OPTIMIZATION) -std=$(CPP_STANDARD) -x c++ $< -o $@ %.o: %.S @echo $(MSG_COMPILE_CMD) Assembling \"$^\" - $(CROSS)gcc -c $(CC_FLAGS) -x assembler-with-cpp $< -o $@ + $(CROSS)gcc -c $(CC_FLAGS) $(ASM_FLAGS) -x assembler-with-cpp $< -o $@ .PRECIOUS : $(OBJECT_FILES) %.elf: $(OBJECT_FILES)