diff --git a/build/Makefile b/build/Makefile
index 8e5880999e25695dbb4070bb1468079e3bb23939..aa28d80fcae3f931b67e55055577abc332b05fc5 100644
--- a/build/Makefile
+++ b/build/Makefile
@@ -9,6 +9,7 @@ EXE_SUFFIX =
 CFLAGS = -std=c99 -O2 -W -Wall -pedantic -pthread -pipe -I. -I.. $(CFLAGS_EXTRA)
 VERSION = $(shell perl -lne \
             'print $$1 if /define\s+MONGOOSE_VERSION\s+"(\S+)"/' ../mongoose.h)
+RM = rm -rf
 VDIR = mongoose-$(VERSION)
 
 # Stock windows binary builds with Lua and YASSL library.
@@ -62,6 +63,7 @@ LINK = $(MSVC)/bin/link $(LINK_FLAGS)
 
 ifeq ($(OS), Windows_NT)
   EXE_SUFFIX = .exe
+  RM = del
 else
   UNAME_S := $(shell uname -s)
   ifeq ($(UNAME_S), Linux)
@@ -160,6 +162,6 @@ release: tarball macos
 
 clean:
 	@cd ../examples && $(MAKE) clean
-	@rm -rf *.o *.core $(PROG) *.obj *.so $(PROG).txt *.dSYM *.tgz \
+	@$(RM) *.o *.core $(PROG) *.obj *.so $(PROG).txt *.dSYM *.tgz \
 	$(PROG).exe *.dll *.lib res.o res.RES *.dSYM *.zip *.pdb \
 	*.exe *dmg* $(PROG)-* unix_unit_test
diff --git a/examples/Makefile b/examples/Makefile
index a7544ad7eed06a9841cc2cf20c5c6a4ab4ba25ab..9469554225d61cb6a45f9a2f14c398ac1aa75200 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,7 +1,9 @@
 CFLAGS  = -W -Wall -I.. -pthread -g -pipe $(COPT)
 DLL_FLAGS = -DLUA_COMPAT_ALL -I../build
+RM = rm -rf
 
 ifeq ($(OS),Windows_NT)
+  RM = del /q /f
 else
   UNAME_S := $(shell uname -s)
   DLL_FLAGS += -shared
@@ -43,4 +45,4 @@ windows:
 #$(CL) lua_dll.c $(CLFLAGS) $(DLL_FLAGS) /DLL $(LFLAGS) /SUBSYSTEM:WINDOWS /ENTRY:luaopen_lua_dll /EXPORT:luaopen_lua_dll /out:lua_dll.dll
 
 clean:
-	@rm -rf hello upload post websocket chat *.exe *.dSYM *.obj .*o
+	-@$(RM) hello upload post websocket chat *.exe *.dSYM *.obj .*o