1dnl
2dnl autoconf for Pacemaker
3dnl
4dnl License: GNU General Public License (GPL)
5
6dnl ===============================================
7dnl Bootstrap
8dnl ===============================================
9AC_PREREQ(2.59)
10
11dnl Suggested structure:
12dnl     information on the package
13dnl     checks for programs
14dnl     checks for libraries
15dnl     checks for header files
16dnl     checks for types
17dnl     checks for structures
18dnl     checks for compiler characteristics
19dnl     checks for library functions
20dnl     checks for system services
21
22m4_include([version.m4])
23AC_INIT([pacemaker], VERSION_NUMBER, [users@clusterlabs.org],
24        [pacemaker], PCMK_URL)
25dnl Workaround autoconf < 2.64
26if test x"${PACKAGE_URL}" = x""; then
27	AC_SUBST([PACKAGE_URL], PCMK_URL)
28fi
29
30PCMK_FEATURES=""
31HB_PKG=heartbeat
32
33AC_CONFIG_AUX_DIR(.)
34AC_CANONICAL_HOST
35
36dnl Where #defines go (e.g. `AC_CHECK_HEADERS' below)
37dnl
38dnl Internal header: include/config.h
39dnl   - Contains ALL defines
40dnl   - include/config.h.in is generated automatically by autoheader
41dnl   - NOT to be included in any header files except lha_internal.h
42dnl     (which is also not to be included in any other header files)
43dnl
44dnl External header: include/crm_config.h
45dnl   - Contains a subset of defines checked here
46dnl   - Manually edit include/crm_config.h.in to have configure include
47dnl     new defines
48dnl   - Should not include HAVE_* defines
49dnl   - Safe to include anywhere
50AM_CONFIG_HEADER(include/config.h include/crm_config.h)
51ALL_LINGUAS="en fr"
52
53dnl Older distros may need: AM_INIT_AUTOMAKE($PACKAGE_NAME, $PACKAGE_VERSION)
54dnl tar-ustar:      use (older) POSIX variant of generated tar rather than v7
55AM_INIT_AUTOMAKE([foreign tar-ustar])
56dnl Versioned attributes implementation is not yet production-ready
57AC_DEFINE_UNQUOTED(ENABLE_VERSIONED_ATTRS, 0, Enable versioned attributes)
58
59dnl automake >= 1.11 offers --enable-silent-rules for suppressing the output from
60dnl normal compilation.  When a failure occurs, it will then display the full
61dnl command line
62dnl Wrap in m4_ifdef to avoid breaking on older platforms
63m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
64
65dnl Example 2.4. Silent Custom Rule to Generate a File
66dnl %-bar.pc: %.pc
67dnl	$(AM_V_GEN)$(LN_S) $(notdir $^) $@
68
69CC_IN_CONFIGURE=yes
70export CC_IN_CONFIGURE
71
72LDD=ldd
73BUILD_ATOMIC_ATTRD=1
74
75dnl ========================================================================
76dnl Compiler characteristics
77dnl ========================================================================
78
79AC_PROG_CC dnl Can force other with environment variable "CC".
80AM_PROG_CC_C_O
81AC_PROG_CC_STDC
82gl_EARLY
83gl_INIT
84
85LT_INIT([dlopen])
86LTDL_INIT([convenience])
87
88AC_PROG_YACC
89AM_PROG_LEX
90
91AC_C_STRINGIZE
92AC_TYPE_SIZE_T
93AC_CHECK_SIZEOF(char)
94AC_CHECK_SIZEOF(short)
95AC_CHECK_SIZEOF(int)
96AC_CHECK_SIZEOF(long)
97AC_CHECK_SIZEOF(long long)
98AC_STRUCT_TIMEZONE
99
100dnl ===============================================
101dnl Helpers
102dnl ===============================================
103cc_supports_flag() {
104         local CFLAGS="-Werror $@"
105         AC_MSG_CHECKING(whether $CC supports "$@")
106         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[ ]])], [RC=0; AC_MSG_RESULT(yes)],[RC=1; AC_MSG_RESULT(no)])
107         return $RC
108}
109
110try_extract_header_define() {
111	  AC_MSG_CHECKING(if $2 in $1 exists)
112	  Cfile=$srcdir/extract_define.$2.${$}
113	  printf "#include <stdio.h>\n" > ${Cfile}.c
114	  printf "#include <%s>\n" $1 >> ${Cfile}.c
115	  printf "int main(int argc, char **argv) {\n" >> ${Cfile}.c
116	  printf "#ifdef %s\n" $2 >> ${Cfile}.c
117	  printf "printf(\"%%s\", %s);\n" $2 >> ${Cfile}.c
118	  printf "#endif \n return 0; }\n" >> ${Cfile}.c
119	  $CC $CFLAGS ${Cfile}.c -o ${Cfile} 2>/dev/null
120	  value=
121	  if test -x ${Cfile}; then
122	      value=`${Cfile} 2>/dev/null`
123	  fi
124	  if  test x"${value}" == x""; then
125	      value=$3
126	      AC_MSG_RESULT(default: $value)
127	  else
128	      AC_MSG_RESULT($value)
129	  fi
130	  printf $value
131	  rm -rf ${Cfile}.c ${Cfile} ${Cfile}.dSYM ${Cfile}.gcno
132	}
133
134extract_header_define() {
135	  AC_MSG_CHECKING(for $2 in $1)
136	  Cfile=$srcdir/extract_define.$2.${$}
137	  printf "#include <stdio.h>\n" > ${Cfile}.c
138	  printf "#include <%s>\n" $1 >> ${Cfile}.c
139	  printf "int main(int argc, char **argv) { printf(\"%%s\", %s); return 0; }\n" $2 >> ${Cfile}.c
140	  $CC $CFLAGS ${Cfile}.c -o ${Cfile}
141	  value=`${Cfile}`
142	  AC_MSG_RESULT($value)
143	  printf $value
144	  rm -rf ${Cfile}.c ${Cfile} ${Cfile}.dSYM ${Cfile}.gcno
145	}
146
147dnl ===============================================
148dnl Configure Options
149dnl ===============================================
150
151
152dnl --enable-* options
153
154AC_ARG_ENABLE([ansi],
155    [AS_HELP_STRING([--enable-ansi],
156        [force GCC to compile to ANSI standard for older compilers. @<:@no@:>@])],
157)
158
159AC_ARG_ENABLE([fatal-warnings],
160    [AS_HELP_STRING([--enable-fatal-warnings],
161        [enable pedantic and fatal warnings for gcc @<:@yes@:>@])],
162)
163
164AC_ARG_ENABLE([quiet],
165    [AS_HELP_STRING([--enable-quiet],
166        [suppress make output unless there is an error @<:@no@:>@])],
167)
168
169AC_ARG_ENABLE([no-stack],
170    [AS_HELP_STRING([--enable-no-stack],
171        [build only the policy engine and its requirements @<:@no@:>@])],
172)
173
174AC_ARG_ENABLE([upstart],
175    [AS_HELP_STRING([--enable-upstart],
176        [enable support for managing resources via Upstart @<:@try@:>@])],
177    [],
178    [enable_upstart=try],
179)
180
181AC_ARG_ENABLE([systemd],
182    [AS_HELP_STRING([--enable-systemd],
183        [enable support for managing resources via systemd @<:@try@:>@])],
184    [],
185    [enable_systemd=try],
186)
187
188AC_ARG_ENABLE([hardening],
189    [AS_HELP_STRING([--enable-hardening],
190        [harden the resulting executables/libraries @<:@try@:>@])],
191    [ HARDENING="${enableval}" ],
192    [ HARDENING=try ],
193)
194
195dnl --with-* options
196
197AC_DEFUN([VERSION_ARG],
198    [AC_ARG_WITH([version],
199        [AS_HELP_STRING([--with-version=VERSION],
200            [override package version @<:@$1@:>@])],
201        [ PACKAGE_VERSION="$withval" ])]
202)
203VERSION_ARG(VERSION_NUMBER)
204
205AC_ARG_WITH(ais,
206    [AS_HELP_STRING([--with-ais],
207        [support the Corosync messaging and membership layer])],
208    [ SUPPORT_CS=$withval ],
209    [ SUPPORT_CS=try ],
210)
211
212AC_ARG_WITH([corosync],
213    [AS_HELP_STRING([--with-corosync],
214        [support the Corosync messaging and membership layer])],
215    [ SUPPORT_CS=$withval ]
216dnl	initialized in AC_ARG_WITH(ais...) already,
217dnl	don't reset to try if it was given as --without-ais
218)
219
220AC_ARG_WITH(heartbeat,
221    [AS_HELP_STRING([--with-heartbeat],
222       [support the Heartbeat messaging and membership layer])],
223    [ SUPPORT_HEARTBEAT=$withval ],
224    [ SUPPORT_HEARTBEAT=try ],
225)
226
227AC_ARG_WITH(cman,
228    [AS_HELP_STRING([--with-cman],
229       [support the consumption of membership and quorum from cman])],
230    [ SUPPORT_CMAN=$withval ],
231    [ SUPPORT_CMAN=try ],
232)
233
234AC_ARG_WITH(cpg,
235    [AS_HELP_STRING([--with-cs-quorum],
236       [support the consumption of membership and quorum from corosync])],
237    [ SUPPORT_CS_QUORUM=$withval ],
238    [ SUPPORT_CS_QUORUM=try ],
239)
240
241AC_ARG_WITH([nagios],
242    [AS_HELP_STRING([--with-nagios],
243        [support nagios remote monitoring])],
244    [ SUPPORT_NAGIOS=$withval ],
245    [ SUPPORT_NAGIOS=try ],
246)
247
248AC_ARG_WITH([nagios-plugin-dir],
249    [AS_HELP_STRING([--with-nagios-plugin-dir=DIR],
250        [directory for nagios plugins @<:@LIBEXECDIR/nagios/plugins@:>@])],
251    [ NAGIOS_PLUGIN_DIR="$withval" ]
252)
253
254AC_ARG_WITH([nagios-metadata-dir],
255    [AS_HELP_STRING([--with-nagios-metadata-dir=DIR],
256        [directory for nagios plugins metadata @<:@DATADIR/nagios/plugins-metadata@:>@])],
257    [ NAGIOS_METADATA_DIR="$withval" ]
258)
259
260AC_ARG_WITH(snmp,
261    [AS_HELP_STRING([--with-snmp],
262        [support the SNMP protocol])],
263    [ SUPPORT_SNMP=$withval ],
264    [ SUPPORT_SNMP=try ],
265)
266
267AC_ARG_WITH(esmtp,
268    [AS_HELP_STRING([--with-esmtp],
269        [support the sending mail notifications with the esmtp library])],
270    [ SUPPORT_ESMTP=$withval ],
271    [ SUPPORT_ESMTP=try ],
272)
273
274AC_ARG_WITH([acl],
275    [AS_HELP_STRING([--with-acl],
276        [support CIB ACL])],
277    [ SUPPORT_ACL=$withval ],
278    [ SUPPORT_ACL=yes ],
279)
280
281AC_ARG_WITH([cibsecrets],
282    [AS_HELP_STRING([--with-cibsecrets],
283        [support separate file for CIB secrets])],
284    [ SUPPORT_CIBSECRETS=$withval ],
285    [ SUPPORT_CIBSECRETS=no ],
286)
287
288PCMK_GNUTLS_PRIORITIES="NORMAL"
289AC_ARG_WITH([gnutls-priorities],
290    [AS_HELP_STRING([--with-gnutls-priorities],
291        [default GnuTLS cipher priorities @<:@NORMAL@:>@])],
292    [ test x"$withval" = x"no" || PCMK_GNUTLS_PRIORITIES="$withval" ]
293)
294
295CSPREFIX=""
296AC_ARG_WITH(ais-prefix,
297    [AS_HELP_STRING([--with-ais-prefix=DIR],
298        [prefix used when Corosync was installed @<:@PREFIX@:>@])],
299    [ CSPREFIX=$withval ],
300    [ CSPREFIX=$prefix ])
301
302INITDIR=""
303AC_ARG_WITH([initdir],
304    [AS_HELP_STRING([--with-initdir=DIR],
305        [directory for init (rc) scripts])],
306    [ INITDIR="$withval" ]
307)
308
309systemdsystemunitdir="${systemdsystemunitdir-}"
310AC_ARG_WITH([systemdsystemunitdir],
311    [AS_HELP_STRING([--with-systemdsystemunitdir=DIR],
312        [directory for systemd unit files (advanced option: must match what systemd uses)])],
313    [ systemdsystemunitdir="$withval" ]
314)
315
316SUPPORT_PROFILING=0
317AC_ARG_WITH([profiling],
318    [AS_HELP_STRING([--with-profiling],
319        [disable optimizations for effective profiling])],
320    [ SUPPORT_PROFILING=$withval ]
321)
322
323AC_ARG_WITH([coverage],
324    [AS_HELP_STRING([--with-coverage],
325        [disable optimizations for effective profiling])],
326    [ SUPPORT_COVERAGE=$withval ]
327)
328
329PUBLICAN_BRAND="common"
330AC_ARG_WITH([brand],
331    [AS_HELP_STRING([--with-brand=brand],
332        [brand to use for generated documentation (set empty for no docs) @<:@common@:>@])],
333    [ test x"$withval" = x"no" || PUBLICAN_BRAND="$withval" ]
334)
335AC_SUBST(PUBLICAN_BRAND)
336
337BUG_URL=""
338AC_ARG_WITH([bug-url],
339    [AS_HELP_STRING([--with-bug-url=DIR],
340        [address where users should submit bug reports @<:@https://bugs.clusterlabs.org/enter_bug.cgi?product=Pacemaker@:>@])],
341    [ BUG_URL="$withval" ]
342)
343
344ASCIIDOC_CLI_TYPE="pcs"
345AC_ARG_WITH(doc-cli,
346    [AS_HELP_STRING([--with-doc-cli=cli_type],
347        [CLI type to use for generated documentation @<:@pcs@:>@])],
348    [ ASCIIDOC_CLI_TYPE="$withval" ])
349AC_SUBST(ASCIIDOC_CLI_TYPE)
350
351CONFIGDIR=""
352AC_ARG_WITH([configdir],
353    [AS_HELP_STRING([--with-configdir=DIR],
354        [directory for Pacemaker configuration file @<:@SYSCONFDIR/sysconfig@:>@])],
355    [ CONFIGDIR="$withval" ]
356)
357
358dnl The not-yet-released autoconf 2.70 will have a --runstatedir option.
359dnl Until that's available, emulate it with our own --with-runstatedir.
360pcmk_runstatedir=""
361AC_ARG_WITH([runstatedir],
362    [AS_HELP_STRING([--with-runstatedir=DIR],
363        [modifiable per-process data @<:@LOCALSTATEDIR/run@:>@ (ignored if --runstatedir is available)])],
364    [ pcmk_runstatedir="$withval" ]
365)
366
367dnl This defaults to /usr/lib rather than libdir because it's determined by the
368dnl OCF project and not pacemaker. Even if a user wants to install pacemaker to
369dnl /usr/local or such, the OCF agents will be expected in their usual
370dnl location. However, we do give the user the option to override it.
371OCF_ROOT_DIR=""
372AC_ARG_WITH([ocfdir],
373    [AS_HELP_STRING([--with-ocfdir=DIR],
374        [OCF resource agent root directory (advanced option: changing this may break other cluster components unless similarly configured) @<:@/usr/local/lib/ocf@:>@])],
375    [ OCF_ROOT_DIR="$withval" ]
376)
377
378CRM_DAEMON_USER=""
379AC_ARG_WITH([daemon-user],
380    [AS_HELP_STRING([--with-daemon-user=USER],
381        [user to run unprivileged Pacemaker daemons as (advanced option: changing this may break other cluster components unless similarly configured) @<:@hacluster@:>@])],
382    [ CRM_DAEMON_USER="$withval" ]
383)
384
385CRM_DAEMON_GROUP=""
386AC_ARG_WITH([daemon-group],
387    [AS_HELP_STRING([--with-daemon-group=GROUP],
388        [group to run unprivileged Pacemaker daemons as (advanced option: changing this may break other cluster components unless similarly configured) @<:@haclient@:>@])],
389    [ CRM_DAEMON_GROUP="$withval" ]
390)
391
392dnl Options deprecated in 2.0 series
393
394AC_ARG_WITH([pkg-name],
395    [AS_HELP_STRING([--with-pkg-name=name],
396        [override package name (if you are a packager needing to pretend)])],
397    [ PACKAGE_NAME="$withval" ]
398)
399
400AC_ARG_WITH([pkgname],
401    [AS_HELP_STRING([--with-pkgname=name],
402        [name for pkg (typically for Solaris)])],
403    [ PKGNAME="$withval" ],
404    [ PKGNAME="LXHAhb" ],
405)
406AC_SUBST(PKGNAME)
407
408
409dnl ===============================================
410dnl General Processing
411dnl ===============================================
412
413AC_DEFINE_UNQUOTED(PACEMAKER_VERSION, "$PACKAGE_VERSION",
414                   [Current pacemaker version])
415
416PACKAGE_SERIES=`echo $PACKAGE_VERSION | awk -F. '{ print $1"."$2 }'`
417AC_SUBST(PACKAGE_SERIES)
418AC_SUBST(PACKAGE_VERSION)
419
420AC_SUBST(HB_PKG)
421
422INIT_EXT=""
423echo Our Host OS: $host_os/$host
424
425
426AC_MSG_NOTICE(Sanitizing prefix: ${prefix})
427case $prefix in
428  NONE)
429	prefix=/usr
430	dnl Fix default variables - "prefix" variable if not specified
431	if test "$localstatedir" = "\${prefix}/var"; then
432		localstatedir="/var"
433	fi
434	if test "$sysconfdir" = "\${prefix}/etc"; then
435		sysconfdir="/etc"
436	fi
437	;;
438esac
439
440
441AC_MSG_NOTICE(Sanitizing exec_prefix: ${exec_prefix})
442case $exec_prefix in
443  dnl For consistency with Heartbeat, map NONE->$prefix
444  NONE)	  exec_prefix=$prefix;;
445  prefix) exec_prefix=$prefix;;
446esac
447
448AC_MSG_NOTICE(Sanitizing ais_prefix: ${CSPREFIX})
449case $CSPREFIX in
450  dnl For consistency with Heartbeat, map NONE->$prefix
451  NONE)	  CSPREFIX=$prefix;;
452  prefix) CSPREFIX=$prefix;;
453esac
454
455AC_MSG_NOTICE(Sanitizing INITDIR: ${INITDIR})
456case $INITDIR in
457  prefix) INITDIR=$prefix;;
458  "")
459    AC_MSG_CHECKING(which init (rc) directory to use)
460      for initdir in /etc/init.d /etc/rc.d/init.d /sbin/init.d	\
461	   /usr/local/etc/rc.d /etc/rc.d
462      do
463        if
464          test -d $initdir
465        then
466          INITDIR=$initdir
467          break
468        fi
469      done
470      AC_MSG_RESULT($INITDIR);;
471esac
472AC_SUBST(INITDIR)
473
474AC_MSG_NOTICE(Sanitizing libdir: ${libdir})
475case $libdir in
476  dnl For consistency with Heartbeat, map NONE->$prefix
477  prefix|NONE)
478    AC_MSG_CHECKING(which lib directory to use)
479    for aDir in lib64 lib
480    do
481      trydir="${exec_prefix}/${aDir}"
482      if
483        test -d ${trydir}
484      then
485        libdir=${trydir}
486        break
487      fi
488    done
489    AC_MSG_RESULT($libdir);
490    ;;
491esac
492
493dnl Expand autoconf variables so that we don't end up with '${prefix}'
494dnl in #defines and python scripts
495dnl NOTE: Autoconf deliberately leaves them unexpanded to allow
496dnl    make exec_prefix=/foo install
497dnl No longer being able to do this seems like no great loss to me...
498
499eval prefix="`eval echo ${prefix}`"
500eval exec_prefix="`eval echo ${exec_prefix}`"
501eval bindir="`eval echo ${bindir}`"
502eval sbindir="`eval echo ${sbindir}`"
503eval libexecdir="`eval echo ${libexecdir}`"
504eval datadir="`eval echo ${datadir}`"
505eval sysconfdir="`eval echo ${sysconfdir}`"
506eval sharedstatedir="`eval echo ${sharedstatedir}`"
507eval localstatedir="`eval echo ${localstatedir}`"
508eval libdir="`eval echo ${libdir}`"
509eval includedir="`eval echo ${includedir}`"
510eval oldincludedir="`eval echo ${oldincludedir}`"
511eval infodir="`eval echo ${infodir}`"
512eval mandir="`eval echo ${mandir}`"
513
514dnl Home-grown variables
515
516if [ test "x${runstatedir}" = "x" ]; then
517    if [ test "x${pcmk_runstatedir}" = "x" ]; then
518        runstatedir="${localstatedir}/run"
519    else
520        runstatedir="${pcmk_runstatedir}"
521    fi
522fi
523eval runstatedir="$(eval echo ${runstatedir})"
524AC_DEFINE_UNQUOTED([PCMK_RUN_DIR], ["$runstatedir"],
525		   [Location for modifiable per-process data])
526AC_SUBST(runstatedir)
527
528eval INITDIR="${INITDIR}"
529eval docdir="`eval echo ${docdir}`"
530if test x"${docdir}" = x""; then
531   docdir=${datadir}/doc/${PACKAGE}-${VERSION}
532   #docdir=${datadir}/doc/packages/${PACKAGE}
533fi
534AC_SUBST(docdir)
535if test x"${CONFIGDIR}" = x""; then
536    CONFIGDIR="${sysconfdir}/sysconfig"
537fi
538AC_SUBST(CONFIGDIR)
539
540if test x"${BUG_URL}" = x""; then
541    BUG_URL="https://bugs.clusterlabs.org/enter_bug.cgi?product=Pacemaker"
542fi
543AC_SUBST(BUG_URL)
544
545
546if test x"${PCMK_GNUTLS_PRIORITIES}" = x""; then
547    AC_MSG_ERROR([Empty string not applicable with --with-gnutls-priorities])
548fi
549AC_DEFINE_UNQUOTED([PCMK_GNUTLS_PRIORITIES], ["$PCMK_GNUTLS_PRIORITIES"],
550                   [GnuTLS cipher priorities])
551
552for j in prefix exec_prefix bindir sbindir libexecdir datadir sysconfdir \
553    sharedstatedir localstatedir libdir includedir oldincludedir infodir \
554    mandir INITDIR docdir CONFIGDIR
555do
556  dirname=`eval echo '${'${j}'}'`
557  if
558    test ! -d "$dirname"
559  then
560    AC_MSG_WARN([$j directory ($dirname) does not exist!])
561  fi
562done
563
564us_auth=
565AC_CHECK_HEADER([sys/socket.h], [
566    AC_CHECK_DECL([SO_PEERCRED], [
567        # Linux
568        AC_CHECK_TYPE([struct ucred], [
569            us_auth=peercred_ucred;
570            AC_DEFINE([US_AUTH_PEERCRED_UCRED], [1],
571                      [Define if Unix socket auth method is
572                       getsockopt(s, SO_PEERCRED, &ucred, ...)])
573        ], [
574            # OpenBSD
575            AC_CHECK_TYPE([struct sockpeercred], [
576                us_auth=localpeercred_sockepeercred;
577                AC_DEFINE([US_AUTH_PEERCRED_SOCKPEERCRED], [1],
578                          [Define if Unix socket auth method is
579                           getsockopt(s, SO_PEERCRED, &sockpeercred, ...)])
580            ], [], [[#include <sys/socket.h>]])
581        ], [[#define _GNU_SOURCE
582             #include <sys/socket.h>]])
583    ], [], [[#include <sys/socket.h>]])
584])
585
586if test -z "${us_auth}"; then
587    # FreeBSD
588    AC_CHECK_DECL([getpeereid], [
589        us_auth=getpeereid;
590        AC_DEFINE([US_AUTH_GETPEEREID], [1],
591                  [Define if Unix socket auth method is
592                   getpeereid(s, &uid, &gid)])
593    ], [
594        # Solaris/OpenIndiana
595        AC_CHECK_DECL([getpeerucred], [
596            us_auth=getpeerucred;
597            AC_DEFINE([US_AUTH_GETPEERUCRED], [1],
598                      [Define if Unix socket auth method is
599                       getpeercred(s, &ucred)])
600        ], [
601            AC_MSG_ERROR([No way to authenticate a Unix socket peer])
602        ], [[#include <ucred.h>]])
603    ])
604fi
605
606dnl This OS-based decision-making is poor autotools practice;
607dnl feature-based mechanisms are strongly preferred.
608dnl
609dnl So keep this section to a bare minimum; regard as a "necessary evil".
610
611case "$host_os" in
612*bsd*|*dragonfly*)
613		AC_DEFINE_UNQUOTED(ON_BSD, 1, Compiling for BSD platform)
614		LIBS="-L/usr/local/lib"
615		CPPFLAGS="$CPPFLAGS -I/usr/local/include"
616		INIT_EXT=".sh"
617		;;
618*solaris*)
619		AC_DEFINE_UNQUOTED(ON_SOLARIS, 1, Compiling for Solaris platform)
620		;;
621*linux*)
622		AC_DEFINE_UNQUOTED(ON_LINUX, 1, Compiling for Linux platform)
623 		;;
624darwin*)
625		AC_DEFINE_UNQUOTED(ON_DARWIN, 1, Compiling for Darwin platform)
626  		LIBS="$LIBS -L${prefix}/lib"
627  		CFLAGS="$CFLAGS -I${prefix}/include"
628		;;
629esac
630
631dnl Eventually remove this
632if test "$cross_compiling" != "yes"; then
633   CPPFLAGS="$CPPFLAGS -I${prefix}/include/heartbeat"
634fi
635
636AC_SUBST(INIT_EXT)
637AC_MSG_NOTICE(Host CPU: $host_cpu)
638
639case "$host_cpu" in
640  ppc64|powerpc64)
641    case $CFLAGS in
642     *powerpc64*)			;;
643     *)	if test "$GCC" = yes; then
644	  CFLAGS="$CFLAGS -m64"
645	fi				;;
646    esac
647esac
648
649AC_MSG_CHECKING(which format is needed to print uint64_t)
650
651ac_save_CFLAGS=$CFLAGS
652CFLAGS="-Wall -Werror"
653
654AC_COMPILE_IFELSE(
655    [AC_LANG_PROGRAM(
656      [
657#include <stdio.h>
658#include <stdint.h>
659#include <stdlib.h>
660      ],
661      [
662int max = 512;
663uint64_t bignum = 42;
664char *buffer = malloc(max);
665const char *random = "random";
666snprintf(buffer, max-1, "<quorum id=%lu quorate=%s/>", bignum, random);
667fprintf(stderr, "Result: %s\n", buffer);
668      ]
669    )],
670    [U64T="%lu"],
671    [U64T="%llu"]
672)
673CFLAGS=$ac_save_CFLAGS
674
675AC_MSG_RESULT($U64T)
676AC_DEFINE_UNQUOTED(U64T, "$U64T", Correct printf format for logging uint64_t)
677
678dnl ===============================================
679dnl Program Paths
680dnl ===============================================
681
682PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin"
683export PATH
684
685
686dnl Replacing AC_PROG_LIBTOOL with AC_CHECK_PROG because LIBTOOL
687dnl was NOT being expanded all the time thus causing things to fail.
688AC_CHECK_PROGS(LIBTOOL, glibtool libtool libtool15 libtool13)
689
690AM_PATH_PYTHON
691AC_CHECK_PROGS(MAKE, gmake make)
692AC_PATH_PROGS(HTML2TXT, lynx w3m)
693AC_PATH_PROGS(HELP2MAN, help2man)
694AC_PATH_PROGS(POD2MAN, pod2man, pod2man)
695AC_PATH_PROGS([ASCIIDOC_CONV], [asciidoc asciidoctor])
696AC_PATH_PROGS(PUBLICAN, publican)
697AC_PATH_PROGS(INKSCAPE, inkscape)
698AC_PATH_PROGS(XSLTPROC, xsltproc)
699AC_PATH_PROGS(XMLCATALOG, xmlcatalog)
700AC_PATH_PROGS(FOP, fop)
701AC_PATH_PROGS(SSH, ssh, /usr/bin/ssh)
702AC_PATH_PROGS(SCP, scp, /usr/bin/scp)
703AC_PATH_PROGS(TAR, tar)
704AC_PATH_PROGS(MD5, md5)
705AC_PATH_PROGS(TEST, test)
706PKG_PROG_PKG_CONFIG
707AC_PATH_PROGS(XML2CONFIG, xml2-config)
708AC_PATH_PROGS(VALGRIND_BIN, valgrind, /usr/bin/valgrind)
709AC_DEFINE_UNQUOTED(VALGRIND_BIN, "$VALGRIND_BIN", Valgrind command)
710
711dnl Disable these until we decide if the stonith config file should be supported
712dnl AC_PATH_PROGS(BISON, bison)
713dnl AC_PATH_PROGS(FLEX, flex)
714dnl AC_PATH_PROGS(HAVE_YACC, $YACC)
715
716if test x"${LIBTOOL}" = x""; then
717   AC_MSG_ERROR(You need (g)libtool installed in order to build ${PACKAGE})
718fi
719if test x"${MAKE}" = x""; then
720   AC_MSG_ERROR(You need (g)make installed in order to build ${PACKAGE})
721fi
722
723AM_CONDITIONAL(BUILD_HELP, test x"${HELP2MAN}" != x"")
724if test x"${HELP2MAN}" != x""; then
725   PCMK_FEATURES="$PCMK_FEATURES generated-manpages"
726fi
727
728MANPAGE_XSLT=""
729if test x"${XSLTPROC}" != x""; then
730  AC_MSG_CHECKING(docbook to manpage transform)
731  # first try to figure out correct template using xmlcatalog query,
732  # resort to extensive (semi-deterministic) file search if that fails
733  DOCBOOK_XSL_URI='http://docbook.sourceforge.net/release/xsl/current'
734  DOCBOOK_XSL_PATH='manpages/docbook.xsl'
735  MANPAGE_XSLT=$(${XMLCATALOG} "" ${DOCBOOK_XSL_URI}/${DOCBOOK_XSL_PATH} \
736                 | sed -n 's|^file://||p;q')
737  if test x"${MANPAGE_XSLT}" = x""; then
738    DIRS=$(find "${datadir}" -name $(basename $(dirname ${DOCBOOK_XSL_PATH})) \
739           -type d | LC_ALL=C sort)
740    XSLT=$(basename ${DOCBOOK_XSL_PATH})
741    for d in ${DIRS}; do
742      if test -f "${d}/${XSLT}"; then
743         MANPAGE_XSLT="${d}/${XSLT}"
744         break
745      fi
746    done
747  fi
748fi
749AC_MSG_RESULT($MANPAGE_XSLT)
750AC_SUBST(MANPAGE_XSLT)
751
752AM_CONDITIONAL(BUILD_XML_HELP, test x"${MANPAGE_XSLT}" != x"")
753if test x"${MANPAGE_XSLT}" != x""; then
754   PCMK_FEATURES="$PCMK_FEATURES agent-manpages"
755fi
756
757AM_CONDITIONAL([IS_ASCIIDOC], [echo "${ASCIIDOC_CONV}" | grep -Eq 'asciidoc$'])
758AM_CONDITIONAL([BUILD_ASCIIDOC], [test "x${ASCIIDOC_CONV}" != x])
759if test "x${ASCIIDOC_CONV}" != x; then
760   PCMK_FEATURES="$PCMK_FEATURES ascii-docs"
761fi
762
763SUPPORT_STONITH_CONFIG=0
764if test x"${HAVE_YACC}" != x"" -a x"${FLEX}" != x"" -a x"${BISON}" != x""; then
765   SUPPORT_STONITH_CONFIG=1
766   PCMK_FEATURES="$PCMK_FEATURES st-conf"
767fi
768
769AM_CONDITIONAL(BUILD_STONITH_CONFIG, test $SUPPORT_STONITH_CONFIG = 1)
770AC_DEFINE_UNQUOTED(SUPPORT_STONITH_CONFIG, $SUPPORT_STONITH_CONFIG, Support a stand-alone stonith config file in addition to the CIB)
771
772publican_intree_brand=no
773if test x"${PUBLICAN_BRAND}" != x"" \
774   && test x"${PUBLICAN}" != x"" \
775   && test x"${INKSCAPE}" != x""; then
776   dnl special handling for clusterlabs brand (possibly in-tree version used)
777   test "${PUBLICAN_BRAND}" != "clusterlabs" \
778      || test -d /usr/share/publican/Common_Content/clusterlabs
779   if test $? -ne 0; then
780      dnl Unknown option: brand_dir vs. Option brand_dir requires an argument
781      if ${PUBLICAN} build --brand_dir 2>&1 | grep -Eq 'brand_dir$'; then
782         AC_MSG_WARN([Cannot use in-tree clusterlabs brand, resorting to common])
783         PUBLICAN_BRAND=common
784      else
785         publican_intree_brand=yes
786      fi
787   fi
788   AC_MSG_NOTICE([Enabling Publican-generated documentation using ${PUBLICAN_BRAND} brand])
789   PCMK_FEATURES="$PCMK_FEATURES publican-docs"
790fi
791AM_CONDITIONAL([BUILD_DOCBOOK],
792               [test x"${PUBLICAN_BRAND}" != x"" \
793                && test x"${PUBLICAN}" != x"" \
794                && test x"${INKSCAPE}" != x""])
795AM_CONDITIONAL([PUBLICAN_INTREE_BRAND],
796               [test x"${publican_intree_brand}" = x"yes"])
797
798dnl ========================================================================
799dnl checks for library functions to replace them
800dnl
801dnl     NoSuchFunctionName:
802dnl             is a dummy function which no system supplies.  It is here to make
803dnl             the system compile semi-correctly on OpenBSD which doesn't know
804dnl             how to create an empty archive
805dnl
806dnl     scandir: Only on BSD.
807dnl             System-V systems may have it, but hidden and/or deprecated.
808dnl             A replacement function is supplied for it.
809dnl
810dnl     setenv: is some bsdish function that should also be avoided (use
811dnl             putenv instead)
812dnl             On the other hand, putenv doesn't provide the right API for the
813dnl             code and has memory leaks designed in (sigh...)  Fortunately this
814dnl             A replacement function is supplied for it.
815dnl
816dnl     strerror: returns a string that corresponds to an errno.
817dnl             A replacement function is supplied for it.
818dnl
819dnl	strnlen: is a gnu function similar to strlen, but safer.
820dnl		We wrote a tolearably-fast replacement function for it.
821dnl
822dnl	strndup: is a gnu function similar to strdup, but safer.
823dnl		We wrote a tolearably-fast replacement function for it.
824
825AC_REPLACE_FUNCS(alphasort NoSuchFunctionName scandir setenv strerror strchrnul unsetenv strnlen strndup)
826
827dnl ===============================================
828dnl Libraries
829dnl ===============================================
830AC_CHECK_LIB(socket, socket)			dnl -lsocket
831AC_CHECK_LIB(c, dlopen)				dnl if dlopen is in libc...
832AC_CHECK_LIB(dl, dlopen)			dnl -ldl (for Linux)
833AC_CHECK_LIB(rt, sched_getscheduler)            dnl -lrt (for Tru64)
834AC_CHECK_LIB(gnugetopt, getopt_long)		dnl -lgnugetopt ( if available )
835AC_CHECK_LIB(pam, pam_start)			dnl -lpam (if available)
836
837AC_CHECK_FUNCS([sched_setscheduler])
838
839AC_CHECK_LIB(uuid, uuid_parse)			dnl load the library if necessary
840AC_CHECK_FUNCS(uuid_unparse)			dnl OSX ships uuid_* as standard functions
841
842AC_CHECK_HEADERS(uuid/uuid.h)
843
844if test "x$ac_cv_func_uuid_unparse" != xyes; then
845   AC_MSG_ERROR(You do not have the libuuid development package installed)
846fi
847
848if test x"${PKG_CONFIG}" = x""; then
849   AC_MSG_ERROR(You need pkgconfig installed in order to build ${PACKAGE})
850fi
851
852if
853   $PKG_CONFIG --exists glib-2.0
854then
855	GLIBCONFIG="$PKG_CONFIG glib-2.0"
856else
857	set -x
858        echo PKG_CONFIG_PATH=$PKG_CONFIG_PATH
859	$PKG_CONFIG --exists glib-2.0; echo $?
860	$PKG_CONFIG --cflags glib-2.0; echo $?
861	$PKG_CONFIG glib-2.0; echo $?
862	set +x
863
864	AC_MSG_ERROR(You need glib2-devel installed in order to build ${PACKAGE})
865fi
866AC_MSG_RESULT(using $GLIBCONFIG)
867
868#
869#	Where is dlopen?
870#
871if test "$ac_cv_lib_c_dlopen" = yes; then
872	LIBADD_DL=""
873elif test "$ac_cv_lib_dl_dlopen" = yes; then
874	LIBADD_DL=-ldl
875else
876        LIBADD_DL=${lt_cv_dlopen_libs}
877fi
878
879if test "X$GLIBCONFIG" != X; then
880	AC_MSG_CHECKING(for special glib includes: )
881	GLIBHEAD=`$GLIBCONFIG --cflags`
882	AC_MSG_RESULT($GLIBHEAD)
883	CPPFLAGS="$CPPFLAGS $GLIBHEAD"
884
885	AC_MSG_CHECKING(for glib library flags)
886	GLIBLIB=`$GLIBCONFIG --libs`
887	AC_MSG_RESULT($GLIBLIB)
888	LIBS="$LIBS $GLIBLIB"
889fi
890
891dnl FreeBSD needs -lcompat for ftime() used by lrmd.c
892AC_CHECK_LIB([compat], [ftime], [COMPAT_LIBS='-lcompat'])
893AC_SUBST(COMPAT_LIBS)
894
895dnl ========================================================================
896dnl Headers
897dnl ========================================================================
898
899AC_HEADER_STDC
900AC_CHECK_HEADERS(arpa/inet.h)
901AC_CHECK_HEADERS(asm/types.h)
902AC_CHECK_HEADERS(assert.h)
903AC_CHECK_HEADERS(auth-client.h)
904AC_CHECK_HEADERS(ctype.h)
905AC_CHECK_HEADERS(dirent.h)
906AC_CHECK_HEADERS(errno.h)
907AC_CHECK_HEADERS(fcntl.h)
908AC_CHECK_HEADERS(getopt.h)
909AC_CHECK_HEADERS(glib.h)
910AC_CHECK_HEADERS(grp.h)
911AC_CHECK_HEADERS(limits.h)
912AC_CHECK_HEADERS(linux/errqueue.h)
913AC_CHECK_HEADERS(linux/swab.h)
914AC_CHECK_HEADERS(malloc.h)
915AC_CHECK_HEADERS(netdb.h)
916AC_CHECK_HEADERS(netinet/in.h)
917AC_CHECK_HEADERS(netinet/ip.h)
918AC_CHECK_HEADERS(pam/pam_appl.h)
919AC_CHECK_HEADERS(pthread.h)
920AC_CHECK_HEADERS(pwd.h)
921AC_CHECK_HEADERS(security/pam_appl.h)
922AC_CHECK_HEADERS(sgtty.h)
923AC_CHECK_HEADERS(signal.h)
924AC_CHECK_HEADERS(stdarg.h)
925AC_CHECK_HEADERS(stddef.h)
926AC_CHECK_HEADERS(stdio.h)
927AC_CHECK_HEADERS(stdlib.h)
928AC_CHECK_HEADERS(string.h)
929AC_CHECK_HEADERS(strings.h)
930AC_CHECK_HEADERS(sys/dir.h)
931AC_CHECK_HEADERS(sys/ioctl.h)
932AC_CHECK_HEADERS(sys/param.h)
933AC_CHECK_HEADERS(sys/poll.h)
934AC_CHECK_HEADERS(sys/reboot.h)
935AC_CHECK_HEADERS(sys/resource.h)
936AC_CHECK_HEADERS(sys/select.h)
937AC_CHECK_HEADERS(sys/socket.h)
938AC_CHECK_HEADERS(sys/signalfd.h)
939AC_CHECK_HEADERS(sys/sockio.h)
940AC_CHECK_HEADERS(sys/stat.h)
941AC_CHECK_HEADERS(sys/time.h)
942AC_CHECK_HEADERS(sys/timeb.h)
943AC_CHECK_HEADERS(sys/types.h)
944AC_CHECK_HEADERS(sys/uio.h)
945AC_CHECK_HEADERS(sys/un.h)
946AC_CHECK_HEADERS(sys/utsname.h)
947AC_CHECK_HEADERS(sys/wait.h)
948AC_CHECK_HEADERS(time.h)
949AC_CHECK_HEADERS(unistd.h)
950AC_CHECK_HEADERS(winsock.h)
951
952dnl These headers need prerequisits before the tests will pass
953dnl AC_CHECK_HEADERS(net/if.h)
954dnl AC_CHECK_HEADERS(netinet/icmp6.h)
955dnl AC_CHECK_HEADERS(netinet/ip6.h)
956dnl AC_CHECK_HEADERS(netinet/ip_icmp.h)
957
958AC_MSG_CHECKING(for special libxml2 includes)
959if test "x$XML2CONFIG" = "x"; then
960   AC_MSG_ERROR(libxml2 config not found)
961else
962   XML2HEAD="`$XML2CONFIG --cflags`"
963   AC_MSG_RESULT($XML2HEAD)
964   AC_CHECK_LIB(xml2, xmlReadMemory)
965   AC_CHECK_LIB(xslt, xsltApplyStylesheet)
966fi
967
968CPPFLAGS="$CPPFLAGS $XML2HEAD"
969
970AC_CHECK_HEADERS(libxml/xpath.h)
971AC_CHECK_HEADERS(libxslt/xslt.h)
972if test "$ac_cv_header_libxml_xpath_h" != "yes"; then
973   AC_MSG_ERROR(The libxml developement headers were not found)
974fi
975if test "$ac_cv_header_libxslt_xslt_h" != "yes"; then
976   AC_MSG_ERROR(The libxslt developement headers were not found)
977fi
978
979AC_CACHE_CHECK(whether __progname and __progname_full are available,
980                pf_cv_var_progname,
981                AC_TRY_LINK([extern char *__progname, *__progname_full;],
982                    [__progname = "foo"; __progname_full = "foo bar";],
983                    pf_cv_var_progname="yes", pf_cv_var_progname="no"))
984
985if test "$pf_cv_var_progname" = "yes"; then
986    AC_DEFINE(HAVE___PROGNAME,1,[ ])
987fi
988
989dnl ========================================================================
990dnl Structures
991dnl ========================================================================
992
993AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,[[#include <time.h>]])
994AC_CHECK_MEMBERS([lrm_op_t.rsc_deleted],,,[[#include <lrm/lrm_api.h>]])
995AC_CHECK_MEMBER([struct dirent.d_type],
996    AC_DEFINE(HAVE_STRUCT_DIRENT_D_TYPE,1,[Define this if struct dirent has d_type]),,
997    [#include <dirent.h>])
998
999dnl ========================================================================
1000dnl Functions
1001dnl ========================================================================
1002
1003AC_CHECK_FUNCS(g_log_set_default_handler)
1004AC_CHECK_FUNCS(getopt, AC_DEFINE(HAVE_DECL_GETOPT,  1, [Have getopt function]))
1005AC_CHECK_FUNCS(nanosleep, AC_DEFINE(HAVE_DECL_NANOSLEEP,  1, [Have nanosleep function]))
1006
1007dnl ========================================================================
1008dnl   bzip2
1009dnl ========================================================================
1010AC_CHECK_HEADERS(bzlib.h)
1011AC_CHECK_LIB(bz2, BZ2_bzBuffToBuffCompress)
1012
1013if test x$ac_cv_lib_bz2_BZ2_bzBuffToBuffCompress != xyes ; then
1014   AC_MSG_ERROR(BZ2 libraries not found)
1015fi
1016
1017if test x$ac_cv_header_bzlib_h != xyes; then
1018   AC_MSG_ERROR(BZ2 Development headers not found)
1019fi
1020
1021dnl ========================================================================
1022dnl sighandler_t is missing from Illumos, Solaris11 systems
1023dnl ========================================================================
1024
1025AC_MSG_CHECKING([for sighandler_t])
1026AC_TRY_COMPILE([#include <signal.h>],[sighandler_t *f;],
1027has_sighandler_t=yes,has_sighandler_t=no)
1028AC_MSG_RESULT($has_sighandler_t)
1029if test "$has_sighandler_t" = "yes" ; then
1030    AC_DEFINE( HAVE_SIGHANDLER_T, 1, [Define if sighandler_t available] )
1031fi
1032
1033dnl ========================================================================
1034dnl   ncurses
1035dnl ========================================================================
1036dnl
1037dnl A few OSes (e.g. Linux) deliver a default "ncurses" alongside "curses".
1038dnl Many non-Linux deliver "curses"; sites may add "ncurses".
1039dnl
1040dnl However, the source-code recommendation for both is to #include "curses.h"
1041dnl (i.e. "ncurses" still wants the include to be simple, no-'n', "curses.h").
1042dnl
1043dnl ncurse takes precedence.
1044dnl
1045AC_CHECK_HEADERS(curses.h)
1046AC_CHECK_HEADERS(curses/curses.h)
1047AC_CHECK_HEADERS(ncurses.h)
1048AC_CHECK_HEADERS(ncurses/ncurses.h)
1049
1050dnl Although n-library is preferred, only look for it if the n-header was found.
1051CURSESLIBS=''
1052if test "$ac_cv_header_ncurses_h" = "yes"; then
1053  AC_CHECK_LIB(ncurses, printw,
1054    [AC_DEFINE(HAVE_LIBNCURSES,1, have ncurses library)]
1055  )
1056  CURSESLIBS=`$PKG_CONFIG --libs ncurses` || CURSESLIBS='-lncurses'
1057fi
1058
1059if test "$ac_cv_header_ncurses_ncurses_h" = "yes"; then
1060  AC_CHECK_LIB(ncurses, printw,
1061    [AC_DEFINE(HAVE_LIBNCURSES,1, have ncurses library)]
1062  )
1063  CURSESLIBS=`$PKG_CONFIG --libs ncurses` || CURSESLIBS='-lncurses'
1064fi
1065
1066dnl Only look for non-n-library if there was no n-library.
1067if test X"$CURSESLIBS" = X"" -a "$ac_cv_header_curses_h" = "yes"; then
1068  AC_CHECK_LIB(curses, printw,
1069    [CURSESLIBS='-lcurses'; AC_DEFINE(HAVE_LIBCURSES,1, have curses library)]
1070  )
1071fi
1072
1073dnl Only look for non-n-library if there was no n-library.
1074if test X"$CURSESLIBS" = X"" -a "$ac_cv_header_curses_curses_h" = "yes"; then
1075  AC_CHECK_LIB(curses, printw,
1076    [CURSESLIBS='-lcurses'; AC_DEFINE(HAVE_LIBCURSES,1, have curses library)]
1077  )
1078fi
1079
1080if test "x$CURSESLIBS" != "x"; then
1081   PCMK_FEATURES="$PCMK_FEATURES ncurses"
1082fi
1083
1084dnl Check for printw() prototype compatibility
1085if test X"$CURSESLIBS" != X"" && cc_supports_flag -Wcast-qual && cc_supports_flag -Werror; then
1086    ac_save_LIBS=$LIBS
1087    LIBS="$CURSESLIBS"
1088    ac_save_CFLAGS=$CFLAGS
1089    CFLAGS="-Wcast-qual -Werror"
1090    # avoid broken test because of hardened build environment in Fedora 23+
1091    # - https://fedoraproject.org/wiki/Changes/Harden_All_Packages
1092    # - https://bugzilla.redhat.com/1297985
1093    if cc_supports_flag -fPIC; then
1094        CFLAGS="$CFLAGS -fPIC"
1095    fi
1096
1097    AC_MSG_CHECKING(whether printw() requires argument of "const char *")
1098    AC_LINK_IFELSE(
1099	    [AC_LANG_PROGRAM(
1100	      [
1101#if defined(HAVE_NCURSES_H)
1102#  include <ncurses.h>
1103#elif defined(HAVE_NCURSES_NCURSES_H)
1104#  include <ncurses/ncurses.h>
1105#elif defined(HAVE_CURSES_H)
1106#  include <curses.h>
1107#endif
1108	      ],
1109	      [printw((const char *)"Test");]
1110	    )],
1111	    [ac_cv_compatible_printw=yes],
1112	    [ac_cv_compatible_printw=no]
1113    )
1114
1115    LIBS=$ac_save_LIBS
1116    CFLAGS=$ac_save_CFLAGS
1117
1118    AC_MSG_RESULT([$ac_cv_compatible_printw])
1119
1120    if test "$ac_cv_compatible_printw" = no; then
1121		AC_MSG_WARN([The printw() function of your ncurses or curses library is old, we will disable usage of the library. If you want to use this library anyway, please update to newer version of the library, ncurses 5.4 or later is recommended. You can get the library from http://www.gnu.org/software/ncurses/.])
1122		AC_MSG_NOTICE([Disabling curses])
1123		AC_DEFINE(HAVE_INCOMPATIBLE_PRINTW, 1, [Do we have incompatible printw() in curses library?])
1124    fi
1125fi
1126
1127AC_SUBST(CURSESLIBS)
1128
1129dnl ========================================================================
1130dnl    Profiling and GProf
1131dnl ========================================================================
1132
1133AC_MSG_NOTICE(Old CFLAGS: $CFLAGS)
1134case $SUPPORT_COVERAGE in
1135     1|yes|true)
1136	SUPPORT_PROFILING=1
1137	PCMK_FEATURES="$PCMK_FEATURES coverage"
1138	CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
1139	dnl During linking, make sure to specify -lgcov or -coverage
1140
1141        dnl Enable gprof
1142	#LIBS="$LIBS -pg"
1143	#CFLAGS="$CFLAGS -pg"
1144	;;
1145esac
1146
1147case $SUPPORT_PROFILING in
1148     1|yes|true)
1149	SUPPORT_PROFILING=1
1150
1151	dnl Disable various compiler optimizations
1152	CFLAGS="$CFLAGS -fno-omit-frame-pointer -fno-inline -fno-builtin "
1153	dnl CFLAGS="$CFLAGS -fno-inline-functions -fno-default-inline -fno-inline-functions-called-once -fno-optimize-sibling-calls"
1154
1155	dnl Turn off optimization so tools can get accurate line numbers
1156	CFLAGS=`echo $CFLAGS | sed -e 's/-O.\ //g' -e 's/-Wp,-D_FORTIFY_SOURCE=.\ //g' -e 's/-D_FORTIFY_SOURCE=.\ //g'`
1157	CFLAGS="$CFLAGS -O0 -g3 -gdwarf-2"
1158
1159	dnl Update features
1160	PCMK_FEATURES="$PCMK_FEATURES profile"
1161	;;
1162     *) SUPPORT_PROFILING=0;;
1163esac
1164AC_MSG_NOTICE(New CFLAGS: $CFLAGS)
1165AC_DEFINE_UNQUOTED(SUPPORT_PROFILING, $SUPPORT_PROFILING, Support for profiling)
1166
1167dnl ========================================================================
1168dnl    Cluster infrastructure - Heartbeat / LibQB
1169dnl ========================================================================
1170
1171dnl Compatibility checks
1172AC_CHECK_MEMBERS([struct lrm_ops.fail_rsc],,,[[#include <lrm/lrm_api.h>]])
1173
1174if test x${enable_no_stack} = xyes; then
1175    SUPPORT_HEARTBEAT=no
1176    SUPPORT_CS=no
1177fi
1178
1179PKG_CHECK_MODULES(libqb, libqb >= 0.13)
1180CPPFLAGS="$libqb_CFLAGS $CPPFLAGS"
1181LIBS="$libqb_LIBS $LIBS"
1182AC_CHECK_HEADERS(qb/qbipc_common.h)
1183AC_CHECK_LIB(qb, qb_ipcs_connection_auth_set)
1184
1185PCMK_FEATURES="$PCMK_FEATURES libqb-logging libqb-ipc"
1186
1187AC_CHECK_FUNCS(qb_ipcs_connection_get_buffer_size, AC_DEFINE(HAVE_IPCS_GET_BUFFER_SIZE,  1, [Have qb_ipcc_get_buffer_size function]))
1188
1189
1190AC_CHECK_HEADERS(heartbeat/hb_config.h)
1191AC_CHECK_HEADERS(heartbeat/glue_config.h)
1192AC_CHECK_HEADERS(stonith/stonith.h)
1193AC_CHECK_HEADERS(agent_config.h)
1194
1195GLUE_HEADER=none
1196HAVE_GLUE=0
1197if test "$ac_cv_header_heartbeat_glue_config_h" = "yes";  then
1198   GLUE_HEADER=glue_config.h
1199   HAVE_GLUE=1
1200
1201elif test "$ac_cv_header_heartbeat_hb_config_h" = "yes"; then
1202   GLUE_HEADER=hb_config.h
1203   HAVE_GLUE=1
1204else
1205   AC_MSG_WARN(cluster-glue development headers were not found)
1206fi
1207
1208if test "$ac_cv_header_stonith_stonith_h" = "yes";  then
1209   PCMK_FEATURES="$PCMK_FEATURES lha-fencing"
1210fi
1211AM_CONDITIONAL([BUILD_LHA_SUPPORT], [test "$ac_cv_header_stonith_stonith_h" = "yes"])
1212
1213if test $HAVE_GLUE = 1; then
1214   dnl On Debian, AC_CHECK_LIBS fail if a library has any unresolved symbols
1215   dnl So check for all the dependencies (so they're added to LIBS) before checking for -lplumb
1216   AC_CHECK_LIB(pils, PILLoadPlugin)
1217   AC_CHECK_LIB(plumb, G_main_add_IPC_Channel)
1218fi
1219
1220dnl ===============================================
1221dnl Variables needed for substitution
1222dnl ===============================================
1223CRM_DTD_DIRECTORY="${datadir}/pacemaker"
1224AC_DEFINE_UNQUOTED(CRM_DTD_DIRECTORY,"$CRM_DTD_DIRECTORY", Location for the Pacemaker Relax-NG Schema)
1225AC_SUBST(CRM_DTD_DIRECTORY)
1226
1227CRM_CORE_DIR=`try_extract_header_define $GLUE_HEADER HA_COREDIR ${localstatedir}/lib/pacemaker/cores`
1228AC_DEFINE_UNQUOTED(CRM_CORE_DIR,"$CRM_CORE_DIR", Location to store core files produced by Pacemaker daemons)
1229AC_SUBST(CRM_CORE_DIR)
1230
1231if test x"${CRM_DAEMON_USER}" = x""; then
1232    CRM_DAEMON_USER=`try_extract_header_define $GLUE_HEADER HA_CCMUSER hacluster`
1233fi
1234AC_DEFINE_UNQUOTED(CRM_DAEMON_USER,"$CRM_DAEMON_USER", User to run Pacemaker daemons as)
1235AC_SUBST(CRM_DAEMON_USER)
1236
1237if test x"${CRM_DAEMON_GROUP}" = x""; then
1238    CRM_DAEMON_GROUP=`try_extract_header_define $GLUE_HEADER HA_APIGROUP haclient`
1239fi
1240AC_DEFINE_UNQUOTED(CRM_DAEMON_GROUP,"$CRM_DAEMON_GROUP", Group to run Pacemaker daemons as)
1241AC_SUBST(CRM_DAEMON_GROUP)
1242
1243CRM_LOG_DIR="${localstatedir}/log/pacemaker"
1244AC_DEFINE_UNQUOTED(CRM_LOG_DIR,"$CRM_LOG_DIR", Where Pacemaker can store log files)
1245AC_SUBST(CRM_LOG_DIR)
1246
1247CRM_PACEMAKER_DIR=${localstatedir}/lib/pacemaker
1248AC_DEFINE_UNQUOTED(CRM_PACEMAKER_DIR,"$CRM_PACEMAKER_DIR", Location to store directory produced by Pacemaker daemons)
1249AC_SUBST(CRM_PACEMAKER_DIR)
1250
1251CRM_BLACKBOX_DIR=${localstatedir}/lib/pacemaker/blackbox
1252AC_DEFINE_UNQUOTED(CRM_BLACKBOX_DIR,"$CRM_BLACKBOX_DIR", Where to keep blackbox dumps)
1253AC_SUBST(CRM_BLACKBOX_DIR)
1254
1255PE_STATE_DIR="${localstatedir}/lib/pacemaker/pengine"
1256AC_DEFINE_UNQUOTED(PE_STATE_DIR,"$PE_STATE_DIR", Where to keep PEngine outputs)
1257AC_SUBST(PE_STATE_DIR)
1258
1259CRM_CONFIG_DIR="${localstatedir}/lib/pacemaker/cib"
1260AC_DEFINE_UNQUOTED(CRM_CONFIG_DIR,"$CRM_CONFIG_DIR", Where to keep configuration files)
1261AC_SUBST(CRM_CONFIG_DIR)
1262
1263CRM_CONFIG_CTS="${localstatedir}/lib/pacemaker/cts"
1264AC_DEFINE_UNQUOTED(CRM_CONFIG_CTS,"$CRM_CONFIG_CTS", Where to keep cts stateful data)
1265AC_SUBST(CRM_CONFIG_CTS)
1266
1267CRM_LEGACY_CONFIG_DIR="${localstatedir}/lib/heartbeat/crm"
1268AC_DEFINE_UNQUOTED(CRM_LEGACY_CONFIG_DIR,"$CRM_LEGACY_CONFIG_DIR", Where Pacemaker used to keep configuration files)
1269AC_SUBST(CRM_LEGACY_CONFIG_DIR)
1270
1271CRM_DAEMON_DIR="${libexecdir}/pacemaker"
1272AC_DEFINE_UNQUOTED(CRM_DAEMON_DIR,"$CRM_DAEMON_DIR", Location for Pacemaker daemons)
1273AC_SUBST(CRM_DAEMON_DIR)
1274
1275HB_DAEMON_DIR=`try_extract_header_define $GLUE_HEADER HA_LIBHBDIR $libdir/heartbeat`
1276AC_DEFINE_UNQUOTED(HB_DAEMON_DIR,"$HB_DAEMON_DIR", Location Heartbeat expects Pacemaker daemons to be in)
1277AC_SUBST(HB_DAEMON_DIR)
1278
1279dnl Needed so that the Corosync plugin can clear out the directory as Heartbeat does
1280HA_STATE_DIR=`try_extract_header_define $GLUE_HEADER HA_VARRUNDIR ${runstatedir}`
1281AC_DEFINE_UNQUOTED(HA_STATE_DIR,"$HA_STATE_DIR", Where Heartbeat keeps state files and sockets)
1282AC_SUBST(HA_STATE_DIR)
1283
1284CRM_STATE_DIR="${runstatedir}/crm"
1285AC_DEFINE_UNQUOTED([CRM_STATE_DIR], ["$CRM_STATE_DIR"],
1286		   [Where to keep state files and sockets])
1287AC_SUBST(CRM_STATE_DIR)
1288
1289CRM_RSCTMP_DIR=`try_extract_header_define agent_config.h HA_RSCTMPDIR ${runstatedir}/resource-agents`
1290AC_MSG_CHECKING(Scratch dir for resource agents)
1291AC_MSG_RESULT($CRM_RSCTMP_DIR)
1292AC_DEFINE_UNQUOTED(CRM_RSCTMP_DIR,"$CRM_RSCTMP_DIR", Where resource agents should keep state files)
1293AC_SUBST(CRM_RSCTMP_DIR)
1294
1295dnl Needed for the location of hostcache in CTS.py
1296HA_VARLIBHBDIR=`try_extract_header_define $GLUE_HEADER HA_VARLIBHBDIR ${localstatedir}/lib/heartbeat`
1297AC_SUBST(HA_VARLIBHBDIR)
1298
1299AC_DEFINE_UNQUOTED(UUID_FILE,"$localstatedir/lib/heartbeat/hb_uuid", Location of Heartbeat's UUID file)
1300
1301if test "x$OCF_ROOT_DIR" = "x"; then
1302    OCF_ROOT_DIR=`try_extract_header_define $GLUE_HEADER OCF_ROOT_DIR /usr/local/lib/ocf`
1303fi
1304AC_SUBST(OCF_ROOT_DIR)
1305
1306OCF_RA_DIR=`try_extract_header_define $GLUE_HEADER OCF_RA_DIR $OCF_ROOT_DIR/resource.d`
1307AC_DEFINE_UNQUOTED(OCF_RA_DIR,"$OCF_RA_DIR", Location for OCF RAs)
1308AC_SUBST(OCF_RA_DIR)
1309
1310RH_STONITH_DIR="$sbindir"
1311AC_DEFINE_UNQUOTED(RH_STONITH_DIR,"$RH_STONITH_DIR", Location for Red Hat Stonith agents)
1312AC_DEFINE_UNQUOTED(SBIN_DIR,"$sbindir", Location for system binaries)
1313
1314RH_STONITH_PREFIX="fence_"
1315AC_DEFINE_UNQUOTED(RH_STONITH_PREFIX,"$RH_STONITH_PREFIX", Prefix for Red Hat Stonith agents)
1316
1317AC_PATH_PROGS(GIT, git false)
1318AC_MSG_CHECKING(build version)
1319
1320BUILD_VERSION=3850484742
1321if test $BUILD_VERSION != ":%h$"; then
1322   AC_MSG_RESULT(archive hash: $BUILD_VERSION)
1323
1324elif test -x $GIT -a -d .git; then
1325   BUILD_VERSION=`$GIT log --pretty="format:%h" -n 1`
1326   AC_MSG_RESULT(git hash: $BUILD_VERSION)
1327
1328else
1329   # The current directory name make a reasonable default
1330   # Most generated archives will include the hash or tag
1331   BASE=`basename $PWD`
1332   BUILD_VERSION=`echo $BASE | sed s:.*[[Pp]]acemaker-::`
1333   AC_MSG_RESULT(directory based hash: $BUILD_VERSION)
1334fi
1335
1336AC_DEFINE_UNQUOTED(BUILD_VERSION, "$BUILD_VERSION", Build version)
1337AC_SUBST(BUILD_VERSION)
1338
1339
1340HAVE_dbus=0
1341HAVE_upstart=0
1342HAVE_systemd=0
1343PKG_CHECK_MODULES(DBUS, dbus-1, ,HAVE_dbus=0)
1344
1345AC_DEFINE_UNQUOTED(SUPPORT_DBUS, $HAVE_dbus, Support dbus)
1346AM_CONDITIONAL(BUILD_DBUS, test $HAVE_dbus = 1)
1347
1348if test $HAVE_dbus = 1; then
1349   CFLAGS="$CFLAGS `$PKG_CONFIG --cflags dbus-1`"
1350fi
1351
1352DBUS_LIBS="$CFLAGS `$PKG_CONFIG --libs dbus-1`"
1353AC_SUBST(DBUS_LIBS)
1354
1355AC_CHECK_TYPES([DBusBasicValue],,,[[#include <dbus/dbus.h>]])
1356
1357if test "x${enable_systemd}" != xno; then
1358	if test $HAVE_dbus = 0; then
1359		if test "x${enable_systemd}" = xyes; then
1360			AC_MSG_FAILURE([cannot enable systemd without DBus])
1361		else
1362			enable_systemd=no
1363		fi
1364	fi
1365	if test "x${enable_systemd}" = xtry; then
1366		AC_MSG_CHECKING([for systemd version query result via dbus-send])
1367		ret=$({ dbus-send --system --print-reply \
1368		        --dest=org.freedesktop.systemd1 \
1369		        /org/freedesktop/systemd1 \
1370		        org.freedesktop.DBus.Properties.Get \
1371		        string:org.freedesktop.systemd1.Manager \
1372		        string:Version 2>/dev/null \
1373		        || echo "this borked"; } | tail -n1)
1374		# sanitize output a bit (interested just in value, not type),
1375		# ret is intentionally unenquoted so as to normalize whitespace
1376		ret=$(echo ${ret} | cut -d' ' -f2-)
1377		AC_MSG_RESULT([${ret}])
1378		if test "x${ret}" != xborked \
1379		   || systemctl --version 2>/dev/null | grep -q systemd; then
1380			enable_systemd=yes
1381		else
1382			enable_systemd=no
1383		fi
1384	fi
1385fi
1386
1387AC_MSG_CHECKING([whether to enable support for managing resources via systemd])
1388AC_MSG_RESULT([${enable_systemd}])
1389if test "x${enable_systemd}" = xyes; then
1390	HAVE_systemd=1
1391	PCMK_FEATURES="$PCMK_FEATURES systemd"
1392
1393    AC_MSG_CHECKING([which system unit file directory to use])
1394    PKG_CHECK_VAR([systemdsystemunitdir], [systemd], [systemdsystemunitdir])
1395    AC_MSG_RESULT([${systemdsystemunitdir}])
1396    if test "x${systemdsystemunitdir}" = x""; then
1397        AC_MSG_FAILURE([cannot enable systemd when systemdsystemunitdir unresolved])
1398	fi
1399fi
1400AC_SUBST([systemdsystemunitdir])
1401
1402AC_DEFINE_UNQUOTED(SUPPORT_SYSTEMD, $HAVE_systemd, Support systemd based system services)
1403AM_CONDITIONAL(BUILD_SYSTEMD, test $HAVE_systemd = 1)
1404AC_SUBST(SUPPORT_SYSTEMD)
1405
1406if test "x${enable_upstart}" != xno; then
1407	if test $HAVE_dbus = 0; then
1408		if test "x${enable_upstart}" = xyes; then
1409			AC_MSG_FAILURE([cannot enable Upstart without DBus])
1410		else
1411			enable_upstart=no
1412		fi
1413	fi
1414	if test "x${enable_upstart}" = xtry; then
1415		AC_MSG_CHECKING([for Upstart version query result via dbus-send])
1416		ret=$({ dbus-send --system --print-reply --dest=com.ubuntu.Upstart \
1417		        /com/ubuntu/Upstart org.freedesktop.DBus.Properties.Get \
1418		        string:com.ubuntu.Upstart0_6 string:version 2>/dev/null \
1419		        || echo "this borked"; } | tail -n1)
1420		# sanitize output a bit (interested just in value, not type),
1421		# ret is intentionally unenquoted so as to normalize whitespace
1422		ret=$(echo ${ret} | cut -d' ' -f2-)
1423		AC_MSG_RESULT([${ret}])
1424		if test "x${ret}" != xborked \
1425		   || initctl --version 2>/dev/null | grep -q upstart; then
1426			enable_upstart=yes
1427		else
1428			enable_upstart=no
1429		fi
1430	fi
1431fi
1432AC_MSG_CHECKING([whether to enable support for managing resources via Upstart])
1433AC_MSG_RESULT([${enable_upstart}])
1434if test "x${enable_upstart}" = xyes; then
1435	HAVE_upstart=1
1436	PCMK_FEATURES="$PCMK_FEATURES upstart"
1437fi
1438
1439AC_DEFINE_UNQUOTED(SUPPORT_UPSTART, $HAVE_upstart, Support upstart based system services)
1440AM_CONDITIONAL(BUILD_UPSTART, test $HAVE_upstart = 1)
1441AC_SUBST(SUPPORT_UPSTART)
1442
1443
1444case $SUPPORT_NAGIOS in
1445     1|yes|true|try)
1446        SUPPORT_NAGIOS=1;;
1447     *)
1448        SUPPORT_NAGIOS=0;;
1449esac
1450
1451if test $SUPPORT_NAGIOS = 1; then
1452    PCMK_FEATURES="$PCMK_FEATURES nagios"
1453fi
1454
1455AC_DEFINE_UNQUOTED(SUPPORT_NAGIOS, $SUPPORT_NAGIOS, Support nagios plugins)
1456AM_CONDITIONAL(BUILD_NAGIOS, test $SUPPORT_NAGIOS = 1)
1457
1458if test x"$NAGIOS_PLUGIN_DIR" = x""; then
1459    NAGIOS_PLUGIN_DIR="${libexecdir}/nagios/plugins"
1460fi
1461
1462AC_DEFINE_UNQUOTED(NAGIOS_PLUGIN_DIR, "$NAGIOS_PLUGIN_DIR", Directory for nagios plugins)
1463AC_SUBST(NAGIOS_PLUGIN_DIR)
1464
1465if test x"$NAGIOS_METADATA_DIR" = x""; then
1466    NAGIOS_METADATA_DIR="${datadir}/nagios/plugins-metadata"
1467fi
1468
1469AC_DEFINE_UNQUOTED(NAGIOS_METADATA_DIR, "$NAGIOS_METADATA_DIR", Directory for nagios plugins metadata)
1470AC_SUBST(NAGIOS_METADATA_DIR)
1471
1472STACKS=""
1473CLUSTERLIBS=""
1474
1475dnl ========================================================================
1476dnl    Cluster stack - Heartbeat
1477dnl ========================================================================
1478
1479case $SUPPORT_HEARTBEAT in
14801|yes|true|try)
1481   AC_MSG_CHECKING(for heartbeat support)
1482   AC_CHECK_LIB(hbclient, ll_cluster_new, [SUPPORT_HEARTBEAT=1],
1483		[if test $SUPPORT_HEARTBEAT != try; then
1484			AC_MSG_FAILURE(Unable to support Heartbeat: client libraries not found)
1485		fi])
1486
1487   if test $SUPPORT_HEARTBEAT = 1 ; then
1488	STACKS="$STACKS heartbeat"
1489	dnl objdump -x ${libdir}/libccmclient.so | grep SONAME | awk '{print $2}'
1490	AC_DEFINE_UNQUOTED(CCM_LIBRARY, "libccmclient.so.1", Library to load for ccm support)
1491	AC_DEFINE_UNQUOTED(HEARTBEAT_LIBRARY, "libhbclient.so.1", Library to load for heartbeat support)
1492	BUILD_ATOMIC_ATTRD=0
1493   else
1494	SUPPORT_HEARTBEAT=0
1495   fi
1496   ;;
1497*) SUPPORT_HEARTBEAT=0;;
1498esac
1499
1500AM_CONDITIONAL(BUILD_HEARTBEAT_SUPPORT, test $SUPPORT_HEARTBEAT = 1)
1501AC_DEFINE_UNQUOTED(SUPPORT_HEARTBEAT, $SUPPORT_HEARTBEAT, Support the Heartbeat messaging and membership layer)
1502AC_SUBST(SUPPORT_HEARTBEAT)
1503
1504dnl ========================================================================
1505dnl    Cluster stack - Corosync
1506dnl ========================================================================
1507
1508dnl Normalize the values
1509case $SUPPORT_CS in
1510     1|yes|true)
1511		SUPPORT_CS=yes
1512		missingisfatal=1;;
1513     try)	missingisfatal=0;;
1514     *) SUPPORT_CS=no;;
1515esac
1516
1517AC_MSG_CHECKING(for native corosync)
1518COROSYNC_LIBS=""
1519CS_USES_LIBQB=0
1520
1521PCMK_SERVICE_ID=9
1522
1523if test $SUPPORT_CS = no; then
1524    AC_MSG_RESULT(no (disabled))
1525    SUPPORT_CS=0
1526else
1527    AC_MSG_RESULT($SUPPORT_CS, with '$CSPREFIX')
1528    SUPPORT_CS=1
1529    PKG_CHECK_MODULES(cpg,    libcpg) dnl Fatal
1530    PKG_CHECK_MODULES(cfg,    libcfg) dnl Fatal
1531    PKG_CHECK_MODULES(cmap,   libcmap,   HAVE_cmap=1,   HAVE_cmap=0)
1532    PKG_CHECK_MODULES(cman,   libcman,   HAVE_cman=1,   HAVE_cman=0)
1533    PKG_CHECK_MODULES(confdb, libconfdb, HAVE_confdb=1, HAVE_confdb=0)
1534    PKG_CHECK_MODULES(fenced, libfenced, HAVE_fenced=1, HAVE_fenced=0)
1535    PKG_CHECK_MODULES(quorum, libquorum, HAVE_quorum=1, HAVE_quorum=0)
1536    PKG_CHECK_MODULES(oldipc, libcoroipcc, HAVE_oldipc=1, HAVE_oldipc=0)
1537
1538    if test $HAVE_oldipc = 1; then
1539	CFLAGS="$CFLAGS $oldipc_FLAGS $cpg_FLAGS $cfg_FLAGS"
1540        COROSYNC_LIBS="$COROSYNC_LIBS $oldipc_LIBS $cpg_LIBS $cfg_LIBS"
1541    else
1542        CS_USES_LIBQB=1
1543	CFLAGS="$CFLAGS $libqb_FLAGS $cpg_FLAGS $cfg_FLAGS"
1544        COROSYNC_LIBS="$COROSYNC_LIBS $libqb_LIBS $cpg_LIBS $cfg_LIBS"
1545        AC_CHECK_LIB(corosync_common, cs_strerror)
1546    fi
1547
1548    AC_DEFINE_UNQUOTED(HAVE_CONFDB, $HAVE_confdb, Have the old herarchial Corosync config API)
1549    AC_DEFINE_UNQUOTED(HAVE_CMAP, $HAVE_cmap, Have the new non-herarchial Corosync config API)
1550fi
1551
1552
1553if test $SUPPORT_CS = 1 -a x$HAVE_oldipc = x0 ; then
1554    dnl Support for plugins was removed about the time the IPC was
1555    dnl moved to libqb.
1556    dnl The only option now is the built-in quorum API
1557    CFLAGS="$CFLAGS $cmap_CFLAGS $quorum_CFLAGS"
1558    COROSYNC_LIBS="$COROSYNC_LIBS $cmap_LIBS $quorum_LIBS"
1559
1560    STACKS="$STACKS corosync-native"
1561    AC_DEFINE_UNQUOTED(SUPPORT_CS_QUORUM, 1, Support the consumption of membership and quorum from corosync)
1562fi
1563
1564SUPPORT_PLUGIN=0
1565if test $SUPPORT_CS = 1 -a x$HAVE_confdb = x1; then
1566    dnl Need confdb to support cman and the plugins
1567    SUPPORT_PLUGIN=1
1568    BUILD_ATOMIC_ATTRD=0
1569    AC_MSG_CHECKING([for corosync path for plugins])
1570    PKG_CHECK_VAR([LCRSODIR], [corosync], [lcrsodir], [
1571       AC_MSG_RESULT([$LCRSODIR])
1572    ],[
1573       AC_SUBST([LCRSODIR], [$libdir])
1574       AC_MSG_RESULT([$LCRSODIR (fallback)])
1575    ])
1576    STACKS="$STACKS corosync-plugin"
1577    COROSYNC_LIBS="$COROSYNC_LIBS $confdb_LIBS"
1578
1579    if test $SUPPORT_CMAN != no; then
1580        if test $HAVE_cman = 1 -a $HAVE_fenced = 1; then
1581            SUPPORT_CMAN=1
1582	    STACKS="$STACKS cman"
1583            CFLAGS="$CFLAGS $cman_FLAGS $fenced_FLAGS"
1584            COROSYNC_LIBS="$COROSYNC_LIBS $cman_LIBS $fenced_LIBS"
1585        fi
1586    fi
1587fi
1588
1589dnl Normalize SUPPORT_CS and SUPPORT_CMAN for use with #if directives
1590if test $SUPPORT_CMAN != 1; then
1591    SUPPORT_CMAN=0
1592fi
1593
1594if test $SUPPORT_CS = 1; then
1595    CLUSTERLIBS="$CLUSTERLIBS $COROSYNC_LIBS"
1596
1597elif test $SUPPORT_CS != 0; then
1598    SUPPORT_CS=0
1599    if test $missingisfatal = 0; then
1600        AC_MSG_WARN(Unable to support Corosync: $aisreason)
1601    else
1602        AC_MSG_FAILURE(Unable to support Corosync: $aisreason)
1603    fi
1604fi
1605
1606AC_DEFINE_UNQUOTED(SUPPORT_COROSYNC, $SUPPORT_CS,    Support the Corosync messaging and membership layer)
1607AC_DEFINE_UNQUOTED(SUPPORT_CMAN,     $SUPPORT_CMAN,  Support the consumption of membership and quorum from cman)
1608AC_DEFINE_UNQUOTED(CS_USES_LIBQB,    $CS_USES_LIBQB, Does corosync use libqb for its ipc)
1609AC_DEFINE_UNQUOTED(PCMK_SERVICE_ID,  $PCMK_SERVICE_ID, Corosync service number)
1610AC_DEFINE_UNQUOTED(SUPPORT_PLUGIN,   $SUPPORT_PLUGIN, Support the Pacemaker plugin for Corosync)
1611
1612AM_CONDITIONAL(BUILD_CS_SUPPORT, test $SUPPORT_CS = 1)
1613AM_CONDITIONAL(BUILD_CS_PLUGIN, test $SUPPORT_PLUGIN = 1)
1614AM_CONDITIONAL(BUILD_CMAN, test $SUPPORT_CMAN = 1)
1615
1616AM_CONDITIONAL(BUILD_ATOMIC_ATTRD, test $BUILD_ATOMIC_ATTRD = 1)
1617AC_DEFINE_UNQUOTED(HAVE_ATOMIC_ATTRD, $BUILD_ATOMIC_ATTRD, Support the new atomic attrd)
1618
1619AC_SUBST(SUPPORT_CMAN)
1620AC_SUBST(SUPPORT_CS)
1621AC_SUBST(SUPPORT_PLUGIN)
1622
1623dnl
1624dnl    Cluster stack - Sanity
1625dnl
1626
1627if test x${enable_no_stack} = xyes; then
1628    AC_MSG_NOTICE(No cluster stack supported.  Just building the Policy Engine)
1629    PCMK_FEATURES="$PCMK_FEATURES no-cluster-stack"
1630else
1631    AC_MSG_CHECKING(for supported stacks)
1632    if test x"$STACKS" = x; then
1633      AC_MSG_FAILURE(You must support at least one cluster stack (heartbeat or corosync) )
1634    fi
1635    AC_MSG_RESULT($STACKS)
1636    PCMK_FEATURES="$PCMK_FEATURES $STACKS"
1637fi
1638
1639if test ${BUILD_ATOMIC_ATTRD} = 1; then
1640    PCMK_FEATURES="$PCMK_FEATURES atomic-attrd"
1641fi
1642AC_SUBST(CLUSTERLIBS)
1643
1644dnl ========================================================================
1645dnl    SNMP
1646dnl ========================================================================
1647
1648case $SUPPORT_SNMP in
1649     1|yes|true) missingisfatal=1;;
1650     try)        missingisfatal=0;;
1651     *)		 SUPPORT_SNMP=no;;
1652esac
1653
1654SNMPLIBS=""
1655
1656AC_MSG_CHECKING(for snmp support)
1657if test $SUPPORT_SNMP = no; then
1658   AC_MSG_RESULT(no (disabled))
1659   SUPPORT_SNMP=0
1660else
1661    SNMPCONFIG=""
1662    AC_MSG_RESULT($SUPPORT_SNMP)
1663    AC_CHECK_HEADERS(net-snmp/net-snmp-config.h)
1664
1665    if test "x${ac_cv_header_net_snmp_net_snmp_config_h}" != "xyes"; then
1666 	SUPPORT_SNMP="no"
1667    fi
1668
1669    if test $SUPPORT_SNMP != no; then
1670	AC_PATH_PROGS(SNMPCONFIG, net-snmp-config)
1671	if test "X${SNMPCONFIG}" = "X"; then
1672		AC_MSG_RESULT(You need the net_snmp development package to continue.)
1673		SUPPORT_SNMP=no
1674	fi
1675    fi
1676
1677    if test $SUPPORT_SNMP != no; then
1678	AC_MSG_CHECKING(for special snmp libraries)
1679	SNMPLIBS=`$SNMPCONFIG --agent-libs`
1680	AC_MSG_RESULT($SNMPLIBS)
1681    fi
1682
1683    if test $SUPPORT_SNMP != no; then
1684        savedLibs=$LIBS
1685        LIBS="$LIBS $SNMPLIBS"
1686
1687        dnl    On many systems libcrypto is needed when linking against libsnmp.
1688        dnl    Check to see if it exists, and if so use it.
1689	dnl AC_CHECK_LIB(crypto, CRYPTO_free, CRYPTOLIB="-lcrypto",)
1690	dnl AC_SUBST(CRYPTOLIB)
1691
1692        AC_CHECK_FUNCS(netsnmp_transport_open_client)
1693        if test $ac_cv_func_netsnmp_transport_open_client != yes; then
1694            AC_CHECK_FUNCS(netsnmp_tdomain_transport)
1695            if test $ac_cv_func_netsnmp_tdomain_transport != yes; then
1696                SUPPORT_SNMP=no
1697	    else
1698                AC_DEFINE_UNQUOTED(NETSNMPV53, 1, [Use the older 5.3 version of the net-snmp API])
1699            fi
1700        fi
1701        LIBS=$savedLibs
1702    fi
1703
1704    if test $SUPPORT_SNMP = no; then
1705   	SNMPLIBS=""
1706   	SUPPORT_SNMP=0
1707     	if test $missingisfatal = 0; then
1708	    AC_MSG_WARN(Unable to support SNMP)
1709        else
1710	    AC_MSG_FAILURE(Unable to support SNMP)
1711        fi
1712    else
1713   	SUPPORT_SNMP=1
1714    fi
1715fi
1716
1717if test $SUPPORT_SNMP = 1; then
1718   PCMK_FEATURES="$PCMK_FEATURES snmp"
1719fi
1720
1721AC_SUBST(SNMPLIBS)
1722AM_CONDITIONAL(ENABLE_SNMP, test "$SUPPORT_SNMP" = "1")
1723AC_DEFINE_UNQUOTED(ENABLE_SNMP, $SUPPORT_SNMP, Build in support for sending SNMP traps)
1724
1725dnl ========================================================================
1726dnl    ESMTP
1727dnl ========================================================================
1728
1729case $SUPPORT_ESMTP in
1730     1|yes|true) missingisfatal=1;;
1731     try)        missingisfatal=0;;
1732     *)		 SUPPORT_ESMTP=no;;
1733esac
1734
1735ESMTPLIB=""
1736
1737AC_MSG_CHECKING(for esmtp support)
1738if test $SUPPORT_ESMTP = no; then
1739   AC_MSG_RESULT(no (disabled))
1740   SUPPORT_ESMTP=0
1741else
1742   ESMTPCONFIG=""
1743   AC_MSG_RESULT($SUPPORT_ESMTP)
1744   AC_CHECK_HEADERS(libesmtp.h)
1745
1746   if test "x${ac_cv_header_libesmtp_h}" != "xyes"; then
1747	ENABLE_ESMTP="no"
1748   fi
1749
1750   if test $SUPPORT_ESMTP != no; then
1751	AC_PATH_PROGS(ESMTPCONFIG, libesmtp-config)
1752	if test "X${ESMTPCONFIG}" = "X"; then
1753		AC_MSG_RESULT(You need the libesmtp development package to continue.)
1754		SUPPORT_ESMTP=no
1755	fi
1756   fi
1757
1758   if test $SUPPORT_ESMTP != no; then
1759	AC_MSG_CHECKING(for special esmtp libraries)
1760	ESMTPLIBS=`$ESMTPCONFIG --libs | tr '\n' ' '`
1761	AC_MSG_RESULT($ESMTPLIBS)
1762   fi
1763
1764   if test $SUPPORT_ESMTP = no; then
1765   	SUPPORT_ESMTP=0
1766     	if test $missingisfatal = 0; then
1767	    AC_MSG_WARN(Unable to support ESMTP)
1768        else
1769	    AC_MSG_FAILURE(Unable to support ESMTP)
1770        fi
1771   else
1772   	SUPPORT_ESMTP=1
1773        PCMK_FEATURES="$PCMK_FEATURES libesmtp"
1774   fi
1775fi
1776
1777AC_SUBST(ESMTPLIBS)
1778AM_CONDITIONAL(ENABLE_ESMTP, test "$SUPPORT_ESMTP" = "1")
1779AC_DEFINE_UNQUOTED(ENABLE_ESMTP, $SUPPORT_ESMTP, Build in support for sending mail notifications with ESMTP)
1780
1781dnl ========================================================================
1782dnl    ACL
1783dnl ========================================================================
1784
1785case $SUPPORT_ACL in
1786     1|yes|true) missingisfatal=1;;
1787     try)        missingisfatal=0;;
1788     *)		 SUPPORT_ACL=no;;
1789esac
1790
1791AC_MSG_CHECKING(for acl support)
1792if test $SUPPORT_ACL = no; then
1793    AC_MSG_RESULT(no (disabled))
1794    SUPPORT_ACL=0
1795else
1796    AC_MSG_RESULT($SUPPORT_ACL)
1797
1798    SUPPORT_ACL=1
1799    AC_CHECK_LIB(qb, qb_ipcs_connection_auth_set)
1800    if test $ac_cv_lib_qb_qb_ipcs_connection_auth_set != yes; then
1801        SUPPORT_ACL=0
1802    fi
1803
1804    if test $SUPPORT_ACL = 0; then
1805        if test $missingisfatal = 0; then
1806            AC_MSG_WARN(Unable to support ACL. You need to use libqb > 0.13.0)
1807        else
1808            AC_MSG_FAILURE(Unable to support ACL. You need to use libqb > 0.13.0)
1809        fi
1810    fi
1811fi
1812
1813if test $SUPPORT_ACL = 1; then
1814    PCMK_FEATURES="$PCMK_FEATURES acls"
1815fi
1816
1817AM_CONDITIONAL(ENABLE_ACL, test "$SUPPORT_ACL" = "1")
1818AC_DEFINE_UNQUOTED(ENABLE_ACL, $SUPPORT_ACL, Build in support for CIB ACL)
1819
1820dnl ========================================================================
1821dnl    CIB secrets
1822dnl ========================================================================
1823
1824case $SUPPORT_CIBSECRETS in
1825     1|yes|true|try)
1826        SUPPORT_CIBSECRETS=1;;
1827     *)
1828        SUPPORT_CIBSECRETS=0;;
1829esac
1830
1831AC_DEFINE_UNQUOTED(SUPPORT_CIBSECRETS, $SUPPORT_CIBSECRETS, Support CIB secrets)
1832AM_CONDITIONAL(BUILD_CIBSECRETS, test $SUPPORT_CIBSECRETS = 1)
1833
1834if test $SUPPORT_CIBSECRETS = 1; then
1835    PCMK_FEATURES="$PCMK_FEATURES cibsecrets"
1836
1837    LRM_CIBSECRETS_DIR="${localstatedir}/lib/pacemaker/lrm/secrets"
1838    AC_DEFINE_UNQUOTED(LRM_CIBSECRETS_DIR,"$LRM_CIBSECRETS_DIR", Location for CIB secrets)
1839    AC_SUBST(LRM_CIBSECRETS_DIR)
1840
1841    LRM_LEGACY_CIBSECRETS_DIR="${localstatedir}/lib/heartbeat/lrm/secrets"
1842    AC_DEFINE_UNQUOTED(LRM_LEGACY_CIBSECRETS_DIR,"$LRM_LEGACY_CIBSECRETS_DIR", Legacy location for CIB secrets)
1843    AC_SUBST(LRM_LEGACY_CIBSECRETS_DIR)
1844fi
1845
1846dnl ========================================================================
1847dnl    GnuTLS
1848dnl ========================================================================
1849
1850AC_CHECK_HEADERS(gnutls/gnutls.h)
1851AC_CHECK_HEADERS(security/pam_appl.h pam/pam_appl.h)
1852
1853dnl GNUTLS library: Attempt to determine by 'libgnutls-config' program.
1854dnl If no 'libgnutls-config', try traditional autoconf means.
1855AC_PATH_PROGS(LIBGNUTLS_CONFIG, libgnutls-config)
1856
1857if test -n "$LIBGNUTLS_CONFIG"; then
1858	AC_MSG_CHECKING(for gnutls header flags)
1859	GNUTLSHEAD="`$LIBGNUTLS_CONFIG --cflags`";
1860	AC_MSG_RESULT($GNUTLSHEAD)
1861	AC_MSG_CHECKING(for gnutls library flags)
1862	GNUTLSLIBS="`$LIBGNUTLS_CONFIG --libs`";
1863	AC_MSG_RESULT($GNUTLSLIBS)
1864fi
1865AC_CHECK_LIB(gnutls, gnutls_init)
1866AC_CHECK_FUNCS(gnutls_priority_set_direct)
1867 AC_CHECK_FUNCS([gnutls_sec_param_to_pk_bits]) dnl since 2.12.0 (2011-03-24)
1868
1869AC_SUBST(GNUTLSHEAD)
1870AC_SUBST(GNUTLSLIBS)
1871
1872
1873dnl ========================================================================
1874dnl    System Health
1875dnl ========================================================================
1876
1877dnl Check if servicelog development package is installed
1878SERVICELOG=servicelog-1
1879SERVICELOG_EXISTS="no"
1880AC_MSG_CHECKING(for $SERVICELOG packages)
1881if
1882    $PKG_CONFIG --exists $SERVICELOG
1883then
1884    PKG_CHECK_MODULES([SERVICELOG], [servicelog-1])
1885    SERVICELOG_EXISTS="yes"
1886fi
1887AC_MSG_RESULT($SERVICELOG_EXISTS)
1888AM_CONDITIONAL(BUILD_SERVICELOG, test "$SERVICELOG_EXISTS" = "yes")
1889
1890dnl Check if OpenIMPI packages and servicelog are installed
1891OPENIPMI="OpenIPMI OpenIPMIposix"
1892OPENIPMI_SERVICELOG_EXISTS="no"
1893AC_MSG_CHECKING(for $SERVICELOG $OPENIPMI packages)
1894if
1895    $PKG_CONFIG --exists $OPENIPMI $SERVICELOG
1896then
1897    PKG_CHECK_MODULES([OPENIPMI_SERVICELOG],[OpenIPMI OpenIPMIposix])
1898    OPENIPMI_SERVICELOG_EXISTS="yes"
1899fi
1900AC_MSG_RESULT($OPENIPMI_SERVICELOG_EXISTS)
1901AM_CONDITIONAL(BUILD_OPENIPMI_SERVICELOG, test "$OPENIPMI_SERVICELOG_EXISTS" = "yes")
1902
1903dnl ========================================================================
1904dnl Compiler flags
1905dnl ========================================================================
1906
1907dnl Make sure that CFLAGS is not exported. If the user did
1908dnl not have CFLAGS in their environment then this should have
1909dnl no effect. However if CFLAGS was exported from the user's
1910dnl environment, then the new CFLAGS will also be exported
1911dnl to sub processes.
1912if export | fgrep " CFLAGS=" > /dev/null; then
1913	SAVED_CFLAGS="$CFLAGS"
1914	unset CFLAGS
1915	CFLAGS="$SAVED_CFLAGS"
1916	unset SAVED_CFLAGS
1917fi
1918
1919AC_ARG_VAR([CFLAGS_HARDENED_LIB], [extra C compiler flags for hardened libraries])
1920AC_ARG_VAR([LDFLAGS_HARDENED_LIB], [extra linker flags for hardened libraries])
1921
1922AC_ARG_VAR([CFLAGS_HARDENED_EXE], [extra C compiler flags for hardened executables])
1923AC_ARG_VAR([LDFLAGS_HARDENED_EXE], [extra linker flags for hardened executables])
1924
1925CC_EXTRAS=""
1926
1927if test "$GCC" != yes; then
1928        CFLAGS="$CFLAGS -g"
1929	enable_fatal_warnings=no
1930else
1931        CFLAGS="$CFLAGS -ggdb"
1932
1933dnl When we don't have diagnostic push / pull, we can't explicitly disable
1934dnl checking for nonliteral formats in the places where they occur on purpose
1935dnl thus we disable nonliteral format checking globally as we are aborting
1936dnl on warnings.
1937dnl what makes the things really ugly is that nonliteral format checking is
1938dnl obviously available as an extra switch in very modern gcc but for older
1939dnl gcc this is part of -Wformat=2
1940dnl so if we have push/pull we can enable -Wformat=2 -Wformat-nonliteral
1941dnl if we don't have push/pull but -Wformat-nonliteral we can enable -Wformat=2
1942dnl otherwise none of both
1943
1944        gcc_diagnostic_push_pull=no
1945        SAVED_CFLAGS="$CFLAGS"
1946        CFLAGS="$CFLAGS -Werror"
1947        AC_MSG_CHECKING([for gcc diagnostic push / pull])
1948        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1949#pragma GCC diagnostic push
1950#pragma GCC diagnostic pop
1951        ]])], [
1952                AC_MSG_RESULT([yes])
1953                gcc_diagnostic_push_pull=yes
1954        ], AC_MSG_RESULT([no]))
1955        CFLAGS="$SAVED_CFLAGS"
1956
1957        if cc_supports_flag "-Wformat-nonliteral"; then
1958                gcc_format_nonliteral=yes
1959        else
1960                gcc_format_nonliteral=no
1961        fi
1962
1963	# We had to eliminate -Wnested-externs because of libtool changes
1964	# Make sure to order options so that the former stand for prerequisites
1965	# of the latter (e.g., -Wformat-nonliteral requires -Wformat).
1966        EXTRA_FLAGS="-fgnu89-inline
1967		-Wall
1968		-Waggregate-return
1969		-Wbad-function-cast
1970		-Wcast-align
1971		-Wdeclaration-after-statement
1972		-Wendif-labels
1973		-Wfloat-equal
1974		-Wformat-security
1975		-Wmissing-prototypes
1976		-Wmissing-declarations
1977		-Wnested-externs
1978		-Wno-long-long
1979		-Wno-strict-aliasing
1980		-Wpointer-arith
1981		-Wstrict-prototypes
1982		-Wwrite-strings
1983		-Wunused-but-set-variable
1984		-Wunsigned-char"
1985
1986        if test "x$gcc_diagnostic_push_pull" = "xyes"; then
1987                AC_DEFINE([GCC_FORMAT_NONLITERAL_CHECKING_ENABLED], [],
1988			[gcc can complain about nonliterals in format])
1989                EXTRA_FLAGS="$EXTRA_FLAGS
1990                        -Wformat=2
1991                        -Wformat-nonliteral"
1992        else
1993                if test "x$gcc_format_nonliteral" = "xyes"; then
1994                        EXTRA_FLAGS="$EXTRA_FLAGS
1995                        -Wformat=2"
1996                fi
1997        fi
1998
1999# Additional warnings it might be nice to enable one day
2000#		-Wshadow
2001#		-Wunreachable-code
2002	for j in $EXTRA_FLAGS
2003	do
2004	  if
2005	    cc_supports_flag $CC_EXTRAS $j
2006	  then
2007	    CC_EXTRAS="$CC_EXTRAS $j"
2008	  fi
2009	done
2010
2011dnl In lib/ais/Makefile.am there's a gcc option available as of v4.x
2012
2013	GCC_MAJOR=`gcc -v 2>&1 | awk 'END{print $3}' | sed 's/[.].*//'`
2014	AM_CONDITIONAL(GCC_4, test "${GCC_MAJOR}" = 4)
2015
2016dnl System specific options
2017
2018	case "$host_os" in
2019  	*linux*|*bsd*|*dragonfly*)
2020		if test "${enable_fatal_warnings}" = "unknown"; then
2021        		enable_fatal_warnings=yes
2022        	fi
2023          	;;
2024	esac
2025
2026	if test "x${enable_fatal_warnings}" != xno && cc_supports_flag -Werror ; then
2027	   enable_fatal_warnings=yes
2028	else
2029	   enable_fatal_warnings=no
2030        fi
2031
2032	if test "x${enable_ansi}" = xyes && cc_supports_flag -std=iso9899:199409 ; then
2033	  AC_MSG_NOTICE(Enabling ANSI Compatibility)
2034	  CC_EXTRAS="$CC_EXTRAS -ansi -D_GNU_SOURCE -DANSI_ONLY"
2035	fi
2036
2037  	AC_MSG_NOTICE(Activated additional gcc flags: ${CC_EXTRAS})
2038fi
2039
2040dnl
2041dnl Hardening flags
2042dnl
2043dnl The prime control of whether to apply (targeted) hardening build flags and
2044dnl which ones is --{enable,disable}-hardening option passed to ./configure:
2045dnl
2046dnl --enable-hardening=try (default):
2047dnl     depending on whether any of CFLAGS_HARDENED_EXE, LDFLAGS_HARDENED_EXE,
2048dnl     CFLAGS_HARDENED_LIB or LDFLAGS_HARDENED_LIB environment variables
2049dnl     (see below) is set and non-null, all these custom flags (even if not
2050dnl     set) are used as are, otherwise the best effort is made to offer
2051dnl     reasonably strong hardening in several categories (RELRO, PIE,
2052dnl     "bind now", stack protector) according to what the selected toolchain
2053dnl     can offer
2054dnl
2055dnl --enable-hardening:
2056dnl     same effect as --enable-hardening=try when the environment variables
2057dnl     in question are suppressed
2058dnl
2059dnl --disable-hardening:
2060dnl     do not apply any targeted hardening measures at all
2061dnl
2062dnl The user-injected environment variables that regulate the hardening in
2063dnl default case are as follows:
2064dnl
2065dnl * CFLAGS_HARDENED_EXE, LDFLAGS_HARDENED_EXE
2066dnl    compiler and linker flags (respectively) for daemon programs
2067dnl    (attrd, cib, crmd, lrmd, stonithd, pacemakerd, pacemaker_remoted,
2068dnl    pengine)
2069dnl
2070dnl * CFLAGS_HARDENED_LIB, LDFLAGS_HARDENED_LIB
2071dnl    compiler and linker flags (respectively) for libraries linked
2072dnl    with the daemon programs
2073dnl
2074dnl Note that these are purposedly targeted variables (addressing particular
2075dnl targets all over the scattered Makefiles) and have no effect outside of
2076dnl the predestined scope (e.g., CLI utilities).  For a global reach,
2077dnl use CFLAGS, LDFLAGS, etc. as usual.
2078dnl
2079dnl For guidance on the suitable flags consult, for instance:
2080dnl https://fedoraproject.org/wiki/Changes/Harden_All_Packages#Detailed_Harden_Flags_Description
2081dnl https://owasp.org/index.php/C-Based_Toolchain_Hardening#GCC.2FBinutils
2082dnl
2083
2084if test "x${HARDENING}" != "xtry"; then
2085	unset CFLAGS_HARDENED_EXE
2086	unset CFLAGS_HARDENED_LIB
2087	unset LDFLAGS_HARDENED_EXE
2088	unset LDFLAGS_HARDENED_LIB
2089fi
2090if test "x${HARDENING}" = "xno"; then
2091	AC_MSG_NOTICE([Hardening: explicitly disabled])
2092elif test "x${HARDENING}" = "xyes" \
2093    || test "$(env | grep -Ec '^(C|LD)FLAGS_HARDENED_(EXE|LIB)=.')" = 0; then
2094	dnl We'll figure out on our own...
2095	CFLAGS_HARDENED_EXE=
2096	CFLAGS_HARDENED_LIB=
2097	LDFLAGS_HARDENED_EXE=
2098	LDFLAGS_HARDENED_LIB=
2099	relro=0
2100	pie=0
2101	bindnow=0
2102	# daemons incl. libs: partial RELRO
2103	flag="-Wl,-z,relro"
2104	CC_CHECK_LDFLAGS(["${flag}"],
2105		[LDFLAGS_HARDENED_EXE="${LDFLAGS_HARDENED_EXE} ${flag}";
2106		 LDFLAGS_HARDENED_LIB="${LDFLAGS_HARDENED_LIB} ${flag}";
2107		 relro=1]
2108	)
2109	# daemons: PIE for both CFLAGS and LDFLAGS
2110	if cc_supports_flag -fPIE; then
2111		flag="-pie"
2112		CC_CHECK_LDFLAGS(["${flag}"],
2113			[CFLAGS_HARDENED_EXE="${CFLAGS_HARDENED_EXE} -fPIE";
2114			 LDFLAGS_HARDENED_EXE="${LDFLAGS_HARDENED_EXE} ${flag}";
2115			 pie=1]
2116		)
2117	fi
2118	# daemons incl. libs: full RELRO if sensible + as-needed linking
2119	#                     so as to possibly mitigate startup performance
2120	#                     hit caused by excessive linking with unneeded
2121	#                     libraries
2122	if test "${relro}" = 1 && test "${pie}" = 1; then
2123		flag="-Wl,-z,now"
2124		CC_CHECK_LDFLAGS(["${flag}"],
2125			[LDFLAGS_HARDENED_EXE="${LDFLAGS_HARDENED_EXE} ${flag}";
2126			 LDFLAGS_HARDENED_LIB="${LDFLAGS_HARDENED_LIB} ${flag}";
2127			 bindnow=1]
2128		)
2129	fi
2130	if test "${bindnow}" = 1; then
2131		flag="-Wl,--as-needed"
2132		CC_CHECK_LDFLAGS(["${flag}"],
2133			[LDFLAGS_HARDENED_EXE="${LDFLAGS_HARDENED_EXE} ${flag}";
2134			 LDFLAGS_HARDENED_LIB="${LDFLAGS_HARDENED_LIB} ${flag}"]
2135		)
2136	fi
2137	# universal: prefer strong > all > default stack protector if possible
2138	flag=
2139	if cc_supports_flag -fstack-protector-strong; then
2140		flag="-fstack-protector-strong"
2141	elif cc_supports_flag -fstack-protector-all; then
2142		flag="-fstack-protector-all"
2143	elif cc_supports_flag -fstack-protector; then
2144		flag="-fstack-protector"
2145	fi
2146	if test -n "${flag}"; then
2147		CC_EXTRAS="${CC_EXTRAS} ${flag}"
2148		stackprot=1
2149	fi
2150	if test "${relro}" = 1 \
2151	|| test "${pie}" = 1 \
2152	|| test "${stackprot}" = 1; then
2153		AC_MSG_NOTICE(
2154		[Hardening: relro=${relro} pie=${pie} bindnow=${bindnow} stackprot=${flag}])
2155	else
2156		AC_MSG_WARN([Hardening: no suitable features in the toolchain detected])
2157	fi
2158else
2159	AC_MSG_NOTICE([Hardening: using custom flags])
2160fi
2161
2162CFLAGS="$CFLAGS $CC_EXTRAS"
2163
2164NON_FATAL_CFLAGS="$CFLAGS"
2165AC_SUBST(NON_FATAL_CFLAGS)
2166
2167dnl
2168dnl We reset CFLAGS to include our warnings *after* all function
2169dnl checking goes on, so that our warning flags don't keep the
2170dnl AC_*FUNCS() calls above from working.  In particular, -Werror will
2171dnl *always* cause us troubles if we set it before here.
2172dnl
2173dnl
2174if test "x${enable_fatal_warnings}" = xyes ; then
2175   AC_MSG_NOTICE(Enabling Fatal Warnings)
2176   CFLAGS="$CFLAGS -Werror"
2177fi
2178AC_SUBST(CFLAGS)
2179
2180dnl This is useful for use in Makefiles that need to remove one specific flag
2181CFLAGS_COPY="$CFLAGS"
2182AC_SUBST(CFLAGS_COPY)
2183
2184AC_SUBST(LIBADD_DL)	dnl extra flags for dynamic linking libraries
2185AC_SUBST(LIBADD_INTL)	dnl extra flags for GNU gettext stuff...
2186
2187AC_SUBST(LOCALE)
2188
2189dnl Options for cleaning up the compiler output
2190QUIET_LIBTOOL_OPTS=""
2191QUIET_MAKE_OPTS=""
2192if test "x${enable_quiet}" = "xyes"; then
2193   QUIET_LIBTOOL_OPTS="--quiet"
2194   QUIET_MAKE_OPTS="--quiet"
2195fi
2196
2197AC_MSG_RESULT(Supress make details: ${enable_quiet})
2198
2199dnl Put the above variables to use
2200LIBTOOL="${LIBTOOL} --tag=CC \$(QUIET_LIBTOOL_OPTS)"
2201MAKE="${MAKE} \$(QUIET_MAKE_OPTS)"
2202
2203AC_SUBST(CC)
2204AC_SUBST(MAKE)
2205AC_SUBST(LIBTOOL)
2206AC_SUBST(QUIET_MAKE_OPTS)
2207AC_SUBST(QUIET_LIBTOOL_OPTS)
2208AC_DEFINE_UNQUOTED(CRM_FEATURES, "$PCMK_FEATURES", Set of enabled features)
2209AC_SUBST(PCMK_FEATURES)
2210
2211dnl The Makefiles and shell scripts we output
2212AC_CONFIG_FILES(Makefile				        \
2213Doxyfile							\
2214coverage.sh							\
2215cts/Makefile					        	\
2216	cts/CTSvars.py						\
2217	cts/LSBDummy						\
2218	cts/HBDummy						\
2219	cts/benchmark/Makefile					\
2220	cts/benchmark/clubench					\
2221	cts/lxc_autogen.sh					\
2222	cts/pacemaker-cts-dummyd.service			\
2223cib/Makefile							\
2224attrd/Makefile							\
2225crmd/Makefile							\
2226pengine/Makefile						\
2227	pengine/regression.core.sh				\
2228doc/Makefile							\
2229	doc/Clusters_from_Scratch/publican.cfg			\
2230	doc/Pacemaker_Development/publican.cfg			\
2231	doc/Pacemaker_Explained/publican.cfg			\
2232	doc/Pacemaker_Remote/publican.cfg			\
2233include/Makefile						\
2234	include/crm/Makefile					\
2235		include/crm/cib/Makefile			\
2236		include/crm/common/Makefile			\
2237		include/crm/cluster/Makefile			\
2238		include/crm/fencing/Makefile			\
2239		include/crm/pengine/Makefile			\
2240replace/Makefile						\
2241lib/Makefile							\
2242	lib/pacemaker.pc					\
2243	lib/pacemaker-cib.pc					\
2244	lib/pacemaker-lrmd.pc					\
2245	lib/pacemaker-service.pc				\
2246	lib/pacemaker-pengine.pc				\
2247	lib/pacemaker-fencing.pc				\
2248	lib/pacemaker-cluster.pc				\
2249	lib/ais/Makefile					\
2250	lib/common/Makefile					\
2251	lib/cluster/Makefile					\
2252	lib/cib/Makefile					\
2253	lib/pengine/Makefile					\
2254	lib/transition/Makefile					\
2255	lib/fencing/Makefile					\
2256	lib/lrmd/Makefile					\
2257	lib/services/Makefile					\
2258mcp/Makefile							\
2259	mcp/pacemaker						\
2260	mcp/pacemaker.service					\
2261	mcp/pacemaker.upstart					\
2262	mcp/pacemaker.combined.upstart				\
2263fencing/Makefile                                                \
2264        fencing/regression.py                                   \
2265lrmd/Makefile                                                   \
2266        lrmd/regression.py                                      \
2267        lrmd/pacemaker_remote.service				\
2268        lrmd/pacemaker_remote					\
2269extra/Makefile							\
2270	extra/alerts/Makefile					\
2271	extra/resources/Makefile				\
2272	extra/logrotate/Makefile				\
2273	extra/logrotate/pacemaker				\
2274tools/Makefile							\
2275	tools/crm_report					\
2276        tools/report.collector                                  \
2277        tools/report.common                                     \
2278	tools/cibsecret						\
2279	tools/crm_mon.service					\
2280	tools/crm_mon.upstart					\
2281xml/Makefile							\
2282lib/gnu/Makefile						\
2283		)
2284
2285AC_CONFIG_FILES([cts/pacemaker-cts-dummyd], [chmod +x cts/pacemaker-cts-dummyd])
2286AC_CONFIG_FILES([tools/pcmk_simtimes], [chmod +x tools/pcmk_simtimes])
2287
2288dnl Now process the entire list of files added by previous
2289dnl  calls to AC_CONFIG_FILES()
2290AC_OUTPUT()
2291
2292dnl *****************
2293dnl Configure summary
2294dnl *****************
2295
2296AC_MSG_RESULT([])
2297AC_MSG_RESULT([$PACKAGE configuration:])
2298AC_MSG_RESULT([  Version                  = ${VERSION} (Build: $BUILD_VERSION)])
2299AC_MSG_RESULT([  Features                 =${PCMK_FEATURES}])
2300AC_MSG_RESULT([])
2301AC_MSG_RESULT([  Prefix                   = ${prefix}])
2302AC_MSG_RESULT([  Executables              = ${sbindir}])
2303AC_MSG_RESULT([  Man pages                = ${mandir}])
2304AC_MSG_RESULT([  Libraries                = ${libdir}])
2305AC_MSG_RESULT([  Header files             = ${includedir}])
2306AC_MSG_RESULT([  Arch-independent files   = ${datadir}])
2307AC_MSG_RESULT([  State information        = ${localstatedir}])
2308AC_MSG_RESULT([  System configuration     = ${sysconfdir}])
2309if test $SUPPORT_PLUGIN = 1; then
2310AC_MSG_RESULT([  Corosync Plugins         = ${LCRSODIR}])
2311fi
2312AC_MSG_RESULT([])
2313AC_MSG_RESULT([  HA group name            = ${CRM_DAEMON_GROUP}])
2314AC_MSG_RESULT([  HA user name             = ${CRM_DAEMON_USER}])
2315AC_MSG_RESULT([])
2316AC_MSG_RESULT([  CFLAGS                   = ${CFLAGS}])
2317AC_MSG_RESULT([  CFLAGS_HARDENED_EXE      = ${CFLAGS_HARDENED_EXE}])
2318AC_MSG_RESULT([  CFLAGS_HARDENED_LIB      = ${CFLAGS_HARDENED_LIB}])
2319AC_MSG_RESULT([  LDFLAGS_HARDENED_EXE     = ${LDFLAGS_HARDENED_EXE}])
2320AC_MSG_RESULT([  LDFLAGS_HARDENED_LIB     = ${LDFLAGS_HARDENED_LIB}])
2321AC_MSG_RESULT([  Libraries                = ${LIBS}])
2322AC_MSG_RESULT([  Stack Libraries          = ${CLUSTERLIBS}])
2323AC_MSG_RESULT([  Unix socket auth method  = ${us_auth}])
2324