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

DEPTH		= ../..

MODULE		= moz

REQUIRES	= \
	addr \
	applet \
	img \
	edtplug \
	jtools \
	lay \
	layer \
	js \
	libfont \
	mariner \
	msg \
	java \
	plds \
    nsprpub \
	parse \
    plug \
	plugimpl \
	hook \
	pref \
	rdf \
	security \
	softupdt \
	libreg \
	style \
	util \
	$(NULL)

CSRCS = \
	main.c \
	stubctxt.c \
	stubdlgs.c \
	stubedit.c \
	stubenc.c \
	stubform.c \
	stubgrid.c \
	stubhelp.c \
	stubimg.c \
	stublay.c \
	stubloc.c \
	stubmail.c \
	stubmisc.c \
	stubplug.c \
	stubps.c \
	stubrdf.c \
	stubrgn.c \
	stubsec.c \
	stubstr.c \
	stubtime.c \
	$(NULL)

######################################################################

include $(DEPTH)/config/config.mk

CCLD		= $(CCC)
LDFLAGS		= $(CFLAGS)
NOMD_LDFLAGS	= $(NOMD_CFLAGS)

OBJS		= $(CSRCS:.c=.o) $(CPPSRCS:.cc=.o)

NSPR_LIB	= $(DIST)/lib/libplds21.a \
	$(DIST)/lib/libplc21.a \
	$(DIST)/lib/libnspr21.a

ifdef DBMALLOC
NSPR_LIB	+= $(DIST)/lib/libdbmalloc.a
endif

CFLAGS		+= -DENABLE_MARINER


#
# We need libnet.a in there twice because libmsg and libnet have circular
# dependencies on functions.
#
BASIC_LIBS	= \
		  $(XFE2_LIB) \
		  $(MICROLINE_LIB) \
		  $(ICONS_LIB) \
		  $(DTWIDGETS_LIB) \
		  $(XFE_WIDGETS_BM_LIB) \
		  $(XFE_WIDGETS_LIB) \
		  $(DIST)/lib/libnetcnvts.a	\
		  $(DIST)/lib/libnetwork.a	\
		  $(DIST)/lib/libnetcache.a	\
		  $(DIST)/lib/libnetutil.a      \
		  $(DIST)/lib/libcnetinit.a	\
		  $(DIST)/lib/libabouturl.a	\
		  $(DIST)/lib/libdataurl.a	\
		  $(DIST)/lib/libnetcnvts.a	\
		  $(DIST)/lib/libfileurl.a	\
		  $(DIST)/lib/libftpurl.a	\
		  $(DIST)/lib/libgophurl.a	\
		  $(DIST)/lib/libhttpurl.a	\
		  $(DIST)/lib/libjsurl.a	\
		  $(DIST)/lib/libmarimurl.a	\
		  $(DIST)/lib/libremoturl.a	\
		  $(DIST)/lib/libnetwork.a	\
		  $(DIST)/lib/libmimetype.a \
		  $(DIST)/lib/lib$(LITE_PREFIX)rdf.a \
		  $(DIST)/lib/lib$(LITE_PREFIX)xml.a \
		  $(DIST)/lib/lib$(LITE_PREFIX)lay.a \
		  $(DIST)/lib/libxlate.a \
		  $(DIST)/lib/libpng.a \
		  $(DIST)/lib/libmariner.a \
		  $(DIST)/lib/libimg.a \
		  $(DIST)/lib/libprivacy.a \
		  $(NULL)

ifdef MOZ_LOC_INDEP
BASIC_LIBS	+= $(DIST)/lib/libli.a
endif

ifdef JAVA_OR_NSJVM
JAVA_JMC = $(DIST)/lib/libjmc.a      # XXX To be removed...
endif

BASIC_LIBS	+= \
		  $(DIST)/lib/libpng.a \
		  $(JAVA_JMC) \
		  $(DIST)/lib/libjpeg.a \
		  $(DIST)/lib/libhook.a \
		  $(DIST)/lib/libparse.a \
		  $(DIST)/lib/lib$(LITE_PREFIX)pref.a \
		  $(DIST)/lib/lib$(LITE_PREFIX)i18n.a \
		  $(DIST)/lib/libpics.a \
		  $(DIST)/lib/libpwcac.a \
		  $(DIST)/lib/libreg.a \
		  $(NULL)

