Create separate makefiles for tests for more flexibility.

diff --git a/Make.rules.in b/Make.rules.in
index f07b8d1..40c840d 100644
--- a/Make.rules.in
+++ b/Make.rules.in
@@ -20,8 +20,6 @@
 # SUBDIRS      : subdirectories that contain a Makefile
 # EXTRASUBDIRS : subdirectories that do not contain a Makefile
 # INSTALLSUBDIRS : subdirectories to run make install/uninstall into
-# PLTESTS      : Perl test scripts
-# CTESTS       : C test sources
 
 # First some useful definitions
 
@@ -70,6 +68,7 @@
 MKINSTALLDIRS= $(TOPSRCDIR)/tools/mkinstalldirs
 WINAPI_CHECK = $(TOPSRCDIR)/tools/winapi_check/winapi_check
 WINEWRAPPER  = $(TOPSRCDIR)/tools/winewrapper
+RUNTEST      = $(TOPSRCDIR)/programs/winetest/runtest
 WINEBUILD    = $(TOOLSDIR)/tools/winebuild/winebuild
 MAKEDEP      = $(TOOLSDIR)/tools/makedep
 WRC          = $(TOOLSDIR)/tools/wrc/wrc
@@ -81,14 +80,6 @@
 LIBUNICODE= -L$(TOPOBJDIR)/unicode -lwine_unicode
 LIBUUID   = -L$(TOPOBJDIR)/ole -lwine_uuid
 
-RUNTEST      = $(TOPSRCDIR)/programs/winetest/runtest
-RUNTESTFLAGS = -q -P wine -M $(MODULE) -T $(TOPOBJDIR)
-TESTRESULTS  = $(PLTESTS:.pl=.ok) $(CTESTS:.c=.ok)
-TESTPROGRAM  = tests/$(MODULE:%.dll=%)_test.exe
-TESTLIST     = tests/testlist.c
-TESTOBJS     = $(TESTMAIN) $(TESTLIST:.c=.o) $(CTESTS:.c=.o)
-TESTMAIN     = $(TOPOBJDIR)/programs/winetest/wtmain.o
-
 @SET_MAKE@
 
 # Installation infos
@@ -149,10 +140,10 @@
 	$(LINT) -c $(ALLLINTFLAGS) $< || ( $(RM) $@ && exit 1 )
 
 .c.ok:
-	$(RUNTEST) $(RUNTESTFLAGS) -p $(TESTPROGRAM)$(DLLEXT) $< && touch $@
+	$(RUNTEST) $(RUNTESTFLAGS) $< && touch $@
 
 .pl.ok:
-	$(RUNTEST) $(RUNTESTFLAGS) $(PLTESTPROGRAM:%=-p %) $< && touch $@
+	$(RUNTEST) $(RUNTESTFLAGS) $< && touch $@
 
 # 'all' target first in case the enclosing Makefile didn't define any target
 
@@ -226,7 +217,7 @@
 	cd `dirname $@` && $(MAKE) depend
 
 depend: $(MAKEDEP) $(SUBDIRS:%=%/__depend__)
-	$(MAKEDEP) $(DIVINCL) -C$(SRCDIR) $(C_SRCS) $(RC_SRCS) $(RC_SRCS16) $(MC_SRCS) $(EXTRA_SRCS) $(CTESTS)
+	$(MAKEDEP) $(DIVINCL) -C$(SRCDIR) $(C_SRCS) $(RC_SRCS) $(RC_SRCS16) $(MC_SRCS) $(EXTRA_SRCS)
 
 .PHONY: depend $(SUBDIRS:%=%/__depend__)
 
@@ -242,10 +233,9 @@
 	-cd `dirname $@` && $(RM) $(CLEAN_FILES)
 
 testclean:: $(SUBDIRS:%=%/__testclean__)
-	$(RM) $(TESTRESULTS)
 
 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
-	$(RM) $(CLEAN_FILES) $(GEN_C_SRCS) $(GEN_ASM_SRCS) $(RC_SRCS:.rc=.res) $(RC_SRCS16:.rc=.res) $(MC_SRCS:.mc=.mc.rc) $(TESTRESULTS) $(TESTLIST) $(TESTPROGRAM) $(PROGRAMS)
+	$(RM) $(CLEAN_FILES) $(GEN_C_SRCS) $(GEN_ASM_SRCS) $(RC_SRCS:.rc=.res) $(RC_SRCS16:.rc=.res) $(MC_SRCS:.mc=.mc.rc) $(PROGRAMS)
 
 .PHONY: clean testclean $(SUBDIRS:%=%/__clean__) $(SUBDIRS:%=%/__testclean__) $(EXTRASUBDIRS:%=%/__clean__)
 
@@ -263,33 +253,20 @@
 
 .PHONY: install uninstall $(INSTALLSUBDIRS:%=%/__install__) $(INSTALLSUBDIRS:%=%/__uninstall__)
 
-# Rules for testing
+# Rules for checking that no imports are missing
 
-check test:: $(TESTRESULTS)
+$(SUBDIRS:%=%/__checklink__): dummy
+	@cd `dirname $@` && $(MAKE) checklink
+
+.PHONY: checklink $(SUBDIRS:%=%/__checklink__)
+
+# Rules for testing
 
 $(SUBDIRS:%=%/__test__): dummy
 	@cd `dirname $@` && $(MAKE) test
 
 .PHONY: check test $(SUBDIRS:%=%/__test__)
 
-$(PLTESTS:.pl=.ok): $(PLTESTPROGRAM)
-$(CTESTS:.c=.ok): $(TESTPROGRAM)$(DLLEXT)
-
-$(TESTMAIN):
-	cd $(TOPOBJDIR)/programs/winetest && $(MAKE) wtmain.o
-
-$(TESTLIST): Makefile.in
-	$(TOPSRCDIR)/programs/winetest/make_ctests $(CTESTS) >$(TESTLIST) || $(RM) $(TESTLIST)
-
-$(TESTPROGRAM).so: $(TESTPROGRAM).spec.o $(TESTOBJS)
-	$(LDSHARED) @LDDLLFLAGS@ $(TESTPROGRAM).spec.o $(TESTOBJS) -o $@ $(LIBWINE) $(LIBS)
-
-$(TESTPROGRAM).spec.c: $(TESTOBJS) $(WINEBUILD)
-	$(LDPATH) $(WINEBUILD) $(DEFS) -o $@ -exe $(TESTPROGRAM) -mcui $(TESTOBJS) -L$(DLLDIR) $(TESTIMPORTS:%=-l%)
-
-$(TESTPROGRAM): $(TESTOBJS)
-	$(CC) $(TESTOBJS) -o $@ $(TESTIMPORTS:%=-l%) $(LIBWINE) $(LIBS)
-
 # Misc. rules
 
 $(SPEC_SRCS:.spec=.spec.c): $(WINEBUILD)
