#
# Makefile for the VBox debugger.
#

#
# Copyright (C) 2006 InnoTek Systemberatung GmbH
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation,
# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
# distribution. VirtualBox OSE is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY of any kind.
#
# If you received this file as part of a commercial VirtualBox
# distribution, then only the terms of your commercial VirtualBox
# license agreement apply instead of the previous paragraph.
#

DEPTH = ../../..
include $(PATH_KBUILD)/header.kmk

LIBRARIES = Debugger
ifdef VBOX_WITH_DEBUGGER_GUI
DLLS      = VBoxDbg
PROGRAMS  = tstVBoxDbg
endif

ifndef VBOX_OSE
INSTALLS.win.x86 = dbghelp
endif


#
# Debugger library
#
Debugger_TEMPLATE  = VBOXR3
Debugger_DEFS      = IN_VMM_R3 IN_PDM_R3 IN_CFGM_R3 IN_IOM_R3 IN_SUP_R3 IN_VM_R3 IN_RT_R3 IN_CPUM_R3 IN_SELM_R3 IN_PGM_R3 IN_TRPM_R3 IN_MM_R3 IN_DBG_R3 IN_DBGF_R3 IN_DIS_R3
Debugger_SOURCES   = \
	DBGConsole.cpp \
	DBGCTcp.cpp

#
# The testcase.
#
tstVBoxDbg_TEMPLATE     = VBOXQTGUIEXE
tstVBoxDbg_SOURCES      = testcase/tstVBoxDbg.cpp
tstVBoxDbg_LIBS         = \
	$(LIB_RUNTIME) \
	$(LIB_VMM)
tstVBoxDbg_LIBS.win     = \
	$(PATH_LIB)/VBoxDbg.lib
tstVBoxDbg_LIBS.linux   = \
	$(PATH_BIN)/VBoxDbg.so
tstVBoxDbg_LIBS         = \
	$(LIB_VMM) \
	$(LIB_RUNTIME)


#
# Debugger GUI component.
#
VBoxDbg_TEMPLATE = VBOXQTGUI
VBoxDbg_DEFS = IN_DBG_R3
VBoxDbg_INCS = \
	. \
	$(PATH_VBoxDbg)/ui \
	$(PATH_VBoxDbg)/moc \
	$(PATH_VBoxDbg)/include

# QDesigner UI sources
VBoxDbg_QT_UISRCS =

# Headers containing definitions of classes that use the Q_OBJECT macro
VBoxDbg_QT_MOCHDRS = \
	VBoxDbgConsole.h \
	VBoxDbgStats.h \
	VBoxDbgGui.h

# UI headers (ui.h) containing local definitions of classes that use the Q_OBJECT macro
VBoxDbg_QT_MOCUIHDRS =

VBoxDbg_GENSRCS = \
	$(foreach moc,$(notdir $(basename $(VBoxDbg_QT_MOCHDRS))), $(PATH_VBoxDbg)/moc/moc_$(moc).cpp) \
	$(foreach ui,$(notdir $(basename $(VBoxDbg_QT_UISRCS))), $(PATH_VBoxDbg)/ui/$(ui).cpp $(PATH_VBoxDbg)/moc/moc_$(ui).cpp)

VBoxDbg_GENHDRS = \
	$(foreach mocui,$(basename $(VBoxDbg_QT_MOCUIHDRS)), $(PATH_VBoxDbg)/moc/$(mocui).moc) \
	$(foreach moc,$(basename $(VBoxDbg_QT_MOCSRCS)), $(PATH_VBoxDbg)/moc/$(moc).moc) \
	$(foreach ui,$(basename $(VBoxDbg_QT_UISRCS)), $(PATH_VBoxDbg)/$(ui).h)

VBoxDbg_SOURCES    = \
	$(VBoxDbg_GENSRCS) \
	VBoxDbg.cpp \
	VBoxDbgGui.cpp \
	VBoxDbgBase.cpp \
	VBoxDbgConsole.cpp \
	VBoxDbgStats.cpp \
	DBGConsole.cpp

VBoxDbg_LIBS = $(LIB_VMM)

# generated files we need to clean manually
VBoxDbg_CLEAN += \
	$(VBoxDbg_GENSRCS) \
	$(VBoxDbg_GENHDRS)


#
# Install the dbghelp.dll binary.
#
dbghelp_INST = bin/
dbghelp_SOURCES.x86 = win32/dbghelp.dll
dbghelp_SOURCES.amd64 = win64/dbghelp.dll


include $(PATH_KBUILD)/footer.kmk


#
# Source file generation rules
#

##  Generate a rule to create a MOC source file from a header containing
#   classes that use the Q_OBJECT macro.
#   @param  $mochdr     the header file with Q_OBJECT
define def_qt_gen_src_moc
$(eval mocsrc := $(PATH_$(target))/moc/moc_$(notdir $(basename $(mochdr))).cpp)
$$(mocsrc): $(mochdr)
	$(MKDIR) -p $(basename $(mocsrc))
	$(VBOX_MOC) $(mochdr) -o $(mocsrc)

endef

