configure.ac 12.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.59])
AC_INIT([clsync],[0.4],[Dmitry Yu Okunev <dyokunev@ut.mephi.ru>],,[https://github.com/xaionaro/clsync])
AC_CONFIG_SRCDIR([sync.c])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([1.11 foreign -Wall -Wno-portability])
AC_CONFIG_HEADERS([config.h])
AC_PROG_CC([gcc cc])
AM_PROG_CC_C_O
AC_PROG_CC_STDC
AC_CONFIG_MACRO_DIR([m4])
AC_PROG_LIBTOOL
AM_PROG_LIBTOOL

LT_INIT

PKG_INSTALLDIR

AC_CANONICAL_HOST

m4_include(m4/ax_pthread.m4)
AX_PTHREAD(
	[
		CC="$PTHREAD_CC"
		LIBS="$LIBS $PTHREAD_LIBS"
		CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
		LDFLAGS="$LDFLAGS $PTHREAD_LDFLAGS"
	], [
		AC_MSG_ERROR([Pthread library not found. Please set PTHREAD_CFLAGS and PTHREAD_LIBS correctly for your setup])
	]
)


HAVE_BACKTRACE=1
case $host_os in
	*bsd*)
		AC_SEARCH_LIBS([backtrace], [execinfo], [],
			[HAVE_BACKTRACE=])
		;;
esac

dnl --enable-clsync
AC_ARG_ENABLE(clsync,
AS_HELP_STRING(--disable-clsync,
[do not build clsync binary, default: build clsync]))
AM_CONDITIONAL([CLSYNC], [test "x$enable_clsync" != "xno"])

dnl check for glibc only if clsync is being build
AS_IF([test "x$enable_clsync" != "xno"], [
    PKG_CHECK_MODULES(GLIB,  [glib-2.0])
])

dnl --enable-cluster
AC_ARG_ENABLE(cluster,
AS_HELP_STRING(--enable-cluster,
[enable clustering support (not yet implemented), default: no]))

AS_IF([test "x$enable_cluster" = "xyes"], [CPPFLAGS="${CPPFLAGS} -DCLUSTER_SUPPORT"
	dnl mhash check
	AC_ARG_WITH(mhash,
	AS_HELP_STRING(--with-mhash,
	[use mhash instead of internal version of hash algo, default: enabled]))

	AS_IF([test "x$with_mhash" = "xno"], [], [
	AC_CHECK_HEADER([mhash.h], [], [AC_MSG_ERROR("Unable to find mhash.h")])
	AC_SEARCH_LIBS([mhash_init], [mhash], [CPPFLAGS="${CPPFLAGS} -DHAVE_MHASH"],
		[AC_MSG_ERROR("Unable to find libmhash")])
	])
])


dnl --enable-socket
AC_ARG_ENABLE(socket,
AS_HELP_STRING(--enable-socket,
[enable control socket support, default: no]))

AS_IF([test "x$enable_socket" = "xyes"],
[CPPFLAGS="${CPPFLAGS} -DENABLE_SOCKET"])

AM_CONDITIONAL([SOCKET], [test "x$enable_socket" = "xyes"])

dnl --enable-libclsync
AC_ARG_ENABLE(socket-library,
AS_HELP_STRING(--enable-socket-library,
[build libclsync socket library, default: no]))
AM_CONDITIONAL([LIBCLSYNC], [test "x$enable_socket_library" = "xyes"])

dnl --enable-unshare
AC_ARG_ENABLE(unshare,
AS_HELP_STRING(--disable-unshare,
[disable support of unshare(), default: enabled]))

AS_IF([ test "x$enable_unshare" != "xno" ],
[
    AC_CHECK_FUNC([unshare], [HAVE_UNSHARE=1])
])

dnl --enable-highload-locks
AC_ARG_ENABLE(highload-locks,
AS_HELP_STRING(--enable-highload-locks,
[enable locks for high loaded instances (it requires more CPU, but it's faster) for --thread-splitting [not well tested, can cause deadlocks with 100% CPU utilization], default: no]))
AM_CONDITIONAL([HLLOCKS], [test "x$enable_highload_locks" = "xyes"])

dnl --enable-debug
AC_ARG_ENABLE(debug,
AS_HELP_STRING(--enable-debug,
[enable debugging support, default: yes; value: no, yes, force]),
[case "${enableval}" in
	(0|"no")    debug=0 ;;
	(1|"yes")   debug=1 ;;
	(2|"force") debug=2 ;;
	(*)         AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
esac],
[debug=1])

AS_IF([ test "$debug" -ge 1 ],
[CFLAGS="${CFLAGS} -pipe -Wall -O0 -ggdb3" CPPFLAGS="${CPPFLAGS} -D_DEBUG_SUPPORT"])

AS_IF([ test "$debug" -ge 2 ],
[CPPFLAGS="${CPPFLAGS} -D_DEBUG_FORCE"])

dnl --paranoid
AC_ARG_ENABLE(paranoid,
AS_HELP_STRING([--enable-paranoid],
[set paranoid level of code security, default: 1, values: 0, 1, 2]),
[case "${enableval}" in
	(0|"no")    paranoid=0 ;;
	(1|"yes")   paranoid=1 ;;
	(2)         paranoid=2 ;;
	(*)         AC_MSG_ERROR([bad value ${enableval} for --enable-paranoid]) ;;
esac],
[paranoid=1])

AS_IF(
	[test $paranoid -ge 1],
	[
		CPPFLAGS="${CPPFLAGS} -D_FORTIFY_SOURCE=2 -DPARANOID"
		CFLAGS="${CFLAGS} -fstack-protector-all -Wall --param ssp-buffer-size=4"
		LDFLAGS="${LDFLAGS} -Xlinker -zrelro"
		AX_CHECK_COMPILE_FLAG([-fstack-check], [CFLAGS="${CFLAGS} -fstack-check"])
	]
)
AS_IF([test $paranoid -eq 2], [CPPFLAGS="${CPPFLAGS} -DVERYPARANOID"])

# Checks for programs.
AC_PROG_CC_C99
AC_PROG_INSTALL
PKG_PROG_PKG_CONFIG([0.20])

# Checks for libraries.
dnl libdl
AC_CHECK_HEADER([dlfcn.h], [], [AC_MSG_ERROR("Unable to find dlfcn.h")])
AC_SEARCH_LIBS([dlopen], [dl], [LDFLAGS="${LDFLAGS} -rdynamic"],
[AC_MSG_ERROR("Unable to find libdl")])

dnl -lrt is needed on < glibc-2.17
AC_SEARCH_LIBS([clock_getres], [rt], [],
    [AC_MSG_ERROR("Unable to find librt; clock_getres() is needed")])

dnl searching for getmntent
AC_CHECK_FUNC([getmntent], [HAVE_GETMNTENT=1])

dnl searching for pivot_root
AC_CHECK_FUNC([pivot_root], [HAVE_PIVOTROOT=1])

dnl libcgroup check
AC_ARG_WITH(libcgroup,
	AS_HELP_STRING(--with-libcgroup,
		[Enable cgroup support via libcgroup; values: no, check, yes; default: check]),
	[],
	[with_libcgroup=check]
)

case "$with_libcgroup" in
	yes)

		AC_CHECK_LIB([cgroup], [cgroup_init],
			[
				AC_CHECK_HEADER(libcgroup.h, [], [AC_MSG_FAILURE([Cannot find libcgroup.h])])
				LDFLAGS="${LDFLAGS} -lcgroup"
				HAVE_LIBCGROUP=1
			],
			[
				AC_MSG_FAILURE(
					[Cannot find libcgroup])
			]
		)
		;;
	check)
		AC_CHECK_LIB([cgroup], [cgroup_init],
			[
				AC_CHECK_HEADER(libcgroup.h, [], [AC_MSG_FAILURE([Cannot find libcgroup.h])])
				LDFLAGS="${LDFLAGS} -lcgroup"
				HAVE_LIBCGROUP=1
			],
			[]
		)
		;;
esac

dnl capabilities check
AC_ARG_WITH(capabilities,
	AS_HELP_STRING(--with-capabilities,
		[Enable linux capabilities support; values: no, check, yes; default: check]),
	[],
	[with_capabilities=check]
)

case "$with_capabilities" in
	yes)
		AC_CHECK_FUNC([capset],
			[
				AC_CHECK_HEADER(sys/capability.h, [HAVE_CAPABILITIES=2], [AC_MSG_FAILURE([Cannot find sys/capability.h])])
			],
			[
				AC_MSG_FAILURE([There is no capabilities support on this system])
			]
		)
		;;
	check)
		AC_CHECK_FUNC([capset],
			[
				AC_CHECK_HEADER(sys/capability.h, [HAVE_CAPABILITIES=2])
			]
		)
		;;
esac

dnl tre check

#AC_ARG_WITH(tre,
#	AS_HELP_STRING(--with-tre,
#		[Enable tre support be able to predict which directories should be scanned for excludes; values: no, check, yes; default: check]),
#	[],
#	[with_tre=check]
#)
#
#case "$with_tre" in
#	yes)
#		AC_CHECK_LIB([tre], [tre_regaexec],
#			[
#				AC_CHECK_HEADER(tre/tre.h, [], [AC_MSG_FAILURE([Cannot find tre/tre.h])])
#				LDFLAGS="${LDFLAGS} -ltre"
#				HAVE_TRE=1
#			],
#			[
#				AC_MSG_FAILURE(
#					[Cannot find libtre])
#			]
#		)
#		;;
#	check)
#		AC_CHECK_LIB([tre], [tre_regaexec],
#			[
#				AC_CHECK_HEADER(tre/tre.h, [], [AC_MSG_FAILURE([Cannot find tre/tre.h])])
#				LDFLAGS="${LDFLAGS} -ltre"
#				HAVE_TRE=1
#			],
#			[]
#		)
#		;;
#esac

dnl kqueue/inotify/bsm

AC_ARG_WITH(kqueue,
	AS_HELP_STRING(--with-kqueue,
		[Enable kqueue support; values: no, native, lib, check; default: check]),
	[],
	[with_kqueue=check]
)

AC_ARG_WITH(inotify,
	AS_HELP_STRING(--with-inotify,
		[Enable inotify support; values: no, native, lib, check; default: check]),
	[],
	[with_inotify=check]
)

AC_ARG_WITH(gio,
	AS_HELP_STRING(--with-gio,
		[Enable GIO support as FS monitor subsystem; values: no, lib, check; default: check]),
	[],
	[with_gio=check]
)

AC_ARG_WITH(bsm,
	AS_HELP_STRING(--with-bsm,
		[Enable BSM (Sun/*BSD audit) support as FS monitor subsystem; values: no, lib, check; default: check]),
	[],
	[with_bsm=check]
)

case "$with_kqueue" in
	check)
		AC_CHECK_FUNC([kqueue],
			[
				HAVE_KQUEUE=2
			],
			AC_CHECK_LIB([kqueue], [kqueue],
				[
					AC_CHECK_HEADER(sys/event.h, [
						LDFLAGS="${LDFLAGS} -lkqueue"
						HAVE_KQUEUE=1
					])
				],
			)
		)
		;;
	native)
		AC_CHECK_FUNC([kqueue],
			[
				AC_CHECK_HEADER(sys/event.h, [], [AC_MSG_FAILURE([Cannot find sys/event.h])])
				HAVE_KQUEUE=2
			],
			[
				AC_MSG_FAILURE(
					[There is no kqueue native support on this system])
			]
		)
		;;
	lib)
		AC_CHECK_LIB([kqueue], [kqueue],
			[
				AC_CHECK_HEADER(sys/event.h, [], [AC_MSG_FAILURE([Cannot find sys/event.h])])
				LDFLAGS="${LDFLAGS} -lkqueue"
				HAVE_KQUEUE=1
			],
			[
				AC_MSG_FAILURE(
					[Cannot find libkqueue])
			]
		)
		;;
esac

case "$with_inotify" in
	check)
		AC_CHECK_FUNC([inotify_init],
			[
				HAVE_INOTIFY=2
			],
			AC_CHECK_LIB([inotify], [inotify_init],
				[
					AC_CHECK_HEADER(sys/inotify.h, [
						LDFLAGS="${LDFLAGS} -linotify"
						HAVE_INOTIFY=1
					])
				],
			)
		)
		;;
	native)
		AC_CHECK_FUNC([inotify_init],
			[
				AC_CHECK_HEADER(sys/inotify.h, [], [AC_MSG_FAILURE([Cannot find sys/inotify.h])])
				HAVE_INOTIFY=2
			],
			[
				AC_MSG_FAILURE(
					[There is no inotify native support on this system])
			]
		)
		;;
	lib)
		AC_CHECK_LIB([inotify], [inotify_init],
			[
				AC_CHECK_HEADER(sys/inotify.h, [], [AC_MSG_FAILURE([Cannot find sys/inotify.h])])
				LDFLAGS="${LDFLAGS} -linotify"
				HAVE_INOTIFY=1
			],
			[
				AC_MSG_FAILURE(
					[Cannot find libinotify])
			]
		)
		;;
esac

case "$with_gio" in
	check)
		PKG_CHECK_MODULES(GIO,  [gio-2.0], [
			HAVE_GIO=1
			AC_SUBST([GIO_CFLAGS])
			AC_SUBST([GIO_LIBS])
		])
		;;
	lib)
		PKG_CHECK_MODULES(GIO,  [gio-2.0], [
			HAVE_GIO=1
			AC_SUBST([GIO_CFLAGS])
			AC_SUBST([GIO_LIBS])
		], [
			AC_MSG_FAILURE([Cannot find libgio-2.0])
		])
		;;
esac

case "$with_bsm" in
	check)
		AC_CHECK_FUNC([au_fetch_tok],
			[
				HAVE_BSM=2
			],
			AC_CHECK_LIB([bsm], [au_fetch_tok],
				[
					AC_CHECK_HEADER(bsm/libbsm.h, [
						LDFLAGS="${LDFLAGS} -lbsm"
						HAVE_BSM=1
					])
				],
			)
		)
		;;
	lib)
		AC_CHECK_LIB([bsm], [au_fetch_tok],
			[
				AC_CHECK_HEADER(bsm/libbsm.h, [], [AC_MSG_FAILURE([Cannot find bsm/libbsm.h])])
				LDFLAGS="${LDFLAGS} -lbsm"
				HAVE_BSM=1
			],
			[
				AC_MSG_FAILURE(
					[Cannot find libbsm])
			]
		)
		;;
esac
#AC_CHECK_PROG([HAVE_DTRACEPIPE], [dtrace], [found])

AS_IF([test "$HAVE_INOTIFY" != ""], [AC_CHECK_FUNC([inotify_init1], [], [INOTIFY_OLD=1])])

dnl searching for seccomp
AC_ARG_WITH(libseccomp,
	AS_HELP_STRING(--with-libseccomp,
		[Enable seccomp support be able to forbid extra syscalls; values: no, check, yes; default: check]),
	[],
	[with_libseccomp=check]
)

case "$with_libseccomp" in
	yes)
		AC_CHECK_TYPES([scmp_filter_ctx],                   [],               [AC_MSG_FAILURE([Cannot find valid seccomp.h])],       [[#include <seccomp.h>]])
		AC_CHECK_DECLS([seccomp_syscall_resolve_name_arch], [],               [AC_MSG_FAILURE([Cannot find valid seccomp.h])],       [[#include <seccomp.h>]])
		AC_CHECK_TYPES([struct seccomp_data],               [HAVE_SECCOMP=1], [AC_MSG_FAILURE([Cannot find valid linux/seccomp.h])], [[#include <linux/seccomp.h>]])
		;;
	check)
		AC_CHECK_TYPES([scmp_filter_ctx], [
			AC_CHECK_DECLS([seccomp_syscall_resolve_name_arch], [
				AC_CHECK_TYPES([struct seccomp_data], [HAVE_SECCOMP=1], [], [[#include <linux/seccomp.h>]])
			], [], [[#include <seccomp.h>]])
		], [], [[#include <seccomp.h>]])
		;;
esac
AS_IF([test "$HAVE_CAPABILITIES" != ""], [
])

AM_CONDITIONAL([HAVE_KQUEUE],       [test "x$HAVE_KQUEUE"       != "x"])
AM_CONDITIONAL([HAVE_INOTIFY],      [test "x$HAVE_INOTIFY"      != "x"])
AM_CONDITIONAL([INOTIFY_OLD],       [test "x$INOTIFY_OLD"       != "x"])
AM_CONDITIONAL([HAVE_FANOTIFY],     [test "x$HAVE_FANOTIFY"     != "x"])
AM_CONDITIONAL([HAVE_BSM],          [test "x$HAVE_BSM"          != "x"])
AM_CONDITIONAL([HAVE_GIO],          [test "x$HAVE_GIO"          != "x"])
AM_CONDITIONAL([HAVE_DTRACEPIPE],   [test "x$HAVE_DTRACEPIPE"   != "x"])
AM_CONDITIONAL([HAVE_BACKTRACE],    [test "x$HAVE_BACKTRACE"    != "x"])
AM_CONDITIONAL([HAVE_CAPABILITIES], [test "x$HAVE_CAPABILITIES" != "x"])
AM_CONDITIONAL([HAVE_GETMNTENT],    [test "x$HAVE_GETMNTENT"    != "x"])
AM_CONDITIONAL([HAVE_PIVOTROOT],    [test "x$HAVE_PIVOTROOT"    != "x"])
AM_CONDITIONAL([HAVE_UNSHARE],      [test "x$HAVE_UNSHARE"      != "x"])
AM_CONDITIONAL([HAVE_SECCOMP],      [test "x$HAVE_SECCOMP"      != "x"])
AM_CONDITIONAL([HAVE_TRE],          [test "x$HAVE_TRE"          != "x"])
AM_CONDITIONAL([HAVE_LIBCGROUP],    [test "x$HAVE_LIBCGROUP"    != "x"])

AS_IF([test "$HAVE_KQUEUE" = '' -a "$HAVE_INOTIFY" = '' -a "$HAVE_FANOTIFY" = '' -a "$HAVE_BSM" = '' ], [AC_MSG_FAILURE([kqueue, inotify and bsm are not supported on this system])])

LIBS="${GLIB_LIBS} ${LIBS}"
AM_CPPFLAGS="${GLIB_CFLAGS}"
AC_SUBST(AM_CPPFLAGS)


AC_CONFIG_FILES([Makefile examples/Makefile pkgconfig/libclsync.pc])
AC_OUTPUT