configure.ac 4.4 KB
Newer Older
1 2 3 4
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.67])
AC_INIT([libbsd], m4_esyscmd([./get-version]), [libbsd@lists.freedesktop.org])
5
AC_CONFIG_SRCDIR([src/strlcpy.c])
6 7 8
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])

9
AM_INIT_AUTOMAKE([1.9 foreign nostdinc subdir-objects no-dist-gzip dist-xz])
10 11 12 13

m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
                            [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])

14
LIBBSD_ABI_MAJOR=0
Guillem Jover's avatar
Guillem Jover committed
15
LIBBSD_ABI_MINOR=9
Guillem Jover's avatar
Guillem Jover committed
16
LIBBSD_ABI_PATCH=1
17 18 19 20

LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
AC_SUBST([LIBBSD_ABI])

21 22 23
# Check and store if we got user supplied variables
user_CFLAGS=${CFLAGS-unset}

24 25 26 27 28 29 30 31 32 33 34
# Checks for operating system services and capabilities.
AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE

LT_INIT

# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S

35 36 37 38 39
# Set default compiler variables
if test "$user_CFLAGS" = unset && test "$GCC" = yes; then
  CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter"
fi

40
# Checks for libraries.
41 42 43 44 45
AC_CHECK_LIB([testu01], [unif01_CreateExternGenBits],
             [TESTU01_LIBS="-ltestu01"])
AC_SUBST([TESTU01_LIBS])
AM_CONDITIONAL([HAVE_LIBTESTU01],
               [test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
46

47
AS_CASE([$host_os],
48
  [*-gnu*], [
49
    # In old glibc versions (< 2.17) clock_gettime() is in librt.
50 51 52 53
    saved_LIBS="$LIBS"
    AC_SEARCH_LIBS([clock_gettime], [rt], [CLOCK_GETTIME_LIBS="-lrt"])
    AC_SUBST([CLOCK_GETTIME_LIBS])
    LIBS="$saved_LIBS"
54
  ],
55
  [*-musl*], [
56 57 58
    # Upstream refuses to define this, we will do it ourselves then.
    AC_DEFINE([__MUSL__], [1], [Define to 1 if we are building for musl])
  ],
59 60
)

61
# Checks for header files.
Aaron Dierking's avatar
Aaron Dierking committed
62
AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h grp.h])
63 64 65

# Checks for typedefs, structures, and compiler characteristics.
AC_C_INLINE
66
AC_C_TYPEOF
67 68 69 70
AC_TYPE_INT64_T
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
71
AC_TYPE_UID_T
72 73 74
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T

75 76 77 78 79 80 81
AC_CHECK_DECL([F_CLOSEM],
              [AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
                         [Define to 1 if you have fcntl(F_CLOSEM)])],
              [],
              [#include <limits.h>
               #include <fcntl.h>])

82 83 84 85 86 87 88 89
AC_CACHE_CHECK(
	[for GNU .init_array section support],
	[libbsd_cv_gnu_init_array_support],
	[AC_RUN_IFELSE(
		[AC_LANG_SOURCE(
[[
static int rc = 1;
static void init(int argc) { if (argc == 1) rc = 0; }
90
void (*init_func)(int argc) __attribute__((__section__(".init_array"))) = init;
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
int main() { return rc; }
]]
		)],
		[libbsd_cv_gnu_init_array_support=yes],
		[libbsd_cv_gnu_init_array_support=no],
		[AC_PREPROC_IFELSE(
			[AC_LANG_SOURCE(
[[
/* Look for a known libc that supports .init_array with the GNU extension
 * to pass main() arguments to the init functions. */
#include <stdlib.h>
#if defined __GLIBC_PREREQ
#  if __GLIBC_PREREQ(2, 4)
/* glibc supports GNU .init_array since 2.4. */
#  else
#    error glibc does not support GNU .init_array
#  endif
#else
/*
 * Basic SysV ABI .init_array support, init functions do not get arguments:
 * - Bionic since its inception.
 * - uClibc since 0.9.29.
 */
#  error unknown whether libc supports GNU .init_array
#endif
]]
			)],
			[libbsd_cv_gnu_init_array_support=yes],
			[libbsd_cv_gnu_init_array_support=no])
		]
	)]
)
123 124
AM_CONDITIONAL([BUILD_LIBBSD_CTOR],
               [test "$libbsd_cv_gnu_init_array_support" = yes])
125

126
# Checks for library functions.
127 128 129 130 131 132 133 134 135
AC_MSG_CHECKING([for program_invocation_short_name])
AC_LINK_IFELSE(
	[AC_LANG_PROGRAM([[#include <errno.h>]],
	                 [[const char *p = program_invocation_short_name;]])],
	[AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
	           [Define to 1 if you have program_invocation_short_name])
	 AC_MSG_RESULT([yes])],
	[AC_MSG_RESULT([no])])

136 137
AC_MSG_CHECKING([for __progname])
AC_LINK_IFELSE(
138 139
	[AC_LANG_PROGRAM([[extern char *__progname;]],
	                 [[printf("%s", __progname);]])],
140 141 142 143
	[AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
	 AC_MSG_RESULT([yes])],
	[AC_MSG_RESULT([no])])

144
AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
145
                getauxval getentropy getexecname getline \
146
                pstat_getproc sysconf])
147
AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xtrue"])
148 149 150 151 152 153 154

AC_CONFIG_FILES([
	Makefile
	include/Makefile
	man/Makefile
	src/Makefile
	src/libbsd.pc
155
	src/libbsd-ctor.pc
156
	src/libbsd-overlay.pc
157
	test/Makefile
158 159 160
])
AC_CONFIG_HEADERS([config.h])
AC_OUTPUT