diff --git a/Makefile.in b/Makefile.in
index edca0b9..f92d1da 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -128,13 +128,9 @@
 
 # Test rules
 
-checklink::
+checklink:: $(TESTSUBDIRS:%=%/__checklink__)
 	$(CC) -o checklink $(TOPSRCDIR)/library/checklink.c && $(RM) checklink
 
-checklink::
-	@cd dlls && $(MAKE) checklink
-	@cd programs && $(MAKE) checklink
-
 test_environment: dummy
 	@cd programs/winetest && $(MAKE) test_environment
 
@@ -142,7 +138,7 @@
 
 check test:: $(TESTSUBDIRS:%=%/__test__)
 
-.PHONY: checklink test_environment
+.PHONY: test_environment
 
 # Misc rules
 
diff --git a/configure b/configure
index eb3cffb..2b22474 100755
--- a/configure
+++ b/configure
@@ -13902,8 +13902,6 @@
 
 ac_config_commands="$ac_config_commands controls"
 
-ac_config_commands="$ac_config_commands dlls/advapi32/tests"
-
 ac_config_commands="$ac_config_commands dlls/ddraw/d3ddevice"
 
 ac_config_commands="$ac_config_commands dlls/ddraw/dclipper"
@@ -13930,24 +13928,12 @@
 
 ac_config_commands="$ac_config_commands dlls/kernel/messages"
 
-ac_config_commands="$ac_config_commands dlls/kernel/tests"
-
-ac_config_commands="$ac_config_commands dlls/oleaut32/tests"
-
-ac_config_commands="$ac_config_commands dlls/shlwapi/tests"
-
 ac_config_commands="$ac_config_commands dlls/user/dde"
 
 ac_config_commands="$ac_config_commands dlls/user/resources"
 
-ac_config_commands="$ac_config_commands dlls/user/tests"
-
 ac_config_commands="$ac_config_commands dlls/wineps/data"
 
-ac_config_commands="$ac_config_commands dlls/wininet/tests"
-
-ac_config_commands="$ac_config_commands dlls/winsock/tests"
-
 ac_config_commands="$ac_config_commands files"
 
 ac_config_commands="$ac_config_commands graphics"
@@ -13991,10 +13977,13 @@
 MAKE_DLL_RULES=dlls/Makedll.rules
 
 
+MAKE_TEST_RULES=dlls/Maketest.rules
+
+
 MAKE_PROG_RULES=programs/Makeprog.rules
 
 
