Index: trunk/kBuild/footer.kmk
===================================================================
--- trunk/kBuild/footer.kmk	(revision 188)
+++ trunk/kBuild/footer.kmk	(revision 189)
@@ -4,5 +4,5 @@
 # kBuild - File included at top of makefile.
 #
-# Copyright (c) source004 knut st. osmundsen <bird-srcspam@anduin.net>
+# Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
 #
 #
@@ -35,9 +35,10 @@
 # all targets.
 ALL_TARGETS := \
-	$(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) \
-	$(PROGRAMS)  $(PROGRAMS.$(BUILD_TARGET)) \
-	$(DLLS)      $(DLLS.$(BUILD_TARGET)) \
-	$(SYSMODS)   $(SYSMODS.$(BUILD_TARGET)) \
-	$(OTHERS)    $(OTHERS.$(BUILD_TARGET))
+	$(LIBRARIES)   $(LIBRARIES.$(BUILD_TARGET)) \
+	$(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) \
+	$(DLLS)        $(DLLS.$(BUILD_TARGET)) \
+	$(PROGRAMS)    $(PROGRAMS.$(BUILD_TARGET)) \
+	$(SYSMODS)     $(SYSMODS.$(BUILD_TARGET)) \
+	$(OTHERS)      $(OTHERS.$(BUILD_TARGET))
 
 # dependency files.
@@ -56,4 +57,5 @@
 _SYSMODS:=
 _DIRS   :=
+_IMPORT_LIBS :=
 
 # all objs of a specific target
@@ -719,4 +721,185 @@
 
 #
+# DLLS
+#
+
+## DLL (one).
+# @param    $(target)   Normalized target (program) name.
+define def_dll
+# dllmod basics
+$(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 TARGET_$(target) := $(dll))
+
+# source -> object
+$(eval $(def_target_sources))
+
+# dllmod linking.
+$(eval tool        := $(call _TARGET_TOOL,$(target),LD))
+$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
+$(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        := $($(target)_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_BIN)/$(notdir $(dll)))
+$(pubdll) : $(dll) $(dir $(pubdll)).dir_created
+	$(CP) $(dll) $(pubdll)
+
+$(eval TARGET_PUB_$(target) := $(pubdll))
+_DLLS += $(pubdll)
+_OUT_FILES += $(dll) $(pubdll)
+else
+_DLLS += $(dll)
+_OUT_FILES += $(dll)
+endif
+_OBJS += $(_OBJS_$(target))
+endef
+
+# Process dlls
+$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)), $(eval $(def_dll)))
+
+
+
+#
+# Process import libraries.
+#
+#	- On OS/2 and windows these are libraries.
+#   - On other platforms they are fake DLLs.
+ifeq ($(subst win32,os2,$(BUILD_TARGET)),os2)
+$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(def_lib)))
+else
+$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(def_dll)))
+endif
+$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval _IMPORT_LIBS += $(firstword $(TARGET_PUB_$(target)) $(TARGET_$(target)))))
+
+
+#
 # PROGRAMS
 #
@@ -871,170 +1054,4 @@
 
 #
-# DLLS
-#
-
-## DLL (one).
-# @param    $(target)   Normalized target (program) name.
-define def_dll
-# dllmod basics
-$(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 TARGET_$(target) := $(dll))
-
-# source -> object
-$(eval $(def_target_sources))
-
-# dllmod linking.
-$(eval tool        := $(call _TARGET_TOOL,$(target),LD))
-$(eval outbase     := $(call _TARGET_BASE,$(target),$(target)))
-$(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        := $($(target)_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_BIN)/$(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) $(DLLS.$(BUILD_TARGET)), $(eval $(def_dll)))
-
-
-#
 # SYSMODS
 #
@@ -1241,5 +1258,5 @@
 
 #PASSES ?= needed libraries binaries others publish
-PASSES ?= libraries binaries others
+PASSES ?= libraries dlls binaries others
 
 ## Proritized list of the default makefile when walking subdirectories.
@@ -1310,6 +1327,13 @@
 
 ## PASS: binaries
-# This pass builds binary targets, i.e. programs, dlls, system modules and stuff.
-pass_binaries_doit: $(_DLLS) $(_EXES) $(_SYSMODS) $(_OTHER_BINARIES)
+# This pass builds dll targets.
+pass_dlls_doit: $(_DLLS) $(_OTHER_DLLS)
+pass := dlls
+PASS := DLLS
+$(eval $(def_pass))
+
+## PASS: binaries
+# This pass builds binary targets, i.e. programs, system modules and stuff.
+pass_binaries_doit: $(_EXES) $(_SYSMODS) $(_OTHER_BINARIES)
 pass := binaries
 PASS := BINARIES
@@ -1376,7 +1400,8 @@
 target:    needed libraries binaries others
 objects:   $(_OBJS)
-programs:  $(_EXES)
-dlls:      $(_DLLS)
-sysmods:   $(_SYSMODS)
+libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
+dlls:      $(_DLLS) 
+programs:  $(_EXES) 
+sysmods:   $(_SYSMODS) 
 
 
