Index: trunk/kBuild/units/qt4.kmk
===================================================================
--- trunk/kBuild/units/qt4.kmk	(revision 1672)
+++ trunk/kBuild/units/qt4.kmk	(revision 1675)
@@ -28,6 +28,6 @@
 
 # Add our target properties.
-PROPS_SINGLE += MOCTOOL UICTOOL RCCTOOL
-PROPS_ACCUMULATE_R += MOCDEFS MOCFLAGS UICFLAGS RCCFLAGS
+PROPS_SINGLE += QTTOOL MOCTOOL UICTOOL RCCTOOL LRCTOOL QT_TRANSLATIONS_INST QT_TRANSLATIONS_TEMPLATE
+PROPS_ACCUMULATE_R += MOCDEFS MOCFLAGS UICFLAGS RCCFLAGS LRCFLAGS QT_TRANSLATIONS QT_MOCSRCS QT_MOCHDRS
 
 
@@ -63,6 +63,6 @@
  TOOL_QT4_UIC       ?= $(PATH_TOOL_QT4_BIN)/uic$(HOST_SUFF_EXE)
  TOOL_QT4_RCC       ?= $(PATH_TOOL_QT4_BIN)/rcc$(HOST_SUFF_EXE)
+ TOOL_QT4_LRC       ?= $(PATH_TOOL_QT4_BIN)/lrelease$(HOST_SUFF_EXE)
  TOOL_QT4_LUPDATE   ?= $(PATH_TOOL_QT4_BIN)/lupdate$(HOST_SUFF_EXE)
- TOOL_QT4_LRELEASE  ?= $(PATH_TOOL_QT4_BIN)/lrelease$(HOST_SUFF_EXE)
 else
  # Pathless, relies on the environment.
@@ -70,6 +70,6 @@
  TOOL_QT4_UIC       ?= uic$(HOST_SUFF_EXE)
  TOOL_QT4_RCC       ?= rcc$(HOST_SUFF_EXE)
+ TOOL_QT4_LRC       ?= lrelease$(HOST_SUFF_EXE)
  TOOL_QT4_LUPDATE   ?= lupdate$(HOST_SUFF_EXE)
- TOOL_QT4_LRELEASE  ?= lrelease$(HOST_SUFF_EXE)
 endif
 
@@ -190,4 +190,25 @@
 endef
 
