#
# 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

include $(topsrcdir)/config/config.mk

MODULE		= apprunner
REQUIRES	= xpcom \
		  xpconnect \
		  string \
		  webbrwsr \
		  widget \
		  dom \
		  necko \
		  pref \
		  appshell \
		  gfx \
		  chrome \
		  xpinstall \
		  uriloader \
		  view \
		  windowwatcher \
		  embed_base \
		  embedcomponents \
		  mpfilelocprovider \
		  browser \
		  docshell \
		  uconv \
		  locale \
		  xremoteservice \
		  profile \
		  $(NULL)
# for jprof
REQUIRES	+= jprof
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
REQUIRES	+= \
		  intl \
		  profile \
		  $(NULL)
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
REQUIRES	+= intl profile appcomps
endif

ifeq ($(USE_SHORT_LIBNAME),1)
PROGRAM		= mozilla$(BIN_SUFFIX)
else
PROGRAM		= mozilla-bin$(BIN_SUFFIX)
endif

# [ghzil] novo ime
PROGRAM		= ghostzilla.exe

CPPSRCS		= \
		nsAppRunner.cpp \
		nsWindowCreator.cpp \
		showOSAlert.cpp \
		$(NULL)

ifneq ($(OS_ARCH),WINNT)
CPPSRCS		+= nsSigHandlers.cpp
endif

XP_LIBS		= \
		$(EXTRA_DSO_LDOPTS) \
		$(EXTRA_DSO_LIBS) \
		$(DIST)/lib/ghostzilla.lib \
		$(NULL)

ifndef BUILD_STATIC_LIBS

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

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

EXTRA_DEPS	+= \
	$(STATIC_EXTRA_DEPS) \
	$(NULL)
DEFINES		+= $(STATIC_DEFINES)
CPPSRCS		+= $(STATIC_CPPSRCS)
EXTRA_DSO_LDOPTS+= -L$(DEPTH)/dist/lib/components
EXTRA_DSO_LIBS	+= $(STATIC_EXTRA_DSO_LIBS)
REQUIRES	+= $(STATIC_REQUIRES)
XP_LIBS		+= $(STATIC_EXTRA_LIBS)

endif

XP_LIBS		+= \
		$(MOZ_JS_LIBS) \
		$(XPCOM_LIBS) \
		$(NSPR_LIBS) \
		$(NULL)

ifdef NS_TRACE_MALLOC
DEFINES		+= -DNS_TRACE_MALLOC
endif

ifdef MOZ_JPROF
XP_LIBS         += -ljprof
endif

LIBS		= $(XP_LIBS)

ifdef GC_LEAK_DETECTOR
LIBS += -lboehm
endif

ifeq ($(MOZ_WIDGET_TOOLKIT),beos)
BEOS_PROGRAM_RESOURCE = $(srcdir)/apprunner-beos.rsrc
CPPSRCS += nsNativeAppSupportBeOS.cpp
CPPSRCS += nsNativeAppSupportBase.cpp
endif

ifeq ($(MOZ_WIDGET_TOOLKIT),photon)
CPPSRCS += nsNativeAppSupportPh.cpp
LIBS += -lphexlib -lph
endif

ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
CPPSRCS += nsNativeAppSupportOS2.cpp
CPPSRCS += nsNativeAppSupportBase.cpp
RESFILE = splashos2.res
endif

ifeq ($(MOZ_WIDGET_TOOLKIT),gtk)
SPLASH_XPM = $(srcdir)/splash.xpm
CPPSRCS += nsNativeAppSupportGtk.cpp \
	   nsNativeAppSupportBase.cpp
DEFINES += -DSPLASH_XPM=\"$(SPLASH_XPM)\"
LIBS += $(MOZ_GTK_LDFLAGS)
endif

ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
RCINCLUDE = splash.rc
DEFINES	+= -DWIN32_LEAN_AND_MEAN
CPPSRCS += nsNativeAppSupportWin.cpp nsNativeAppSupportBase.cpp
OS_LIBS += comctl32.lib comdlg32.lib uuid.lib shell32.lib ole32.lib oleaut32.lib version.lib winspool.lib
endif

ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
CMMSRCS += nsNativeAppSupportForCocoa.mm
LDFLAGS += \
        -framework Cocoa \
        $(NULL)
endif

ifeq ($(OS_ARCH),OS2)
ifdef BUILD_STATIC_LIBS
EXE_DEF_FILE = mozilla.def
endif
endif

include $(topsrcdir)/config/rules.mk

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

ifeq ($(MOZ_WIDGET_TOOLKIT),gtk)
$(PROGRAM): $(SPLASH_XPM)
endif

ifeq ($(OS_ARCH),Darwin)
EXTRA_DSO_LDOPTS := $(subst -dynamiclib,-execute,$(EXTRA_DSO_LDOPTS))

ifdef BUILD_STATIC_LIBS
LDFLAGS	+= -framework QuickTime
endif

endif

