1AC_PREREQ([2.69])
2AC_INIT([OpenPAM], [20230627], [des@des.no], [openpam], [https://openpam.org/])
3AC_CONFIG_SRCDIR([lib/libpam/pam_start.c])
4AC_CONFIG_MACRO_DIR([m4])
5AM_INIT_AUTOMAKE([foreign])
6AM_CONFIG_HEADER([config.h])
7
8# C compiler and features
9AC_LANG(C)
10AC_PROG_CC([clang gcc cc])
11AC_PROG_CC_STDC
12AC_PROG_CPP
13AC_PROG_CXX([clang++ g++ c++])
14AC_GNU_SOURCE
15AC_C_CONST
16AC_C_RESTRICT
17AC_C_VOLATILE
18AX_COMPILER_VENDOR
19
20# libtool
21LT_PREREQ([2.2.6])
22LT_INIT([disable-static dlopen])
23
24# pkg-config
25AX_PROG_PKG_CONFIG
26
27# other programs
28AC_PROG_INSTALL
29
30LIB_MAJ=2
31AC_SUBST(LIB_MAJ)
32AC_DEFINE_UNQUOTED(LIB_MAJ, $LIB_MAJ, [OpenPAM library major number])
33
34AC_ARG_ENABLE([debug],
35    AC_HELP_STRING([--enable-debug],
36        [turn debugging macros on]),
37    AC_DEFINE(OPENPAM_DEBUG, 1, [Turn debugging macros on]))
38
39AC_ARG_ENABLE([unversioned-modules],
40    AC_HELP_STRING([--disable-unversioned-modules],
41        [support loading of unversioned modules]),
42    [AS_IF([test x"$enableval" = x"no"], [
43        AC_DEFINE(DISABLE_UNVERSIONED_MODULES,
44            1,
45            [Whether loading unversioned modules support is disabled])
46    ])])
47
48AC_ARG_WITH([modules-dir],
49    AC_HELP_STRING([--with-modules-dir=DIR],
50        [OpenPAM modules directory]),
51    [AS_IF([test x"$withval" != x"no"], [
52        OPENPAM_MODULES_DIR="$withval"
53        AC_DEFINE_UNQUOTED(OPENPAM_MODULES_DIR,
54            "${OPENPAM_MODULES_DIR%/}",
55            [OpenPAM modules directory])
56    ])])
57AC_SUBST(OPENPAM_MODULES_DIR)
58AM_CONDITIONAL([CUSTOM_MODULES_DIR], [test x"$OPENPAM_MODULES_DIR" != x""])
59
60AC_ARG_WITH([doc],
61    AC_HELP_STRING([--without-doc], [do not build documentation]),
62    [],
63    [with_doc=yes])
64AM_CONDITIONAL([WITH_DOC], [test x"$with_doc" = x"yes"])
65
66AC_ARG_WITH([pam-unix],
67    AC_HELP_STRING([--with-pam-unix], [build sample pam_unix(8) module]),
68    [],
69    [with_pam_unix=no])
70AM_CONDITIONAL([WITH_PAM_UNIX], [test x"$with_pam_unix" = x"yes"])
71
72AC_ARG_WITH(pamtest,
73    AC_HELP_STRING([--with-pamtest], [build test application]),
74    [],
75    [with_pamtest=no])
76AM_CONDITIONAL([WITH_PAMTEST], [test x"$with_pamtest" = x"yes"])
77
78AC_ARG_WITH(su,
79    AC_HELP_STRING([--with-su], [build sample su(1) implementation]),
80    [],
81    [with_su=no])
82AM_CONDITIONAL([WITH_SU], [test x"$with_su" = x"yes"])
83
84AC_ARG_WITH(system-libpam,
85    AC_HELP_STRING([--with-system-libpam], [use system libpam]),
86    [],
87    [with_system_libpam=no])
88AM_CONDITIONAL([WITH_SYSTEM_LIBPAM], [test x"$with_system_libpam" = x"yes"])
89
90AC_CHECK_HEADERS([crypt.h])
91
92AC_CHECK_FUNCS([asprintf vasprintf])
93AC_CHECK_FUNCS([dlfunc fdlopen])
94AC_CHECK_FUNCS([fpurge])
95AC_CHECK_FUNCS([setlogmask])
96AC_CHECK_FUNCS([strlcat strlcmp strlcpy strlset])
97
98saved_LIBS="${LIBS}"
99LIBS=""
100AC_CHECK_LIB([dl], [dlopen])
101DL_LIBS="${LIBS}"
102LIBS="${saved_LIBS}"
103AC_SUBST(DL_LIBS)
104
105saved_LIBS="${LIBS}"
106LIBS=""
107AC_CHECK_LIB([pam], [pam_start])
108SYSTEM_LIBPAM="${LIBS}"
109LIBS="${saved_LIBS}"
110AC_SUBST(SYSTEM_LIBPAM)
111
112AX_PKG_CONFIG_CHECK([cryb-test],
113  [AC_MSG_NOTICE([Cryb test framework found, unit tests enabled.])],
114  [AC_MSG_WARN([Cryb test framework not found, unit tests disabled.])])
115AM_CONDITIONAL([WITH_TEST], [test x"$CRYB_TEST_LIBS" != x""])
116
117AC_ARG_ENABLE([developer-warnings],
118    AS_HELP_STRING([--enable-developer-warnings], [enable strict warnings (default is NO)]),
119    [CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual"])
120AC_ARG_ENABLE([debugging-symbols],
121    AS_HELP_STRING([--enable-debugging-symbols], [enable debugging symbols (default is NO)]),
122    [CFLAGS="${CFLAGS} -O0 -g -fno-inline"])
123AC_ARG_ENABLE([werror],
124    AS_HELP_STRING([--enable-werror], [use -Werror (default is NO)]),
125    [CFLAGS="${CFLAGS} -Werror"])
126
127AC_ARG_ENABLE([code-coverage],
128    AS_HELP_STRING([--enable-code-coverage],
129        [enable code coverage]))
130AS_IF([test x"$enable_code_coverage" = x"yes"], [
131    AM_COND_IF([WITH_TEST], [
132        AS_IF([test x"$ax_cv_c_compiler_vendor" = x"clang"], [
133            CFLAGS="${CFLAGS} -fprofile-instr-generate -fcoverage-mapping"
134            clang_code_coverage="yes"
135	    AC_SUBST([clang_ver], [${CC#clang}])
136        ], [
137            AC_MSG_ERROR([code coverage is only supported with clang])
138        ])
139        AC_DEFINE([WITH_CODE_COVERAGE], [1], [Define to 1 if code coverage is enabled])
140        AC_MSG_NOTICE([code coverage enabled])
141    ], [
142        AC_MSG_ERROR([code coverage requires unit tests])
143    ])
144])
145AM_CONDITIONAL([WITH_CODE_COVERAGE], [test x"$enable_code_coverage" = x"yes"])
146AM_CONDITIONAL([CLANG_CODE_COVERAGE], [test x"$clang_code_coverage" = x"yes"])
147
148AC_CONFIG_FILES([
149    Makefile
150    bin/Makefile
151    bin/openpam_dump_policy/Makefile
152    bin/pamtest/Makefile
153    bin/su/Makefile
154    doc/Makefile
155    doc/man/Makefile
156    freebsd/Makefile
157    include/Makefile
158    include/security/Makefile
159    lib/Makefile
160    lib/libpam/Makefile
161    misc/Makefile
162    modules/Makefile
163    modules/pam_deny/Makefile
164    modules/pam_permit/Makefile
165    modules/pam_return/Makefile
166    modules/pam_unix/Makefile
167    t/Makefile
168])
169AC_CONFIG_FILES([misc/coverity.sh],[chmod +x misc/coverity.sh])
170AC_OUTPUT
171