• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21#***************************************************************************
22
23AC_DEFUN([CURL_WITH_NSS], [
24if test "x$OPT_NSS" != xno; then
25  ssl_msg=
26
27  if test X"$OPT_NSS" != Xno; then
28
29    addld=""
30    addlib=""
31    addcflags=""
32    nssprefix=""
33    version=""
34
35    if test "x$OPT_NSS" = "xyes"; then
36
37      CURL_CHECK_PKGCONFIG(nss)
38
39      if test "$PKGCONFIG" != "no" ; then
40        addlib=`$PKGCONFIG --libs nss`
41        addcflags=`$PKGCONFIG --cflags nss`
42        version=`$PKGCONFIG --modversion nss`
43        nssprefix=`$PKGCONFIG --variable=prefix nss`
44      else
45        dnl Without pkg-config, we check for nss-config
46
47        check=`nss-config --version 2>/dev/null`
48        if test -n "$check"; then
49          addlib=`nss-config --libs`
50          addcflags=`nss-config --cflags`
51          version=`nss-config --version`
52          nssprefix=`nss-config --prefix`
53        else
54          addlib="-lnss3"
55          addcflags=""
56          version="unknown"
57        fi
58      fi
59    else
60      NSS_PCDIR="$OPT_NSS/lib/pkgconfig"
61      if test -f "$NSS_PCDIR/nss.pc"; then
62        CURL_CHECK_PKGCONFIG(nss, [$NSS_PCDIR])
63        if test "$PKGCONFIG" != "no" ; then
64          addld=`CURL_EXPORT_PCDIR([$NSS_PCDIR]) $PKGCONFIG --libs-only-L nss`
65          addlib=`CURL_EXPORT_PCDIR([$NSS_PCDIR]) $PKGCONFIG --libs-only-l nss`
66          addcflags=`CURL_EXPORT_PCDIR([$NSS_PCDIR]) $PKGCONFIG --cflags nss`
67          version=`CURL_EXPORT_PCDIR([$NSS_PCDIR]) $PKGCONFIG --modversion nss`
68          nssprefix=`CURL_EXPORT_PCDIR([$NSS_PCDIR]) $PKGCONFIG --variable=prefix nss`
69        fi
70      fi
71    fi
72
73    if test -z "$addlib"; then
74      # Without pkg-config, we'll kludge in some defaults
75      AC_MSG_WARN([Using hard-wired libraries and compilation flags for NSS.])
76      addld="-L$OPT_NSS/lib"
77      addlib="-lssl3 -lsmime3 -lnss3 -lplds4 -lplc4 -lnspr4"
78      addcflags="-I$OPT_NSS/include"
79      version="unknown"
80      nssprefix=$OPT_NSS
81    fi
82
83    CLEANLDFLAGS="$LDFLAGS"
84    CLEANLIBS="$LIBS"
85    CLEANCPPFLAGS="$CPPFLAGS"
86
87    LDFLAGS="$addld $LDFLAGS"
88    LIBS="$addlib $LIBS"
89    if test "$addcflags" != "-I/usr/include"; then
90       CPPFLAGS="$CPPFLAGS $addcflags"
91    fi
92
93    dnl The function SSL_VersionRangeSet() is needed to enable TLS > 1.0
94    AC_CHECK_LIB(nss3, SSL_VersionRangeSet,
95     [
96     AC_DEFINE(USE_NSS, 1, [if NSS is enabled])
97     AC_SUBST(USE_NSS, [1])
98     USE_NSS="yes"
99     NSS_ENABLED=1
100     ssl_msg="NSS"
101     test nss != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
102     ],
103     [
104       LDFLAGS="$CLEANLDFLAGS"
105       LIBS="$CLEANLIBS"
106       CPPFLAGS="$CLEANCPPFLAGS"
107     ])
108
109    if test "x$USE_NSS" = "xyes"; then
110      AC_MSG_NOTICE([detected NSS version $version])
111
112      dnl PK11_CreateManagedGenericObject() was introduced in NSS 3.34 because
113      dnl PK11_DestroyGenericObject() does not release resources allocated by
114      dnl PK11_CreateGenericObject() early enough.
115      AC_CHECK_FUNC(PK11_CreateManagedGenericObject,
116        [
117          AC_DEFINE(HAVE_PK11_CREATEMANAGEDGENERICOBJECT, 1,
118                    [if you have the PK11_CreateManagedGenericObject function])
119        ])
120
121      dnl needed when linking the curl tool without USE_EXPLICIT_LIB_DEPS
122      NSS_LIBS=$addlib
123      AC_SUBST([NSS_LIBS])
124
125      dnl when shared libs were found in a path that the run-time
126      dnl linker doesn't search through, we need to add it to
127      dnl CURL_LIBRARY_PATH to prevent further configure tests to fail
128      dnl due to this
129      if test "x$cross_compiling" != "xyes"; then
130        CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$nssprefix/lib$libsuff"
131        export CURL_LIBRARY_PATH
132        AC_MSG_NOTICE([Added $nssprefix/lib$libsuff to CURL_LIBRARY_PATH])
133      fi
134
135    fi dnl NSS found
136
137  fi dnl NSS not disabled
138
139  test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
140fi
141
142])
143