1 # Copyright 1999-2019 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 ~sh 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_ENABLE_WERROR=0 #567158
180 export NSS_USE_SYSTEM_SQLITE=1
181 export NSDISTMODE=copy
182 export NSS_ENABLE_ECC=1
183 export FREEBL_NO_DEPEND=1
184 export FREEBL_LOWHASH=1
185 export NSS_SEED_ONLY_DEV_URANDOM=1
190 # Build the host tools first.
191 LDFLAGS="${BUILD_LDFLAGS}" \
192 XCFLAGS="${BUILD_CFLAGS}" \
193 NSPR_LIB_DIR="${T}/fakedir" \
194 emake -j1 -C coreconf \
195 CC="$(tc-getBUILD_CC)" \
196 ${buildbits:-${mybits}}
197 makeargs+=( NSINSTALL="${PWD}/$(find -type f -name nsinstall)" )
199 # Then build the target tools.
200 for d in . lib/dbm ; do
201 CPPFLAGS="${myCPPFLAGS}" \
202 XCFLAGS="${CFLAGS} ${CPPFLAGS}" \
203 NSPR_LIB_DIR="${T}/fakedir" \
204 emake -j1 "${makeargs[@]}" -C ${d}
208 # Altering these 3 libraries breaks the CHK verification.
209 # All of the following cause it to break:
213 # http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn6.html
214 # Either we have to NOT strip them, or we have to forcibly resign after
216 #local_libdir="$(get_libdir)"
218 # */${local_libdir}/libfreebl3.so*
219 # */${local_libdir}/libnssdbm3.so*
220 # */${local_libdir}/libsoftokn3.so*"
222 export NSS_CHK_SIGN_LIBS="freebl3 nssdbm3 softokn3"
227 einfo "Resigning core NSS libraries for FIPS validation"
230 for i in ${NSS_CHK_SIGN_LIBS} ; do
231 local libname=lib${i}.so
232 local chkname=lib${i}.chk
234 -i "${libdir}"/${libname} \
235 -o "${libdir}"/${chkname}.tmp \
237 "${libdir}"/${chkname}.tmp \
238 "${libdir}"/${chkname} \
239 || die "Failed to sign ${libname}"
247 for i in ${NSS_CHK_SIGN_LIBS} ; do
248 local libfname="${libdir}/lib${i}.so"
249 # If the major version has changed, then we have old chk files.
250 [ ! -f "${libfname}" -a -f "${libfname}.chk" ] \
251 && rm -f "${libfname}.chk"
255 multilib_src_install() {
256 pushd dist >/dev/null || die
258 dodir /usr/$(get_libdir)
259 cp -L */lib/*$(get_libname) "${ED}"/usr/$(get_libdir) || die "copying shared libs failed"
261 for i in crmf freebl nssb nssckfw ; do
262 cp -L */lib/lib${i}.a "${ED}"/usr/$(get_libdir) || die "copying libs failed"
265 # Install nss-config and pkgconfig file
267 cp -L */bin/nss-config "${ED}"/usr/bin || die
268 dodir /usr/$(get_libdir)/pkgconfig
269 cp -L */lib/pkgconfig/nss.pc "${ED}"/usr/$(get_libdir)/pkgconfig || die
271 # create an nss-softokn.pc from nss.pc for libfreebl and some private headers
273 sed -e 's#Libs:#Libs: -lfreebl#' \
274 -e 's#Cflags:#Cflags: -I${includedir}/private#' \
275 */lib/pkgconfig/nss.pc >"${ED}"/usr/$(get_libdir)/pkgconfig/nss-softokn.pc \
276 || die "could not create nss-softokn.pc"
278 # all the include files
279 insinto /usr/include/nss
280 doins public/nss/*.{h,api}
281 insinto /usr/include/nss/private
282 doins private/nss/{blapi,alghmac}.h
284 popd >/dev/null || die
287 # Always enabled because we need it for chk generation.
288 nssutils=( shlibsign )
290 if multilib_is_native_abi ; then
292 # The tests we do not need to install.
293 #nssutils_test="bltest crmftest dbtest dertimetest
294 #fipstest remtest sdrtest"
295 # checkcert utils has been removed in nss-3.22:
296 # https://bugzilla.mozilla.org/show_bug.cgi?id=1187545
297 # https://hg.mozilla.org/projects/nss/rev/df1729d37870
298 # certcgi has been removed in nss-3.36:
299 # https://bugzilla.mozilla.org/show_bug.cgi?id=1426602
336 # install man-pages for utils (bug #516810)
339 pushd dist/*/bin >/dev/null || die
340 for f in ${nssutils[@]}; do
343 popd >/dev/null || die
346 # Prelink breaks the CHK files. We don't have any reliable way to run
347 # shlibsign after prelink.
348 dodir /etc/prelink.conf.d
349 printf -- "-b ${EPREFIX}/usr/$(get_libdir)/lib%s.so\n" ${NSS_CHK_SIGN_LIBS} \
350 > "${ED}"/etc/prelink.conf.d/nss.conf
354 multilib_pkg_postinst() {
355 # We must re-sign the libraries AFTER they are stripped.
356 local shlibsign="${EROOT}/usr/bin/shlibsign"
357 # See if we can execute it (cross-compiling & such). #436216
358 "${shlibsign}" -h >&/dev/null
359 if [[ $? -gt 1 ]] ; then
360 shlibsign="shlibsign"
362 generate_chk "${shlibsign}" "${EROOT}"/usr/$(get_libdir)
365 multilib_foreach_abi multilib_pkg_postinst
369 multilib_pkg_postrm() {
370 cleanup_chk "${EROOT}"/usr/$(get_libdir)
373 multilib_foreach_abi multilib_pkg_postrm