Bug 835919 - Allow optionally building nss without softoken in the tree, r=rrelya
authorElio Maldonado <emaldona@redhat.com>
Tue, 09 Apr 2013 22:37:08 -0700
changeset 10728 351b2d508a32b42e2a3bd70f4537953aa12fe0ca
parent 10727 b786ac75c1c7fc57bc85fb82ae0a7fddda69878c
child 10729 7d72e33ef88f31883f5c2cea84d262ececd81ee0
push id38
push useremaldona@redhat.com
push dateWed, 10 Apr 2013 05:37:21 +0000
reviewersrrelya
bugs835919
Bug 835919 - Allow optionally building nss without softoken in the tree, r=rrelya
cmd/Makefile
cmd/manifest.mn
cmd/platlibs.mk
lib/Makefile
lib/manifest.mn
tests/cipher/cipher.sh
tests/common/init.sh
tests/fips/fips.sh
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -9,16 +9,24 @@ DEPTH = ..
 
 include manifest.mn
 include $(CORE_DEPTH)/coreconf/config.mk
 
 ifdef BUILD_LIBPKIX_TESTS
 DIRS += libpkix
 endif
 
+ifeq ($(NSS_BUILD_WITHOUT_SOFTOKEN),1)
+BLTEST_SRCDIR=
+FIPSTEST_SRCDIR=
+else
+BLTEST_SRCDIR   = bltest
+FIPSTEST_SRCDIR = fipstest
+endif
+
 LOWHASHTEST_SRCDIR=
 ifeq ($(FREEBL_LOWHASH),1)
 LOWHASHTEST_SRCDIR = lowhashtest  # Add the lowhashtest directory to DIRS.
 endif
 
 INCLUDES += \
 	-I$(DIST)/../public/security \
 	-I./include \
--- a/cmd/manifest.mn
+++ b/cmd/manifest.mn
@@ -6,29 +6,29 @@
 DEPTH	= ..
 # MODULE	= seccmd
 
 REQUIRES = nss nspr libdbm
 
 DIRS = lib  \
  addbuiltin \
  atob  \
- bltest \
+ $(BLTEST_SRCDIR) \
  btoa  \
  certcgi \
  certutil  \
  checkcert  \
  chktest  \
  crlutil  \
  crmftest \
  dbtest \
  derdump  \
  digest  \
  httpserv  \
- fipstest  \
+ $(FIPSTEST_SRCDIR)  \
  $(LOWHASHTEST_SRCDIR)  \
  listsuites \
  makepqg  \
  multinit \
  ocspclnt  \
  ocspresp \
  oidcalc  \
  p7content  \
--- a/cmd/platlibs.mk
+++ b/cmd/platlibs.mk
@@ -31,17 +31,28 @@ DBMLIB = $(NULL)
 else
 DBMLIB = $(DIST)/lib/$(LIB_PREFIX)dbm.$(LIB_SUFFIX) 
 endif
 
 ifdef USE_STATIC_LIBS
 
 DEFINES += -DNSS_USE_STATIC_LIBS
 # $(PROGRAM) has explicit dependencies on $(EXTRA_LIBS)
-CRYPTOLIB=$(SOFTOKEN_LIB_DIR)/$(LIB_PREFIX)freebl.$(LIB_SUFFIX)
+ifndef USE_SYSTEM_FREEBL
+CRYPTOLIB=$(DIST)/lib/$(LIB_PREFIX)freebl.$(LIB_SUFFIX)
+SOFTOKENLIB=$(DIST)/lib/$(LIB_PREFIX)softokn.$(LIB_SUFFIX)
+else
+# Use the system freebl and softoken libraries
+CRYPTOLIB=$(FREEBL_LIB_DIR)/$(LIB_PREFIX)freebl.$(LIB_SUFFIX)
+SOFTOKENLIB=
+EXTRA_SHARED_LIBS += \
+	-L$(SOFTOKEN_LIB_DIR) \
+	-lsoftokn3 \
+	$(NULL)
+endif
 
 PKIXLIB = \
 	$(DIST)/lib/$(LIB_PREFIX)pkixtop.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pkixutil.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pkixsystem.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pkixcrlsel.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pkixmodule.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pkixstore.$(LIB_SUFFIX) \
@@ -62,17 +73,17 @@ EXTRA_LIBS += \
 	$(DIST)/lib/$(LIB_PREFIX)ssl.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)sectool.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pkcs12.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pkcs7.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)certhi.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)cryptohi.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pk11wrap.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)certdb.$(LIB_SUFFIX) \
-	$(DIST)/lib/$(LIB_PREFIX)softokn.$(LIB_SUFFIX) \
+	$(SOFTOKENLIB) \
 	$(CRYPTOLIB) \
 	$(DIST)/lib/$(LIB_PREFIX)nsspki.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)nssdev.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)nssb.$(LIB_SUFFIX) \
 	$(PKIXLIB) \
 	$(DBMLIB) \
 	$(DIST)/lib/$(LIB_PREFIX)$(SQLITE_LIB_NAME).$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)nssutil3.$(LIB_SUFFIX) \
