# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../nss/nss.conf
# Copyright (C) 2011 The OpenSDE Project
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

srcdir=$pkg-$ver/mozilla/security
libdir="$libdir/$pkg"
includedir="$includedir/$pkg"

# use buildloops because first we need to build stuff in 3 different subdirs
buildloops=3

nss_preconf() {
	# reset make options
	makeopt=''

	# 64bit architecture support
	case "$arch" in
		*64)    var_append makeopt ' ' 'USE_64=1' ;;
	esac

	var_append makeopt ' ' "NSPR_INCLUDE_DIR=$(pkgprefix -r includedir nspr)"
	var_append makeopt ' ' "NSPR_LIB_DIR=$(pkgprefix -r libdir nspr)"

	if pkginstalled -f sqlite; then
		var_append makeopt ' ' "NSS_USE_SYSTEM_SQLITE=1"
	fi

	var_append makeopt ' ' "NSS_ENABLE_ECC=1"
	var_append makeopt ' ' "FREEBL_NO_DEPEND=1"
	var_append makeopt ' ' "OBJDIR_NAME=$pkg-build"

	var_append makeopt ' ' "NSDISTMODE=copy"

	case $buildloop in
		1)	var_insert makeopt ' ' "-C coreconf"
			;;
		2)	var_insert makeopt ' ' "-C dbm"
			;;
		3)	var_insert makeopt ' ' "-C nss"
			# run custom install function
			hook_add postmake 5 'nss_install'
			;;
	esac	
}
hook_add preconf 3 'nss_preconf'

# do not run make install
makeinstopt=""

# custom install function
nss_install() {
	echo "installing ..."
	rm -rf $root$includedir
	mkdir -p $root$includedir
	cp -av ../dist/public/nss/*.h $root$includedir/
	cp -avf ../dist/$pkg-build/lib/*.a $root$libdir/
	cp -avf ../dist/$pkg-build/lib/*.so $root$libdir/
	cp -avf ../dist/$pkg-build/bin/* $root$bindir/
}