##  Generate a rule to create a MOC include file from a source containing
#   local classes that use the Q_OBJECT macro. This include is then included
#   by that source, so it must be generated before the source gets compiled.
#   @param  $mocsrc     the source file with Q_OBJECT
define def_qt_gen_inc_moc
$(eval mocobj := $(PATH_$(target)_$(mocsrc))/$(notdir $(basename $(mocsrc)))$(SUFF_OBJ))
$(eval mocinc := $(PATH_$(target))/moc/$(notdir $(basename $(mocsrc))).moc)
$$(mocobj): $(mocinc)
$$(mocinc): $(mocsrc)
	$(MKDIR) -p $(basename $(mocinc))
	$(VBOX_MOC) -i $(mocsrc) -o $(mocinc)

endef

##  Generate a rule to create a MOC include file from a UI header (ui.h) containing
#   local classes that use the Q_OBJECT macro. This include is then included
#   by that header, so it must be generated before the UI source gets compiled.
#   @param  $mocuihdr     the UI header file with Q_OBJECT
define def_qt_gen_inc_mocuihdr
$(eval uisrc    := $(PATH_$(target))/ui/$(notdir $(basename $(basename $(mocuihdr)))).cpp)
$(eval uiobj    := $(PATH_$(target)_$(uisrc))/$(notdir $(basename $(uisrc)))$(SUFF_OBJ))
$(eval mocuiinc := $(PATH_$(target))/moc/$(notdir $(basename $(mocuihdr))).moc)
$$(uisrc): $(mocuiinc)
$$(mocuiinc): $(mocuihdr)
	$(MKDIR) -p $(basename $(mocuiinc))
	$(VBOX_MOC) -i $(mocuihdr) -o $(mocuiinc)

endef

define def_qt_gen_src_ui
$(eval uisrc  := $(PATH_$(target))/ui/$(notdir $(basename $(uifile))).cpp)
$(eval uihdr  := $(PATH_$(target))/ui/$(notdir $(basename $(uifile))).h)
$(eval mocsrc := $(PATH_$(target))/moc/moc_$(notdir $(basename $(uifile))).cpp)

$$(uihdr): $(uifile) | $(call DIRDEP,$(dir $(uihdr)))
	$(VBOX_UIC) $(uifile) -o $(uihdr)

$$(uisrc): $(uihdr) $(uifile) $(wildcard $(uifile).h) | $(call DIRDEP,$(dir $(uisrc)))
	$(VBOX_UIC) $(uifile) -i $(uihdr) -o $(uisrc)

$$(mocsrc): $(uihdr) | $(call DIRDEP,$(dir $(mocsrc)))
	$(VBOX_MOC) $(uihdr) -o $(mocsrc)

endef

## Generate rules for generating the Qt source for a target.
# @param   $target  Target name.
define def_qt_gen_src
# moc srcs from hdrs with Q_OBJECT
$(foreach mochdr,$($(target)_QT_MOCHDRS),$(eval $(def_qt_gen_src_moc)))
# moc includes from srcs with Q_OBJECT
$(foreach mocsrc,$($(target)_QT_MOCSRCS),$(eval $(def_qt_gen_inc_moc)))
# moc includes from UI headers with Q_OBJECT
$(foreach mocuihdr,$($(target)_QT_MOCUIHDRS),$(eval $(def_qt_gen_inc_mocuihdr)))
# ui
$(foreach uifile,$($(target)_QT_UISRCS)  ,$(eval $(def_qt_gen_src_ui)))
# dirs
$(call DIRDEP,$(PATH_$(target))/ui/) $(call DIRDEP,$(PATH_$(target))/moc/):
	$(MKDIR) -p $$@

endef

# Generate Qt sources.
$(foreach target,VBoxDbg,$(eval $(def_qt_gen_src)))


$(call DIRDEP,$(PATH_VBoxDbg)/include/):
	$(MKDIR) -p $@


#
# Translation stuff
#

VBoxDbg_TRANSLATIONS = \
	nls/VBoxDbg_de.ts

updatenls:
	$(VBOX_LUPDATE) $(VBoxDbg_SOURCES) $(VBoxDbg_QT_MOCHDRS) $(VBoxDbg_GENHDRS) -ts $(VBoxDbg_TRANSLATIONS)


#
# Hand made dependencies go here
#
$(PATH_VBoxDbg)/gen/ui/VBoxNewVMWzd$(SUFF_OBJ):        $(PATH_VBoxDbg)/ui/VBoxNewVMWzd.h $(PATH_VBoxDbg)/ui/VBoxDiskImageMgrDlg.h
$(PATH_VBoxDbg)/gen/ui/VBoxDiskImageMgrDlg$(SUFF_OBJ): ui/VBoxDiskImageMgrDlg.ui $(PATH_VBoxDbg)/ui/VBoxNewHDWzd.h
$(PATH_VBoxDbg)/gen/ui/VBoxCloseVMDlg$(SUFF_OBJ):      $(PATH_VBoxDbg)/ui/VBoxCloseVMDlg.h


test:
	echo $(VBoxDbg_GENSRCS) | sed -e "s/ /\n/g"

testwrappers: $(WRAPPERSFILE)

