1 dnl Find the compiler and linker flags for CrackLib.
3 dnl Allows the user to specify that the system CrackLib should be used instead
4 dnl of the embedded version by using --with-cracklib. In that case, finds the
5 dnl compiler and linker flags for that version. Also provides
6 dnl --with-cracklib-include and --with-cracklib-lib configure options to
7 dnl specify non-standard paths to the CrackLib headers and libraries.
9 dnl Provides the macro RRA_LIB_CRACKLIB. If --with-cracklib is not specified,
10 dnl this macro will set the Automake conditional EMBEDDED_CRACKLIB. If it is
11 dnl specified, sets the substitution variables CRACKLIB_CPPFLAGS,
12 dnl CRACKLIB_LDFLAGS, and CRACKLIB_LIBS. Also provides
13 dnl RRA_LIB_CRACKLIB_SWITCH to set CPPFLAGS, LDFLAGS, and LIBS to include the
14 dnl remctl libraries, saving the current values first, and
15 dnl RRA_LIB_CRACKLIB_RESTORE to restore those settings to before the last
16 dnl RRA_LIB_CRACKLIB_SWITCH.
18 dnl Depends on RRA_SET_LDFLAGS.
20 dnl Written by Russ Allbery <eagle@eyrie.org>
21 dnl Copyright 2020 Russ Allbery <eagle@eyrie.org>
23 dnl The Board of Trustees of the Leland Stanford Junior University
25 dnl This file is free software; the authors give unlimited permission to copy
26 dnl and/or distribute it, with or without modifications, as long as this
27 dnl notice is preserved.
29 dnl SPDX-License-Identifier: FSFULLR
31 dnl Save the current CPPFLAGS, LDFLAGS, and LIBS settings and switch to
32 dnl versions that include the Kerberos v5 flags. Used as a wrapper, with
33 dnl RRA_LIB_CRACKLIB_RESTORE, around tests.
34 AC_DEFUN([RRA_LIB_CRACKLIB_SWITCH],
35 [rra_cracklib_save_CPPFLAGS="$CPPFLAGS"
36 rra_cracklib_save_LDFLAGS="$LDFLAGS"
37 rra_cracklib_save_LIBS="$LIBS"
38 CPPFLAGS="$CRACKLIB_CPPFLAGS $CPPFLAGS"
39 LDFLAGS="$CRACKLIB_LDFLAGS $LDFLAGS"
40 LIBS="$CRACKLIB_LIBS $LIBS"])
42 dnl Restore CPPFLAGS, LDFLAGS, and LIBS to their previous values (before
43 dnl RRA_LIB_CRACKLIB_SWITCH was called).
44 AC_DEFUN([RRA_LIB_CRACKLIB_RESTORE],
45 [CPPFLAGS="$rra_cracklib_save_CPPFLAGS"
46 LDFLAGS="$rra_cracklib_save_LDFLAGS"
47 LIBS="$rra_cracklib_save_LIBS"])
49 dnl Set CRACKLIB_CPPFLAGS and CRACKLIB_LDFLAGS based on rra_cracklib_root,
50 dnl rra_cracklib_libdir, and rra_cracklib_includedir.
51 AC_DEFUN([_RRA_LIB_CRACKLIB_PATHS],
52 [AS_IF([test x"$rra_cracklib_libdir" != x],
53 [CRACKLIB_LDFLAGS="-L$rra_cracklib_libdir"],
54 [AS_IF([test x"$rra_cracklib_root" != x],
55 [RRA_SET_LDFLAGS([CRACKLIB_LDFLAGS], [$rra_cracklib_root])])])
56 AS_IF([test x"$rra_cracklib_includedir" != x],
57 [CRACKLIB_CPPFLAGS="-I$rra_cracklib_includedir"],
58 [AS_IF([test x"$rra_cracklib_root" != x],
59 [AS_IF([test x"$rra_cracklib_root" != x/usr],
60 [CRACKLIB_CPPFLAGS="-I${rra_cracklib_root}/include"])])])])
62 dnl Sanity-check the results of the CrackLib library search to be sure we can
63 dnl really link a CrackLib program.
64 AC_DEFUN([_RRA_LIB_CRACKLIB_CHECK],
65 [RRA_LIB_CRACKLIB_SWITCH
66 AC_CHECK_FUNC([FascistCheck], ,
67 [AC_MSG_FAILURE([unable to link with CrackLib library])])
68 RRA_LIB_CRACKLIB_RESTORE])
71 AC_DEFUN([RRA_LIB_CRACKLIB],
76 rra_cracklib_includedir=
80 AC_SUBST([CRACKLIB_CPPFLAGS])
81 AC_SUBST([CRACKLIB_LDFLAGS])
82 AC_SUBST([CRACKLIB_LIBS])
84 AC_ARG_WITH([cracklib],
85 [AS_HELP_STRING([--with-cracklib@<:@=DIR@:>@],
86 [Use system CrackLib instead of embedded copy])],
87 [AS_IF([test x"$withval" != xno], [rra_system_cracklib=yes])
88 AS_IF([test x"$withval" == xno], [rra_no_cracklib=yes])
89 AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
90 [rra_cracklib_root="$withval"])])
91 AC_ARG_WITH([cracklib-include],
92 [AS_HELP_STRING([--with-cracklib-include=DIR],
93 [Location of CrackLib headers])],
94 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
95 [rra_cracklib_includedir="$withval"])])
96 AC_ARG_WITH([cracklib-lib],
97 [AS_HELP_STRING([--with-cracklib-lib=DIR],
98 [Location of cracklib libraries])],
99 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
100 [rra_cracklib_libdir="$withval"])])
102 AS_IF([test x"$rra_no_cracklib" != xyes],
103 [AC_DEFINE([HAVE_CRACKLIB], 1, [Define if CrackLib is available.])])
104 AM_CONDITIONAL([EMBEDDED_CRACKLIB],
105 [test x"$rra_system_cracklib" != xyes && test x"$rra_no_cracklib" != xyes])
106 AS_IF([test x"$rra_system_cracklib" = xyes],
107 [_RRA_LIB_CRACKLIB_PATHS
108 CRACKLIB_LIBS="-lcrack"
109 _RRA_LIB_CRACKLIB_CHECK])])