diff --git a/Makefile b/Makefile
index 2274323a4ec02a74f2ba570af363664d9348bd3f..55361dddda63c9c508aa530037b0abcf2a600cb0 100644
--- a/Makefile
+++ b/Makefile
@@ -134,9 +134,10 @@ dos: dos-tag
 	${LINKER} ${OPTIM} ${DASH}o bin/gmsh${EXEEXT} ${GMSH_LIBS}
 
 dos-lib: dos-tag
-	for %%i in (${GMSH_DIRS}); do gmake -C %%i cpobj
-	${AR} ${ARFLAGS}lib/libGmsh${LIBEXT} lib/*${OBJEXT}
-	erase lib\*${OBJEXT}
+	for %%i in (${GMSH_DIRS}); do gmake -C %%i
+	${AR} ${ARFLAGS}bin\libGmsh${LIBEXT} lib\*${LIBEXT}
+	erase lib\*${LIBEXT}
+	move bin\libGmsh${LIBEXT} lib
 
 dos-clean:
 	for %%i in (doc lib ${GMSH_DIRS}) do gmake -C %%i clean
diff --git a/contrib/ANN/Makefile b/contrib/ANN/Makefile
index 62d88af134039afbd99ca389dd32be860e95542f..b27c183b6f46edc3b5b7f935a68509f958f32f47 100644
--- a/contrib/ANN/Makefile
+++ b/contrib/ANN/Makefile
@@ -3,90 +3,11 @@
 # See the LICENSE.txt file for license information. Please report all
 # bugs and problems to <gmsh@geuz.org>.
 
-include ../../variables
-
-LIB = ../../lib/libGmshANN${LIBEXT}
-
-INC = ${DASH}I../../Common ${DASH}I./include
-
-CFLAGS = ${OPTIM} ${FLAGS} ${INC} ${SYSINCLUDE}
-
-SRC = src/ANN.cpp\
-      src/bd_fix_rad_search.cpp\
-      src/bd_pr_search.cpp\
-      src/bd_search.cpp\
-      src/bd_tree.cpp\
-      src/brute.cpp\
-      src/kd_dump.cpp\
-      src/kd_fix_rad_search.cpp\
-      src/kd_pr_search.cpp\
-      src/kd_search.cpp\
-      src/kd_split.cpp\
-      src/kd_tree.cpp\
-      src/kd_util.cpp\
-      src/perf.cpp
-
-OBJ = ${SRC:.cpp=${OBJEXT}}
-
-.SUFFIXES: ${OBJEXT} .cpp
-
-${LIB}: ${OBJ} 
-	${AR} ${ARFLAGS}${LIB} ${OBJ} 
-	${RANLIB} ${LIB}
-
-cpobj: ${OBJ} 
-	cp -f ${OBJ} ../../lib/
-
-.cpp${OBJEXT}:
-	${CXX} ${CFLAGS} ${DASH}c $< ${DASH}o ${<:.cpp=${OBJEXT}}
-	if [ -r ${notdir ${<:.cpp=${OBJEXT}}} ]; then\
-           mv -f ${notdir ${<:.cpp=${OBJEXT}}} ${<:.cpp=${OBJEXT}};\
-        fi
+default:
+	@cd src && ${MAKE}
 
 clean:
-	rm -f src/*.o src/*.obj
+	@cd src && ${MAKE} clean
 
 depend:
-	(sed '/^# DO NOT DELETE THIS LINE/q' Makefile && \
-	${CXX} -MM ${CFLAGS} ${SRC} \
-	) >Makefile.new
-	cp Makefile Makefile.bak
-	cp Makefile.new Makefile
-	rm -f Makefile.new
-
-# DO NOT DELETE THIS LINE
-ANN.o: src/ANN.cpp include/ANN/ANNx.h include/ANN/ANN.h \
-  include/ANN/ANNperf.h
-bd_fix_rad_search.o: src/bd_fix_rad_search.cpp src/bd_tree.h \
-  include/ANN/ANNx.h include/ANN/ANN.h src/kd_tree.h \
-  src/kd_fix_rad_search.h src/kd_util.h src/pr_queue_k.h \
-  include/ANN/ANNperf.h
-bd_pr_search.o: src/bd_pr_search.cpp src/bd_tree.h include/ANN/ANNx.h \
-  include/ANN/ANN.h src/kd_tree.h src/kd_pr_search.h src/kd_util.h \
-  src/pr_queue.h include/ANN/ANNperf.h src/pr_queue_k.h
-bd_search.o: src/bd_search.cpp src/bd_tree.h include/ANN/ANNx.h \
-  include/ANN/ANN.h src/kd_tree.h src/kd_search.h src/kd_util.h \
-  src/pr_queue_k.h include/ANN/ANNperf.h
-bd_tree.o: src/bd_tree.cpp src/bd_tree.h include/ANN/ANNx.h \
-  include/ANN/ANN.h src/kd_tree.h src/kd_util.h src/kd_split.h \
-  include/ANN/ANNperf.h
-brute.o: src/brute.cpp include/ANN/ANNx.h include/ANN/ANN.h \
-  src/pr_queue_k.h include/ANN/ANNperf.h
-kd_dump.o: src/kd_dump.cpp src/kd_tree.h include/ANN/ANNx.h \
-  include/ANN/ANN.h src/bd_tree.h
-kd_fix_rad_search.o: src/kd_fix_rad_search.cpp src/kd_fix_rad_search.h \
-  src/kd_tree.h include/ANN/ANNx.h include/ANN/ANN.h src/kd_util.h \
-  src/pr_queue_k.h include/ANN/ANNperf.h
-kd_pr_search.o: src/kd_pr_search.cpp src/kd_pr_search.h src/kd_tree.h \
-  include/ANN/ANNx.h include/ANN/ANN.h src/kd_util.h src/pr_queue.h \
-  include/ANN/ANNperf.h src/pr_queue_k.h
-kd_search.o: src/kd_search.cpp src/kd_search.h src/kd_tree.h \
-  include/ANN/ANNx.h include/ANN/ANN.h src/kd_util.h src/pr_queue_k.h \
-  include/ANN/ANNperf.h
-kd_split.o: src/kd_split.cpp src/kd_tree.h include/ANN/ANNx.h \
-  include/ANN/ANN.h src/kd_util.h src/kd_split.h
-kd_tree.o: src/kd_tree.cpp src/kd_tree.h include/ANN/ANNx.h \
-  include/ANN/ANN.h src/kd_split.h src/kd_util.h include/ANN/ANNperf.h
-kd_util.o: src/kd_util.cpp src/kd_util.h src/kd_tree.h include/ANN/ANNx.h \
-  include/ANN/ANN.h include/ANN/ANNperf.h
-perf.o: src/perf.cpp include/ANN/ANN.h include/ANN/ANNperf.h
+	@cd src && ${MAKE} depend
diff --git a/contrib/ANN/src/Makefile b/contrib/ANN/src/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..f4c3704b2fc6ecd2eb0b229c9226cc45cec47dfe
--- /dev/null
+++ b/contrib/ANN/src/Makefile
@@ -0,0 +1,54 @@
+# Gmsh - Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
+#
+# See the LICENSE.txt file for license information. Please report all
+# bugs and problems to <gmsh@geuz.org>.
+
+include ../../../variables
+
+LIB = ../../../lib/libGmshANN${LIBEXT}
+
+INC = ${DASH}I../../../Common ${DASH}I../include
+
+CFLAGS = ${OPTIM} ${FLAGS} ${INC} ${SYSINCLUDE}
+
+SRC = ANN.cpp\
+      bd_fix_rad_search.cpp\
+      bd_pr_search.cpp\
+      bd_search.cpp\
+      bd_tree.cpp\
+      brute.cpp\
+      kd_dump.cpp\
+      kd_fix_rad_search.cpp\
+      kd_pr_search.cpp\
+      kd_search.cpp\
+      kd_split.cpp\
+      kd_tree.cpp\
+      kd_util.cpp\
+      perf.cpp
+
+OBJ = ${SRC:.cpp=${OBJEXT}}
+
+.SUFFIXES: ${OBJEXT} .cpp
+
+${LIB}: ${OBJ} 
+	${AR} ${ARFLAGS}${LIB} ${OBJ} 
+	${RANLIB} ${LIB}
+
+cpobj: ${OBJ} 
+	cp -f ${OBJ} ../../../lib/
+
+.cpp${OBJEXT}:
+	${CXX} ${CFLAGS} ${DASH}c $<
+
+clean:
+	${RM} *.o *.obj
+
+depend:
+	(sed '/^# DO NOT DELETE THIS LINE/q' Makefile && \
+	${CXX} -MM ${CFLAGS} ${SRC} \
+	) >Makefile.new
+	cp Makefile Makefile.bak
+	cp Makefile.new Makefile
+	rm -f Makefile.new
+
+# DO NOT DELETE THIS LINE
diff --git a/contrib/NR/Makefile b/contrib/NR/Makefile
index aa4392752e93af7f60d271b56640d5a9086cce84..a3e8bcad58ac55765deee6db4063fc9e35358d19 100644
--- a/contrib/NR/Makefile
+++ b/contrib/NR/Makefile
@@ -38,7 +38,7 @@ cpobj: ${OBJ}
 	${CXX} ${CFLAGS} ${DASH}c $<
 
 clean:
-	rm -f *.o *.obj
+	${RM} *.o *.obj
 
 depend:
 	(sed '/^# DO NOT DELETE THIS LINE/q' Makefile && \
diff --git a/contrib/NativeFileChooser/Makefile b/contrib/NativeFileChooser/Makefile
index e113b69eed861882df1af5fbc77efacd0b9af355..fe8d7f1eabbaec4871fa8a1cc88c49b02d5aa72f 100644
--- a/contrib/NativeFileChooser/Makefile
+++ b/contrib/NativeFileChooser/Makefile
@@ -27,7 +27,7 @@ cpobj: ${OBJ}
 	${CXX} ${CFLAGS} ${DASH}c $<
 
 clean:
-	rm -f *.o *.obj
+	${RM} *.o *.obj
 
 depend:
 	(sed '/^# DO NOT DELETE THIS LINE/q' Makefile && \
diff --git a/contrib/Tetgen/Makefile b/contrib/Tetgen/Makefile
index 802443f0b2885cbcfc0790dc4f60263a30474fc5..b30e6f399a38648447cf2273296784974ae46b8f 100644
--- a/contrib/Tetgen/Makefile
+++ b/contrib/Tetgen/Makefile
@@ -26,7 +26,7 @@ cpobj: ${OBJ}
 	${CXX} ${CFLAGS} ${DASH}c $<
 
 clean:
-	rm -f *.o *.obj
+	${RM} *.o *.obj
 
 depend:
 	(sed '/^# DO NOT DELETE THIS LINE/q' Makefile && \