summaryrefslogtreecommitdiff
path: root/m4/ax_check_srp.m4
blob: 11e66f50936dca5fe66d127eeee70e21bc178860 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# SYNOPSIS
#
#   AX_CHECK_SRP([action-if-found[, action-if-not-found]])
#
# DESCRIPTION
#
#   Look for libsrp in a number of default locations, or in a provided location
#   (via --with-srp=). Sets
#       SRP_CFLAGS
#       SRP_LDFLAGS
#       SRP_LIBS
#
#   and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
#
# LICENSE
#
#   Copyright (c) 2021 Eivind Naess <eivnaes@yahoo.com>
#
#   Copying and distribution of this file, with or without modification, are
#   permitted in any medium without royalty provided the copyright notice
#   and this notice are preserved. This file is offered as-is, without any
#   warranty.

#serial 1

AC_DEFUN([AX_CHECK_SRP], [
    AC_ARG_WITH([srp],
        [AS_HELP_STRING([--with-srp=DIR],
            [With libsrp support, see http://srp.stanford.edu])],
        [
            case "$withval" in
            "" | y | ye | yes)
                srpdirs="/usr/local /usr/lib /usr"  
              ;;
            n | no)
                with_srp="no"
              ;;
            *)
                srpdirs="$withval"
              ;;
            esac
        ])
    
    if [ test "x${with_srp}" != "xno" ] ; then
        SRP_LIBS="-lsrp"
        for srpdir in $srpdirs; do
            AC_MSG_CHECKING([for srp.h in $srpdir])
            if test -f "$srpdir/include/srp.h"; then
                SRP_CFLAGS="-I$srpdir/include"
                SRP_LDFLAGS="-L$srpdir/lib"
                AC_MSG_RESULT([yes])
                break
            else
                AC_MSG_RESULT([no])
            fi
        done

        # try the preprocessor and linker with our new flags,
        # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS

        AC_MSG_CHECKING([if compiling and linking against libsrp works])

        save_LIBS="$LIBS"
        save_LDFLAGS="$LDFLAGS"
        save_CPPFLAGS="$CPPFLAGS"
        LDFLAGS="$SRP_LDFLAGS $OPENSSL_LDFLAGS $LDFLAGS"
        LIBS="$SRP_LIBS $OPENSSL_LIBS $LIBS"
        CPPFLAGS="$SRP_CFLAGS $OPENSSL_INCLUDES $CPPFLAGS"
        AC_LINK_IFELSE(
            [AC_LANG_PROGRAM(
                [#include <srp.h>
                 #include <stddef.h>], 
                [SRP_use_engine(NULL);])],
            [
                AC_MSG_RESULT([yes])
                with_srp=yes
                $1
            ], [
                AC_MSG_RESULT([no])
                with_srp="no"
                $2
            ])
        CPPFLAGS="$save_CPPFLAGS"
        LDFLAGS="$save_LDFLAGS"
        LIBS="$save_LIBS"

        AC_SUBST([SRP_CFLAGS])
        AC_SUBST([SRP_LIBS])
        AC_SUBST([SRP_LDFLAGS])
    fi

    AM_CONDITIONAL(WITH_SRP, test "x${with_srp}" != "xno")
])