#! gmake
#
# 
# 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 Netscape security libraries.
# 
# The Initial Developer of the Original Code is Netscape
# Communications Corporation.  Portions created by Netscape are 
# Copyright (C) 1994-2000 Netscape Communications Corporation.  All
# Rights Reserved.
# 
# Contributor(s):
# 
# Alternatively, the contents of this file may be used under the
# terms of the GNU General Public License Version 2 or later (the
# "GPL"), in which case the provisions of the GPL are applicable 
# instead of those above.  If you wish to allow use of your 
# version of this file only under the terms of the GPL and not to
# allow others to use your version of this file under the MPL,
# indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by
# the GPL.  If you do not delete the provisions above, a recipient
# may use your version of this file under either the MPL or the
# GPL.
# 
#

#######################################################################
# (1) Include initial platform-independent assignments (MANDATORY).   #
#######################################################################

include manifest.mn

#######################################################################
# (2) Include "global" configuration information. (OPTIONAL)          #
#######################################################################

include $(CORE_DEPTH)/coreconf/config.mk

#######################################################################
# (3) Include "component" configuration information. (OPTIONAL)       #
#######################################################################

#######################################################################
# (4) Include "local" platform-dependent assignments (OPTIONAL).      #
#######################################################################

NLS_SNAPSHOT = 19990122
ifeq ($(OS_ARCH), Linux)
ifeq ($(OS_RELEASE), 2.2)
NLS_SNAPSHOT = 19990820
endif
endif
NLS_ROOTDIR = components/libnls31

ifdef USE_LOCAL_LIBNLS
NLSDIST = $(CORE_DEPTH)/libnls/$(PLATFORM)
else
ifeq ($(OS_ARCH), WINNT)

# Icepicks in my forehead!!
NLS_BUILD_DIST = \\\\IRIDIUM/$(NLS_ROOTDIR)/$(NLS_SNAPSHOT)/$(PLATFORM)
NLS_RELEASE_DIST = \\\\IRIDIUM/$(NLS_ROOTDIR)/$(NLS_SNAPSHOT)/$(PLATFORM)
NLSDIST = $(NLS_BUILD_DIST)

else

NLSDIST = /share/builds/$(NLS_ROOTDIR)/$(NLS_SNAPSHOT)/$(PLATFORM)

endif
endif

# LDAP library
LDAPSDK_SNAPSHOT = 19981116D
LDAPSDK_ROOTDIR = components/ldapsdk31

ifdef USE_LOCAL_LDAPSDK
LDAPSDKDIST = $(CORE_DEPTH)/ldapsdk/$(PLATFORM)
else
ifeq ($(OS_ARCH), WINNT)
LDAPSDK_BUILD_DIST = \\\\IRIDIUM/$(LDAPSDK_ROOTDIR)/$(LDAPSDK_SNAPSHOT)/WINNT$(OS_RELEASE)$(OBJDIR_TAG).OBJ
LDAPSDK_RELEASE_DIST = \\\\IRIDIUM/$(LDAPSDK_ROOTDIR)/$(LDAPSDK_SNAPSHOT)/WINNT$(OS_RELEASE)$(OBJDIR_TAG).OBJ
LDAPSDKDIST = $(LDAPSDK_BUILD_DIST)
else
LDAPSDKDIST = /share/builds/$(LDAPSDK_ROOTDIR)/$(LDAPSDK_SNAPSHOT)/$(PLATFORM)
endif
endif

ifneq ($(OS_ARCH), WINNT)
ifeq ($(OS_ARCH), Linux)
# On linux, we link with libstdc++ (we're always using egcs on linux, right?)
CPLUSPLUSRUNTIME = -L /usr/lib -lstdc++ -lm
else
# libC, presumably, is what we must link with elsewhere
CPLUSPLUSRUNTIME = -lC -lm
endif
endif

NLSLIBDIR = $(NLSDIST)/lib
INCLUDES += -I$(NLSDIST)/include -I$(LDAPSDKDIST)/include

ifeq ($(OS_ARCH), SunOS)
ifeq ($(OS_RELEASE), 5.5.1)
OS_LIBS += -ldl -lsocket -lnsl -lthread -lposix4
endif
ifeq ($(OS_RELEASE), 5.6)
OS_LIBS += -ldl -lsocket -lnsl -lthread -lposix4
endif
endif

ifeq ($(OS_ARCH), Linux)
ifdef USE_PTHREADS
# Replace OS_LIBS, because the order of libpthread, libdl, and libc are
# very important. Otherwise you get horrible crashes.
OS_LIBS = -lpthread -ldl -lc
endif
endif


#######################################################################
# (5) Execute "global" rules. (OPTIONAL)                              #
#######################################################################

include $(CORE_DEPTH)/coreconf/rules.mk

#######################################################################
# (6) Execute "component" rules. (OPTIONAL)                           #
#######################################################################

ifdef NSM_TIMEBOMB
CFLAGS += -DTIMEBOMB
export::
	gmake -f timebomb.mk export libs run
endif


#######################################################################
# (7) Execute "local" rules. (OPTIONAL).                              #
#######################################################################


# can't do this in manifest.mn because OS_ARCH isn't defined there.
ifeq ($(OS_ARCH), WINNT)

NLS_BUILD_SHLIBS = \
	$(NULL)

