#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
#
-# Updates:
+# Updates:
# Arthur Wolf & Adam Green in 2011 - 2012 - Updated to work with mbed.
###############################################################################
# Check for undefined variables.
BUILD_TYPE ?= Release
MRI_BREAK_ON_INIT ?= 1
MRI_UART ?= MRI_UART_MBED_USB
+HEAP_TAGS ?= 0
+WRITE_BUFFER_DISABLE ?= 0
+STACK_SIZE ?= 0
# Configure MRI variables based on BUILD_TYPE build type variable.
# Add in the MBED customization stubs which allow hooking in the MRI debug monitor.
OBJECTS += $(OUTDIR)/mbed_custom.o
+OBJECTS += $(OUTDIR)/configdefault.o
+
# List of the header dependency files, one per object file.
DEPFILES = $(patsubst %.o,%.d,$(OBJECTS))
# DEFINEs to be used when building C/C++ code
DEFINES += -DTARGET_$(DEVICE)
-DEFINES += -DMRI_ENABLE=$(MRI_ENABLE) -DMRI_INIT_PARAMETERS='"$(MRI_INIT_PARAMETERS)"'
+DEFINES += -DMRI_ENABLE=$(MRI_ENABLE) -DMRI_INIT_PARAMETERS='"$(MRI_INIT_PARAMETERS)"'
DEFINES += -DMRI_BREAK_ON_INIT=$(MRI_BREAK_ON_INIT) -DMRI_SEMIHOST_STDIO=$(MRI_SEMIHOST_STDIO)
+DEFINES += -DWRITE_BUFFER_DISABLE=$(WRITE_BUFFER_DISABLE) -DSTACK_SIZE=$(STACK_SIZE)
ifeq "$(OPTIMIZATION)" "0"
DEFINES += -DDEBUG
# Libraries to be linked into final binary
MBED_LIBS = $(MBED_DIR)/$(DEVICE)/GCC_ARM/libmbed.a
SYS_LIBS = -lstdc++_s -lsupc++_s -lm -lgcc -lc_s -lgcc -lc_s -lnosys
-LIBS = $(LIBS_PREFIX)
+LIBS = $(LIBS_PREFIX)
ifeq "$(MRI_ENABLE)" "1"
LIBS += $(MRI_DIR)/mri.ar
# Compiler flags used to enable creation of header dependencies.
DEPFLAGS = -MMD -MP
+# Setup wraps for newlib read/writes to redirect to MRI debugger.
+ifeq "$(MRI_ENABLE)" "1"
+MRI_WRAPS=,--wrap=_read,--wrap=_write,--wrap=semihost_connected
+else
+MRI_WRAPS=
+endif
+
+# Setup wraps to memory allocations routines if we want to tag heap allocations.
+ifeq "$(HEAP_TAGS)" "1"
+DEFINES += -DHEAP_TAGS
+endif
+
# Compiler Options
GCFLAGS += -O$(OPTIMIZATION) -g3 $(DEVICE_CFLAGS)
GCFLAGS += -ffunction-sections -fdata-sections -fno-exceptions -fno-delete-null-pointer-checks
AS_FLAGS += -g3 $(DEVICE_FLAGS)
-# Setup wraps for newlib read/writes to redirect to MRI debugger.
-ifeq "$(MRI_ENABLE)" "1"
-MRI_WRAPS=,--wrap=_read,--wrap=_write,--wrap=semihost_connected
-else
-MRI_WRAPS=
-endif
-
# Linker Options.
-LDFLAGS = $(DEVICE_FLAGS) -specs=$(BUILD_DIR)/startfile.spec -Wl,-Map=$(OUTDIR)/$(PROJECT).map,--cref,--gc-sections,--wrap=_isatty$(MRI_WRAPS) -T$(LSCRIPT)
+LDFLAGS = $(DEVICE_FLAGS) -specs=$(BUILD_DIR)/startfile.spec
+LDFLAGS += -Wl,-Map=$(OUTDIR)/$(PROJECT).map,--cref,--gc-sections,--wrap=_isatty,--wrap=malloc,--wrap=realloc,--wrap=free$(MRI_WRAPS)
+LDFLAGS += -T$(LSCRIPT) -L $(EXTERNAL_DIR)/gcc/LPC1768
ifneq "$(NO_FLOAT_SCANF)" "1"
LDFLAGS += -u _scanf_float
endif
@echo Extracting $@
$(Q) $(MKDIR) $(call convert-slash,$(dir $@)) $(QUIET)
$(Q) $(OBJCOPY) -R .stack -O ihex $< $@
-
+
$(OUTDIR)/$(PROJECT).disasm: $(OUTDIR)/$(PROJECT).elf
@echo Extracting disassembly to $@
$(Q) $(MKDIR) $(call convert-slash,$(dir $@)) $(QUIET)
$(Q) $(OBJDUMP) -d -f -M reg-names-std --demangle $< >$@
-
+
$(OUTDIR)/$(PROJECT).elf: $(LSCRIPT) $(OBJECTS)
@echo Linking $@
$(Q) $(MKDIR) $(call convert-slash,$(dir $@)) $(QUIET)
# Default rules to compile .c and .cpp file to .o
# and assemble .s files to .o
-$(OUTDIR)/mbed_custom.o : $(BUILD_DIR)/mbed_custom.c makefile
+$(OUTDIR)/mbed_custom.o : $(BUILD_DIR)/mbed_custom.cpp makefile
@echo Compiling $<
$(Q) $(MKDIR) $(call convert-slash,$(dir $@)) $(QUIET)
- $(Q) $(GCC) $(GCFLAGS) -c $< -o $@
+ $(Q) $(GPP) $(GPFLAGS) -c $< -o $@
$(OUTDIR)/%.o : %.cpp makefile
@echo Compiling $<
$(Q) $(MKDIR) $(call convert-slash,$(dir $@)) $(QUIET)
$(Q) $(AS) $(AS_FLAGS) -o $@ $<
-#########################################################################
\ No newline at end of file
+$(OUTDIR)/configdefault.o : config.default
+ $(Q) $(OBJCOPY) -I binary -O elf32-littlearm -B arm --readonly-text --rename-section .data=.rodata.configdefault $< $@
+
+#########################################################################