# 
# The contents of this file are subject to the Mozilla 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/MPL/
# 
# 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 the Mozilla browser.
# 
# The Initial Developer of the Original Code is Christopher
# Blizzard. Portions created by Christopher Blizzard are
# Copyright (C) 1999, Mozilla.  All Rights Reserved.
# 
# Contributor(s):
#   Christopher Blizzard <blizzard@mozilla.org>

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

include $(DEPTH)/config/autoconf.mk

MODULE		= gtkembedmoz
LIBRARY_NAME	= gtkembedmoz
REQUIRES	= xpcom \
		  string \
		  docshell \
		  webshell \
		  necko \
		  widget \
		  dom \
		  js \
		  gfx \
		  layout \
		  content \
		  uriloader \
		  webbrwsr \
		  shistory \
		  embed_base \
		  pref \
		  windowwatcher \
		  profdirserviceprovider \
		  $(NULL)

ifdef ACCESSIBILITY
REQUIRES        += accessibility
endif

CPPSRCS		= \
		gtkmozembed2.cpp \
		EmbedPrivate.cpp \
		EmbedWindow.cpp \
		EmbedProgress.cpp \
		EmbedContentListener.cpp \
		EmbedEventListener.cpp \
		EmbedWindowCreator.cpp \
		EmbedStream.cpp

ifdef MOZ_ENABLE_GTK2
CSRCS           = \
		gtkmozembedmarshal.c
CPPSRCS         += \
		EmbedPrompter.cpp \
		GtkPromptService.cpp
endif

# Include config.mk early for any overrides of BUILD_STATIC_LIBS
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

ifdef BUILD_STATIC_LIBS
# Static build stuff
DEFINES         += -D_BUILD_STATIC_BIN=1
CPPSRCS		+= EmbedComponents.cpp

XP_LIBS		+= \
		$(PNG_LIBS) \
		$(JPEG_LIBS) \
		$(ZLIB_LIBS) \
		$(MOZ_GDK_PIXBUF_LIBS) \
		$(MOZ_XIE_LIBS) \
		$(MOZ_XPRINT_LDFLAGS) \
		$(NULL)

ifdef MOZ_PSM
XP_LIBS		+= \
		$(NSS_LIBS) \
		$(NULL)
endif

endif

SHARED_LIBRARY_LIBS= \
		$(DIST)/lib/libembed_base_s.$(LIB_SUFFIX) \
		$(DIST)/lib/libprofdirserviceprovider_s.$(LIB_SUFFIX) \
		$(NULL)

EXPORTS		= \
		gtkmozembed.h \
		gtkmozembed_internal.h

ifdef MOZ_ENABLE_GTK
EXTRA_DSO_LDOPTS = \
		$(MOZ_COMPONENT_LIBS) \
		$(XPCOM_GLUE_LIBS) \
		-lgtksuperwin \
		$(NULL)
endif

ifdef MOZ_ENABLE_GTK2
EXTRA_DSO_LDOPTS = \
		$(MOZ_COMPONENT_LIBS) \
		$(NULL)
endif

EXTRA_DSO_LDOPTS += $(MOZ_GTK_LDFLAGS) $(MOZ_GTK2_LIBS)

include $(topsrcdir)/config/rules.mk

ifeq ($(OS_ARCH), SunOS)
ifndef GNU_CC
# When using Sun's WorkShop compiler, including
# /wherever/workshop-5.0/SC5.0/include/CC/std/time.h
# causes most of these compiles to fail with:
# line 29: Error: Multiple declaration for std::tm.
# So, this gets around the problem.
DEFINES         += -D_TIME_H=1
endif
endif

CXXFLAGS        += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS)
CFLAGS          += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS)

ifdef BUILD_STATIC_LIBS

# This is so sick! We'll work backwards from the embedding manifest to
# produce the set of components that we need to link in to a
# ``minimal'' embedding harness.
ifdef MINIMO
EMBED_MANIFEST=$(topsrcdir)/embedding/config/minimo-unix
else
EMBED_MANIFEST=$(topsrcdir)/embedding/config/basebrowser-unix
endif

ifdef MOZ_FAT_EMBED
EMBED_LINK_COMPS=$(FINAL_LINK_COMPS)
EMBED_LINK_COMP_NAMES=$(FINAL_LINK_COMP_NAMES)
else
EMBED_LINK_COMPS=embed-link-comps
EMBED_LINK_COMP_NAMES=embed-link-comp-names
endif

# Create a map that we can use to go from library name to component
# symbol. N.B. that this will break if the $(FINAL_LINK_COMP_NAMES)
# and $(FINAL_LINK_COMPS) somehow get out-of-sync and aren't in
# _exactly_ the same order. (Hey, this is a hack!)
components: $(FINAL_LINK_COMPS) $(FINAL_LINK_COMP_NAMES)
	paste $(FINAL_LINK_COMPS) $(FINAL_LINK_COMP_NAMES) | sort -k 1,1 > $@

# Compute the embedding libs by extracting them from the embedding
# manifest.
#
# We start by selecting anything that starts with `components/', as
# these are the component libraries. We print the `first' field to
# strip off any crap after the library name. Next, we select for files
# ending with `.so' so we end up with only the libraries. We then rip
# off the `components/lib' prefix and the `.so' suffix, leaving just
# the library name. This list is sorted, and joined with the list of
# components that were actually _built_ to cull out anything that's
# included in the manifest, but wasn't built.
embed-link-comps: $(EMBED_MANIFEST) components
	grep '^components/' $< | \
		awk '{ print $$1; }' | \
		grep '\.so$$' | \
		sed -e 's.^components/lib..' -e 's/\.so//' | \
		sort | \
		join -o 1.1 - components > $@

# Compute the symbols we'll need for the ``minimal embedding client''
# by joining the compoent list with the sorted list of embedding
# components.
embed-link-comp-names: embed-link-comps components
	sort embed-link-comps | join -o 2.2 - components > $@

EmbedComponents.cpp: EmbedComponents.cpp.in Makefile Makefile.in $(EMBED_LINK_COMP_NAMES)
	cat $< | \
	sed -e "s|%DECL_NSGETMODULES%|$(foreach m,$(shell cat $(EMBED_LINK_COMP_NAMES)),DECL_NSGETMODULE($(m)))|" | \
	sed -e "s|%MODULE_LIST%|$(foreach m, $(shell cat $(EMBED_LINK_COMP_NAMES)),MODULE($(m)),)|" \
	> $@

GARBAGE += EmbedComponents.cpp embed-link-comp-names embed-link-comps components
endif


