1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit eutils flag-o-matic multilib toolchain-funcs multilib-minimal
9 RTM_NAME="NSS_${PV//./_}_RTM"
10 # Rev of https://git.fedorahosted.org/cgit/nss-pem.git
11 PEM_GIT_REV="429b0222759d8ad8e6dcd29e62875ae3efd69116"
12 PEM_P="${PN}-pem-20160329"
14 DESCRIPTION="Mozilla's Network Security Services library that implements PKI support"
15 HOMEPAGE="http://www.mozilla.org/projects/security/pki/nss/"
16 SRC_URI="https://archive.mozilla.org/pub/security/nss/releases/${RTM_NAME}/src/${P}.tar.gz
17 cacert? ( https://dev.gentoo.org/~axs/distfiles/${PN}-cacert-class1-class3.patch )
18 nss-pem? ( https://dev.gentoo.org/~polynomial-c/${PEM_P}.tar.xz )"
20 LICENSE="|| ( MPL-2.0 GPL-2 LGPL-2.1 )"
22 KEYWORDS="~alpha amd64 arm arm64 hppa ia64 ~m68k ~mips ppc ppc64 s390 sparc x86 ~amd64-linux ~x86-linux ~x86-macos ~sparc-solaris ~x64-solaris ~x86-solaris"
23 IUSE="cacert +nss-pem utils"
25 >=virtual/pkgconfig-0-r1[${MULTILIB_USEDEP}]
28 >=dev-libs/nspr-${NSPR_VER}[${MULTILIB_USEDEP}]
29 >=dev-db/sqlite-3.8.2[${MULTILIB_USEDEP}]
30 >=sys-libs/zlib-1.2.8-r1[${MULTILIB_USEDEP}]
36 S="${WORKDIR}/${P}/${PN}"
38 MULTILIB_CHOST_TOOLS=(
43 # Custom changes for gentoo
44 "${FILESDIR}/${PN}-3.47-gentoo-fixups.patch"
45 "${FILESDIR}/${PN}-3.21-gentoo-fixup-warnings.patch"
46 "${FILESDIR}/${PN}-3.23-hppa-byte_order.patch"
52 mv "${PN}"/lib/ckfw/pem/ "${S}"/lib/ckfw/ || die
59 "${FILESDIR}/${PN}-3.47-enable-pem.patch"
62 if use cacert ; then #521462
64 "${DISTDIR}/${PN}-cacert-class1-class3.patch"
70 pushd coreconf >/dev/null || die
72 echo 'INCLUDES += -I$(DIST)/include/dbm' \
73 >> headers.mk || die "failed to append include"
76 sed -e '/CORE_DEPTH/s:SOURCE_PREFIX.*$:SOURCE_PREFIX = $(CORE_DEPTH)/dist:' \
80 sed -i -e 's/\$(MKSHLIB) -o/\$(MKSHLIB) \$(LDFLAGS) -o/g' rules.mk
81 popd >/dev/null || die
83 # Fix pkgconfig file for Prefix
84 sed -i -e "/^PREFIX =/s:= /usr:= ${EPREFIX}/usr:" \
85 config/Makefile || die
87 # use host shlibsign if need be #436216
88 if tc-is-cross-compiler ; then
90 -e 's:"${2}"/shlibsign:shlibsign:' \
91 cmd/shlibsign/sign.sh || die
95 sed -i -e "/CRYPTOLIB/s:\$(SOFTOKEN_LIB_DIR):../freebl/\$(OBJDIR):" \
96 lib/ssl/config.mk || die
97 sed -i -e "/CRYPTOLIB/s:\$(SOFTOKEN_LIB_DIR):../../lib/freebl/\$(OBJDIR):" \
98 cmd/platlibs.mk || die
100 multilib_copy_sources
105 multilib_src_configure() {
106 # Ensure we stay multilib aware
107 sed -i -e "/@libdir@/ s:lib64:$(get_libdir):" config/Makefile || die
111 # Most of the arches are the same as $ARCH
112 local t=${1:-${CHOST}}
114 aarch64*)echo "aarch64";;
115 hppa*) echo "parisc";;
117 x86_64*) echo "x86_64";;
123 local cc cppflags="${1}CPPFLAGS" cflags="${1}CFLAGS"
124 if [[ ${1} == BUILD_ ]]; then
129 echo > "${T}"/test.c || die
130 ${cc} ${!cppflags} ${!cflags} -c "${T}"/test.c -o "${T}/${1}test.o" || die
131 case $(file "${T}/${1}test.o") in
132 *32-bit*x86-64*) echo USE_X32=1;;
133 *64-bit*|*ppc64*|*x86_64*) echo USE_64=1;;
134 *32-bit*|*ppc*|*i386*) ;;
135 *) die "Failed to detect whether ${cc} builds 64bits or 32bits, disable distcc if you're using it, please";;
139 multilib_src_compile() {
140 # use ABI to determine bit'ness, or fallback if unset
141 local buildbits mybits
143 n32) mybits="USE_N32=1";;
144 x32) mybits="USE_X32=1";;
145 s390x|*64) mybits="USE_64=1";;
147 einfo "Running compilation test to determine bit'ness"
151 # bitness of host may differ from target
152 if tc-is-cross-compiler; then
153 buildbits=$(nssbits BUILD_)
159 AR="$(tc-getAR) rc \$@"
160 RANLIB="$(tc-getRANLIB)"
165 # Take care of nspr settings #436216
166 local myCPPFLAGS="${CPPFLAGS} $($(tc-getPKG_CONFIG) nspr --cflags)"
167 unset NSPR_INCLUDE_DIR
169 # Do not let `uname` be used.
170 if use kernel_linux ; then
178 export NSS_ALLOW_SSLKEYLOGFILE=1
179 export NSS_ENABLE_WERROR=0 #567158
181 export NSS_USE_SYSTEM_SQLITE=1
182 export NSDISTMODE=copy
183 export NSS_ENABLE_ECC=1
184 export FREEBL_NO_DEPEND=1
185 export FREEBL_LOWHASH=1
186 export NSS_SEED_ONLY_DEV_URANDOM=1
191 # Build the host tools first.
192 LDFLAGS="${BUILD_LDFLAGS}" \
193 XCFLAGS="${BUILD_CFLAGS}" \
194 NSPR_LIB_DIR="${T}/fakedir" \
195 emake -j1 -C coreconf \
196 CC="$(tc-getBUILD_CC)" \
197 ${buildbits:-${mybits}}
198 makeargs+=( NSINSTALL="${PWD}/$(find -type f -name nsinstall)" )
200 # Then build the target tools.
201 for d in . lib/dbm ; do
202 CPPFLAGS="${myCPPFLAGS}" \
203 XCFLAGS="${CFLAGS} ${CPPFLAGS}" \
204 NSPR_LIB_DIR="${T}/fakedir" \
205 emake -j1 "${makeargs[@]}" -C ${d}
209 # Altering these 3 libraries breaks the CHK verification.
210 # All of the following cause it to break:
214 # http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn6.html
215 # Either we have to NOT strip them, or we have to forcibly resign after
217 #local_libdir="$(get_libdir)"
219 # */${local_libdir}/libfreebl3.so*
220 # */${local_libdir}/libnssdbm3.so*
221 # */${local_libdir}/libsoftokn3.so*"
223 export NSS_CHK_SIGN_LIBS="freebl3 nssdbm3 softokn3"
228 einfo "Resigning core NSS libraries for FIPS validation"
231 for i in ${NSS_CHK_SIGN_LIBS} ; do
232 local libname=lib${i}.so
233 local chkname=lib${i}.chk
235 -i "${libdir}"/${libname} \
236 -o "${libdir}"/${chkname}.tmp \
238 "${libdir}"/${chkname}.tmp \
239 "${libdir}"/${chkname} \
240 || die "Failed to sign ${libname}"
248 for i in ${NSS_CHK_SIGN_LIBS} ; do
249 local libfname="${libdir}/lib${i}.so"
250 # If the major version has changed, then we have old chk files.
251 [ ! -f "${libfname}" -a -f "${libfname}.chk" ] \
252 && rm -f "${libfname}.chk"
256 multilib_src_install() {
257 pushd dist >/dev/null || die
259 dodir /usr/$(get_libdir)
260 cp -L */lib/*$(get_libname) "${ED}"/usr/$(get_libdir) || die "copying shared libs failed"
262 for i in crmf freebl nssb nssckfw ; do
263 cp -L */lib/lib${i}.a "${ED}"/usr/$(get_libdir) || die "copying libs failed"
266 # Install nss-config and pkgconfig file
268 cp -L */bin/nss-config "${ED}"/usr/bin || die
269 dodir /usr/$(get_libdir)/pkgconfig
270 cp -L */lib/pkgconfig/nss.pc "${ED}"/usr/$(get_libdir)/pkgconfig || die
272 # create an nss-softokn.pc from nss.pc for libfreebl and some private headers
274 sed -e 's#Libs:#Libs: -lfreebl#' \
275 -e 's#Cflags:#Cflags: -I${includedir}/private#' \
276 */lib/pkgconfig/nss.pc >"${ED}"/usr/$(get_libdir)/pkgconfig/nss-softokn.pc \
277 || die "could not create nss-softokn.pc"
279 # all the include files
280 insinto /usr/include/nss
281 doins public/nss/*.{h,api}
282 insinto /usr/include/nss/private
283 doins private/nss/{blapi,alghmac}.h
285 popd >/dev/null || die
288 # Always enabled because we need it for chk generation.
289 nssutils=( shlibsign )
291 if multilib_is_native_abi ; then
293 # The tests we do not need to install.
294 #nssutils_test="bltest crmftest dbtest dertimetest
295 #fipstest remtest sdrtest"
296 # checkcert utils has been removed in nss-3.22:
297 # https://bugzilla.mozilla.org/show_bug.cgi?id=1187545
298 # https://hg.mozilla.org/projects/nss/rev/df1729d37870
299 # certcgi has been removed in nss-3.36:
300 # https://bugzilla.mozilla.org/show_bug.cgi?id=1426602
337 # install man-pages for utils (bug #516810)
340 pushd dist/*/bin >/dev/null || die
341 for f in ${nssutils[@]}; do
344 popd >/dev/null || die
347 # Prelink breaks the CHK files. We don't have any reliable way to run
348 # shlibsign after prelink.
349 dodir /etc/prelink.conf.d
350 printf -- "-b ${EPREFIX}/usr/$(get_libdir)/lib%s.so\n" ${NSS_CHK_SIGN_LIBS} \
351 > "${ED}"/etc/prelink.conf.d/nss.conf
355 multilib_pkg_postinst() {
356 # We must re-sign the libraries AFTER they are stripped.
357 local shlibsign="${EROOT}/usr/bin/shlibsign"
358 # See if we can execute it (cross-compiling & such). #436216
359 "${shlibsign}" -h >&/dev/null
360 if [[ $? -gt 1 ]] ; then
361 shlibsign="shlibsign"
363 generate_chk "${shlibsign}" "${EROOT}"/usr/$(get_libdir)
366 multilib_foreach_abi multilib_pkg_postinst
370 multilib_pkg_postrm() {
371 cleanup_chk "${EROOT}"/usr/$(get_libdir)
374 multilib_foreach_abi multilib_pkg_postrm