BASIC_LIBS_2	= \
		  $(DIST)/lib/lib$(LITE_PREFIX)xp.a \
		  $(DIST)/lib/libdbm.a \
		  $(DIST)/lib/libcaps.a \
		  $(DIST)/lib/libxpcom.a \
		  $(DIST)/lib/lib$(LITE_PREFIX)rdf.a \
		  $(NULL)


# jwz: link in libmime all the time.
# but it needs to be before libnetutil, and I don't know how to do that,
# so just link against libnetutil twice.

BASIC_LIBS	+= \
		  $(DIST)/lib/libmime.a		\
		  $(DIST)/lib/libnetutil.a      \
		  $(NULL)


ifdef MOZ_MAIL_NEWS
ifdef MOZ_SECURITY
BASIC_LIBS	+= \
		  $(DIST)/lib/libns_mime.a \
		  $(NULL)
endif
BASIC_LIBS_2	+= \
		  $(DIST)/lib/libldap.a \
		  $(NULL)

endif

BASIC_LIBS	+= \
		  $(DIST)/lib/libmisc.a \
		  $(DIST)/lib/libprgrss.a \
		  $(NULL)

ifdef MOZ_LDAP
BASIC_LIBS	+= \
		$(DIST)/lib/libldap.a \
		$(DIST)/lib/liblber.a \
		$(NULL)
endif

ifdef MOZ_MAIL_NEWS
BASIC_LIBS	+= \
		  $(DIST)/lib/libmozmsg.a \
		  $(NULL)
ifdef MOZ_SECURITY
BASIC_LIBS	+= $(DIST)/lib/libmsg.a \
		$(NULL)
endif
BASIC_LIBS	+= $(DIST)/lib/libaddr.a \
		  $(DIST)/lib/libneo.a \
		  $(DIST)/lib/libaddr.a \
		  $(NULL)
endif

ifdef MOZ_MAIL_NEWS
BASIC_LIBS	+= $(DIST)/lib/libnntpurl.a \
		  $(DIST)/lib/libsmtpurl.a	\
		  $(DIST)/lib/libimap4url.a	\
		  $(DIST)/lib/libpop3url.a	\
		  $(DIST)/lib/libmailbxurl.a	\
		  $(DIST)/lib/libcrtldurl.a	\
		  $(NULL)
endif

ifdef MOZ_MAIL_NEWS
ifdef MOZ_LDAP
BASIC_LIBS	+= $(DIST)/lib/libldapurl.a \
		  $(NULL)
endif
endif

ifdef MOZ_CALENDAR
BASIC_LIBS	+= \
		  $(DIST)/lib/libjulian.a \
		  $(DIST)/lib/libnscnv30.a \
		  $(DIST)/lib/libnsuni30.a \
		  $(DIST)/lib/libnsfmt30.a \
		  $(NULL)
endif

BASIC_LIBS	+= \
		  $(DIST)/lib/lib$(LITE_PREFIX)plug.a \
		  $(DIST)/lib/libutil.a \
		  $(DIST)/lib/libfont.a \
		  $(NULL)

ifndef NO_LAYERS
BASIC_LIBS	+= $(DIST)/lib/liblayer.a
endif

########################################################################
# Java
#

ifdef MOZ_JAVA
#
# Monolithic Java
#

BASIC_LIBS	+= \
		  $(DIST)/lib/lib$(LITE_PREFIX)applet.a \
		  $(DIST)/lib/libjrt.a \
		  $(DIST)/lib/libjmd.a \
		  $(NULL)

ifdef EDITOR
BASIC_LIBS	+= $(DIST)/lib/libedtplug.a
endif

