From fdc9d219d37ead607dbc9076f69ad4a1616c0086 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Tue, 9 Apr 2013 00:00:19 +0200 Subject: [PATCH] Adding GDB support to the makefile. Use the build option DEBUG=GDB to have the .elf file contain debugging symbols. --- Makefile | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 80ff2822e..82a8ee31b 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,9 @@ TARGET ?= NAZE # Compile-time options OPTIONS ?= +# Debugger optons, must be empty or GDB +DEBUG ?= + ############################################################################### # Things that need to be maintained as the source changes # @@ -114,10 +117,9 @@ INCLUDE_DIRS = $(SRC_DIR) \ $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x \ ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -CFLAGS = $(ARCH_FLAGS) \ +BASE_CFLAGS = $(ARCH_FLAGS) \ $(addprefix -D,$(OPTIONS)) \ $(addprefix -I,$(INCLUDE_DIRS)) \ - -Os \ -Wall \ -ffunction-sections \ -fdata-sections \ @@ -148,6 +150,16 @@ ifeq ($(filter $(TARGET),$(VALID_TARGETS)),) $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS)) endif +ifeq ($(DEBUG),GDB) +CFLAGS = $(BASE_CFLAGS) \ + -ggdb \ + -O0 +else +CFLAGS = $(BASE_CFLAGS) \ + -Os +endif + + TARGET_HEX = $(BIN_DIR)/baseflight_$(TARGET).hex TARGET_ELF = $(BIN_DIR)/baseflight_$(TARGET).elf TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))