@@ -97,17 +108,17 @@ EXTRA_LIBS += \
 	$(DIST)/lib/$(LIB_PREFIX)pkcs12.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pkcs7.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)certhi.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pk11wrap.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)cryptohi.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)certhi.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)nsspki.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pk11wrap.$(LIB_SUFFIX) \
-	$(DIST)/lib/$(LIB_PREFIX)softokn.$(LIB_SUFFIX) \
+	$(SOFTOKENLIB) \
 	$(DIST)/lib/$(LIB_PREFIX)certdb.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)nsspki.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)nssdev.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)nssb.$(LIB_SUFFIX) \
 	$(CRYPTOLIB) \
 	$(DBMLIB) \
 	$(PKIXLIB) \
 	$(DIST)/lib/$(LIB_PREFIX)nss.$(LIB_SUFFIX) \
@@ -180,18 +191,32 @@ EXTRA_SHARED_LIBS += \
 	-lnssutil3 \
 	-L$(NSPR_LIB_DIR) \
 	-lplc4 \
 	-lplds4 \
 	-lnspr4 \
 	$(NULL)
 endif
 
+ifdef SOFTOKEN_LIB_DIR
+ifdef NSS_USE_SYSTEM_FREEBL
+EXTRA_SHARED_LIBS += -L$(SOFTOKEN_LIB_DIR) -lsoftokn3
+endif
+endif
+
 endif # USE_STATIC_LIBS
 
+# If a platform has a system freebl, set USE_SYSTEM_FREEBL to 1 and
+# FREEBL_LIBS to the linker command-line arguments for the system nss-util
+# (for example, -lfreebl3 on fedora) in the platform's config file in coreconf.
+ifdef NSS_USE_SYSTEM_FREEBL
+FREEBL_LIBS = $(FREEBL_LIB_DIR)/$(LIB_PREFIX)freebl.$(LIB_SUFFIX)
+EXTRA_LIBS += $(FREEBL_LIBS)
+endif
+
 # If a platform has a system zlib, set USE_SYSTEM_ZLIB to 1 and
 # ZLIB_LIBS to the linker command-line arguments for the system zlib
 # (for example, -lz) in the platform's config file in coreconf.
 ifndef USE_SYSTEM_ZLIB
 ZLIB_LIBS = $(DIST)/lib/$(LIB_PREFIX)zlib.$(LIB_SUFFIX)
 endif
 
 JAR_LIBS = $(DIST)/lib/$(LIB_PREFIX)jar.$(LIB_SUFFIX)
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -57,8 +57,19 @@ include $(CORE_DEPTH)/coreconf/rules.mk
 #######################################################################
 
 
 
 #######################################################################
 # (7) Execute "local" rules. (OPTIONAL).                              #
 #######################################################################
 
+ifeq ($(NSS_BUILD_WITHOUT_SOFTOKEN),1)
+# Not included when building nss without softoken
+UTIL_SRCDIR=
+FREEBL_SRCDIR=
+SOFTOKEN_SRCDIR=
+else
+# default is to include all
+UTIL_SRCDIR = util
+FREEBL_SRCDIR = freebl
+SOFTOKEN_SRCDIR = softoken
+endif
--- a/lib/manifest.mn
+++ b/lib/manifest.mn
@@ -11,17 +11,17 @@ DEPTH      = ..
 #  softoken and prereqs.
 #  stan (not a separate dll yet)
 #  libpkix (not a separate dll)
 #  nss base (traditional)
 #  ssl
 #  smime
 #  ckfw (builtins module)
 #  crmf jar (not dll's)
-DIRS =  util freebl $(SQLITE_SRCDIR) $(DBM_SRCDIR) softoken \
+DIRS = $(UTIL_SRCDIR) $(FREEBL_SRCDIR) $(SQLITE_SRCDIR) $(SOFTOKEN_SRCDIR) \
 	base dev pki \
 	libpkix \
 	certdb certhigh pk11wrap cryptohi nss \
 	$(ZLIB_SRCDIR) ssl \
 	pkcs12 pkcs7 smime \
 	crmf jar \
 	ckfw $(SYSINIT_SRCDIR) \
 	$(NULL)
--- a/tests/cipher/cipher.sh
+++ b/tests/cipher/cipher.sh
@@ -61,23 +61,26 @@ cipher_main()
   do
       if [ -n "$EXP_RET" -a "$EXP_RET" != "#" ] ; then
           PARAM=`echo $PARAM | sed -e "s/_-/ -/g"`
           TESTNAME=`echo $TESTNAME | sed -e "s/_/ /g"`
           echo "$SCRIPTNAME: $TESTNAME --------------------------------"
           failedStr=""
           inOff=0
           res=0
