• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) 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# SPDX-License-Identifier: curl
22#
23#***************************************************************************
24
25AC_DEFUN([CURL_WITH_NSS], [
26if test "x$OPT_NSS" != xno; then
27  ssl_msg=
28
29  if test X"$OPT_NSS" != Xno; then
30
31    addld=""
32    addlib=""
33    addcflags=""
34    nssprefix=""
35    version=""
36
37    if test "x$OPT_NSS" = "xyes"; then
38
39      CURL_CHECK_PKGCONFIG(nss)
40
41      if test "$PKGCONFIG" != "no" ; then
42        addlib=`$PKGCONFIG --libs nss`
43        addcflags=`$PKGCONFIG --cflags nss`
44        version=`$PKGCONFIG --modversion nss`
45        nssprefix=`$PKGCONFIG --variable=prefix nss`
46      else
47        dnl Without pkg-config, we check for nss-config
48
49        check=`nss-config --version 2>/dev/null`
50        if test -n "$check"; then
51          addlib=`nss-config --libs`
52          addcflags=`nss-config --cflags`
53          version=`nss-config --version`
54          nssprefix=`nss-config --prefix`
55        else
56          addlib="-lnss3"
57          addcflags=""
58          version="unknown"
59        fi
60      fi
61    else
62      NSS_PCDIR="$OPT_NSS/lib/pkgconfig"
63      if test -f "$NSS_PCDIR/nss.pc"; then
64        CURL_CHECK_PKGCONFIG(nss, [$NSS_PCDIR])
65        if test "$PKGCONFIG" != "no" ; then
66          addld=`CURL_EXPORT_PCDIR([$NSS_PCDIR]) $PKGCONFIG --libs-only-L nss`
67          addlib=`CURL_EXPORT_PCDIR([$NSS_PCDIR]) $PKGCONFIG --libs-only-l nss`
68          addcflags=`CURL_EXPORT_PCDIR([$NSS_PCDIR]) $PKGCONFIG --cflags nss`
69          version=`CURL_EXPORT_PCDIR([$NSS_PCDIR]) $PKGCONFIG --modversion nss`
70          nssprefix=`CURL_EXPORT_PCDIR([$NSS_PCDIR]) $PKGCONFIG --variable=prefix nss`
71        fi
72      fi
73    fi
74
75    if test -z "$addlib"; then
76      # Without pkg-config, we'll kludge in some defaults
77      AC_MSG_WARN([Using hard-wired libraries and compilation flags for NSS.])
78      addld="-L$OPT_NSS/lib"
79      addlib="-lssl3 -lsmime3 -lnss3 -lplds4 -lplc4 -lnspr4"
80      addcflags="-I$OPT_NSS/include"
81      version="unknown"
82      nssprefix=$OPT_NSS
83    fi
84
85    CLEANLDFLAGS="$LDFLAGS"
86    CLEANLIBS="$LIBS"
87    CLEANCPPFLAGS="$CPPFLAGS"
88
89    LDFLAGS="$addld $LDFLAGS"
90    LIBS="$addlib $LIBS"
91    if test "$addcflags" != "-I/usr/include"; then
92       CPPFLAGS="$CPPFLAGS $addcflags"
93    fi
94
95    dnl The function SSL_VersionRangeSet() is needed to enable TLS > 1.0
96    AC_CHECK_LIB(nss3, SSL_VersionRangeSet,
97     [
98     AC_DEFINE(USE_NSS, 1, [if NSS is enabled])
99     AC_SUBST(USE_NSS, [1])
100     USE_NSS="yes"
101     NSS_ENABLED=1
102     ssl_msg="NSS"
103     test nss != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
104     ],
105     [
106       LDFLAGS="$CLEANLDFLAGS"
107       LIBS="$CLEANLIBS"
108       CPPFLAGS="$CLEANCPPFLAGS"
109     ])
110
111    if test "x$USE_NSS" = "xyes"; then
112      AC_MSG_NOTICE([detected NSS version $version])
113
114      dnl PK11_CreateManagedGenericObject() was introduced in NSS 3.34 because
115      dnl PK11_DestroyGenericObject() does not release resources allocated by
116      dnl PK11_CreateGenericObject() early enough.
117      AC_CHECK_FUNC(PK11_CreateManagedGenericObject,
118        [
119          AC_DEFINE(HAVE_PK11_CREATEMANAGEDGENERICOBJECT, 1,
120                    [if you have the PK11_CreateManagedGenericObject function])
121        ])
122
123      dnl needed when linking the curl tool without USE_EXPLICIT_LIB_DEPS
124      NSS_LIBS=$addlib
125      AC_SUBST([NSS_LIBS])
126
127      dnl when shared libs were found in a path that the run-time
128      dnl linker doesn't search through, we need to add it to
129      dnl CURL_LIBRARY_PATH to prevent further configure tests to fail
130      dnl due to this
131      if test "x$cross_compiling" != "xyes"; then
132        CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$nssprefix/lib$libsuff"
133        export CURL_LIBRARY_PATH
134        AC_MSG_NOTICE([Added $nssprefix/lib$libsuff to CURL_LIBRARY_PATH])
135      fi
136
137    fi dnl NSS found
138
139  fi dnl NSS not disabled
140
141  test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
142fi
143
144])
145