-ac_config_files="$ac_config_files Make.rules dlls/Makedll.rules programs/Makeprog.rules Makefile debugger/Makefile dlls/Makefile dlls/advapi32/Makefile dlls/avicap32/Makefile dlls/avifil32/Makefile dlls/comcat/Makefile dlls/comctl32/Makefile dlls/commdlg/Makefile dlls/crtdll/Makefile dlls/crypt32/Makefile dlls/d3d8/Makefile dlls/dciman32/Makefile dlls/ddraw/Makefile dlls/devenum/Makefile dlls/dinput/Makefile dlls/dinput8/Makefile dlls/dplay/Makefile dlls/dplayx/Makefile dlls/dsound/Makefile dlls/gdi/Makefile dlls/glu32/Makefile dlls/icmp/Makefile dlls/imagehlp/Makefile dlls/imm32/Makefile dlls/kernel/Makefile dlls/lzexpand/Makefile dlls/mapi32/Makefile dlls/mpr/Makefile dlls/msacm/Makefile dlls/msacm/imaadp32/Makefile dlls/msacm/msadp32/Makefile dlls/msacm/msg711/Makefile dlls/msacm/winemp3/Makefile dlls/msdmo/Makefile dlls/msimg32/Makefile dlls/msisys/Makefile dlls/msnet32/Makefile dlls/msrle32/Makefile dlls/msvcrt/Makefile dlls/msvcrt20/Makefile dlls/msvideo/Makefile dlls/netapi32/Makefile dlls/ntdll/Makefile dlls/odbc32/Makefile dlls/ole32/Makefile dlls/oleaut32/Makefile dlls/olecli/Makefile dlls/oledlg/Makefile dlls/olepro32/Makefile dlls/olesvr/Makefile dlls/opengl32/Makefile dlls/psapi/Makefile dlls/qcap/Makefile dlls/quartz/Makefile dlls/rasapi32/Makefile dlls/richedit/Makefile dlls/rpcrt4/Makefile dlls/serialui/Makefile dlls/setupapi/Makefile dlls/shdocvw/Makefile dlls/shell32/Makefile dlls/shfolder/Makefile dlls/shlwapi/Makefile dlls/snmpapi/Makefile dlls/sti/Makefile dlls/tapi32/Makefile dlls/ttydrv/Makefile dlls/twain/Makefile dlls/url/Makefile dlls/urlmon/Makefile dlls/user/Makefile dlls/version/Makefile dlls/win32s/Makefile dlls/winaspi/Makefile dlls/winedos/Makefile dlls/wineps/Makefile dlls/wininet/Makefile dlls/winmm/Makefile dlls/winmm/joystick/Makefile dlls/winmm/mcianim/Makefile dlls/winmm/mciavi/Makefile dlls/winmm/mcicda/Makefile dlls/winmm/mciseq/Makefile dlls/winmm/mciwave/Makefile dlls/winmm/midimap/Makefile dlls/winmm/wavemap/Makefile dlls/winmm/winealsa/Makefile dlls/winmm/winearts/Makefile dlls/winmm/wineaudioio/Makefile dlls/winmm/winenas/Makefile dlls/winmm/wineoss/Makefile dlls/winnls/Makefile dlls/winsock/Makefile dlls/winspool/Makefile dlls/wintrust/Makefile dlls/wow32/Makefile dlls/wsock32/Makefile dlls/x11drv/Makefile documentation/Makefile include/Makefile library/Makefile miscemu/Makefile ole/Makefile programs/Makefile programs/avitools/Makefile programs/clock/Makefile programs/cmdlgtst/Makefile programs/control/Makefile programs/expand/Makefile programs/notepad/Makefile programs/osversioncheck/Makefile programs/progman/Makefile programs/regapi/Makefile programs/regedit/Makefile programs/regsvr32/Makefile programs/regtest/Makefile programs/uninstaller/Makefile programs/view/Makefile programs/wcmd/Makefile programs/wineconsole/Makefile programs/winefile/Makefile programs/winemine/Makefile programs/winepath/Makefile programs/winetest/Makefile programs/winhelp/Makefile programs/winver/Makefile server/Makefile tools/Makefile tools/widl/Makefile tools/winapi/Makefile tools/winebuild/Makefile tools/winedump/Makefile tools/wmc/Makefile tools/wpp/Makefile tools/wrc/Makefile tsx11/Makefile unicode/Makefile"
+ac_config_files="$ac_config_files Make.rules dlls/Makedll.rules dlls/Maketest.rules programs/Makeprog.rules Makefile debugger/Makefile dlls/Makefile dlls/advapi32/Makefile dlls/advapi32/tests/Makefile dlls/avicap32/Makefile dlls/avifil32/Makefile dlls/comcat/Makefile dlls/comctl32/Makefile dlls/commdlg/Makefile dlls/crtdll/Makefile dlls/crypt32/Makefile dlls/d3d8/Makefile dlls/dciman32/Makefile dlls/ddraw/Makefile dlls/devenum/Makefile dlls/dinput/Makefile dlls/dinput8/Makefile dlls/dplay/Makefile dlls/dplayx/Makefile dlls/dsound/Makefile dlls/gdi/Makefile dlls/glu32/Makefile dlls/icmp/Makefile dlls/imagehlp/Makefile dlls/imm32/Makefile dlls/kernel/Makefile dlls/kernel/tests/Makefile dlls/lzexpand/Makefile dlls/mapi32/Makefile dlls/mpr/Makefile dlls/msacm/Makefile dlls/msacm/imaadp32/Makefile dlls/msacm/msadp32/Makefile dlls/msacm/msg711/Makefile dlls/msacm/winemp3/Makefile dlls/msdmo/Makefile dlls/msimg32/Makefile dlls/msisys/Makefile dlls/msnet32/Makefile dlls/msrle32/Makefile dlls/msvcrt/Makefile dlls/msvcrt20/Makefile dlls/msvideo/Makefile dlls/netapi32/Makefile dlls/ntdll/Makefile dlls/odbc32/Makefile dlls/ole32/Makefile dlls/oleaut32/Makefile dlls/oleaut32/tests/Makefile dlls/olecli/Makefile dlls/oledlg/Makefile dlls/olepro32/Makefile dlls/olesvr/Makefile dlls/opengl32/Makefile dlls/psapi/Makefile dlls/qcap/Makefile dlls/quartz/Makefile dlls/rasapi32/Makefile dlls/richedit/Makefile dlls/rpcrt4/Makefile dlls/serialui/Makefile dlls/setupapi/Makefile dlls/shdocvw/Makefile dlls/shell32/Makefile dlls/shfolder/Makefile dlls/shlwapi/Makefile dlls/shlwapi/tests/Makefile dlls/snmpapi/Makefile dlls/sti/Makefile dlls/tapi32/Makefile dlls/ttydrv/Makefile dlls/twain/Makefile dlls/url/Makefile dlls/urlmon/Makefile dlls/user/Makefile dlls/user/tests/Makefile dlls/version/Makefile dlls/win32s/Makefile dlls/winaspi/Makefile dlls/winedos/Makefile dlls/wineps/Makefile dlls/wininet/Makefile dlls/wininet/tests/Makefile dlls/winmm/Makefile dlls/winmm/joystick/Makefile dlls/winmm/mcianim/Makefile dlls/winmm/mciavi/Makefile dlls/winmm/mcicda/Makefile dlls/winmm/mciseq/Makefile dlls/winmm/mciwave/Makefile dlls/winmm/midimap/Makefile dlls/winmm/wavemap/Makefile dlls/winmm/winealsa/Makefile dlls/winmm/winearts/Makefile dlls/winmm/wineaudioio/Makefile dlls/winmm/winenas/Makefile dlls/winmm/wineoss/Makefile dlls/winnls/Makefile dlls/winsock/Makefile dlls/winsock/tests/Makefile dlls/winspool/Makefile dlls/wintrust/Makefile dlls/wow32/Makefile dlls/wsock32/Makefile dlls/x11drv/Makefile documentation/Makefile include/Makefile library/Makefile miscemu/Makefile ole/Makefile programs/Makefile programs/avitools/Makefile programs/clock/Makefile programs/cmdlgtst/Makefile programs/control/Makefile programs/expand/Makefile programs/notepad/Makefile programs/osversioncheck/Makefile programs/progman/Makefile programs/regapi/Makefile programs/regedit/Makefile programs/regsvr32/Makefile programs/regtest/Makefile programs/uninstaller/Makefile programs/view/Makefile programs/wcmd/Makefile programs/wineconsole/Makefile programs/winefile/Makefile programs/winemine/Makefile programs/winepath/Makefile programs/winetest/Makefile programs/winhelp/Makefile programs/winver/Makefile server/Makefile tools/Makefile tools/widl/Makefile tools/winapi/Makefile tools/winebuild/Makefile tools/winedump/Makefile tools/wmc/Makefile tools/wpp/Makefile tools/wrc/Makefile tsx11/Makefile unicode/Makefile"
 
 
 cat >confcache <<\_ACEOF
@@ -14473,11 +14462,13 @@
   # Handling of arguments.
   "Make.rules" ) CONFIG_FILES="$CONFIG_FILES Make.rules" ;;
   "dlls/Makedll.rules" ) CONFIG_FILES="$CONFIG_FILES dlls/Makedll.rules" ;;
+  "dlls/Maketest.rules" ) CONFIG_FILES="$CONFIG_FILES dlls/Maketest.rules" ;;
   "programs/Makeprog.rules" ) CONFIG_FILES="$CONFIG_FILES programs/Makeprog.rules" ;;
   "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
   "debugger/Makefile" ) CONFIG_FILES="$CONFIG_FILES debugger/Makefile" ;;
   "dlls/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/Makefile" ;;
   "dlls/advapi32/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/advapi32/Makefile" ;;
+  "dlls/advapi32/tests/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/advapi32/tests/Makefile" ;;
   "dlls/avicap32/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/avicap32/Makefile" ;;
   "dlls/avifil32/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/avifil32/Makefile" ;;
   "dlls/comcat/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/comcat/Makefile" ;;
@@ -14500,6 +14491,7 @@
   "dlls/imagehlp/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/imagehlp/Makefile" ;;
   "dlls/imm32/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/imm32/Makefile" ;;
   "dlls/kernel/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/kernel/Makefile" ;;
+  "dlls/kernel/tests/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/kernel/tests/Makefile" ;;
   "dlls/lzexpand/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/lzexpand/Makefile" ;;
   "dlls/mapi32/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/mapi32/Makefile" ;;
   "dlls/mpr/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/mpr/Makefile" ;;
@@ -14521,6 +14513,7 @@
   "dlls/odbc32/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/odbc32/Makefile" ;;
   "dlls/ole32/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/ole32/Makefile" ;;
   "dlls/oleaut32/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/oleaut32/Makefile" ;;
