#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation.  Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): 
#

DEPTH			= ../../..
topsrcdir		= ../../..
srcdir			= .
VPATH			= .

include $(DEPTH)/config/autoconf.mk

DIRS			:= public

MODULE			= webshell_tests
REQUIRES	= xpcom \
		  string \
		  embed_base \
		  webshell \
		  widget \
		  gfx \
		  layout \
		  content \
		  dom \
		  webbrwsr \
		  docshell \
		  util \
		  uriloader \
		  locale \
		  necko \
		  htmlparser \
		  view \
		  pref \
		  intl \
		  unicharutil \
		  editor \
		  windowwatcher \
		  xpconnect \
		  js \
		  $(NULL)

PROGRAM			:= viewer$(BIN_SUFFIX)

CPPSRCS			= \
			$(TOOLKIT_CPPSRCS) \
			nsBaseDialog.cpp \
			nsFindDialog.cpp \
			nsXPBaseWindow.cpp \
			nsTableInspectorDialog.cpp \
			nsImageInspectorDialog.cpp \
			nsPrintSetupDialog.cpp \
			nsBrowserWindow.cpp \
			nsEditorMode.cpp \
			nsThrobber.cpp \
			nsViewerApp.cpp \
			nsWebCrawler.cpp \
			nsWebBrowserChrome.cpp \
			nsWindowCreator.cpp \
			$(NULL)

ifeq (,$(filter beos os2 photon mac cocoa windows,$(MOZ_WIDGET_TOOLKIT)))
DIRS			+= unix
VIEWER_TK_LIBS	= unix/$(MOZ_WIDGET_TOOLKIT)/libviewer_$(MOZ_WIDGET_TOOLKIT)_s.a
else
ifeq ($(MOZ_WIDGET_TOOLKIT),beos)
BEOS_PROGRAM_RESOURCE	= $(srcdir)/viewer-beos.rsrc
TOOLKIT_CPPSRCS		= nsBeOSMain.cpp
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
TOOLKIT_CPPSRCS		= nsOS2Main.cpp nsWidgetSupport.cpp
DIRS           += os2
VIEWER_TK_LIBS		= os2/$(LIB_PREFIX)viewer_os2_s.$(LIB_SUFFIX)
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),photon)
TOOLKIT_CPPSRCS		= nsPhMain.cpp nsPhMenu.cpp
endif
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
TOOLKIT_CPPSRCS		= nsMacMain.cpp
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
TOOLKIT_CPPSRCS		= nsWinMain.cpp JSConsole.cpp nsWidgetSupport.cpp 
DIRS			+= windows
VIEWER_TK_LIBS		= windows/$(LIB_PREFIX)viewer_windows_s.$(LIB_SUFFIX)
endif # windows
endif # unix

ifeq ($(MOZ_WIDGET_TOOLKIT),gtk)
GTK_GLUE		= -lgtksuperwin
endif

ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
TK_LIBS += -framework Cocoa
endif

EXTRA_DSO_LIBS	= gkgfx

ifdef NS_TRACE_MALLOC
EXTRA_DSO_LIBS	+= tracemalloc
endif

ifeq ($(OS_ARCH),WINNT)
RESFILE		= viewer.res
EXTRA_DSO_LIBS	+= xpwidgets_s dbgrobot widget_windows
# Get rid of console window
ifdef GNU_CC
LDFLAGS		+= -mwindows
endif
endif

ifeq ($(OS_ARCH),OS2)
RESFILE		= vieweros2.res
DEFINES       += -DUSE_LOCAL_WIDGETS 
XP_DIST_LIBS  += $(DIST)/lib/components/wdgtos2.lib
endif

ifdef MOZ_OJI
ifeq ($(OS_ARCH),WINNT)
EXTRA_DSO_LIBS	+= jsj$(MOZ_BITS)$(VERSION_NUMBER)
else
EXTRA_DSO_LIBS	+= jsj
endif
endif
ifdef MOZ_PERF_METRICS
EXTRA_DSO_LIBS		+= mozutil_s
endif

XP_LIBS			= \
			$(MOZ_WIDGET_SUPPORT_LIBS) \
			$(EXTRA_DSO_LIBS) \
			$(XP_DIST_LIBS) \
			$(MOZ_JS_LIBS) \
			$(MOZ_UNICHARUTIL_LIBS) \
			$(XPCOM_LIBS) \
			$(NSPR_LIBS) \
			$(NULL)

LIBS			= \
			$(VIEWER_TK_LIBS) \
			$(GTK_GLUE) \
			$(XP_LIBS) \
			$(PROFILER_LIBS) \
			$(NULL)

EXTRA_LIBS		= $(TK_LIBS)

XLIB_LIBS		= unix/xlib/libviewer_xlib_s.a $(XP_LIBS) $(MOZ_XLIB_LDFLAGS)
GTK_LIBS		= unix/gtk/libviewer_gtk_s.a -lgtksuperwin $(XP_LIBS) $(MOZ_GTK_LDFLAGS)

