Index: trunk/kBuild/footer.kmk
===================================================================
--- trunk/kBuild/footer.kmk	(revision 129)
+++ trunk/kBuild/footer.kmk	(revision 130)
@@ -658,5 +658,5 @@
 $(eval publib := $(PATH_LIB)/$(notdir $(lib)))
 $(publib) : $(lib) $(dir $(publib)).dir_created
-	$(CP) $(lib) $(publib) 
+	$(CP) $(lib) $(publib)
 	
 _LIBS += $(publib)
@@ -778,14 +778,4 @@
 $(eval deps        := )
 #
-$(eval deffile    := $(strip $(firstword
-	$($(target)_DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
-	$($(target)_DEFFILE.$(BUILD_TARGET))\
-	$($(target)_DEFFILE.$(BUILD_TYPE))\
-	$($(target)_DEFFILE)\
-	$(DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
-	$(DEFFILE.$(BUILD_TARGET))\
-	$(DEFFILE.$(BUILD_TYPE))\
-	$(DEFFILE)\
-)))
 $(eval custom_pre    := $(strip $(firstword
 	$($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
@@ -811,8 +801,17 @@
 
 $(eval $(TOOL_$(tool)_LINK_PROGRAM))
-
+# publish rule (still need work)
+ifndef $(target)_noinst
+$(eval pubexe := $(PATH_LIB)/$(notdir $(exe)))
+$(pubexe) : $(exe) $(dir $(pubexe)).dir_created
+	$(CP) $(exe) $(pubexe)
+	
+_DLLS += $(pubexe)
+_OUT_FILES += $(exe) $(pubexe)
+else
+_DLLS += $(exe)
+_OUT_FILES += $(exe)
+endif
 _OBJS += $(_OBJS_$(target))
-_EXES += $(exe)
-_OUT_FILES += $(exe)
 endef
 
@@ -826,4 +825,159 @@
 #
 
+## DLL (one).
+# @param    $(target)   Normalized target (program) name.
+define def_dll
+# source -> object
+$(eval $(def_target_sources))
+
+# dllmod
+$(eval tool        := $(call _TARGET_TOOL,$(target),LD))
+$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
+$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
+$(eval dllsuff     := $(firstword $($(target)_DLLSUFF) $($(target)_DLLSUFF) $(TOOL_$(tool)_LDDLLSUFF) $(SUFF_DLL)))
+$(eval dll         := $(outbase)$(dllsuff))
+$(eval objs         = $(_OBJS_$(target)))
+$(eval flags       :=\
+	$(TOOL_$(tool)_LDFLAGS)\
+	$(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
+	$(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
+	$(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
+	$(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
+	$(LDFLAGS)\
+	$(LDFLAGS.$(BUILD_TYPE))\
+	$(LDFLAGS.$(BUILD_TARGET))\
+	$(LDFLAGS.$(BUILD_TARGET_ARCH))\
+	$(LDFLAGS.$(BUILD_TARGET_CPU))\
+	$($(target)_LDFLAGS)\
+	$($(target)_LDFLAGS.$(BUILD_TYPE))\
+	$($(target)_LDFLAGS.$(BUILD_TARGET))\
+	$($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
+	$($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
+)
+$(eval libs        :=\
+	$($(target)_LIBS.$(BUILD_TARGET_CPU))\
+	$($(target)_LIBS.$(BUILD_TARGET_ARCH))\
+	$($(target)_LIBS.$(BUILD_TARGET))\
+	$($(target)_LIBS.$(BUILD_TYPE))\
+	$($(target)_LIBS)\
+	$(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
+				   $($(target)_SDKS.$(BUILD_TYPE)) \
+				   $($(target)_SDKS),\
+	$(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
+	$(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
+	$(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
+	$(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
+	$(SDK_$(sdk)_LIBS))\
+	$(LIBS.$(BUILD_TARGET_CPU))\
+	$(LIBS.$(BUILD_TARGET_ARCH))\
+	$(LIBS.$(BUILD_TARGET))\
+	$(LIBS.$(BUILD_TYPE))\
+	$(LIBS)\
+	$(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
+				   $(SDKS.$(BUILD_TYPE)) \
+				   $(SDKS),\
+	$(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
+	$(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
+	$(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
+	$(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
+	$(SDK_$(sdk)_LIBS))\
+	$(TOOL_$(tool)_LIBS.$(BUILD_TARGET_CPU))\
+	$(TOOL_$(tool)_LIBS.$(BUILD_TARGET_ARCH))\
+	$(TOOL_$(tool)_LIBS.$(BUILD_TARGET))\
+	$(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
+	$(TOOL_$(tool)_LIBS)\
+)
+$(eval libpath    :=\
+	$($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
+	$($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
+	$($(target)_LIBPATH.$(BUILD_TARGET))\
+	$($(target)_LIBPATH.$(BUILD_TYPE))\
+	$($(target)_LIBPATH)\
+	$(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
+				   $($(target)_SDKS.$(BUILD_TYPE)) \
+				   $($(target)_SDKS),\
+	$(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
+	$(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
+	$(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
+	$(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
+	$(SDK_$(sdk)_LIBPATH))\
+	$(LIBPATH.$(BUILD_TARGET_CPU))\
+	$(LIBPATH.$(BUILD_TARGET_ARCH))\
+	$(LIBPATH.$(BUILD_TARGET))\
+	$(LIBPATH.$(BUILD_TYPE))\
+	$(LIBPATH)\
+	$(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
+				   $(SDKS.$(BUILD_TYPE)) \
+				   $(SDKS),\
+	$(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
+	$(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
+	$(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
+	$(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
+	$(SDK_$(sdk)_LIBPATH))\
+	$(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
+	$(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
+	$(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
+	$(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
+	$(TOOL_$(tool)_LIBPATH)\
+)
+$(eval dirdep      := $(dir $(dll)).dir_created)
+## @todo fix dependencies
+$(eval deps        := )
+#
+$(eval custom_pre    := $(strip $(firstword
+	$($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
+	$($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
+	$($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
+	$($(target)_CUSTOM_PRE)\
+	$(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
+	$(CUSTOM_PRE.$(BUILD_TARGET))\
+	$(CUSTOM_PRE.$(BUILD_TYPE))\
+	$(CUSTOM_PRE)\
+)))
+$(eval custom_post    := $(strip $(firstword
+	$($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
+	$($(target)_CUSTOM_POST.$(BUILD_TARGET))\
+	$($(target)_CUSTOM_POST.$(BUILD_TYPE))\
+	$($(target)_CUSTOM_POST)\
+	$(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
+	$(CUSTOM_POST.$(BUILD_TARGET))\
+	$(CUSTOM_POST.$(BUILD_TYPE))\
+	$(CUSTOM_POST)\
+)))
+$(eval othersrc    := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
+
+ifndef TOOL_$(tool)_LINK_DLL
+$$(warning kBuild: TOOL_$(tool)_LINK_DLL is not defined. target=$(target) )
+$$(warning kBuild: tools: \
+	1 $($(target)_$(source)TOOL.$(BUILD_TARGET)) \
+	2 $($(target)_$(source)TOOL) \
+	3 $($(target)_TOOL.$(BUILD_TARGET)) \
+	4 $($(target)_TOOL) \
+	5 $($(source)TOOL) \
+	6 $($(source)TOOL.$(BUILD_TARGET)) \
+	7 $(TOOL.$(BUILD_TARGET)) \
+	8 $(TOOL) )
+endif	
+
+$(eval $(TOOL_$(tool)_LINK_DLL))
+
+					
+# publish rule (still need work)
+ifndef $(target)_noinst
+$(eval pubdll := $(PATH_LIB)/$(notdir $(dll)))
+$(pubdll) : $(dll) $(dir $(pubdll)).dir_created
+	$(CP) $(dll) $(pubdll)
+	
+_DLLS += $(pubdll)
+_OUT_FILES += $(dll) $(pubdll)
+else
+_DLLS += $(dll)
+_OUT_FILES += $(dll)
+endif
+_OBJS += $(_OBJS_$(target))
+endef
+
+# Process dlls
+$(foreach target, $(DLLS), $(eval $(def_dll)))
 
 
@@ -832,5 +986,5 @@
 #
 
-## System moduler (one).
+## System module (one).
 # @param    $(target)   Normalized target (program) name.
 define def_sysmod
@@ -932,14 +1086,4 @@
 $(eval deps        := )
 #
-$(eval deffile    := $(strip $(firstword
-	$($(target)_DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
-	$($(target)_DEFFILE.$(BUILD_TARGET))\
-	$($(target)_DEFFILE.$(BUILD_TYPE))\
-	$($(target)_DEFFILE)\
-	$(DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
-	$(DEFFILE.$(BUILD_TARGET))\
-	$(DEFFILE.$(BUILD_TYPE))\
-	$(DEFFILE)\
-)))
 $(eval custom_pre    := $(strip $(firstword
 	$($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
@@ -979,10 +1123,20 @@
 $(eval $(TOOL_$(tool)_LINK_SYSMOD))
 
-_OBJS += $(_OBJS_$(target))
+# publish rule (still need work)
+ifndef $(target)_noinst
+$(eval pubsys := $(PATH_LIB)/$(notdir $(sys)))
+$(pubsys) : $(sys) $(dir $(pubsys)).dir_created
+	$(CP) $(sys) $(pubsys)
+	
+_SYSMODS += $(pubsys)
+_OUT_FILES += $(sys) $(pubsys)
+else
 _SYSMODS += $(sys)
 _OUT_FILES += $(sys)
-endef
-
-# Process libraries
+endif
+_OBJS += $(_OBJS_$(target))
+endef
+
+# Process sysmods
 $(foreach target, $(SYSMODS), $(eval $(def_sysmod)))
 
@@ -1003,5 +1157,5 @@
 # Directories.
 #
-_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(dir $(_OUT_FILES) $(_OBJS))))
+_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(sort $(dir $(_OUT_FILES) $(_OBJS)))))
 
 define def_createdir
@@ -1155,5 +1309,5 @@
 all_recursive: $(foreach pass,$(PASSES),pass_$(pass))
 
-rebuild: clean 
+rebuild: clean
 	$(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
 
Index: trunk/kBuild/header.kmk
===================================================================
--- trunk/kBuild/header.kmk	(revision 129)
+++ trunk/kBuild/header.kmk	(revision 130)
@@ -285,5 +285,5 @@
 endif
 
-## ABSPATH - makes a path absolute.
+## ABSPATH - make paths absolute.
 # This implementation is clumsy and doesn't resolve '..' and '.' components.
 #
@@ -293,4 +293,9 @@
                       $(if $(patsubst %:,,$(firstword $(subst :,: ,$(path)))),$(PATH_CURRENT)/$(path),$(path)),\
                       $(path))))
+## DIRDEP - make create directory dependencies.
+#
+# @param	$1	The paths to the directories which must be created.
+DIRDEP = $(foreach path,$(1),$(path)/.dir_created)
+		
 
 ## Cygwin kludge.
Index: trunk/kBuild/tools/GCC.kmk
===================================================================
--- trunk/kBuild/tools/GCC.kmk	(revision 129)
+++ trunk/kBuild/tools/GCC.kmk	(revision 130)
@@ -58,4 +58,10 @@
 TOOL_GCC_LDFLAGS.debug      := -g
 TOOL_GCC_LDFLAGS.release    := -s
+TOOL_GCC_LDFLAGS.dll.os2    := -Zdll
+ifndef TOOL_GCC_LDFLAGS.$(BUILD_TARGET)
+TOOL_GCC_LDFLAGS.dll        := -shared
+else
+TOOL_GCC_LDFLAGS.dll        := $(TOOL_GCC_LDFLAGS.$(BUILD_TARGET))
+endif
 
 
@@ -138,5 +144,5 @@
 # @param	$(dirdep)   Directory creation dependency.
 # @param	$(deps)		Other dependencies.
-# @param	$(deffile)  Definition file. (optional, PC only)
+# @param	$(othersrc) Unhandled sources.
 # @param	$(custom_pre)   Custom step invoked before linking.
 # @param	$(custom_post)  Custom step invoked after linking.
@@ -158,2 +164,32 @@
 endef
 
+
+## Link program
+# @param    $(target)   Normalized main target name.
+# @param    $(exe)		Program name.
+# @param    $(objs)     Object files to link together.
+# @param    $(libs)     Libraries to search.
+# @param    $(libpath)  Library search paths.
+# @param    $(flags)    Flags.
+# @param	$(dirdep)   Directory creation dependency.
+# @param	$(deps)		Other dependencies.
+# @param	$(othersrc) Unhandled sources.
+# @param	$(custom_pre)   Custom step invoked before linking.
+# @param	$(custom_post)  Custom step invoked after linking.
+#
+# @param    $(outbase)  Output basename (full). Use this for list files and such.
+define TOOL_GCC_LINK_DLL
+#$ (warning dbg: TOOL_GCC_LINK_DLL: target=$(target) exe=$(exe) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
+$(exe): $(dirdep) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(deps)
+	$(call MSG_L1,Creating Program $$@)
+ifneq ($(custom_pre),)
+	$(eval $(custom_pre))
+endif	
+	$(TOOL_GCC_LD) $(TOOL_GCC_LDFLAGS.dll) $(flags) -o $$@ $(objs) \
+	$(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
+ifneq ($(custom_post),)
+	$(eval $(custom_post))
+endif	
+	
+endef
+
Index: trunk/kBuild/tools/GCC3.kmk
===================================================================
--- trunk/kBuild/tools/GCC3.kmk	(revision 129)
+++ trunk/kBuild/tools/GCC3.kmk	(revision 130)
@@ -57,4 +57,9 @@
 TOOL_GCC3_LDFLAGS.debug      := -g
 TOOL_GCC3_LDFLAGS.release    := -s
+ifndef TOOL_GCC3_LDFLAGS.$(BUILD_TARGET)
+TOOL_GCC3_LDFLAGS.dll        := -shared
+else
+TOOL_GCC3_LDFLAGS.dll        := $(TOOL_GCC3_LDFLAGS.$(BUILD_TARGET))
+endif
 
 
@@ -137,5 +142,5 @@
 # @param	$(dirdep)   Directory creation dependency.
 # @param	$(deps)		Other dependencies.
-# @param	$(deffile)  Definition file. (optional, PC only)
+# @param	$(othersrc) Unhandled sources.
 # @param	$(custom_pre)   Custom step invoked before linking.
 # @param	$(custom_post)  Custom step invoked after linking.
@@ -155,7 +160,36 @@
 	$(eval $(custom_post))
 endif	
-	$(MKDIR) -p $(PATH_BIN)
-	$(CP) $$@ $(PATH_BIN)/
 	
 endef
 
+
+## Link DLL
+# @param    $(target)   Normalized main target name.
+# @param    $(dll)		Program name.
+# @param    $(objs)     Object files to link together.
+# @param    $(libs)     Libraries to search.
+# @param    $(libpath)  Library search paths.
+# @param    $(flags)    Flags.
+# @param	$(dirdep)   Directory creation dependency.
+# @param	$(deps)		Other dependencies.
+# @param	$(othersrc) Unhandled sources.
+# @param	$(custom_pre)   Custom step invoked before linking.
+# @param	$(custom_post)  Custom step invoked after linking.
+#
+# @param    $(outbase)  Output basename (full). Use this for list files and such.
+define TOOL_GCC3_LINK_DLL
+#$ (warning dbg: TOOL_GCC3_LINK_PROGRAM: target=$(target) dll=$(dll) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
+$(dll): $(dirdep) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(deps)
+	$(call MSG_L1,Creating Program $$@)
+ifneq ($(custom_pre),)
+	$(eval $(custom_pre))
+endif	
+	$(TOOL_GCC3_LD) $(TOOL_GCC3_LDFLAGS.dll) $(flags) -o $$@ $(objs) \
+	$(foreach p,$(libpath), -L$(p)) \
+	$(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
+ifneq ($(custom_post),)
+	$(eval $(custom_post))
+endif	
+	
+endef
+
Index: trunk/kBuild/tools/MINGW32.kmk
===================================================================
--- trunk/kBuild/tools/MINGW32.kmk	(revision 129)
+++ trunk/kBuild/tools/MINGW32.kmk	(revision 130)
@@ -171,5 +171,5 @@
 # @param	$(dirdep)   Directory creation dependency.
 # @param	$(deps)		Other dependencies.
-# @param	$(deffile)  Definition file. (optional, PC only)
+# @param	$(othersrc) Unhandled sources.
 # @param	$(custom_pre)   Custom step invoked before linking.
 # @param	$(custom_post)  Custom step invoked after linking.
@@ -189,6 +189,4 @@
 	$(eval $(custom_post))
 endif	
-	$(MKDIR) -p $(PATH_BIN)
-	$(CP) $$@ $(PATH_BIN)/
 	
 endef
Index: trunk/kBuild/tools/VCC70.kmk
===================================================================
--- trunk/kBuild/tools/VCC70.kmk	(revision 129)
+++ trunk/kBuild/tools/VCC70.kmk	(revision 130)
@@ -143,5 +143,5 @@
 # @param	$(dirdep)   Directory creation dependency.
 # @param	$(deps)		Other dependencies.
-# @param	$(deffile)  Definition file. (optional, PC only)
+# @param	$(othersrc) Unhandled sources.
 # @param	$(custom_pre)   Custom step invoked before linking.
 # @param	$(custom_post)  Custom step invoked after linking.
@@ -149,5 +149,5 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_VCC70_LINK_PROGRAM
-#$ (warning dbg: TOOL_VCC70_LINK_PROGRAM: target=$(target) exe=$(exe) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
+#$ (warning dbg: TOOL_VCC70_LINK_PROGRAM: target=$(target) exe=$(exe) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
 $(exe): $(dirdep) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(deps)
 	$(call MSG_L1,Creating Program $$@)
@@ -159,8 +159,9 @@
 		/MAPINFO:EXPORTS /MAPINFO:LINES \
 		/MAP:$(outbase).map \
+		$(foreach def,$(filter %.def,$(othersrc)), /DEF:$(def)) \
+		$(filter %.exp %.res,$(othersrc)) \
+		$(foreach p,$(libpath), /LIBPATH:$(p)) \
 		$(subst /,\\,$(objs)) \
 		$(subst /,\\,$(libs))
-	$(MKDIR) -p $(PATH_BIN)
-	$(CP) $$@ $(PATH_BIN)/
 ifneq ($(custom_post),)
 	$(eval $(custom_post))
@@ -180,5 +181,5 @@
 # @param	$(dirdep)   Directory creation dependency.
 # @param	$(deps)		Other dependencies.
-# @param	$(deffile)  Definition file. (optional, PC only)
+# @param	$(othersrc) Unhandled sources.
 # @param	$(custom_pre)   Custom step invoked before linking.
 # @param	$(custom_post)  Custom step invoked after linking.
@@ -186,5 +187,5 @@
 # @param    $(outbase)  Output basename (full). Use this for list files and such.
 define TOOL_VCC70_LINK_SYSMOD
-#$ (warning dbg: TOOL_VCC70_LINK_SYSMOD: target=$(target) sys=$(sys) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
+#$ (warning dbg: TOOL_VCC70_LINK_SYSMOD: target=$(target) sys=$(sys) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
 $(sys): $(dirdep) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(deps)
 	$(call MSG_L1,Creating Program $$@)
@@ -196,8 +197,9 @@
 		/MAPINFO:EXPORTS /MAPINFO:LINES \
 		/MAP:$(outbase).map \
+		$(foreach def,$(filter %.def,$(othersrc)), /DEF:$(def)) \
+		$(filter %.exp %.res,$(othersrc)) \
+		$(foreach p,$(libpath), /LIBPATH:$(p)) \
 		$(subst /,\\,$(objs)) \
 		$(subst /,\\,$(libs))
-	$(MKDIR) -p $(PATH_BIN)
-	$(CP) $$@ $(PATH_BIN)/
 ifneq ($(custom_post),)
 	$(eval $(custom_post))
@@ -207,2 +209,45 @@
 endef
 
+
+## Link system module (windows aka driver, linux aka kernel module)
+# @param    $(target)   Normalized main target name.
+# @param    $(dll)		System module name.
+# @param    $(objs)     Object files to link together.
+# @param    $(libs)     Libraries to search.
+# @param    $(libpath)  Library search paths.
+# @param    $(flags)    Flags.
+# @param	$(dirdep)   Directory creation dependency.
+# @param	$(deps)		Other dependencies.
+# @param	$(othersrc) Unhandled sources.
+# @param	$(custom_pre)   Custom step invoked before linking.
+# @param	$(custom_post)  Custom step invoked after linking.
+#
+# @param    $(outbase)  Output basename (full). Use this for list files and such.
+define TOOL_VCC70_LINK_DLL
+#$ (warning dbg: TOOL_VCC70_LINK_DLL: target=$(target) dll=$(dll) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
+$(dll): $(dirdep) $(call DIRDEP,$(PATH_LIB)) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(deps)
+	$(call MSG_L1,Creating Program $$@)
+ifneq ($(custom_pre),)
+	$(eval $(custom_pre))
+endif	
+	$(TOOL_VCC70_LD) $(flags) \
+		/OUT:$(dll) \
+		/IMPLIB:$(outbase).lib \
+		/MAPINFO:EXPORTS /MAPINFO:LINES \
+		/MAP:$(outbase).map \
+		/DLL \
+		$(foreach def,$(filter %.def,$(othersrc)), /DEF:$(def)) \
+		$(filter %.exp %.res,$(othersrc)) \
+		$(foreach p,$(libpath), /LIBPATH:$(p)) \
+		$(subst /,\\,$(objs)) \
+		$(subst /,\\,$(libs))
+ifeq ($(filter %.exp .def,$(othersrc)),)
+	$(CP) $(outbase).exp $(outbase).lib $(PATH_LIB)/
+endif
+ifneq ($(custom_post),)
+	$(eval $(custom_post))
+endif	
+_OUT_FILES += $(outbase).map $(outbase).lib $(outbase).exp
+
+endef
+