+  "dlls/oleaut32/tests/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/oleaut32/tests/Makefile" ;;
   "dlls/olecli/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/olecli/Makefile" ;;
   "dlls/oledlg/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/oledlg/Makefile" ;;
   "dlls/olepro32/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/olepro32/Makefile" ;;
@@ -14538,6 +14531,7 @@
   "dlls/shell32/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/shell32/Makefile" ;;
   "dlls/shfolder/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/shfolder/Makefile" ;;
   "dlls/shlwapi/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/shlwapi/Makefile" ;;
+  "dlls/shlwapi/tests/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/shlwapi/tests/Makefile" ;;
   "dlls/snmpapi/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/snmpapi/Makefile" ;;
   "dlls/sti/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/sti/Makefile" ;;
   "dlls/tapi32/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/tapi32/Makefile" ;;
@@ -14546,12 +14540,14 @@
   "dlls/url/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/url/Makefile" ;;
   "dlls/urlmon/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/urlmon/Makefile" ;;
   "dlls/user/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/user/Makefile" ;;
+  "dlls/user/tests/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/user/tests/Makefile" ;;
   "dlls/version/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/version/Makefile" ;;
   "dlls/win32s/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/win32s/Makefile" ;;
   "dlls/winaspi/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/winaspi/Makefile" ;;
   "dlls/winedos/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/winedos/Makefile" ;;
   "dlls/wineps/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/wineps/Makefile" ;;
   "dlls/wininet/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/wininet/Makefile" ;;
+  "dlls/wininet/tests/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/wininet/tests/Makefile" ;;
   "dlls/winmm/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/winmm/Makefile" ;;
   "dlls/winmm/joystick/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/winmm/joystick/Makefile" ;;
   "dlls/winmm/mcianim/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/winmm/mcianim/Makefile" ;;
@@ -14568,6 +14564,7 @@
   "dlls/winmm/wineoss/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/winmm/wineoss/Makefile" ;;
   "dlls/winnls/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/winnls/Makefile" ;;
   "dlls/winsock/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/winsock/Makefile" ;;
+  "dlls/winsock/tests/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/winsock/tests/Makefile" ;;
   "dlls/winspool/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/winspool/Makefile" ;;
   "dlls/wintrust/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/wintrust/Makefile" ;;
   "dlls/wow32/Makefile" ) CONFIG_FILES="$CONFIG_FILES dlls/wow32/Makefile" ;;
@@ -14613,7 +14610,6 @@
   "tsx11/Makefile" ) CONFIG_FILES="$CONFIG_FILES tsx11/Makefile" ;;
   "unicode/Makefile" ) CONFIG_FILES="$CONFIG_FILES unicode/Makefile" ;;
   "controls" ) CONFIG_COMMANDS="$CONFIG_COMMANDS controls" ;;
-  "dlls/advapi32/tests" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/advapi32/tests" ;;
   "dlls/ddraw/d3ddevice" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/ddraw/d3ddevice" ;;
   "dlls/ddraw/dclipper" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/ddraw/dclipper" ;;
   "dlls/ddraw/ddraw" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/ddraw/ddraw" ;;
@@ -14627,15 +14623,9 @@
   "dlls/gdi/mfdrv" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/gdi/mfdrv" ;;
   "dlls/gdi/win16drv" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/gdi/win16drv" ;;
   "dlls/kernel/messages" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/kernel/messages" ;;
-  "dlls/kernel/tests" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/kernel/tests" ;;
-  "dlls/oleaut32/tests" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/oleaut32/tests" ;;
-  "dlls/shlwapi/tests" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/shlwapi/tests" ;;
   "dlls/user/dde" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/user/dde" ;;
   "dlls/user/resources" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/user/resources" ;;
-  "dlls/user/tests" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/user/tests" ;;
   "dlls/wineps/data" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/wineps/data" ;;
-  "dlls/wininet/tests" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/wininet/tests" ;;
-  "dlls/winsock/tests" ) CONFIG_COMMANDS="$CONFIG_COMMANDS dlls/winsock/tests" ;;
   "files" ) CONFIG_COMMANDS="$CONFIG_COMMANDS files" ;;
   "graphics" ) CONFIG_COMMANDS="$CONFIG_COMMANDS graphics" ;;
   "graphics/x11drv" ) CONFIG_COMMANDS="$CONFIG_COMMANDS graphics/x11drv" ;;
@@ -14820,6 +14810,8 @@
 s,@MAKE_RULES@,,;t t
 /@MAKE_DLL_RULES@/r $MAKE_DLL_RULES
 s,@MAKE_DLL_RULES@,,;t t
+/@MAKE_TEST_RULES@/r $MAKE_TEST_RULES
+s,@MAKE_TEST_RULES@,,;t t
 /@MAKE_PROG_RULES@/r $MAKE_PROG_RULES
 s,@MAKE_PROG_RULES@,,;t t
 CEOF
@@ -15297,8 +15289,6 @@
   case $ac_dest in
     controls ) test -d "controls" || ({ echo "$as_me:$LINENO: creating controls" >&5
 echo "$as_me: creating controls" >&6;} && mkdir "controls") ;;
-    dlls/advapi32/tests ) test -d "dlls/advapi32/tests" || ({ echo "$as_me:$LINENO: creating dlls/advapi32/tests" >&5
-echo "$as_me: creating dlls/advapi32/tests" >&6;} && mkdir "dlls/advapi32/tests") ;;
     dlls/ddraw/d3ddevice ) test -d "dlls/ddraw/d3ddevice" || ({ echo "$as_me:$LINENO: creating dlls/ddraw/d3ddevice" >&5
 echo "$as_me: creating dlls/ddraw/d3ddevice" >&6;} && mkdir "dlls/ddraw/d3ddevice") ;;
     dlls/ddraw/dclipper ) test -d "dlls/ddraw/dclipper" || ({ echo "$as_me:$LINENO: creating dlls/ddraw/dclipper" >&5
@@ -15325,24 +15315,12 @@
 echo "$as_me: creating dlls/gdi/win16drv" >&6;} && mkdir "dlls/gdi/win16drv") ;;
     dlls/kernel/messages ) test -d "dlls/kernel/messages" || ({ echo "$as_me:$LINENO: creating dlls/kernel/messages" >&5
 echo "$as_me: creating dlls/kernel/messages" >&6;} && mkdir "dlls/kernel/messages") ;;