+## Compile a Qt translation file (.ts).
+# @param    $(target)   Normalized main target name.
+# @param    $(source)   Source filename (relative).
+# @param    $(out)      Object file name. This shall be (re)created by the compilation.
+# @param    $(dep)      Dependcy file. This may be (re)created by the compilation.
+# @param    $(flags)    Flags.
+# @param    $(defs)     Definitions.
+# @param    $(incs)     Includes.
+# @param    $(outbase)  Output basename (full). Use this for list files and such.
+#
+TOOL_QT4_LRC_TS_DEPEND =
+TOOL_QT4_LRC_TS_DEPORD =
+TOOL_QT4_LRC_TS_OUTPUT =
+TOOL_QT4_LRC_TS_OUTPUT_MAYBE =
+define TOOL_QT4_LRC_TS_CMDS
+	$(QUIET)$(TOOL_QT4_LRC)\
+		$(flags)\
+		$(source)\
+		-qm $(out)
+endef
+
 
 
@@ -199,12 +220,88 @@
 
 
-##
-# Source handler for .ts sources (translations).
-#
-# @remarks $(evalvalctx me).
-define def_unit_qt4_src_handler_ts
-$(warning def_unit_qt4_src_handler_ts: $(source))
-## @todo not quite sure about this bugger, perhaps the translations doesn't really belong here...
-endef
+## wrapper for the lrelease (LRC) command dependencies.
+ifndef NO_COMPILE_CMDS_DEPS
+ _UNIT_QT_LRC_CMDS_DEP = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_QT_LRC_CMDS_PREV_),$$(commands $(out)),FORCE)
+else
+ _UNIT_QT_LRC_CMDS_DEP =
+endif
+
+##
+# def_unit_qt4_target_pre_handle_translation helper that is expanded before evaluation.
+#
+# This is necessary to resolve reference to local variables before doing
+# assignments and setting up commands. They would otherwise be resolved
+# later in a different context and the result would be completely wrong.
+#
+define def_unit_qt4_target_pre_handle_translation_dx
+
+$(out) + $(more_output) +| $(maybe_output): \
+		$(deps) \
+		$(value _UNIT_QT_LRC_CMDS_DEP) \
+		| \
+		$(orderdeps)
+	%$$(call MSG_TOOL,lrelease,$(target),$(source),$$@)
+	$(QUIET2)$(RM) -f $(out) $(more_output) $(maybe_output) $(dep)
+
+$(cmds)
+
+ifndef NO_COMPILE_CMDS_DEPS
+	%$$(QUIET2)$$(APPEND) '$(dep)'
+	%$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(subst :,_,$(source))_QT_LRC_CMDS_PREV_'
+	%$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
+	%$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
+endif
+
+$(target)_OUT_FILES += $(out) $(more_output) $(maybe_output)
+$(target)-inst-nls_SOURCES += $(out)
+
+endef # def_unit_qt4_target_pre_handle_translation_dx
+
+##
+# Handle a source file listed in QT_TRANSLATIONS.
+#
+# The files listed in QT_TRANSLATIONS are translation files (.ts) which needs
+# to be translated into .qm files that are loadble by Qt.
+#
+# @remarks Invoked via $(evalvalctx ).
+define def_unit_qt4_target_pre_handle_translation
+local type      := LRC
+
+# fetch the properties.
+local tool      := $(kb-src-tool dummy_var)
+local qtnlsdir  := $(PATH_$(target))/qtnls
+local outbase   := $(qtnlsdir)/$(notdir $(basename $(source)))
+local out       := $(outbase).qm
+local dep       := $(out).dep
+local flags     := $(kb-src-prop FLAGS,dummy_var,right-to-left)
+local deps      := $(kb-src-prop DEPS,dummy_var,left-to-right)
+local orderdeps := $(call DIRDEP,$(dir $(outbase))) $(kb-src-prop ORDERDEPS,dummy_var,left-to-right)
+
+# default path + source dep.
+ifneq ($(defpath),)
+local deps      := $(abspathex $(deps) $(source),$($(target)_PATH))
+local incs      := $(abspathex $(incs),$($(target)_PATH))
+else
+local deps      += $(source)
+endif
+
+# call the tool
+ifndef TOOL_$(tool)_LRC_TS_CMDS
+ $(error kBuild: qt lrelease tool not found: TOOL_$(tool)_LRC_TS_CMDS)
+endif
+local cmds         := $(TOOL_$(tool)_LRC_TS_CMDS)
+local more_output  := $(TOOL_$(tool)_LRC_TS_OUTPUT)
+local maybe_output := $(TOOL_$(tool)_LRC_TS_OUTPUT_MAYBE)
+local deps         += $(TOOL_$(tool)_LRC_TS_DEPEND)
+local orderdeps    += $(TOOL_$(tool)_LRC_TS_DEPORD)
+
+# generate the link rule and update some source and target variables.
+ifndef NO_COMPILE_CMDS_DEPS
+ $(eval includedep $(dep))
+endif
+$(eval $(def_unit_qt4_target_pre_handle_translation_dx))
+
+endef # def_unit_qt4_target_pre_handle_translation
+
 
 
@@ -294,4 +391,5 @@
 
 
+
 ## wrapper for the UIC command dependencies.
 ifndef NO_COMPILE_CMDS_DEPS
@@ -302,5 +400,5 @@
 
 ##
-# def_unit_qt4_target_pre_handle_uic_ui helper that is expanded before evaluation.
+# def_unit_qt4_src_handler_ui helper that is expanded before evaluation.
 #
 # This is necessary to resolve reference to local variables before doing
@@ -378,4 +476,5 @@
 
 
+
 ## wrapper for the MOC command dependencies.
 ifndef NO_COMPILE_CMDS_DEPS
@@ -419,8 +518,11 @@
 
 ##