BASIC_LIBS	+= \
		  $(DIST)/lib/libnsn.a \
		  $(DIST)/lib/libnsc.a \
		  $(DIST)/lib/libjpw.a \
		  $(DIST)/lib/libzpw.a \
		  $(DIST)/lib/libiawt.a \
		  $(DIST)/lib/libmmedia.a \
		  $(DIST)/lib/libsoftupdate.a \
		  $(DIST)/lib/libprgrss.a \
		  $(DIST)/lib/libcon.a \
		  $(DIST)/lib/libjbn.a \
		  $(NULL)

ifdef MOZ_SECURITY
BASIC_LIBS	+= $(DIST)/lib/libjsl.a
endif

ifdef MOZ_MAIL_NEWS
BASIC_LIBS	+= $(DIST)/lib/libjsl.a
endif

BASIC_LIBS	+= $(DIST)/lib/libjrt.a

else # !MOZ_JAVA

#
# OJI
#

ifdef MOZ_OJI

BASIC_LIBS      += $(DIST)/lib/liboji.a

ifdef NSJVM

ifdef EDITOR
BASIC_LIBS	+= $(DIST)/lib/libedtplug.a
endif
BASIC_LIBS      += $(DIST)/lib/libsoftupdate.a
else # !NSJVM
BASIC_LIBS	+= \
		  $(DIST)/lib/libstubsj.a \
		  $(DIST)/lib/libstubnj.a \
		  $(NULL)
endif # !NSJVM

BASIC_LIBS      += $(DIST)/lib/libprgrss.a \
		   $(NULL)

else  # !MOZ_OJI
# No Monolithic Java, no OJI, just stubs.

BASIC_LIBS	+= \
		  $(DIST)/lib/libstubsj.a \
		  $(DIST)/lib/libstubnj.a \
		  $(NULL)

endif  # !MOZ_OJI
endif  # !MOZ_JAVA

# XXX To a DSO...
BASIC_LIBS	+= $(DIST)/lib/libzlib.a
BASIC_DSOS      += -lzlib

ifndef NO_MOCHA
# XXX To a DSO...
BASIC_LIBS      += $(DIST)/lib/libjs.a $(DIST)/lib/libjsj.a 
BASIC_DSOS      += -ljs -ljsj
BASIC_LIBS	+= $(DIST)/lib/libmocha.a
endif

# Post-Java libs
BASIC_LIBS	+= $(DIST)/lib/libstyle.a $(DIST)/lib/libreg.a


ifdef MOZ_SECURITY
BASIC_LIBS	+= $(DIST)/lib/libjar.a
else
EXPORT_LIB	= $(DIST)/lib/libhtmldlgs.a $(DIST)/lib/libsecfree.a 
endif


PLUGIN_DSO	= $(DIST)/bin/libnullplugin.so
WEBFONT_DSO	= $(DIST)/bin/libTrueDoc.so

ifndef MOZ_LITE
JSD_DSO		= $(DIST)/bin/libjsd.$(DLL_SUFFIX)
endif

TARGETS		+= $(OBJDIR)/stubfe

ALL_TARGETS = $(TARGETS)

#######################################################################

include $(DEPTH)/config/rules.mk

DEFINES		+= -DNEW_DECODERS

#######################################################################
#
# Set defaults for all platforms.  Each OS_ARCH will override this if
# necessary.
#

ifdef BUILD_OFFICIAL
EXTRA_REL_FILES	+= $(DIST)/bin/vreg $(DEPTH)/l10n/us/xp/bookmark.htm
endif

# Only SunOS4 needs two versions NIS and DNS.
NIS_SRC		=
NIS_OBJS	=
NIS_LIB		=
DNS_LIB		=

# Only SunOS4 needs separate YP versions.
NEED_YP_VERSION	= 0

# Only BSDI, Linux, and SunOS4 need the nls directory.
NEED_NLS	= 0

# Only SunOS5 (Solaris) has MCS.
MCS_CMD		= true

# Only IRIX 5.x uses this.
EXTRA_POST_LINK_CMD	= echo

EXPORT_LDFLAGS	= $(BASIC_LIBS) $(EXPORT_LIB) $(BASIC_LIBS_2) $(OTHER_LIBS) $(NSPR_LIB)
EXPORT_DEPLIBS	= $(BASIC_LIBS) $(EXPORT_LIB) $(BASIC_LIBS_2) $(NSPR_LIB)


