SUMMARY="Mozilla's library that implements PKI support"
DESCRIPTION="Network Security Services (NSS) is a set of libraries designed \
to support cross-platform development of security-enabled client and server \
applications. Applications built with NSS can support SSL v2 and v3, TLS, \
PKCS #5, PKCS #7, PKCS #11, PKCS #12, S/MIME, X.509 v3 certificates, and \
other security standards."
HOMEPAGE="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS"
COPYRIGHT="Mozilla Foundation"
LICENSE="
	GNU GPL v2
	GNU LGPL v2.1
	MPL v2.0
	"
REVISION="1"
NSS_VERSION=`echo $portVersion | sed 's/\./_/g'`
SOURCE_URI="https://ftp.mozilla.org/pub/mozilla.org/security/nss/releases/NSS_${NSS_VERSION}_RTM/src/nss-$portVersion.tar.gz"
CHECKSUM_SHA256="618db0fb2af9f6fc165934d509036b65efc78ab0ae118c06c9488bb667f21d40"
SOURCE_DIR="nss-$portVersion/nss"
PATCHES="nss-$portVersion.patchset"

ARCHITECTURES="x86 x86_64"
if [ $effectiveTargetArchitecture != x86_gcc2 ]; then
    # x86_gcc2 is fine as primary target architecture as long as we're building
    # for a different secondary architecture.
    ARCHITECTURES="$ARCHITECTURES x86_gcc2"
fi
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	nss$secondaryArchSuffix = $portVersion compat >= 3
	cmd:addbuiltin$secondaryArchSuffix = $portVersion compat >= 3
	cmd:atob$secondaryArchSuffix = $portVersion compat >= 3
	cmd:baddbdir$secondaryArchSuffix = $portVersion compat >= 3
	cmd:bltest$secondaryArchSuffix = $portVersion compat >= 3
	cmd:btoa$secondaryArchSuffix = $portVersion compat >= 3
	cmd:certcgi$secondaryArchSuffix = $portVersion compat >= 3
	cmd:certutil$secondaryArchSuffix = $portVersion compat >= 3
	cmd:checkcert$secondaryArchSuffix = $portVersion compat >= 3
	cmd:chktest$secondaryArchSuffix = $portVersion compat >= 3
	cmd:cmsutil$secondaryArchSuffix = $portVersion compat >= 3
	cmd:conflict$secondaryArchSuffix = $portVersion compat >= 3
	cmd:crlutil$secondaryArchSuffix = $portVersion compat >= 3
	cmd:crmftest$secondaryArchSuffix = $portVersion compat >= 3
	cmd:dbtest$secondaryArchSuffix = $portVersion compat >= 3
	cmd:derdump$secondaryArchSuffix = $portVersion compat >= 3
	cmd:dertimetest$secondaryArchSuffix = $portVersion compat >= 3
	cmd:digest$secondaryArchSuffix = $portVersion compat >= 3
	cmd:encodeinttest$secondaryArchSuffix = $portVersion compat >= 3
	cmd:fipstest$secondaryArchSuffix = $portVersion compat >= 3
	cmd:httpserv$secondaryArchSuffix = $portVersion compat >= 3
	cmd:listsuites$secondaryArchSuffix = $portVersion compat >= 3
	cmd:makepqg$secondaryArchSuffix = $portVersion compat >= 3
	cmd:mangle$secondaryArchSuffix = $portVersion compat >= 3
	cmd:modutil$secondaryArchSuffix = $portVersion compat >= 3
	cmd:multinit$secondaryArchSuffix = $portVersion compat >= 3
	cmd:nonspr10$secondaryArchSuffix = $portVersion compat >= 3
	cmd:ocspclnt$secondaryArchSuffix = $portVersion compat >= 3
	cmd:ocspresp$secondaryArchSuffix = $portVersion compat >= 3
	cmd:oidcalc$secondaryArchSuffix = $portVersion compat >= 3
	cmd:p7content$secondaryArchSuffix = $portVersion compat >= 3
	cmd:p7env$secondaryArchSuffix = $portVersion compat >= 3
	cmd:p7sign$secondaryArchSuffix = $portVersion compat >= 3
	cmd:p7verify$secondaryArchSuffix = $portVersion compat >= 3
	cmd:pk11gcmtest$secondaryArchSuffix = $portVersion compat >= 3
	cmd:pk11mode$secondaryArchSuffix = $portVersion compat >= 3
	cmd:pk12util$secondaryArchSuffix = $portVersion compat >= 3
	cmd:pk1sign$secondaryArchSuffix = $portVersion compat >= 3
	cmd:pkix_errcodes$secondaryArchSuffix = $portVersion compat >= 3
	cmd:pp$secondaryArchSuffix = $portVersion compat >= 3
	cmd:pwdecrypt$secondaryArchSuffix = $portVersion compat >= 3
	cmd:remtest$secondaryArchSuffix = $portVersion compat >= 3
	cmd:rsaperf$secondaryArchSuffix = $portVersion compat >= 3
	cmd:sdrtest$secondaryArchSuffix = $portVersion compat >= 3
	cmd:secmodtest$secondaryArchSuffix = $portVersion compat >= 3
	cmd:selfserv$secondaryArchSuffix = $portVersion compat >= 3
	cmd:shlibsign$secondaryArchSuffix = $portVersion compat >= 3
	cmd:signtool$secondaryArchSuffix = $portVersion compat >= 3
	cmd:signver$secondaryArchSuffix = $portVersion compat >= 3
	cmd:ssltap$secondaryArchSuffix = $portVersion compat >= 3
	cmd:strsclnt$secondaryArchSuffix = $portVersion compat >= 3
	cmd:symkeyutil$secondaryArchSuffix = $portVersion compat >= 3
	cmd:tstclnt$secondaryArchSuffix = $portVersion compat >= 3
	cmd:vfychain$secondaryArchSuffix = $portVersion compat >= 3
	cmd:vfyserv$secondaryArchSuffix = $portVersion compat >= 3
	lib:libfreebl3${secondaryArchSuffix} = $portVersion compat >= 3
	lib:libnss3${secondaryArchSuffix} = $portVersion compat >= 3
	lib:libnssckbi${secondaryArchSuffix} = $portVersion compat >= 3
	lib:libnssdbm3${secondaryArchSuffix} = $portVersion compat >= 3
	lib:libnssutil3${secondaryArchSuffix} = $portVersion compat >= 3
	lib:libsmime3${secondaryArchSuffix} = $portVersion compat >= 3
	lib:libsoftokn3${secondaryArchSuffix} = $portVersion compat >= 3
	lib:libssl3${secondaryArchSuffix} = $portVersion compat >= 3
	"