-# Handle a source file listed in QT_MOCSRCS.
-#
-# The files listed in QT_MOCSRCS uses the Q_OBJECT macro and will include
-# a .moc file that we're expected to generate here.
+# Handle a source file listed in QT_MOCHDRSS.
+#
+# The files listed in QT_MOCHDRS uses the Q_OBJECT macro and we will
+# generate a .cpp file for each of them and add it to the generated
+# sources so that it's compiled and linked. (There is an alternative
+# way to do this where the .cpp file is included, this isn't currently
+# supported by this unit.)
 #
 # @remarks Invoked via $(evalvalctx ).
@@ -569,4 +671,20 @@
 define def_unit_qt4_target_pre
 
+# Make QTTOOL the default for the specific Qt tools instead of TOOL.
+ifneq ($($(target)_QTTOOL),)
+ ifeq ($($(target)_MOCTOOL),)
+  $($(target)_MOCTOOL := $($(target)_QTTOOL)
+ endif
+ ifeq ($($(target)_UICTOOL),)
+  $($(target)_UICTOOL := $($(target)_QTTOOL)
+ endif
+ ifeq ($($(target)_RCCTOOL),)
+  $($(target)_RCCTOOL := $($(target)_QTTOOL)
+ endif
+ ifeq ($($(target)_LRCTOOL),)
+  $($(target)_LRCTOOL := $($(target)_QTTOOL)
+ endif
+endif
+
 # Autodetect source files with Q_OBJECT references if QT_MOCSRCS is undefined. (slow)
 # Tip: Use target_QT_MOCSRCS = $(NO_SUCH_VARIABLE) to avoid this.
@@ -587,7 +705,5 @@
 	 .UI:def_unit_qt4_src_handler_ui \
 	.qrc:def_unit_qt4_src_handler_qrc \
-	.qrc:def_unit_qt4_src_handler_qrc \
-	 .ts:def_unit_qt4_src_handler_ts \
-	 .TS:def_unit_qt4_src_handler_ts
+	.qrc:def_unit_qt4_src_handler_qrc
 
 # Calc the MOC and UI output directories and add them to BLDDIRS and INCS.
@@ -595,6 +711,7 @@
 local qtuicdir := $(PATH_$(target))/qtuic
 local qtrccdir := $(PATH_$(target))/qtrcc
-$(eval $(target)_BLDDIRS += $(qtmocdir) $(qtuicdir) $(qtrccdir))
-$(eval $(target)_INCS    += $(qtmocdir) $(qtuicdir) $(qtrccdir))
+local qtnlsdir := $(PATH_$(target))/qtnls
+$(eval $(target)_BLDDIRS += $(qtmocdir) $(qtuicdir) $(qtrccdir) $(qtnlsdir))
+$(eval $(target)_INCS    += $(qtmocdir) $(qtuicdir))
 
 # Deal with QT_MOCSRCS.
@@ -618,4 +735,27 @@
 	, $(evalvalctx def_unit_qt4_target_pre_handle_moc_hdr))
 
+# Deal with QT_TRANSLATIONS.
+# ASSUMES (_ALL_)INSTALLS is processed after the targets using this unit.
+local translations := \
+	$($(target)_QT_TRANSLATIONS.$(_bld_trg)) \
+ 	$($(target)_QT_TRANSLATIONS.$(_bld_trg_arch)) \
+ 	$($(target)_QT_TRANSLATIONS.$(_bld_trg).$(_bld_trg_arch)) \
+ 	$($(target)_QT_TRANSLATIONS.$(_bld_trg_cpu)) \
+ 	$($(target)_QT_TRANSLATIONS.$(_bld_type)) \
+ 	$($(target)_QT_TRANSLATIONS)
+ifneq ($(strip $(translations)),)
+ local expr := _ALL_INSTALLS += $(target)-inst-nls
+ $(eval $(expr))
+ ifdef $(target)_QT_TRANSLATIONS_TEMPLATE
+  $(target)-inst-nls_TEMPLATE := $($(target)_QT_TRANSLATIONS_TEMPLATE)
+ endif
+ ifdef $(target)_QT_TRANSLATIONS_INST
+  $(target)-inst-nls_INST := $($(target)_QT_TRANSLATIONS_INST)
+ endif
+ $(target)-inst-nls_SOURCES :=
+ $(foreach source, $(translations)\
+	, $(evalvalctx def_unit_qt4_target_pre_handle_translation))
+endif
+
 endef # def_unit_qt4_target_pre
 
