1 dnl acinclude.m4 - configure macros used by pacman and libalpm
2 dnl Add some custom macros for pacman and libalpm
4 dnl GCC_STACK_PROTECT_LIB
5 dnl adds -lssp to LIBS if it is available
6 dnl ssp is usually provided as part of libc, but was previously a separate lib
7 dnl It does not hurt to add -lssp even if libc provides SSP - in that case
8 dnl libssp will simply be ignored.
9 AC_DEFUN([GCC_STACK_PROTECT_LIB],[
10 AC_CACHE_CHECK([whether libssp exists], ssp_cv_lib,
13 AC_TRY_LINK(,, ssp_cv_lib=yes, ssp_cv_lib=no)
16 if test $ssp_cv_lib = yes; then
21 dnl GCC_STACK_PROTECT_CC
22 dnl checks -fstack-protector-all with the C compiler, if it exists then updates
23 dnl CFLAGS and defines ENABLE_SSP_CC
24 AC_DEFUN([GCC_STACK_PROTECT_CC],[
26 if test "X$CC" != "X"; then
27 AC_CACHE_CHECK([whether ${CC} accepts -fstack-protector-all],
29 [ssp_old_cflags="$CFLAGS"
30 CFLAGS="$CFLAGS -fstack-protector-all"
31 AC_TRY_COMPILE(,, ssp_cv_cc=yes, ssp_cv_cc=no)
32 CFLAGS="$ssp_old_cflags"
34 if test $ssp_cv_cc = yes; then
35 CFLAGS="$CFLAGS -fstack-protector-all"
36 AC_DEFINE([ENABLE_SSP_CC], 1, [Define if SSP C support is enabled.])
41 dnl GCC_FORTIFY_SOURCE_CC
42 dnl checks -D_FORTIFY_SOURCE with the C compiler, if it exists then updates
44 AC_DEFUN([GCC_FORTIFY_SOURCE_CC],[
46 if test "X$CC" != "X"; then
47 AC_MSG_CHECKING(for FORTIFY_SOURCE support)
48 fs_old_cppflags="$CPPFLAGS"
49 fs_old_cflags="$CFLAGS"
50 CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
51 CFLAGS="$CFLAGS -Werror"
52 AC_TRY_COMPILE([#include <features.h>], [
54 #if !(__GNUC_PREREQ (4, 1) )
55 #error No FORTIFY_SOURCE support
61 CFLAGS="$df_old_cflags"
64 CPPFLAGS="$df_old_cppflags"
65 CFLAGS="$df_old_cflags"
71 dnl checks -fvisibility=internal with the C compiler, if it exists then
72 dnl defines ENABLE_VISIBILITY_CC in both configure script and Makefiles
73 AC_DEFUN([GCC_VISIBILITY_CC],[
75 if test "X$CC" != "X"; then
76 AC_CACHE_CHECK([whether ${CC} accepts -fvisibility=internal],
78 [visibility_old_cflags="$CFLAGS"
79 CFLAGS="$CFLAGS -fvisibility=internal"
80 AC_TRY_COMPILE(,, visibility_cv_cc=yes, visibility_cv_cc=no)
81 CFLAGS="$visibility_old_cflags"
83 if test $visibility_cv_cc = yes; then
84 AC_DEFINE([ENABLE_VISIBILITY_CC], 1, [Define if symbol visibility C support is enabled.])
86 AM_CONDITIONAL([ENABLE_VISIBILITY_CC], test "x$visibility_cv_cc" = "xyes")
90 dnl GCC_GNU89_INLINE_CC
91 dnl checks -fgnu89-inline with the C compiler, if it exists then defines
92 dnl ENABLE_GNU89_INLINE_CC in both configure script and Makefiles
93 AC_DEFUN([GCC_GNU89_INLINE_CC],[
95 if test "X$CC" != "X"; then
96 AC_CACHE_CHECK([for -fgnu89-inline],
98 [ gnu89_inline_old_cflags="$CFLAGS"
99 CFLAGS="$CFLAGS -fgnu89-inline"
100 AC_TRY_COMPILE(,, gnu89_inline_cv_cc=yes, gnu89_inline_cv_cc=no)
101 CFLAGS="$gnu89_inline_old_cflags"
103 if test $gnu89_inline_cv_cc = yes; then
104 AC_DEFINE([ENABLE_GNU89_INLINE_CC], 1, [Define if gnu89 inlining semantics should be used.])
106 AM_CONDITIONAL([ENABLE_GNU89_INLINE_CC], test "x$gnu89_inline_cv_cc" = "xyes")
110 dnl CFLAGS_ADD(PARAMETER, VARIABLE)
111 dnl Adds parameter to VARIABLE if the compiler supports it. For example,
112 dnl CFLAGS_ADD([-Wall],[WARN_FLAGS]).
113 AC_DEFUN([CFLAGS_ADD],
114 [AS_VAR_PUSHDEF([my_cflags], [cflags_cv_warn_$1])dnl
115 AC_CACHE_CHECK([whether compiler handles $1], [my_cflags], [
116 save_CFLAGS="$CFLAGS"
117 CFLAGS="${CFLAGS} $1"
118 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
119 [AS_VAR_SET([my_cflags], [yes])],
120 [AS_VAR_SET([my_cflags], [no])])
121 CFLAGS="$save_CFLAGS"
123 AS_VAR_PUSHDEF([new_cflags], [[$2]])dnl
124 AS_VAR_IF([my_cflags], [yes], [AS_VAR_APPEND([new_cflags], [" $1"])])
125 AS_VAR_POPDEF([new_cflags])dnl
126 AS_VAR_POPDEF([my_cflags])dnl
127 m4_ifval([$2], [AS_LITERAL_IF([$2], [AC_SUBST([$2])], [])])dnl
130 dnl Checks for getmntinfo and determines whether it uses statfs or statvfs
131 AC_DEFUN([FS_STATS_TYPE],
132 [AC_CACHE_CHECK([filesystem statistics type], fs_stats_cv_type,
133 [AC_CHECK_FUNC(getmntinfo,
136 # include <sys/param.h>
137 # include <sys/mount.h>
139 #include <sys/ucred.h>
141 extern int getmntinfo (struct statfs **, int);
144 [fs_stats_cv_type="struct statfs"],
145 [fs_stats_cv_type="struct statvfs"])],
146 [AC_CHECK_FUNC(getmntent,
147 [fs_stats_cv_type="struct statvfs"])]
150 AC_DEFINE_UNQUOTED(FSSTATSTYPE, [$fs_stats_cv_type],
151 [Defined as the filesystem stats type ('statvfs' or 'statfs')])
152 if test $ac_cv_func_getmntinfo = yes; then
153 if test "$fs_stats_cv_type" = "struct statvfs"; then
154 AC_DEFINE([HAVE_GETMNTINFO_STATVFS], 1, [Define if getmntinfo() uses statvfs.])
156 AC_DEFINE([HAVE_GETMNTINFO_STATFS], 1, [Define if getmntinfo() uses statfs.])
161 dnl Checks for PATH_MAX and defines it if not present
162 AC_DEFUN([PATH_MAX_DEFINED],
163 [AC_CACHE_CHECK([PATH_MAX defined], path_max_cv_defined,
164 [AC_EGREP_CPP(yes, [[
166 #if defined(PATH_MAX)
170 [path_max_cv_defined=yes],
171 [path_max_cv_defined=no])]
173 if test $path_max_cv_defined = no; then
174 AC_DEFINE([PATH_MAX], 4096, [Define if PATH_MAX is undefined by limits.h.])