Merge remote-tracking branch 'upstream/edge' into firmconfig
[clinton/Smoothieware.git] / build / common.mk
index b9ddc0d..1a3bb7f 100755 (executable)
@@ -18,7 +18,7 @@
 #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.
@@ -44,6 +44,9 @@ SRC ?= .
 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.
@@ -86,6 +89,8 @@ OBJECTS = $(patsubst %.c,$(OUTDIR)/%.o,$(CSRCS)) $(patsubst %.s,$(OUTDIR)/%.o,$(
 # 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))
 
@@ -103,8 +108,9 @@ INCDIRS += $(SRC) $(PROJINCS) $(MRI_DIR) $(MBED_DIR) $(MBED_DIR)/$(DEVICE)
 
 # 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
@@ -113,7 +119,7 @@ endif
 # 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
@@ -126,6 +132,18 @@ LIBS += $(LIBS_SUFFIX)
 # 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
@@ -141,15 +159,10 @@ AS_GCFLAGS += $(patsubst %,-I%,$(INCDIRS))
 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
@@ -208,12 +221,12 @@ $(OUTDIR)/$(PROJECT).hex: $(OUTDIR)/$(PROJECT).elf
        @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)
@@ -233,10 +246,10 @@ clean:
 #  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 $<
@@ -258,4 +271,7 @@ $(OUTDIR)/%.o : %.s makefile
        $(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 $< $@
+
+#########################################################################