add $J for instant jog of one axis.
[clinton/Smoothieware.git] / build / common.mk
index cd2ff7f..6599646 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.
@@ -70,15 +73,59 @@ endif
 MRI_INIT_PARAMETERS=$(MRI_UART)
 
 # Output Object Directory
-OUTDIR=$(DEVICE)
+OUTDIR=../$(DEVICE)
 
 # List of sources to be compiled/assembled
-CSRCS = $(wildcard $(SRC)/*.c $(SRC)/*/*.c $(SRC)/*/*/*.c $(SRC)/*/*/*/*.c $(SRC)/*/*/*/*/*.c)
+CSRCS1 = $(wildcard $(SRC)/*.c $(SRC)/*/*.c $(SRC)/*/*/*.c $(SRC)/*/*/*/*.c $(SRC)/*/*/*/*/*.c $(SRC)/*/*/*/*/*/*.c)
+# Totally exclude network if NONETWORK is defined
+ifeq "$(NONETWORK)" "1"
+CSRCS2 = $(filter-out $(SRC)/libs/Network/%,$(CSRCS1))
+DEFINES += -DNONETWORK
+else
+CSRCS2 = $(CSRCS1)
+endif
+
+# do not compile the src/testframework as that can only be done with rake
+CSRCS = $(filter-out $(SRC)/testframework/%,$(CSRCS2))
+
+ifeq "$(DISABLEMSD)" "1"
+DEFINES += -DDISABLEMSD
+endif
+
 ASRCS =  $(wildcard $(SRC)/*.S $(SRC)/*/*.S $(SRC)/*/*/*.S $(SRC)/*/*/*/*.S $(SRC)/*/*/*/*/*.S)
 ifneq "$(OS)" "Windows_NT"
 ASRCS +=  $(wildcard $(SRC)/*.s $(SRC)/*/*.s $(SRC)/*/*/*.s $(SRC)/*/*/*/*.s $(SRC)/*/*/*/*/*.s)
 endif
-CPPSRCS = $(wildcard $(SRC)/*.cpp $(SRC)/*/*.cpp $(SRC)/*/*/*.cpp $(SRC)/*/*/*/*.cpp $(SRC)/*/*/*/*/*.cpp)
+
+CPPSRCS1 = $(wildcard $(SRC)/*.cpp $(SRC)/*/*.cpp $(SRC)/*/*/*.cpp $(SRC)/*/*/*/*.cpp $(SRC)/*/*/*/*/*.cpp $(SRC)/*/*/*/*/*/*.cpp)
+ifeq "$(NONETWORK)" "1"
+       CPPSRCS2 = $(filter-out $(SRC)/libs/Network/%,$(CPPSRCS1))
+else
+       ifneq "$(PLAN9)" "1"
+               DEFINES += -DNOPLAN9
+               CPPSRCS2 = $(filter-out $(SRC)/libs/Network/uip/plan9/%,$(CPPSRCS1))
+       else
+               CPPSRCS2 = $(CPPSRCS1)
+       endif
+endif
+
+# CNC build
+ifeq "$(CNC)" "1"
+       CPPSRCS21 = $(filter-out $(SRC)/modules/utils/panel/screens/3dprinter/%,$(CPPSRCS2))
+       DEFINES += -DCNC
+else
+       CPPSRCS21 = $(filter-out $(SRC)/modules/utils/panel/screens/cnc/%,$(CPPSRCS2))
+endif
+
+# Totally exclude any modules listed in EXCLUDE_MODULES
+# uppercase function
+uc = $(subst a,A,$(subst b,B,$(subst c,C,$(subst d,D,$(subst e,E,$(subst f,F,$(subst g,G,$(subst h,H,$(subst i,I,$(subst j,J,$(subst k,K,$(subst l,L,$(subst m,M,$(subst n,N,$(subst o,O,$(subst p,P,$(subst q,Q,$(subst r,R,$(subst s,S,$(subst t,T,$(subst u,U,$(subst v,V,$(subst w,W,$(subst x,X,$(subst y,Y,$(subst z,Z,$1))))))))))))))))))))))))))
+EXL = $(patsubst %,$(SRC)/modules/%/%,$(EXCLUDED_MODULES))
+CPPSRCS3 = $(filter-out $(EXL),$(CPPSRCS21))
+DEFINES += $(call uc, $(subst /,_,$(patsubst %,-DNO_%,$(EXCLUDED_MODULES))))
+
+# do not compile the src/testframework as that can only be done with rake
+CPPSRCS = $(filter-out $(SRC)/testframework/%,$(CPPSRCS3))
 
 # List of the objects files to be compiled/assembled
 OBJECTS = $(patsubst %.c,$(OUTDIR)/%.o,$(CSRCS)) $(patsubst %.s,$(OUTDIR)/%.o,$(patsubst %.S,$(OUTDIR)/%.o,$(ASRCS))) $(patsubst %.cpp,$(OUTDIR)/%.o,$(CPPSRCS))
@@ -86,6 +133,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))
 
@@ -97,14 +146,15 @@ MBED_DIR = $(BUILD_DIR)/../mbed/drop
 MRI_DIR  = $(BUILD_DIR)/../mri
 
 # Include path which points to external library headers and to subdirectories of this project which contain headers.
-SUBDIRS = $(wildcard $(SRC)/* $(SRC)/*/* $(SRC)/*/*/* $(SRC)/*/*/*/* $(SRC)/*/*/*/*/*)
+SUBDIRS = $(wildcard $(SRC)/* $(SRC)/*/* $(SRC)/*/*/* $(SRC)/*/*/*/* $(SRC)/*/*/*/*/* $(SRC)/*/*/*/*/*/*)
 PROJINCS = $(sort $(dir $(SUBDIRS)))
 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
@@ -112,8 +162,9 @@ 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) 
+#SYS_LIBS = -lstdc++_s -lsupc++_s -lm -lgcc -lc_s -lgcc -lc_s -lnosys
+SYS_LIBS = -specs=nano.specs -lstdc++ -lsupc++ -lm -lgcc -lc -lnosys
+LIBS = $(LIBS_PREFIX)
 
 ifeq "$(MRI_ENABLE)" "1"
 LIBS += $(MRI_DIR)/mri.ar
@@ -126,6 +177,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 +204,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 +266,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)
@@ -225,7 +283,7 @@ size: $(OUTDIR)/$(PROJECT).elf
 
 clean:
        @echo Cleaning up all build generated files
-       $(Q) $(REMOVE_DIR) $(OUTDIR) $(QUIET)
+       $(Q) $(REMOVE_DIR) $(call convert-slash,$(OUTDIR)) $(QUIET)
 
 -include $(DEPFILES)
 
@@ -233,10 +291,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 +316,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 $< $@
+
+#########################################################################