# 
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# 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 the Initial Developer are Copyright (C) 1999
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#   Christopher Blizzard <blizzard@mozilla.org>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

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

include $(DEPTH)/config/autoconf.mk

MODULE		= gtkembedmoz
LIBRARY_NAME	= gtkembedmoz
MOZILLA_INTERNAL_API = 1

REQUIRES	= xpcom \
		  string \
		  docshell \
		  necko \
		  widget \
		  dom \
		  gfx \
		  layout \
		  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 \
		$(NULL)

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

include $(topsrcdir)/config/config.mk

# Save the "real" FINAL_LINK_COMP* before we override them
FAT_FINAL_LINK_COMPS := $(FINAL_LINK_COMPS)
FAT_FINAL_LINK_COMP_NAMES := $(FINAL_LINK_COMP_NAMES)

ifdef BUILD_STATIC_LIBS
include $(topsrcdir)/config/static-config.mk
DEFINES += $(STATIC_DEFINES)
CPPSRCS += $(STATIC_CPPSRCS)
EXTRA_DSO_LDOPTS += $(STATIC_EXTRA_LIBS)
EXTRA_DEPS	+= \
	$(STATIC_EXTRA_DEPS) \
	$(NULL)
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) \
		-lgtksuperwin \
		$(NULL)
endif

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

EXTRA_DSO_LDOPTS += $(MOZ_GTK_LDFLAGS) $(MOZ_GTK2_LIBS)

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
FINAL_LINK_LIBS=$(topsrcdir)/embedding/config/minimo-unix-libs
else
EMBED_MANIFEST=$(topsrcdir)/embedding/config/basebrowser-unix
endif

ifndef MOZ_FAT_EMBED
FINAL_LINK_COMPS=embed-link-comps
FINAL_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: $(FAT_FINAL_LINK_COMPS) $(FAT_FINAL_LINK_COMP_NAMES)
	paste $(FAT_FINAL_LINK_COMPS) $(FAT_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 > $@


GARBAGE += embed-link-comp-names embed-link-comps components
endif

include $(topsrcdir)/config/rules.mk
include $(topsrcdir)/config/static-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)
DEFINES         += -D_IMPL_GTKMOZEMBED