-    dlls/kernel/tests ) test -d "dlls/kernel/tests" || ({ echo "$as_me:$LINENO: creating dlls/kernel/tests" >&5
-echo "$as_me: creating dlls/kernel/tests" >&6;} && mkdir "dlls/kernel/tests") ;;
-    dlls/oleaut32/tests ) test -d "dlls/oleaut32/tests" || ({ echo "$as_me:$LINENO: creating dlls/oleaut32/tests" >&5
-echo "$as_me: creating dlls/oleaut32/tests" >&6;} && mkdir "dlls/oleaut32/tests") ;;
-    dlls/shlwapi/tests ) test -d "dlls/shlwapi/tests" || ({ echo "$as_me:$LINENO: creating dlls/shlwapi/tests" >&5
-echo "$as_me: creating dlls/shlwapi/tests" >&6;} && mkdir "dlls/shlwapi/tests") ;;
     dlls/user/dde ) test -d "dlls/user/dde" || ({ echo "$as_me:$LINENO: creating dlls/user/dde" >&5
 echo "$as_me: creating dlls/user/dde" >&6;} && mkdir "dlls/user/dde") ;;
     dlls/user/resources ) test -d "dlls/user/resources" || ({ echo "$as_me:$LINENO: creating dlls/user/resources" >&5
 echo "$as_me: creating dlls/user/resources" >&6;} && mkdir "dlls/user/resources") ;;
-    dlls/user/tests ) test -d "dlls/user/tests" || ({ echo "$as_me:$LINENO: creating dlls/user/tests" >&5
-echo "$as_me: creating dlls/user/tests" >&6;} && mkdir "dlls/user/tests") ;;
     dlls/wineps/data ) test -d "dlls/wineps/data" || ({ echo "$as_me:$LINENO: creating dlls/wineps/data" >&5
 echo "$as_me: creating dlls/wineps/data" >&6;} && mkdir "dlls/wineps/data") ;;
