diff --git a/makefile-binary b/makefile-binary
index faece3163f92702efc54ec256852f295a33ae1e7..879cce91134b4d9273436b13ea3201cb38cb56b7 100644
--- a/makefile-binary
+++ b/makefile-binary
@@ -29,9 +29,38 @@ RELEASE_LINK_PATHS:=$(addsuffix /lib-release, $(addprefix ../, $(LINK_LIBRARIES)
 
 LDFLAGS_RELEASE:=-Wl,--no-as-needed $(addprefix -L, $(RELEASE_LINK_PATHS)) -rdynamic $(addprefix -l, $(LINK_LIBRARIES) $(SYSTEM_LIBRARIES)) $(LTO_PARAM) -Wl,-rpath,.
 
-OBJECTS_DEBUG:=$(patsubst src/%.cpp,obj-debug/%.o, $(shell find src/ -name *cpp))
+OBJECTS_DEBUG:=$(patsubst src/%.cpp,obj-debug/%.o, $(sort $(shell find src/ -name *cpp)))
 
-OBJECTS_RELEASE:=$(patsubst src/%.cpp,obj-release/%.o, $(shell find src/ -name *cpp))
+OBJECTS_RELEASE:=$(patsubst src/%.cpp,obj-release/%.o, $(sort $(shell find src/ -name *cpp)))
+
+# ---------------------------------------------------------------------------------------------------------------------------------------------------------
+# to handle deleted source files
+
+EXISTENT_OBJECTS_DEBUG:=$(sort $(shell find obj-debug/ -name *o))
+
+EXISTENT_OBJECTS_RELEASE:=$(sort $(shell find obj-release/ -name *o))
+
+EXTRA_OBJECTS_DEBUG:=$(filter-out $(OBJECTS_DEBUG), $(EXISTENT_OBJECTS_DEBUG))
+
+EXTRA_OBJECTS_RELEASE:=$(filter-out $(OBJECTS_RELEASE), $(EXISTENT_OBJECTS_RELEASE))
+
+ifneq ($(strip $(EXTRA_OBJECTS_DEBUG)),)
+ifneq ($(wildcard lib-debug/$(FULL_LIBRARY)),)
+ifneq ($(firstword $(EXISTENT_OBJECTS_DEBUG)),)
+$(shell touch $(firstword $(EXISTENT_OBJECTS_DEBUG)))
+endif
+endif
+endif
+
+ifneq ($(strip $(EXTRA_OBJECTS_RELEASE)),)
+ifneq ($(wildcard lib-release/$(FULL_LIBRARY)),)
+ifneq ($(firstword $(EXISTENT_OBJECTS_RELEASE)),)
+$(shell touch $(firstword $(EXISTENT_OBJECTS_RELEASE)))
+endif
+endif
+endif
+
+# ---------------------------------------------------------------------------------------------------------------------------------------------------------
 
 .PHONY: all build-debug clean-debug doc
 
diff --git a/makefile-library b/makefile-library
index 2628aae66874f6a375fc1034201aca0ac05b47e0..7bc241dbe81ff7fd2174c93f5e1a51c72be89ad1 100644
--- a/makefile-library
+++ b/makefile-library
@@ -44,11 +44,60 @@ LDFLAGS_RELEASE:=-rdynamic -shared $(LTO_PARAM) $(addprefix -L, $(RELEASE_LINK_P
 TEST_LDFLAGS_RELEASE:=-Wl,--no-as-needed $(addprefix -L, $(RELEASE_TEST_LINK_PATHS)) -rdynamic $(addprefix -l, $(TEST_LINK_LIBRARIES) $(TEST_SYSTEM_LIBRARIES)) -lcppunit $(LTO_PARAM) -Wl,-rpath,.
 
 
-OBJECTS_DEBUG:=$(patsubst src/%.cpp,obj-debug/%.o, $(shell find src/ -name *cpp))
-TEST_OBJECTS_DEBUG:=$(patsubst test-src/%.cpp,test-obj-debug/%.o, $(shell find test-src/ -name *cpp))
+OBJECTS_DEBUG:=$(patsubst src/%.cpp,obj-debug/%.o, $(sort $(shell find src/ -name *cpp)))
+TEST_OBJECTS_DEBUG:=$(patsubst test-src/%.cpp,test-obj-debug/%.o, $(sort $(shell find test-src/ -name *cpp)))
 
-OBJECTS_RELEASE:=$(patsubst src/%.cpp,obj-release/%.o, $(filter-out $(wildcard src/debug/*), $(shell find src/ -name *cpp)))
-TEST_OBJECTS_RELEASE:=$(patsubst test-src/%.cpp,test-obj-release/%.o, $(shell find test-src/ -name *cpp))
+OBJECTS_RELEASE:=$(patsubst src/%.cpp,obj-release/%.o, $(filter-out $(wildcard src/debug/*), $(sort $(shell find src/ -name *cpp))))
+TEST_OBJECTS_RELEASE:=$(patsubst test-src/%.cpp,test-obj-release/%.o, $(sort $(shell find test-src/ -name *cpp)))
+
+# ---------------------------------------------------------------------------------------------------------------------------------------------------------
+# to handle deleted source files
+
+EXISTENT_OBJECTS_DEBUG:=$(sort $(shell find obj-debug/ -name *o))
+EXISTENT_TEST_OBJECTS_DEBUG:=$(sort $(shell find test-obj-debug/ -name *o))
+
+EXISTENT_OBJECTS_RELEASE:=$(sort $(shell find obj-release/ -name *o))
+EXISTENT_TEST_OBJECTS_RELEASE:=$(sort $(shell find test-obj-release/ -name *o))
+
+EXTRA_OBJECTS_DEBUG:=$(filter-out $(OBJECTS_DEBUG), $(EXISTENT_OBJECTS_DEBUG))
+EXTRA_TEST_OBJECTS_DEBUG:=$(filter-out $(TEST_OBJECTS_DEBUG), $(EXISTENT_TEST_OBJECTS_DEBUG))
+
+EXTRA_OBJECTS_RELEASE:=$(filter-out $(OBJECTS_RELEASE), $(EXISTENT_OBJECTS_RELEASE))
+EXTRA_TEST_OBJECTS_RELEASE:=$(filter-out $(TEST_OBJECTS_RELEASE), $(EXISTENT_TEST_OBJECTS_RELEASE))
+
+ifneq ($(strip $(EXTRA_OBJECTS_DEBUG)),)
+ifneq ($(wildcard lib-debug/$(FULL_LIBRARY)),)
+ifneq ($(firstword $(EXISTENT_OBJECTS_DEBUG)),)
+$(shell touch $(firstword $(EXISTENT_OBJECTS_DEBUG)))
+endif
+endif
+endif
+
+ifneq ($(strip $(EXTRA_TEST_OBJECTS_DEBUG)),)
+ifneq ($(wildcard test-bin-debug/$(TESTBIN)),)
+ifneq ($(firstword $(EXISTENT_TEST_OBJECTS_DEBUG)),)
+$(shell touch $(firstword $(EXISTENT_TEST_OBJECTS_DEBUG)))
+endif
+endif
+endif
+
+ifneq ($(strip $(EXTRA_OBJECTS_RELEASE)),)
+ifneq ($(wildcard lib-release/$(FULL_LIBRARY)),)
+ifneq ($(firstword $(EXISTENT_OBJECTS_RELEASE)),)
+$(shell touch $(firstword $(EXISTENT_OBJECTS_RELEASE)))
+endif
+endif
+endif
+
+ifneq ($(strip $(EXTRA_TEST_OBJECTS_RELEASE)),)
+ifneq ($(wildcard test-bin-release/$(TESTBIN)),)
+ifneq ($(firstword $(EXISTENT_TEST_OBJECTS_RELEASE)),)
+$(shell touch $(firstword $(EXISTENT_TEST_OBJECTS_RELEASE)))
+endif
+endif
+endif
+
+# ---------------------------------------------------------------------------------------------------------------------------------------------------------
 
 .PHONY: all debug release clean build-debug build-release clean-debug clean-release doc