REQUIRES="
	haiku$secondaryArchSuffix >= $haikuVersion
	lib:libnspr4${secondaryArchSuffix} >= 4
	lib:libsqlite3$secondaryArchSuffix
	lib:libz${secondaryArchSuffix}
	"

PROVIDES_devel="
	nss${secondaryArchSuffix}_devel = $portVersion compat >= 3
	devel:libfreebl3${secondaryArchSuffix} = $portVersion compat >= 3
	devel:libnss3${secondaryArchSuffix} = $portVersion compat >= 3
	devel:libnssckbi${secondaryArchSuffix} = $portVersion compat >= 3
	devel:libnssdbm3${secondaryArchSuffix} = $portVersion compat >= 3
	devel:libnssutil3${secondaryArchSuffix} = $portVersion compat >= 3
	devel:libsmime3${secondaryArchSuffix} = $portVersion compat >= 3
	devel:libsoftokn3${secondaryArchSuffix} = $portVersion compat >= 3
	devel:libssl3${secondaryArchSuffix} = $portVersion compat >= 3
	"
REQUIRES_devel="
	nss${secondaryArchSuffix} == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel >= $haikuVersion
	devel:libnspr4${secondaryArchSuffix} >= 4
	devel:libsqlite3$secondaryArchSuffix
	devel:libz${secondaryArchSuffix}
	"
BUILD_PREREQUIRES="
	cmd:autoconf
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:awk
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	# FIXME: $secondaryArchSuffix is wrong here (_arch). What should be used?
	myCPPFLAGS="${CPPFLAGS} `pkg-config nspr --cflags`"
	myLDFLAGS="${LDFLAGS} `pkg-config nspr --libs-only-L`"
	
	export BUILD_OPT=1
	export NSDISTMODE=copy
	export FREEBL_NO_DEPEND=1
	export ASFLAGS=""
	if [ $effectiveTargetArchitecture == 'x86_64' ]; then
		export USE_64=1
	fi
	for d in . lib/dbm ; do
		CPPFLAGS="${myCPPFLAGS}"
		LDFLAGS="${myLDFLAGS}"
		make -j1 -C ${d}
	done
}

INSTALL()
{
	# files are in /sources/dist
	mkdir -p $includeDir $binDir
	mkdir -p $(dirname $libDir)
	mv ../dist/*/bin/* $binDir
	mv ../dist/*/lib $libDir
	mv ../dist/public/nss $includeDir
	
	# set up the develop directory correctly
	prepareInstalledDevelLibs libnss3 libfreebl3 libnssckbi libnssdbm3 \
		libnssutil3 libsmime3 libsoftokn3 libssl3
	fixPkgconfig
	
	# devel package
	packageEntries devel \
		$developDir
		
	rm $libDir/*.a
}

TEST()
{
	echo TODO
	# TODO
}
