# /****************************************************************************
# **
# ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
# ** Contact: 
# **
# ****************************************************************************/

# FLM to build Qt tools.

QT_ROOT:=../../..
TARGETDIR:=$(EPOCROOT)/$(INSTALLPATH)
QMAKEDIR:=$(EPOCROOT)/$(INSTALLPATH)/qt
MKSPECDIR:=$(EPOCROOT)/$(INSTALLPATH)/qt
SOURCEDIR:=$(EXTENSION_ROOT)/$(QT_ROOT)/bin
TOOLSSRCDIR:=$(EXTENSION_ROOT)/$(QT_ROOT)/src/tools
CONFIGURE_APP:=configure$(DOTEXE)

$(call makepath,$(TARGETDIR))

ifneq ($(filter linux,$(HOSTPLATFORM)),)
PLATFORM:=$(PLATFORM.LINUX)
 ifeq ($(XPLATFORM), symbian-sbsv2)
 CONFIGURE_APP:=configure_symbian
 endif
else
PLATFORM:=$(PLATFORM.WIN32)
endif

TARGET_TOOLS:=$(QMAKEDIR)/qmake$(DOTEXE) $(TARGETDIR)/moc$(DOTEXE) $(TARGETDIR)/rcc$(DOTEXE) $(TARGETDIR)/uic$(DOTEXE)
QT_TOOLS:= $(TOOLSSRCDIR)/uic $(TOOLSSRCDIR)/moc $(TOOLSSRCDIR)/rcc
SOURCE_TOOLS:=$(SOURCEDIR)/qmake$(DOTEXE) $(SOURCEDIR)/moc$(DOTEXE) $(SOURCEDIR)/rcc$(DOTEXE) $(SOURCEDIR)/uic$(DOTEXE)

define QtConfiguration
ifneq ($(filter linux,$(HOSTPLATFORM)),)
$(TARGET_TOOLS): $(QT_TOOLS)
else
$(TARGET_TOOLS): $(SOURCEDIR)/qmake$(DOTEXE)
endif
	$(call startrule,qtconf_deploy) \
	$(GNUCP) $(SOURCEDIR)/$$(notdir $$@) $$@ \
	$(call endrule,qtconf_deploy)

ifneq ($(filter linux,$(HOSTPLATFORM)),)
$(QT_TOOLS): $(TOOLSSRCDIR)/bootstrap
	$(call startrule,qtconf_tools_build) \
	cd $$@; \
	$(GNUMAKE38); \
	cd .. \
	$(call endrule,qtconf_tools_build)

$(TOOLSSRCDIR)/bootstrap:$(SOURCEDIR)/qmake$(DOTEXE)
	$(call startrule,qtconf_bootstrap_build) \
	cd $(TOOLSSRCDIR)/bootstrap; \
	$(GNUMAKE38); \
	cd .. \
	$(call endrule,qtconf_bootstrap_build)
endif


$(SOURCEDIR)/qmake$(DOTEXE): $(EXTENSION_ROOT)/$(QT_ROOT)/$(CONFIGURE_APP)
	$(call startrule,qtconf) \
	cd $(EXTENSION_ROOT)/$(QT_ROOT) && unset INCLUDE && unset LIB && $(EXTENSION_ROOT)/$(QT_ROOT)/$(CONFIGURE_APP) -platform $(PLATFORM) -xplatform $(XPLATFORM) $(OPTIONS) \
	$(call endrule,qtconf)
	$(call startrule,syncqt) \
	cd $(EXTENSION_ROOT)/$(QT_ROOT)/bin/ && \
	perl syncqt -base-dir $(EXTENSION_ROOT)/$(QT_ROOT) -copy -oneway -outdir $(EPOCROOT)/epoc32/include/ -outsubdir mw
	$(call endrule,syncqt)
	$(call startrule,mkspecexport) \
	$(GNUCP) -R $(EXTENSION_ROOT)/$(QT_ROOT)/mkspecs $(MKSPECDIR)
	$(call endrule,mkspecexport)
endef

# Here a variable named "done_<sanitised $SISFILE>" gets created
GUARD:=done_$(call sanitise,$(TARGETDIR)/qmake$(DOTEXE))
# If variable "done_..." not set, set it to 1, so that
# UREL and UDEB do not execute makesis twice on the same target 
ifeq ($($(GUARD)),)
$(GUARD):=1
ifneq ($(filter linux,$(HOSTPLATFORM)),)
ALL:: $(QT_TOOLS) $(TARGET_TOOLS)
else
ALL:: $(TARGET_TOOLS)
endif
$(eval $(call QtConfiguration))
$(eval $(call whatmacro,$(TARGET_TOOLS)))
ifeq ($(OSTYPE),unix)
$(eval $(call GenerateStandardCleanTarget,$(QT_TOOLS) $(TARGET_TOOLS) $(SOURCE_TOOLS),$(TARGETDIR)))
else
$(eval $(call GenerateStandardCleanTarget,$(TARGET_TOOLS) $(SOURCE_TOOLS),$(TARGETDIR)))
endif
endif