XP_DIST_DEP_LIBS	:= $(filter-out -L$(DIST)/bin -L$(DIST)/lib, $(XP_DIST_LIBS))
XP_DIST_DEP_LIBS	:= $(wildcard $(addprefix $(DIST)/,$(patsubst -l%,bin/$(LIB_PREFIX)%$(DLL_SUFFIX),$(XP_DIST_DEP_LIBS:-l%_s=lib/lib%_s)))*)

EXTRA_DEPS		= \
			$(XP_DIST_DEP_LIBS) \
			$(VIEWER_TK_LIBS) \
			$(MOZ_WIDGET_SUPPORT_LIBS) \
			$(NULL)

include $(topsrcdir)/config/config.mk

# Force applications to be built non-statically
# when building the mozcomps meta component
ifneq (,$(filter mozcomps,$(MOZ_META_COMPONENTS)))
BUILD_STATIC_LIBS=
BUILD_SHARED_LIBS=1
endif

# Force a build thru DIRS so that dependencies are updated properly
libs::
	+$(LOOP_OVER_DIRS)

# Force applications to be built non-statically
# when building the mozcomps meta component
ifneq (,$(filter mozcomps,$(MOZ_META_COMPONENTS)))
BUILD_STATIC_LIBS=
BUILD_SHARED_LIBS=1
endif

ifdef BUILD_STATIC_LIBS

include $(topsrcdir)/config/static-config.mk

EXTRA_DEPS     += $(STATIC_EXTRA_DEPS)
ifneq ($(OS_ARCH),WINNT)
LDFLAGS        += -L$(DEPTH)/dist/lib/components
endif # !WINNT
EXTRA_DSO_LIBS += $(STATIC_EXTRA_DSO_LIBS)
XP_DIST_LIBS   += $(STATIC_EXTRA_LIBS)
DEFINES        += $(STATIC_DEFINES)
CPPSRCS        += $(STATIC_CPPSRCS)

endif # BUILD_STATIC_LIBS


include $(topsrcdir)/config/rules.mk


ifdef BUILD_STATIC_LIBS
include $(topsrcdir)/config/static-rules.mk
endif # BUILD_STATIC_LIBS


ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
LOCAL_INCLUDES		+= -I$(topsrcdir)/widget/src/mac
ifdef BUILD_STATIC_LIBS
EXTRA_LIBS		+= -framework QuickTime -framework IOKit
endif
endif

CXXFLAGS		+= $(MOZ_TOOLKIT_REGISTRY_CFLAGS)

ifeq ($(OS_ARCH),WINNT)
DEFINES		+= -DUSE_LOCAL_WIDGETS
endif

GARBAGE			+= $(PROGRAM)_gtk $(PROGRAM)_xlib

ifeq ($(OS_ARCH),WINNT)
OS_LIBS		+= $(call EXPAND_LIBNAME, shell32 ole32 oleaut32 imm32 uuid comdlg32)
ifdef GNU_CC
OS_LIBS		+= -lgdi32
else
OS_LIBS		+= oleacc.lib
LDFLAGS		+= -SUBSYSTEM:CONSOLE
endif
ifdef MOZ_NO_DEBUG_RTL
CXXFLAGS	+= -DMOZ_NO_DEBUG_RTL
endif
ifdef NGPREFS
CXXFLAGS	+= -DNGPREFS
endif
endif

libs:: $(PROGRAM) $(srcdir)/mozilla-viewer.sh
ifeq (,$(filter WINNT OS2,$(OS_ARCH)))
	$(INSTALL) $(srcdir)/mozilla-viewer.sh $(DIST)/bin
endif

unix/gtk/libviewer_gtk_s.a:
	@$(MAKE) -C $(@D) $(@F)

unix/xlib/libviewer_xlib_s.a:
	@$(MAKE) -C $(@D) $(@F)

$(PROGRAM)_gtk: $(PROGOBJS) $(EXTRA_DEPS) Makefile Makefile.in unix/gtk/libviewer_gtk_s.a
	$(CCC) $(CXXFLAGS) -o $@ $(PROGOBJS) $(LDFLAGS) $(LIBS_DIR) $(GTK_LIBS) $(OS_LIBS) $(PROFILER_LIBS)
ifdef ENABLE_STRIP
	$(STRIP) $@
endif

$(PROGRAM)_xlib: $(PROGOBJS) $(EXTRA_DEPS) Makefile Makefile.in unix/xlib/libviewer_xlib_s.a
	$(CCC) $(CXXFLAGS) -o $@ $(PROGOBJS) $(LDFLAGS) $(LIBS_DIR) $(XLIB_LIBS) $(OS_LIBS) $(PROFILER_LIBS)
ifdef ENABLE_STRIP
	$(STRIP) $@
endif

ifdef MOZ_ENABLE_GTK
libs:: $(PROGRAM)_gtk
	$(INSTALL) -m 555 $< $(DIST)/bin
endif

ifdef MOZ_ENABLE_XLIB
libs:: $(PROGRAM)_xlib
	$(INSTALL) -m 555 $< $(DIST)/bin
endif