DSO_EX_LIBS	= $(EXPORT_LDFLAGS:$(DIST)/lib/lib%.a=-l%)

#######################################################################
#
# Adjust build based on OS_ARCH.
#

########################################
# IBM Machines
ifeq ($(OS_ARCH),AIX)
CCLD		= svxlC -+
#LDFLAGS		= -bGhooksyslibs -bGlibpathexec -bGnoproc
LDFLAGS		=  -bGnoproc
OTHER_LIBS	=
US_LDFLAGS	+= $(AIX_NSPR_LINK)
EXPORT_LDFLAGS	+= $(AIX_NSPR_LINK)
FRANCE_LDFLAGS	+= $(AIX_NSPR_LINK)
# Grab the NSPR shared library and the "Patched especially for Netscape" version of libsvld.a
EXTRA_REL_FILES	+= $(AIX_NSPR) \
		   $(DEPTH)/config/AIX4.1_libsvld.a \
		   $(DEPTH)/config/AIX4.1_libc.a \
		   $(DEPTH)/config/AIX4.2_libc.a \
		   $(DEPTH)/config/AIX4.1_run_netscape

ifndef NO_WEBFONTS
EXTRA_REL_FILES += $(WEBFONT_DSO)
endif

endif

########################################
# FreeBSD
ifeq ($(OS_ARCH),FreeBSD)
OTHER_LIBS	= -lm $(OS_LIBS)
endif

########################################
# BSDI
ifeq ($(OS_ARCH),BSD_OS)
OTHER_LIBS	= -lm $(OS_LIBS)

ifeq ($(OS_RELEASE),2.1)
OTHER_LIBS	+= -lipc
endif

NEED_NLS	= 1

endif

########################################
# HP Machines
ifeq ($(OS_ARCH),HP-UX)

ifeq ($(OS_RELEASE),B.10)
INCLUDES	+= -I.
endif

HPUX_RESOURCE_HACK	= -Wp,-H16384

OTHER_LIBS	= -L$(DIST)/lib $(OS_LIBS)

ifdef MOZ_EDITOR
EXPORT_DEPLIBS	+= cxxlink-filter
US_DEPLIBS	+= cxxlink-filter
CCLD		= CC -tl,./cxxlink-filter

ifndef NO_WEBFONTS
EXTRA_REL_FILES	+= $(WEBFONT_DSO)
endif

#
# On HP, enable SHLIB_PATH
#
EXTRA_POST_LINK_CMD	= chatr +s enable

endif

endif

########################################
# SGI Machines
ifeq ($(OS_ARCH),IRIX)

#
# Linker will report that '-lSgm' does not resolve any symbols, but it
# should not be removed. SGI dynamically opens the library depending on
# the setting of some resources (e.g. "useEnhancedFSB")
#
OTHER_LIBS	= -lgen -laudio -lm $(OS_LIBS)

#
# On Irix, tag the executable for use by the Indigo Magic Desktop.
# This magic number comes from /usr/lib/filetype/install/netscape.ftr
# shipped by SGI along with their n.nnS version of Mozilla.
#
ifeq ($(OS_RELEASE),5)
EXTRA_POST_LINK_CMD	= /usr/sbin/tag 67150
endif

#
# If we are using gtscc, we must use it as the linker, and we
# can only build statically (no shared libs).
#
CCLD		= CC
ifdef USE_GTSCC
ifndef NO_GTSCC
CCLD		= $(DIST)/bin/gtscc $(GTSCC_LD_OPTIONS) -gtsfile $(DEPTH)/config/$(OBJDIR)/db.gts -gtsrootdir $(DEPTH)
TARGETS		= $(OBJDIR)/stubfe
endif
endif

ifndef NO_WEBFONTS
EXTRA_REL_FILES += $(WEBFONT_DSO)
endif

endif

########################################
# Linux
ifeq ($(OS_ARCH),Linux)

OTHER_LIBS	= /usr/lib/libm.a -ldl

US_LDFLAGS	+= -lc
EXPORT_LDFLAGS	+= -lc
FRANCE_LDFLAGS	+= -lc

endif