-    dlls/wininet/tests ) test -d "dlls/wininet/tests" || ({ echo "$as_me:$LINENO: creating dlls/wininet/tests" >&5
-echo "$as_me: creating dlls/wininet/tests" >&6;} && mkdir "dlls/wininet/tests") ;;
-    dlls/winsock/tests ) test -d "dlls/winsock/tests" || ({ echo "$as_me:$LINENO: creating dlls/winsock/tests" >&5
-echo "$as_me: creating dlls/winsock/tests" >&6;} && mkdir "dlls/winsock/tests") ;;
     files ) test -d "files" || ({ echo "$as_me:$LINENO: creating files" >&5
 echo "$as_me: creating files" >&6;} && mkdir "files") ;;
     graphics ) test -d "graphics" || ({ echo "$as_me:$LINENO: creating graphics" >&5
diff --git a/configure.ac b/configure.ac
index 512a635..3e34fe9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1271,7 +1271,6 @@
 AH_TOP([#define __WINE_CONFIG_H])
 
 WINE_CONFIG_EXTRA_DIR(controls)
-WINE_CONFIG_EXTRA_DIR(dlls/advapi32/tests)
 WINE_CONFIG_EXTRA_DIR(dlls/ddraw/d3ddevice)
 WINE_CONFIG_EXTRA_DIR(dlls/ddraw/dclipper)
 WINE_CONFIG_EXTRA_DIR(dlls/ddraw/ddraw)
@@ -1285,15 +1284,9 @@
 WINE_CONFIG_EXTRA_DIR(dlls/gdi/mfdrv)
 WINE_CONFIG_EXTRA_DIR(dlls/gdi/win16drv)
 WINE_CONFIG_EXTRA_DIR(dlls/kernel/messages)
-WINE_CONFIG_EXTRA_DIR(dlls/kernel/tests)
-WINE_CONFIG_EXTRA_DIR(dlls/oleaut32/tests)
-WINE_CONFIG_EXTRA_DIR(dlls/shlwapi/tests)
 WINE_CONFIG_EXTRA_DIR(dlls/user/dde)
 WINE_CONFIG_EXTRA_DIR(dlls/user/resources)
-WINE_CONFIG_EXTRA_DIR(dlls/user/tests)
 WINE_CONFIG_EXTRA_DIR(dlls/wineps/data)
-WINE_CONFIG_EXTRA_DIR(dlls/wininet/tests)
-WINE_CONFIG_EXTRA_DIR(dlls/winsock/tests)
 WINE_CONFIG_EXTRA_DIR(files)
 WINE_CONFIG_EXTRA_DIR(graphics)
 WINE_CONFIG_EXTRA_DIR(graphics/x11drv)
@@ -1319,17 +1312,22 @@
 MAKE_DLL_RULES=dlls/Makedll.rules
 AC_SUBST_FILE(MAKE_DLL_RULES)
 
+MAKE_TEST_RULES=dlls/Maketest.rules
+AC_SUBST_FILE(MAKE_TEST_RULES)
+
 MAKE_PROG_RULES=programs/Makeprog.rules
 AC_SUBST_FILE(MAKE_PROG_RULES)
 
 AC_CONFIG_FILES([
 Make.rules
 dlls/Makedll.rules
+dlls/Maketest.rules
 programs/Makeprog.rules
 Makefile
 debugger/Makefile
 dlls/Makefile
 dlls/advapi32/Makefile
+dlls/advapi32/tests/Makefile
 dlls/avicap32/Makefile
 dlls/avifil32/Makefile
 dlls/comcat/Makefile
@@ -1352,6 +1350,7 @@
 dlls/imagehlp/Makefile
 dlls/imm32/Makefile
 dlls/kernel/Makefile
+dlls/kernel/tests/Makefile
 dlls/lzexpand/Makefile
 dlls/mapi32/Makefile
 dlls/mpr/Makefile
@@ -1373,6 +1372,7 @@
 dlls/odbc32/Makefile
 dlls/ole32/Makefile
 dlls/oleaut32/Makefile
+dlls/oleaut32/tests/Makefile
 dlls/olecli/Makefile
 dlls/oledlg/Makefile
 dlls/olepro32/Makefile
@@ -1390,6 +1390,7 @@
 dlls/shell32/Makefile
 dlls/shfolder/Makefile
 dlls/shlwapi/Makefile
+dlls/shlwapi/tests/Makefile
 dlls/snmpapi/Makefile
 dlls/sti/Makefile
 dlls/tapi32/Makefile
@@ -1398,12 +1399,14 @@
 dlls/url/Makefile
 dlls/urlmon/Makefile
 dlls/user/Makefile
+dlls/user/tests/Makefile
 dlls/version/Makefile
 dlls/win32s/Makefile
 dlls/winaspi/Makefile
 dlls/winedos/Makefile
 dlls/wineps/Makefile
 dlls/wininet/Makefile
+dlls/wininet/tests/Makefile
 dlls/winmm/Makefile
 dlls/winmm/joystick/Makefile
 dlls/winmm/mcianim/Makefile
@@ -1420,6 +1423,7 @@
 dlls/winmm/wineoss/Makefile
 dlls/winnls/Makefile
 dlls/winsock/Makefile
+dlls/winsock/tests/Makefile
 dlls/winspool/Makefile
 dlls/wintrust/Makefile
 dlls/wow32/Makefile
diff --git a/dlls/.cvsignore b/dlls/.cvsignore
index 4ea3f0a..be1ab9d 100644
--- a/dlls/.cvsignore
+++ b/dlls/.cvsignore
@@ -1,2 +1,3 @@
 Makedll.rules
 Makefile
+Maketest.rules
diff --git a/dlls/Makedll.rules.in b/dlls/Makedll.rules.in
index 1b79089..cfb5726 100644
--- a/dlls/Makedll.rules.in
+++ b/dlls/Makedll.rules.in
@@ -16,7 +16,6 @@
 SPEC_DEF    = $(MAINSPEC).def
 ALL_OBJS    = $(SPEC_SRCS:.spec=.spec.o) $(OBJS) $(MODULE).dbg.o
 ALL_LIBS    = $(LIBWINE) $(EXTRALIBS) $(LIBS)
-TESTIMPORTS = $(MODULE:%.dll=%) $(DELAYIMPORTS) $(IMPORTS)
 
 all: $(MODULE)$(DLLEXT)
 
@@ -45,11 +44,13 @@
 
 CHECKLINK_RPATH = dlls library tsx11 unicode
 
-checklink:: $(MODULE)$(DLLEXT)
+checklink:: $(MODULE)$(DLLEXT) $(SUBDIRS:%=%/__checklink__)
 	$(CC) -o checklink $(CHECKLINK_RPATH:%=-Wl,-rpath,$(TOPOBJDIR)/%) $(TOPSRCDIR)/library/checklink.c $(MODULE)$(DLLEXT) && $(RM) checklink
 
 # Rules for testing
 
+check test:: $(SUBDIRS:%=%/__test__)
+
 $(TESTRESULTS): $(MODULE)$(DLLEXT)
 
 # Sanity check
diff --git a/dlls/Makefile.in b/dlls/Makefile.in
index 15514e5..7fa06e1 100644
--- a/dlls/Makefile.in
+++ b/dlls/Makefile.in
@@ -905,9 +905,6 @@
 
 # Misc rules
 
-$(BUILDSUBDIRS:%=%/__checklink__): dummy
-	@cd `dirname $@` && $(MAKE) checklink
-
 uninstall::
 	-rmdir $(dlldir)
 
@@ -915,6 +912,4 @@
 
 checklink:: $(BUILDSUBDIRS:%=%/__checklink__)
 
-.PHONY: checklink $(BUILDSUBDIRS:%=%/__checklink__)
-
 ### Dependencies:
diff --git a/dlls/Maketest.rules.in b/dlls/Maketest.rules.in
new file mode 100644
index 0000000..8f9cd11
--- /dev/null
+++ b/dlls/Maketest.rules.in
@@ -0,0 +1,71 @@
+# Global rules for building dll unit tests     -*-Makefile-*-
+#
+# Each individual makefile should define the following variables:
+# DLLTEST      : the dll to test
+# CTESTS       : list of C test programs
+# EXTRALIBS    : extra libraries to link in (optional)
+# EXTRADEFS    : extra symbol definitions, like -DWINELIB (optional)
+#
+# plus all variables required by the global Make.rules.in
+#
+
+DEFS         = @DLLFLAGS@ -D__WINE__ $(EXTRADEFS)
+LDDLLFLAGS   = @LDDLLFLAGS@
+
+MODULE       = $(TESTDLL:%.dll=%)_test.exe
+TESTLIST     = testlist.c
+TESTMAIN     = $(TOPOBJDIR)/programs/winetest/wtmain.o
+TESTRESULTS  = $(CTESTS:.c=.ok)
+TESTPROGRAM  = $(MODULE)$(DLLEXT)
+RUNTESTFLAGS = -q -P wine -M $(TESTDLL) -T $(TOPOBJDIR) -p $(TESTPROGRAM)
+
+C_SRCS       = $(CTESTS)
+GEN_C_SRCS   = $(TESTLIST)
+EXTRA_OBJS   = $(TESTMAIN)
+ALL_LIBS     = $(LIBWINE) $(EXTRALIBS) $(LIBS)
+
+@MAKE_RULES@
+
+# Rule for main module spec file
+
+$(MODULE).spec.c: $(RC_SRCS:.rc=.res) $(OBJS) $(WINEBUILD)
+	$(LDPATH) $(WINEBUILD) $(DEFS) -o $@ -exe $(MODULE) -mcui $(RC_SRCS:%.rc=-res %.res) $(OBJS) -L$(DLLDIR) $(DELAYIMPORTS:%=-dl%) $(IMPORTS:%=-l%)
+
+# Rules for .so main module
+
+$(MODULE).so: $(MODULE).spec.o $(OBJS) Makefile.in
+	$(LDSHARED) $(LDDLLFLAGS) $(MODULE).spec.o $(OBJS) -o $@ $(ALL_LIBS)
+
+# Rules for .exe main module
+
+$(MODULE): $(OBJS) $(RCOBJS) Makefile.in
+	$(CC) $(OBJS) $(RCOBJS) -o $@ $(DELAYIMPORTS:%=-l%) $(IMPORTS:%=-l%) $(ALL_LIBS)
+
+# Rules for building test list
+
+$(TESTLIST): Makefile.in
+	$(TOPSRCDIR)/programs/winetest/make_ctests $(CTESTS) >$(TESTLIST) || $(RM) $(TESTLIST)
+
+# Rules for checking that no imports are missing
+
+CHECKLINK_RPATH = library tsx11 unicode
+
+checklink:: $(MODULE).so $(SUBDIRS:%=%/__checklink__)
+	$(CC) -o checklink $(CHECKLINK_RPATH:%=-Wl,-rpath,$(TOPOBJDIR)/%) $(TOPSRCDIR)/library/checklink.c $(MODULE).so && $(RM) checklink
+
+# Rules for testing
+
+check test:: $(TESTRESULTS) $(SUBDIRS:%=%/__test__)
+
+$(TESTRESULTS): $(MODULE)$(DLLEXT)
+
+$(TESTMAIN):
+	cd $(TOPOBJDIR)/programs/winetest && $(MAKE) wtmain.o
+
+# Rules for cleaning
+
+testclean::
+	$(RM) $(TESTRESULTS)
+
+clean::
+	$(RM) $(MODULE) $(TESTLIST) $(TESTRESULTS)
diff --git a/dlls/advapi32/Makefile.in b/dlls/advapi32/Makefile.in
index 8c703dd..04fba43 100644
--- a/dlls/advapi32/Makefile.in
+++ b/dlls/advapi32/Makefile.in
@@ -17,10 +17,7 @@
 	security.c \
 	service.c
 
-CTESTS = \
-	tests/registry.c
-
-EXTRASUBDIRS = tests
+SUBDIRS = tests
 
 @MAKE_DLL_RULES@
 
diff --git a/dlls/advapi32/tests/.cvsignore b/dlls/advapi32/tests/.cvsignore
index b5e478b..1a3fdc2 100644
--- a/dlls/advapi32/tests/.cvsignore
+++ b/dlls/advapi32/tests/.cvsignore
@@ -1,3 +1,4 @@
+Makefile
 advapi32_test.exe.spec.c
 registry.ok
 testlist.c
diff --git a/dlls/advapi32/tests/Makefile.in b/dlls/advapi32/tests/Makefile.in
new file mode 100644
index 0000000..f9d84f7
--- /dev/null
+++ b/dlls/advapi32/tests/Makefile.in
@@ -0,0 +1,13 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+TESTDLL   = advapi32.dll
+IMPORTS   = advapi32 kernel32 ntdll
+
+CTESTS = \
+	registry.c
+
+@MAKE_TEST_RULES@
+
+### Dependencies:
diff --git a/dlls/kernel/Makefile.in b/dlls/kernel/Makefile.in
index 4893eb6..da2d9e1 100644
--- a/dlls/kernel/Makefile.in
+++ b/dlls/kernel/Makefile.in
@@ -35,20 +35,8 @@
 
 EXTRA_OBJS = $(MODULE).glue.o
 
-EXTRASUBDIRS = \
-	messages \
-	nls \
-	tests
-
-CTESTS = \
-	tests/alloc.c \
-	tests/atom.c \
-	tests/directory.c \
-	tests/file.c \
-	tests/locale.c \
-	tests/path.c \
-	tests/process.c \
-	tests/thread.c
+SUBDIRS      = tests
+EXTRASUBDIRS = messages nls
 
 @MAKE_DLL_RULES@
 
diff --git a/dlls/kernel/tests/.cvsignore b/dlls/kernel/tests/.cvsignore
index b7d279a..2e44a5d 100644
--- a/dlls/kernel/tests/.cvsignore
+++ b/dlls/kernel/tests/.cvsignore
@@ -1,3 +1,4 @@
+Makefile
 alloc.ok
 atom.ok
 directory.ok
diff --git a/dlls/kernel/tests/Makefile.in b/dlls/kernel/tests/Makefile.in
new file mode 100644
index 0000000..9e4bd44
--- /dev/null
+++ b/dlls/kernel/tests/Makefile.in
@@ -0,0 +1,20 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+TESTDLL   = kernel32.dll
+IMPORTS   = kernel32
+
+CTESTS = \
+	alloc.c \
+	atom.c \
+	directory.c \
+	file.c \
+	locale.c \
+	path.c \
+	process.c \
+	thread.c
+
+@MAKE_TEST_RULES@
+
+### Dependencies:
diff --git a/dlls/make_dlls b/dlls/make_dlls
index 38cdf72..559a790 100755
--- a/dlls/make_dlls
+++ b/dlls/make_dlls
@@ -42,6 +42,8 @@
 {
     my $module;
 
+    next if $i =~ /\/tests\/Makefile.in/;
+
     open MAKE,$i;
 
     $module = undef;
@@ -283,9 +285,6 @@
 print NEWMAKE <<EOF;
 # Misc rules
 
-\$(BUILDSUBDIRS:%=%/__checklink__): dummy
-	\@cd `dirname \$\@` && \$(MAKE) checklink
-
 uninstall::
 	-rmdir \$(dlldir)
 
@@ -293,8 +292,6 @@
 
 checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
 
-.PHONY: checklink \$(BUILDSUBDIRS:%=%/__checklink__)
-
 ### Dependencies:
 EOF
 
diff --git a/dlls/oleaut32/Makefile.in b/dlls/oleaut32/Makefile.in
index e0017b0..8746b8a 100644
--- a/dlls/oleaut32/Makefile.in
+++ b/dlls/oleaut32/Makefile.in
@@ -28,11 +28,8 @@
 
 RC_SRCS = version.rc
 
-CTESTS = tests/vartest.c
-
-EXTRASUBDIRS = tests
+SUBDIRS = tests
 
 @MAKE_DLL_RULES@
 
 ### Dependencies:
-
diff --git a/dlls/oleaut32/tests/.cvsignore b/dlls/oleaut32/tests/.cvsignore
index 053a6bc..3466e75 100644
--- a/dlls/oleaut32/tests/.cvsignore
+++ b/dlls/oleaut32/tests/.cvsignore
@@ -1,3 +1,4 @@
+Makefile
 oleaut32_test.exe.spec.c
 testlist.c
 vartest.ok
diff --git a/dlls/oleaut32/tests/Makefile.in b/dlls/oleaut32/tests/Makefile.in
new file mode 100644
index 0000000..1b185f5
--- /dev/null
+++ b/dlls/oleaut32/tests/Makefile.in
@@ -0,0 +1,13 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+TESTDLL   = oleaut32.dll
+IMPORTS   = oleaut32
+
+CTESTS = \
+	vartest.c
+
+@MAKE_TEST_RULES@
+
+### Dependencies:
diff --git a/dlls/shlwapi/Makefile.in b/dlls/shlwapi/Makefile.in
index 1dbc130..fa8e77c 100644
--- a/dlls/shlwapi/Makefile.in
+++ b/dlls/shlwapi/Makefile.in
@@ -24,11 +24,7 @@
 	url.c \
 	wsprintf.c
 
-EXTRASUBDIRS = tests
-
-CTESTS = \
-	tests/clist.c \
-	tests/shreg.c
+SUBDIRS = tests
 
 @MAKE_DLL_RULES@
 
diff --git a/dlls/shlwapi/tests/.cvsignore b/dlls/shlwapi/tests/.cvsignore
index 861ac16..9837ff8 100644
--- a/dlls/shlwapi/tests/.cvsignore
+++ b/dlls/shlwapi/tests/.cvsignore
@@ -1,3 +1,4 @@
+Makefile
 clist.ok
 shlwapi_test.exe.spec.c
 shreg.ok
diff --git a/dlls/shlwapi/tests/Makefile.in b/dlls/shlwapi/tests/Makefile.in
new file mode 100644
index 0000000..8a2b60e
--- /dev/null
+++ b/dlls/shlwapi/tests/Makefile.in
@@ -0,0 +1,14 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+TESTDLL   = shlwapi.dll
+IMPORTS   = shlwapi advapi32
+
+CTESTS = \
+	clist.c \
+	shreg.c
+
+@MAKE_TEST_RULES@
+
+### Dependencies:
diff --git a/dlls/user/Makefile.in b/dlls/user/Makefile.in
index 5213d44..a6277c6 100644
--- a/dlls/user/Makefile.in
+++ b/dlls/user/Makefile.in
@@ -82,19 +82,15 @@
 	resources/mouse.rc \
 	resources/version16.rc
 
+SUBDIRS = tests
+
 EXTRA_OBJS = $(MODULE).glue.o
 
 EXTRASUBDIRS = \
 	$(TOPOBJDIR)/controls \
 	$(TOPOBJDIR)/windows \
 	dde \
-	resources \
-	tests
-
-CTESTS = \
-	tests/class.c \
-	tests/sysparams.c \
-	tests/wsprintf.c
+	resources
 
 @MAKE_DLL_RULES@
 
diff --git a/dlls/user/tests/.cvsignore b/dlls/user/tests/.cvsignore
index a509d90..4b8da69 100644
--- a/dlls/user/tests/.cvsignore
+++ b/dlls/user/tests/.cvsignore
@@ -1,3 +1,4 @@
+Makefile
 class.ok
 sysparams.ok
 testlist.c
diff --git a/dlls/user/tests/Makefile.in b/dlls/user/tests/Makefile.in
new file mode 100644
index 0000000..8aae4d4
--- /dev/null
+++ b/dlls/user/tests/Makefile.in
@@ -0,0 +1,15 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+TESTDLL   = user32.dll
+IMPORTS   = user32 gdi32 advapi32
+
+CTESTS = \
+	class.c \
+	sysparams.c \
+	wsprintf.c
+
+@MAKE_TEST_RULES@
+
+### Dependencies:
diff --git a/dlls/wininet/Makefile.in b/dlls/wininet/Makefile.in
index b73faed..59aa1da 100644
--- a/dlls/wininet/Makefile.in
+++ b/dlls/wininet/Makefile.in
@@ -17,13 +17,9 @@
 	utility.c \
 	wininet_main.c
 
-RC_SRCS= \
-	version.rc
+RC_SRCS = version.rc
 
-CTESTS = \
-	tests/http.c
-
-EXTRASUBDIRS = tests
+SUBDIRS = tests
 
 @MAKE_DLL_RULES@
 
diff --git a/dlls/wininet/tests/.cvsignore b/dlls/wininet/tests/.cvsignore
index 1beb01d..e5cdbce 100644
--- a/dlls/wininet/tests/.cvsignore
+++ b/dlls/wininet/tests/.cvsignore
@@ -1,3 +1,4 @@
+Makefile
 http.ok
 testlist.c
 wininet_test.exe.spec.c
diff --git a/dlls/wininet/tests/Makefile.in b/dlls/wininet/tests/Makefile.in
new file mode 100644
index 0000000..5b4b0df
--- /dev/null
+++ b/dlls/wininet/tests/Makefile.in
@@ -0,0 +1,13 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+TESTDLL   = wininet.dll
+IMPORTS   = wininet
+
+CTESTS = \
+	http.c
+
+@MAKE_TEST_RULES@
+
+### Dependencies:
diff --git a/dlls/winsock/Makefile.in b/dlls/winsock/Makefile.in
index bda70f6..ed18254 100644
--- a/dlls/winsock/Makefile.in
+++ b/dlls/winsock/Makefile.in
@@ -14,10 +14,7 @@
 	async.c \
 	socket.c
 
-CTESTS = \
-	tests/sock.c
-
-EXTRASUBDIRS = tests
+SUBDIRS = tests
 
 @MAKE_DLL_RULES@
 
diff --git a/dlls/winsock/tests/.cvsignore b/dlls/winsock/tests/.cvsignore
index accf243..d164a92 100644
--- a/dlls/winsock/tests/.cvsignore
+++ b/dlls/winsock/tests/.cvsignore
@@ -1,3 +1,4 @@
+Makefile
 sock.ok
 testlist.c
 ws2_32_test.exe.spec.c
diff --git a/dlls/winsock/tests/Makefile.in b/dlls/winsock/tests/Makefile.in
new file mode 100644
index 0000000..4c0260b
--- /dev/null
+++ b/dlls/winsock/tests/Makefile.in
@@ -0,0 +1,13 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+TESTDLL   = ws2_32.dll
+IMPORTS   = ws2_32
+
+CTESTS = \
+	sock.c
+
+@MAKE_TEST_RULES@
+
+### Dependencies:
diff --git a/programs/Makefile.in b/programs/Makefile.in
index a708bac..981fa13 100644
--- a/programs/Makefile.in
+++ b/programs/Makefile.in
@@ -92,9 +92,6 @@
 
 # Rules for testing
 
-$(SUBDIRS:%=%/__checklink__): dummy
-	@cd `dirname $@` && $(MAKE) checklink
-
 checklink:: $(SUBDIRS:%=%/__checklink__)
 
 check test:: $(SUBDIRS:%=%/__test__)
diff --git a/programs/Makeprog.rules.in b/programs/Makeprog.rules.in
index 63f9f78..8867f54 100644
--- a/programs/Makeprog.rules.in
+++ b/programs/Makeprog.rules.in
@@ -15,6 +15,7 @@
 ALL_LIBS    = $(LIBWINE) $(EXTRALIBS) $(LIBS)
 BASEMODULE  = $(MODULE:.exe=)
 TESTIMPORTS = $(DELAYIMPORTS) $(IMPORTS)
+RUNTESTFLAGS= -q -P wine -T $(TOPOBJDIR) $(PLTESTPROGRAM:%=-p %)
 
 @MAKE_RULES@
 
@@ -42,12 +43,14 @@
 
 CHECKLINK_RPATH = library tsx11 unicode
 
-checklink:: $(MODULE).so
+checklink:: $(MODULE).so $(SUBDIRS:%=%/__checklink__)
 	$(CC) -o checklink $(CHECKLINK_RPATH:%=-Wl,-rpath,$(TOPOBJDIR)/%) $(TOPSRCDIR)/library/checklink.c $(MODULE).so && $(RM) checklink
 
 # Rules for testing
 
-$(TESTRESULTS): $(MODULE)$(DLLEXT) $(BASEMODULE)$(EXEEXT)
+check test:: $(SUBDIRS:%=%/__test__)
+
+$(TESTRESULTS): $(MODULE)$(DLLEXT)
 
 # Rules for installation
 
diff --git a/programs/winetest/make_ctests b/programs/winetest/make_ctests
index 2bd735e..f7bc2c0 100755
--- a/programs/winetest/make_ctests
+++ b/programs/winetest/make_ctests
@@ -26,7 +26,7 @@
 my @testlist = @ARGV;
 foreach (@testlist)
 {
-    s!.*/([^/]+)\.c$!$1!;
+    s!(.*/)*([^/]+)\.c$!$2!;
     printf "extern void func_%s(void);\n", $_;
 }