Index: /trunk/kBuild/footer.kmk
===================================================================
--- /trunk/kBuild/footer.kmk	(revision 826)
+++ /trunk/kBuild/footer.kmk	(revision 827)
@@ -110,4 +110,5 @@
 _SYSMODS  :=
 _INSTALLS :=
+_INSTALLS_FILES :=
 _INSTALLS_DIRS :=
 _OTHERS   :=
@@ -708,4 +709,10 @@
 	$($(srcname)_DEPS)\
 	$($(target)_DEPS)
+orderdeps := \
+	$($(target)_$(source)_ORDERDEPS)\
+	$($(target)_$(srcname)_ORDERDEPS)\
+	$($(source)_ORDERDEPS)\
+	$($(srcname)_ORDERDEPS)\
+	$($(target)_ORDERDEPS)
 md5 := $(firstword \
 	$($(target)_$(source)_MD5)\
@@ -774,5 +781,5 @@
 $(target)_$(srcname)_FETCH_OUTPUT_ := $(TOOL_$(tool)_FETCH_OUTPUT)
 $(target)_$(srcname)_FETCH_DEPEND_ := $(TOOL_$(tool)_FETCH_DEPEND) $(deps)
-$(target)_$(srcname)_FETCH_DEPORD_ := $(TOOL_$(tool)_FETCH_DEPORD) $(dirdep)
+$(target)_$(srcname)_FETCH_DEPORD_ := $(TOOL_$(tool)_FETCH_DEPORD) $(dirdep) $(orderdeps)
 
 # generate the fetch rule.
@@ -832,5 +839,5 @@
 $(target)_$(srcname)_UNPACK_OUTPUT_ := $(TOOL_$(tool)_UNPACK_OUTPUT)
 $(target)_$(srcname)_UNPACK_DEPEND_ := $(TOOL_$(tool)_UNPACK_DEPEND) $(deps)
-$(target)_$(srcname)_UNPACK_DEPORD_ := $(TOOL_$(tool)_UNPACK_DEPORD) $(dirdep)
+$(target)_$(srcname)_UNPACK_DEPORD_ := $(TOOL_$(tool)_UNPACK_DEPORD) $(dirdep) $(orderdeps)
 
 # generate the fetch rule.
@@ -1123,5 +1130,5 @@
 $(eval $(def_link_install_rule))
 
-_INSTALLS += $(INSTARGET_$(target))
+_INSTALLS_FILES += $(INSTARGET_$(target))
 
 ifdef KBUILD_DO_AUTO_INSTALL
@@ -1213,6 +1220,6 @@
     $($(target)_OBJS_)
 dirdep      := $(call DIRDEP,$(dir $(out)))
-## @todo fix dependencies on makefiles an such
 deps        := $($(target)_DEPS)
+orderdeps   := $($(target)_ORDERDEPS)
 
 # Adjust paths if we got a default path.
@@ -1220,4 +1227,5 @@
  objs := $(call abspathex,$(objs),$(defpath))
  deps := $(call abspathex,$(deps),$(defpath))
+ orderdeps := $(call abspathex,$(orderdeps),$(defpath))
  othersrc := $(call abspathex,$(othersrc),$(defpath))
 endif
@@ -1252,5 +1260,5 @@
 $(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
 $(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
-$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep)
+$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
 
 # generate the link rule.
@@ -1429,6 +1437,6 @@
 	$(TOOL_$(tool)_LIBPATH)
 dirdep      := $(call DIRDEP,$(dir $(out)))
-## @todo fix dependencies
 deps        := $($(target)_DEPS)
+orderdeps   := $($(target)_ORDERDEPS)
 
 # Adjust paths if we got a default path.
@@ -1437,4 +1445,5 @@
  objs := $(call abspathex,$(objs),$(defpath))
  deps := $(call abspathex,$(deps),$(defpath))
+ orderdeps := $(call abspathex,$(orderdeps),$(defpath))
  othersrc := $(call abspathex,$(othersrc),$(defpath))
  # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_PATH)/lib if relative to current dir!
@@ -1442,5 +1451,5 @@
 
 ## @todo this stuff can't be working.
-custom_pre  := $(strip $(firstword \
+custom_pre := $(strip $(firstword \
 	$($(target)_CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\
 	$($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
@@ -1454,5 +1463,5 @@
 	$(CUSTOM_PRE)\
 ))
-custom_post    := $(strip $(firstword \
+custom_post := $(strip $(firstword \
 	$($(target)_CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\
 	$($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
@@ -1513,5 +1522,5 @@
 $(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
 $(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
-$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep)
+$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
 
 # generate the link rule.
@@ -1523,5 +1532,5 @@
 _OUT_FILES += $($(target)_OUTPUT_) $(out)
 _CLEAN_FILES += $($(target)_CLEAN)
-_INSTALLS += $(INSTARGET_$(target))
+_INSTALLS_FILES += $(INSTARGET_$(target))
 
 endef
@@ -1769,11 +1778,9 @@
 # _INSTFUN
 ifdef $(symlnk)_INSTFUN
-instfun := $(symlnk)_INSTFUN
-else
-ifdef $(target)_INSTFUN
+ instfun := $(symlnk)_INSTFUN
+else ifdef $(target)_INSTFUN
 instfun := $(target)_INSTFUN
 else
-instfun := _INSTALL_FILE
-endif
+ instfun := _INSTALL_FILE
 endif
 
@@ -1781,10 +1788,8 @@
 ifdef $(symlnk)_INST
  inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
+else ifdef $(target)_INST
+ inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
 else
- ifdef $(target)_INST
-  inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
- else
-  inst := $(dir $(symlnk))
- endif
+ inst := $(dir $(symlnk))
 endif
 
@@ -1821,10 +1826,8 @@
 ifdef $(directory)_INST
  inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
+else ifdef $(target)_INST
+ inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
 else
- ifdef $(target)_INST
-  inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
- else
-  inst := $(PATH_INS)
- endif
+ inst := $(PATH_INS)
 endif
 
@@ -1878,5 +1881,5 @@
 bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU)  $(BUILD_TARGET_CPU))
 
-INSTARGET_$(target) :=
+INSTARGET_$(target) := $($(target)_GOALS)
 INSTARGET_DIRS_$(target) :=
 
@@ -1890,5 +1893,13 @@
 	$(eval $(value def_install_symlink)))
 
-_INSTALLS += $(INSTARGET_$(target)) $($(target)_GOALS)
+# the collection target
+TARGET_$(target) := $(PATH_TARGET)/$(target).ins
+$(TARGET_$(target)): $(INSTARGET_$(target)) | $(INSTARGET_DIRS_$(target))
+	@$(QUIET2)$(APPEND) $@
+
+$(target): $(TARGET_$(target))
+
+_INSTALLS += $(TARGET_$(target))
+_INSTALLS_FILES += $(INSTARGET_$(target))
 _INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
 endef
@@ -1913,5 +1924,5 @@
 # DIRECTORIES
 #
-_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS)))
+_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS_FILES)))
 $(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
 
@@ -2078,5 +2089,5 @@
 # @todo make this a non-default pass!
 uninstall:
-	$(RM) -f $(_INSTALLS)
+	$(RM) -f $(_INSTALLS_FILES)
 
 install: pass_installs
@@ -2091,5 +2102,5 @@
 sysmods:   $(_SYSMODS)
 others:    $(_OTHERS)
-installs:  $(_INSTALLS_DIRS) $(_INSTALLS)
+installs:  $(_INSTALLS)
 
 
Index: /trunk/src/gmake/kbuild.c
===================================================================
--- /trunk/src/gmake/kbuild.c	(revision 826)
+++ /trunk/src/gmake/kbuild.c	(revision 827)
@@ -1335,5 +1335,5 @@
     struct variable *pOutBase   = kbuild_get_object_base(pTarget, pSource, "outbase");
     struct variable *pObjSuff   = kbuild_get_object_suffix(pTarget, pSource, pTool, pType, pBldTrg, pBldTrgArch, "objsuff");
-    struct variable *pDefs, *pIncs, *pFlags, *pDeps, *pDirDep, *pDep, *pVar, *pOutput;
+    struct variable *pDefs, *pIncs, *pFlags, *pDeps, *pOrderDeps, *pDirDep, *pDep, *pVar, *pOutput;
     struct variable *pObj       = kbuild_set_object_name_and_dep_and_dirdep_and_PATH_target_source(pTarget, pSource, pOutBase, pObjSuff, "obj", &pDep, &pDirDep);
     char *pszDstVar, *pszDst, *pszSrcVar, *pszSrc, *pszVal, *psz;
@@ -1350,12 +1350,14 @@
     if (pDefPath && !pDefPath->value_length)
         pDefPath = NULL;
-    pDefs  = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, NULL,
-                                        "DEFS", "defs", 1/* left-to-right */);
-    pIncs  = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath,
-                                        "INCS", "incs", -1/* right-to-left */);
-    pFlags = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, NULL,
-                                        "FLAGS", "flags", 1/* left-to-right */);
-    pDeps  = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath,
-                                        "DEPS", "deps", 1/* left-to-right */);
+    pDefs      = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, NULL,
+                                            "DEFS", "defs", 1/* left-to-right */);
+    pIncs      = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath,
+                                            "INCS", "incs", -1/* right-to-left */);
+    pFlags     = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, NULL,
+                                            "FLAGS", "flags", 1/* left-to-right */);
+    pDeps      = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath,
+                                            "DEPS", "deps", 1/* left-to-right */);
+    pOrderDeps = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath,
+                                            "ORDERDEPS", "orderdeps", 1/* left-to-right */);
 
     /*
@@ -1429,8 +1431,10 @@
     memcpy(pszDst, "_DEPORD_", sizeof("_DEPORD_"));
     pVar = kbuild_get_recursive_variable(pszSrcVar);
-    psz = pszVal = xmalloc(pVar->value_length + 1 + pDirDep->value_length + 1);
+    psz = pszVal = xmalloc(pVar->value_length + 1 + pDirDep->value_length + 1 + pOrderDeps->value_length + 1);
     memcpy(psz, pVar->value, pVar->value_length);       psz += pVar->value_length;
     *psz++ = ' ';
-    memcpy(psz, pDirDep->value, pDirDep->value_length + 1);
+    memcpy(psz, pDirDep->value, pDirDep->value_length); psz += pDirDep->value_length;
+    *psz++ = ' ';
+    memcpy(psz, pOrderDeps->value, pOrderDeps->value_length + 1);
     do_variable_definition(NILF, pszDstVar, pszVal, o_file, f_simple, 0 /* !target_var */);
     free(pszVal);