+          # If built nss without softoken use the system installed bltest tool. 
+          # The FREEBL_BINDIR location is plaform dependent. See the comments
+          # regarding this location in nss/tests/common/init.sh. 
           while [ $inOff -lt 8 ]
           do
              outOff=0
              while [ $outOff -lt 8 ]
              do
                  echo "bltest -T -m $PARAM -d $CIPHERTESTDIR -1 $inOff -2 $outOff"
-                 ${PROFTOOL} ${BINDIR}/bltest -T -m $PARAM -d $CIPHERTESTDIR -1 $inOff -2 $outOff
+                 ${PROFTOOL} ${FREBL_BINDIR}/bltest -T -m $PARAM -d $CIPHERTESTDIR -1 $inOff -2 $outOff
                  if [ $? -ne 0 ]; then
                      failedStr="$failedStr[$inOff:$outOff]"
                  fi
                  outOff=`expr $outOff + 1`
              done
              inOff=`expr $inOff + 1`
           done
           if [ -n "$failedStr" ]; then
@@ -115,12 +118,20 @@ cipher_cleanup()
 {
   html "</TABLE><BR>"
   cd ${QADIR}
   . common/cleanup.sh
 }
 
 ################## main #################################################
 
+# When building without softoken, bltest isn't built. It was already
+# built and the cipher suite run as part of an nss-softoken build. 
+if [ ! -x ${DIST}/${OBJDIR}/bin/bltest${PROG_SUFFIX} ]; then
+    echo "bltest not built, skipping this test." >> ${LOGFILE}
+    res = 0
+    html_msg $res $EXP_RET "$TESTNAME"
+    return 0
+fi
 cipher_init
 cipher_main
 cipher_gcm
 cipher_cleanup
--- a/tests/common/init.sh
+++ b/tests/common/init.sh
@@ -642,11 +642,19 @@ if [ -z "${INIT_SOURCED}" -o "${INIT_SOU
         IOPR=1
     fi
     #################################################
 
     if [ "${OS_ARCH}" != "WINNT" -a "${OS_ARCH}" != "Android" ]; then
         ulimit -c unlimited
     fi 
 
+    #################################################################
+    # If we built nss without softoken use the system installed tool.
+    # Fedora, for example, uses /usr/lib${ARCH}/unsupported-tools but
+    # other platform may place the system installed tests somewhere else.
+    # The FREEBL_BINDIR environment variable will have been set by the
+    # package maintainer.
+    #
+    FREEBL_BINDIR = [ ${NSS_BUILD_WITHOUT_SOFTOKEN} = "1" ] && ${FREEBL_BINDIR} || ${BINDIR}
     SCRIPTNAME=$0
     INIT_SOURCED=TRUE   #whatever one does - NEVER export this one please
 fi
--- a/tests/fips/fips.sh
+++ b/tests/fips/fips.sh
@@ -218,19 +218,32 @@ fips_140()
   LIBDIR="${DIST}/${OBJDIR}/lib"
   MANGLEDIR="${FIPSDIR}/mangle"
    
   # There are different versions of cp command on different systems, some of them 
   # copies only symlinks, others doesn't have option to disable links, so there
   # is needed to copy files one by one. 
   echo "mkdir ${MANGLEDIR}"
   mkdir ${MANGLEDIR}
+  # When building nss without softoken use the system installed softoken library located
+  # in SOFTOKEN_LIB_DIR. This variable will have been set by the nss package mainainer.
+  # Fedora, for example, installs it in /usr/lib${ARCH} but other platforms may place
+  # the libraries in a different location. 
   for lib in `ls ${LIBDIR}`; do
-    echo "cp ${LIBDIR}/${lib} ${MANGLEDIR}"
-    cp ${LIBDIR}/${lib} ${MANGLEDIR}
+    # Only softoken is used in the mangling test
+    if [ ${lib} = ${DLL_PREFIX}softokn3.so ]; then
+      if [ ${NSS_BUILD_WITHOUT_SOFTOKEN} = "1" ]; then
+        # use the system installed softoken library
+        echo "cp ${SOFTOKEN_LIB_DIR}/${lib} ${MANGLEDIR}"
+        cp ${SOFTOKEN_LIB_DIR}/${lib} ${MANGLEDIR}
+      else
+        echo "cp ${LIBDIR}/${lib} ${MANGLEDIR}"
+        cp ${LIBDIR}/${lib} ${MANGLEDIR}
+      fi
+    fi
   done
     
   echo "$SCRIPTNAME: Detect mangled softoken--------------------------"
   SOFTOKEN=${MANGLEDIR}/${DLL_PREFIX}softokn3.${DLL_SUFFIX}
 
   echo "mangling ${SOFTOKEN}"
   echo "mangle -i ${SOFTOKEN} -o -8 -b 5"
   ${BINDIR}/mangle -i ${SOFTOKEN} -o -8 -b 5 2>&1