########################################
# NCR SYSV 4.0
ifeq ($(OS_ARCH),NCR)
OTHER_LIBS	= -lgen -lm $(OS_LIBS)
endif

########################################
# NEC SYSV 4.2
ifeq ($(OS_ARCH),NEC)
OTHER_LIBS	= -lresolv -lgen -lm $(OS_LIBS)
endif

########################################
# Dec Machines
ifeq ($(OS_ARCH),OSF1)

# We would like to link OSF1 static.
# This is because of motif problems (BadMatch errors on non-default visual)
# on 3.2 and 3.0 (and not on 2.0).
# and you get warnings and core dump when pasting into Mozilla.
# Also, libXm must be dynamic, otherwise Japanese text widgets hang
# the process.
# What a delightful state of affairs. -- erik

OTHER_LIBS	= -ldnet_stub -lm -lots $(OS_LIBS)

EXPORT_LDFLAGS	= $(BASIC_LIBS) $(EXPORT_LIB) $(BASIC_LIBS_2) $(NSPR_LIB) $(OTHER_LIBS)
FRANCE_LDFLAGS	= $(BASIC_LIBS) $(FRANCE_LIB) $(BASIC_LIBS_2) $(NSPR_LIB) $(OTHER_LIBS)
US_LDFLAGS	= $(BASIC_LIBS) $(US_LIB) $(BASIC_LIBS_2) $(NSPR_LIB) $(OTHER_LIBS)

ifdef MOZ_EDITOR
#
# OSF's cxx link command will link in _dynamic_ version of two C++
# libraries. This is bad, they are not shipped on a base system.
# So, we call this special hacked driver script to do the job.
#
#   NOT TRUE FOR DIGITAL UNIX 4.0 OR GREATER
#CCLD		= ./cxxlink-driver -cxx_platform OSF1 -cxx_command cxx

# Hack to add a dependency for executable.
#EXPORT_DEPLIBS	+= cxxlink-driver
#FRANCE_DEPLIBS	+= cxxlink-driver
#US_DEPLIBS	+= cxxlink-driver

# This will also work, but will probably break easily as more C++
# *features* get used (like static constructors - gasp!)
#CCLD		= cc
#OTHER_LIBS	+= /usr/lib/cmplrs/cxx/libcxx.a /usr/lib/cmplrs/cxx/libexc.a
endif

endif

########################################
# SNI ReliantUNIX (SINIX)
ifeq ($(OS_ARCH),ReliantUNIX)
OTHER_LIBS	= $(OS_LIBS)
endif
ifeq ($(OS_ARCH),SINIX-N)
OTHER_LIBS	= $(OS_LIBS)
endif

########################################
# SCO OpenServer
ifeq ($(OS_ARCH),SCOOS)
OTHER_LIBS	= -lm -lPW $(OS_LIBS)

ifdef NEED_XMOS
LIB_XMOS	= $(OBJDIR)/Xmos.o
endif

endif

########################################
# Sun Machines
ifeq ($(OS_ARCH),SunOS)

ifeq ($(OS_RELEASE),4.1)

OTHER_LIBS	= 

ifndef NO_WEBFONTS
EXTRA_REL_FILES += $(WEBFONT_DSO)
endif

ifdef MOZ_EDITOR
OTHER_LIBS	+= -L/tools/ns/lib

#
# Need this guy because the one in libg++.a is broken.
#
BASIC_LIBS	+= $(OBJDIR)/regex.o
$(OBJDIR)/regex.o:	/lib/libc.a
	ar x /lib/libc.a regex.o && mv regex.o $@
endif
#
# Need our own popen to fix the SunOS popen problem
#
BASIC_LIBS += $(OBJDIR)/popen.o
CSRCS	+= popen.c

US_LDFLAGS	+= -lm
EXPORT_LDFLAGS	+= -lm
FRANCE_LDFLAGS	+= -lm

# SunOS had 2 executables. Only the non-nis version need this
NIS_OBJS	= $(OBJDIR)/dns-stub.o
NIS_SRCS	= dns-stub.c
NIS_LIB		= $(NIS_OBJS)
DNS_LIB		= -lresolv