NLS_RELEASE_SHLIBS = \
	$(NULL)

NSPR_STUB_LIBS = \
	$(DIST)/lib/$(NSPR31_LIB_PREFIX)plc3.lib \
	$(DIST)/lib/$(NSPR31_LIB_PREFIX)plds3.lib \
	$(DIST)/lib/$(NSPR31_LIB_PREFIX)nspr3.lib

NSPR_DYNAMIC_LIBS = \
	$(DIST)/lib/$(NSPR31_LIB_PREFIX)plc3.dll \
	$(DIST)/lib/$(NSPR31_LIB_PREFIX)plds3.dll \
	$(DIST)/lib/$(NSPR31_LIB_PREFIX)nspr3.dll

NSPR_LIBS = $(NSPR_DYNAMIC_LIBS)

EXTRA_LIBS = \
	$(DIST)/lib/svrplcy.lib \
	$(DIST)/lib/crmf.lib \
	$(DIST)/lib/pkcs12.lib \
	$(DIST)/lib/nss.lib \
	$(DIST)/lib/cert.lib \
	$(DIST)/lib/key.lib \
	$(DIST)/lib/secmod.lib \
	$(DIST)/lib/crypto.lib \
	$(DIST)/lib/ssl.lib \
	$(DIST)/lib/secutil.lib \
	$(DIST)/lib/hash.lib \
	$(DIST)/lib/pkcs7.lib \
	$(DIST)/lib/dbm.lib \
	$(DIST)/lib/protocol.lib \
	$(NLS_BUILD_SHLIBS) \
	$(NSPR_STUB_LIBS) \
	$(LDAPSDKDIST)/lib/nsldaps32v30.lib \
	wsock32.lib \
	winmm.lib \
	advapi32.lib \
	$(NULL)

else

NLS_SHLIBS = \
	$(NULL)

NLS_STATICLIBS = \
	$(NULL)

NLS_LIBS = $(NLS_STATICLIBS)

NSPR_LIBS = \
	$(DIST)/lib/libplc3.so \
	$(DIST)/lib/libplds3.so \
	$(DIST)/lib/libnspr3.so

ifeq ($(OS_ARCH), SunOS)
NSPR_LINK_LIBS = -L$(DIST)/lib -Bdynamic -lnspr3 -lplc3 -lplds3
else
NSPR_LINK_LIBS = $(NSPR_LIBS)
endif

NLS_RELEASE_SHLIBS =  $(NLS_SHLIBS)

EXTRA_LIBS += \
	$(DIST)/lib/libsvrplcy.a \
	$(DIST)/lib/libcrmf.a \
	$(DIST)/lib/libpkcs12.a \
	$(DIST)/lib/libnss.a \
	$(DIST)/lib/libcert.a \
	$(DIST)/lib/libkey.a \
	$(DIST)/lib/libsecmod.a \
	$(DIST)/lib/libcrypto.a \
	$(DIST)/lib/libssl.a \
	$(DIST)/lib/libsecutil.a \
	$(DIST)/lib/libhash.a \
	$(DIST)/lib/libpkcs7.a \
	$(DIST)/lib/libdbm.a \
	$(DIST)/lib/libprotocol.a \
	$(NSPR_LINK_LIBS) \
	$(NLS_LIBS) \
	$(CPLUSPLUSRUNTIME) \
	$(LDAPSDKDIST)/lib/libldap30.a \
	$(NULL)

endif

release_md::
	$(NSINSTALL) -m 644 $(NLS_RELEASE_SHLIBS) $(SOURCE_RELEASE_PREFIX)/$(SOURCE_RELEASE_BIN_DIR)
	$(NSINSTALL) -m 644 $(NSPR_LIBS) $(SOURCE_RELEASE_PREFIX)/$(SOURCE_RELEASE_BIN_DIR)
	$(NSINSTALL) -m 644 ../ui/$(PLATFORM)/psm*.properties $(SOURCE_RELEASE_PREFIX)/$(SOURCE_RELEASE_BIN_DIR)/ui 
	$(NSINSTALL) -m 644 ../doc/*.htm ../doc/*.html ../doc/*.gif $(SOURCE_RELEASE_PREFIX)/$(SOURCE_RELEASE_BIN_DIR)/doc
ifneq ($(OS_ARCH), WINNT)
	$(NSINSTALL) -m 775 start-psm $(SOURCE_RELEASE_PREFIX)/$(SOURCE_RELEASE_BIN_DIR)
endif


install::
	$(NSINSTALL) -m 644 ../ui/$(PLATFORM)/psm*.properties $(PLATFORM)/ui
	$(NSINSTALL) -m 644 ../doc/*.gif ../doc/*.html ../doc/*.htm $(PLATFORM)/doc
ifneq ($(OS_ARCH), WINNT)
	$(NSINSTALL) -m 775 start-psm $(PLATFORM)
endif

link:
	if test -f $(PROGRAM); then	\
		echo "rm $(PROGRAM)";	\
		rm $(PROGRAM);		\
	fi;				\
	gmake				\

patch: $(PROGRAM)
	if test ! -f $(DIST)/bin/plcypatch$(PROG_SUFFIX); then	\
		gmake import;					\
	fi;
	-$(DIST)/bin/plcypatch $(PLCYPATCH_ARGS) $(PROGRAM)