# This code removes the console from release builds
# (unless you've set MOZ_WINCONSOLE=1).
ifndef MOZ_WINCONSOLE
ifdef MOZ_DEBUG
MOZ_WINCONSOLE=1
else
MOZ_WINCONSOLE=0
endif
endif

# Set link flags according to whether we want a console.
ifeq ($(MOZ_WINCONSOLE),1)
ifeq ($(MOZ_OS2_TOOLS),EMX)
BIN_FLAGS	:= -Zlinker /PM:VIO -Zlinker /Stack:0x30000
endif
ifeq ($(OS_ARCH),WINNT)
LDFLAGS		+= /SUBSYSTEM:CONSOLE
endif
else # MOZ_WINCONSOLE
ifeq ($(MOZ_OS2_TOOLS),VACPP)
LDFLAGS += /PM:PM
endif
ifeq ($(MOZ_OS2_TOOLS),EMX)
BIN_FLAGS	:= -Zlinker /PM:PM -Zlinker /Stack:0x30000
endif
ifeq ($(OS_ARCH),WINNT)
LDFLAGS		+= /SUBSYSTEM:WINDOWS
endif
endif

ifeq ($(OS_ARCH),WINNT)
#
# Control the default heap size.
# This is the heap returned by GetProcessHeap().
# As we use the CRT heap, the default size is too large and wastes VM.
#
# The default heap size is 1MB on Win32.
# The heap will grow if need be.
#
# Set it to 256k.  See bug 127069.
#
LDFLAGS += /HEAP:0x40000
endif

CXXFLAGS	+= $(MOZ_TOOLKIT_REGISTRY_CFLAGS)

LOCAL_INCLUDES	= -I$(srcdir)

ifneq (,$(filter-out OS2 WINNT,$(OS_ARCH)))
mozilla.1: mozilla.man.in Makefile.in Makefile $(DEPTH)/config/autoconf.mk
	@sed -e "s|\@bindir\@|${bindir}|" -e "s|\@libdir\@|${libdir}|" \
		-e "s|\@mozilla_version\@|${MOZILLA_VERSION}|" < $< > $@

libs:: mozilla.1
	$(INSTALL) $< $(DIST)/man/man1

install:: mozilla.1
	$(SYSINSTALL) $(IFLAGS) $< $(DESTDIR)$(mandir)/man1

mozilla:: mozilla.in Makefile.in Makefile $(DEPTH)/config/autoconf.mk
	cat $< | sed -e "s|%MOZAPPDIR%|$(mozappdir)|" \
		-e "s|%MREDIR%|$(mredir)|" > $@
	chmod +x $@

libs:: mozilla
	$(INSTALL) $< $(DIST)/bin

install:: mozilla
	$(SYSINSTALL) $< $(DESTDIR)$(bindir)

GARBAGE += mozilla.1 mozilla

endif

ifeq ($(MOZ_WIDGET_TOOLKIT),photon)
libs:: $(srcdir)/splash.bmp
	$(INSTALL) $< $(DIST)/bin
endif

ifeq ($(OS_ARCH),OS2)
ifdef BUILD_STATIC_LIBS
$(EXE_DEF_FILE):
	rm -f $@
	@echo NAME mozilla >$(EXE_DEF_FILE)
	@echo IMPORTS >>$(EXE_DEF_FILE)
	@echo 	WinQueryProperty		= PMMERGE.5450 >>$(EXE_DEF_FILE)
	@echo 	WinRemoveProperty		= PMMERGE.5451 >>$(EXE_DEF_FILE)
	@echo 	WinSetProperty			= PMMERGE.5452 >>$(EXE_DEF_FILE)
	@echo  	DaxOpenSave					= PMCTLS.295   >>$(EXE_DEF_FILE)
endif
endif

ifeq ($(MOZ_REORDER),1)

LDSCRIPT = ldscript
LDFLAGS += -Wl,-T,$(LDSCRIPT)
GARBAGE += $(LDSCRIPT)
ORDERFILE = $(srcdir)/mozilla-bin.order

$(PROGRAM) : $(LDSCRIPT) $(ORDERFILE)

$(LDSCRIPT): $(ORDERFILE)
	$(PERL) $(topsrcdir)/config/mklinkscript.pl -o $@ $<

endif

ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))

ifdef MOZ_DEBUG
APP_NAME = MozillaDebug
else
APP_NAME = Mozilla
endif

libs:: $(PROGRAM)
	rm -rf $(DIST)/$(APP_NAME).app
	mkdir $(DIST)/$(APP_NAME).app
	cp -R $(srcdir)/macbuild/Contents $(DIST)/$(APP_NAME).app
	cp -RL $(DIST)/bin $(DIST)/$(APP_NAME).app/Contents/MacOS
	cp -RL $(srcdir)/macbuild/mach.icns $(DIST)/$(APP_NAME).app/Contents/Resources/mach.icns
	echo APPLMOZZ > $(DIST)/$(APP_NAME).app/Contents/PkgInfo
endif

echo_objs:
	@echo $(OBJS)