# For release only.
# This is only for SunOS as it has both nis and non-nis
# version of the browser packaged together.
EXTRA_EXPORT_OBJS	= $(XFE_PROGNAME)-nis-export
EXTRA_FRANCE_OBJS	= $(XFE_PROGNAME)-nis-france
EXTRA_US_OBJS		= $(XFE_PROGNAME)-nis-us
EXTRA_NETEXPORT_OBJS	= $(XFE_PROGNAME)-nis-net-export

NEED_YP_VERSION	= 1
NEED_NLS	= 1

endif

########################################
ifneq (,$(filter 5 5.5,$(OS_RELEASE)))

USRLIBDIR	:= /usr/openwin/lib
MCS_CMD		= mcs -d

ifeq ($(CPU_ARCH),sparc)
OTHER_LIBS	= $(OS_LIBS) -lgen -lresolv -lm
ifndef NO_WEBFONTS
EXTRA_REL_FILES += $(WEBFONT_DSO)
endif
else
OTHER_LIBS	= $(OS_LIBS) -lm
LDFLAGS		= $(NOMD_CFLAGS)
endif

OTHER_LIBS += -L/usr/dt/lib -lXm

US_LDFLAGS	= -z defs -L$(USRLIBDIR) \
		  -R$(USRLIBDIR) $(BASIC_LIBS) $(US_LIB) $(BASIC_LIBS_2) \
		  $(OTHER_LIBS) $(NSPR_LIB)
EXPORT_LDFLAGS	= -z defs -L$(USRLIBDIR) \
		  -R$(USRLIBDIR) $(BASIC_LIBS) $(EXPORT_LIB) $(BASIC_LIBS_2) \
		  $(OTHER_LIBS) $(NSPR_LIB)
FRANCE_LDFLAGS	= -z defs -L$(USRLIBDIR) \
		  -R$(USRLIBDIR) $(BASIC_LIBS) $(FRANCE_LIB) $(BASIC_LIBS_2) \
		  $(OTHER_LIBS) $(NSPR_LIB)

endif

endif

########################################
# SCO Unixware 2.1
ifeq ($(OS_ARCH),UNIXWARE)

ifdef NEED_XMOS
LIB_XMOS	= $(OBJDIR)/Xmos.o
endif

OTHER_LIBS	= -lm

US_LDFLAGS	+= -lresolv -lsocket -lc /usr/ucblib/libucb.a
EXPORT_LDFLAGS	+= -lresolv -lsocket -lc /usr/ucblib/libucb.a
FRANCE_LDFLAGS	+= -lresolv -lsocket -lc /usr/ucblib/libucb.a

endif

#######################################################################

# Rules to build the special MOZ_LITE *.o files

$(TARGETS): $(OBJS)

#
# I moved this to ns/config/rules.mk  -mcafee
#



#######################################################################
# Rules to build resources

.SUFFIXES: .ad

stubfe:	$(OBJDIR)/stubfe

$(OBJDIR)/stubfe: $(OBJS) $(EXPORT_OBJS) $(EXPORT_DEPLIBS)
	@$(MAKE_OBJDIR)
	rm -f $@
	$(CCLD) -o $@ $(LDFLAGS) $(OBJS) $(EXPORT_OBJS) $(EXPORT_LDFLAGS) $(DNS_LIB)
	@$(EXTRA_POST_LINK_CMD) $@


install:: $(TARGETS)

ifeq ($(OS_ARCH),AIX)
AIX_HACK	:= $(notdir $(AIX_NSPR))

# Install nspr dynamic library for AIX.
$(AIX_HACK): $(AIX_NSPR)
	$(INSTALL) -m 644 $< .
endif

# Skip java50.jar creation
java50.jar:

export:: $(JAR_NAME)

$(VERSION_OBJS): versionn.h

everything:	all $(ALL_TARGETS)

symbols:
	@echo "TARGETS = $(TARGETS)"
	@echo "RELEASES    = $(RELEASES)"
	@echo "OS_ARCH     = $(OS_ARCH)"
	@echo "OTHER_LIBS  = $(OTHER_LIBS)
