pacman-key: add vim modeline and fix whitespace issues
[pacman-ng.git] / acinclude.m4
blobdf4f83a4e589a159952553b5cd09e9ffaa1f32dc
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,
11     [ssp_old_libs="$LIBS"
12      LIBS="$LIBS -lssp"
13      AC_TRY_LINK(,, ssp_cv_lib=yes, ssp_cv_lib=no)
14      LIBS="$ssp_old_libs"
15     ])
16   if test $ssp_cv_lib = yes; then
17     LIBS="$LIBS -lssp"
18   fi
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],[
25   AC_LANG_ASSERT(C)
26   if test "X$CC" != "X"; then
27     AC_CACHE_CHECK([whether ${CC} accepts -fstack-protector-all],
28       ssp_cv_cc,
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"
33       ])
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.])
37     fi
38   fi
41 dnl GCC_FORTIFY_SOURCE_CC
42 dnl checks -D_FORTIFY_SOURCE with the C compiler, if it exists then updates
43 dnl CFLAGS
44 AC_DEFUN([GCC_FORTIFY_SOURCE_CC],[
45   AC_LANG_ASSERT(C)
46   if test "X$CC" != "X"; then
47     AC_MSG_CHECKING(for FORTIFY_SOURCE support)
48     AC_TRY_COMPILE([#include <features.h>], [
49       int main() {
50       #if !(__GNUC_PREREQ (4, 1) )
51       #error No FORTIFY_SOURCE support
52       #endif
53         return 0;
54       }
55     ], [
56       AC_MSG_RESULT(yes)
57       CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
58     ], [
59       AC_MSG_RESULT(no)
60   ])
61   fi
64 dnl GCC_VISIBILITY_CC
65 dnl checks -fvisibility=internal with the C compiler, if it exists then
66 dnl defines ENABLE_VISIBILITY_CC in both configure script and Makefiles
67 AC_DEFUN([GCC_VISIBILITY_CC],[
68   AC_LANG_ASSERT(C)
69   if test "X$CC" != "X"; then
70     AC_CACHE_CHECK([whether ${CC} accepts -fvisibility=internal],
71       visibility_cv_cc,
72       [visibility_old_cflags="$CFLAGS"
73        CFLAGS="$CFLAGS -fvisibility=internal"
74        AC_TRY_COMPILE(,, visibility_cv_cc=yes, visibility_cv_cc=no)
75        CFLAGS="$visibility_old_cflags"
76       ])
77     if test $visibility_cv_cc = yes; then
78       AC_DEFINE([ENABLE_VISIBILITY_CC], 1, [Define if symbol visibility C support is enabled.])
79     fi
80     AM_CONDITIONAL([ENABLE_VISIBILITY_CC], test "x$visibility_cv_cc" = "xyes")
81   fi
84 dnl GCC_GNU89_INLINE_CC
85 dnl checks -fgnu89-inline with the C compiler, if it exists then defines
86 dnl ENABLE_GNU89_INLINE_CC in both configure script and Makefiles
87 AC_DEFUN([GCC_GNU89_INLINE_CC],[
88   AC_LANG_ASSERT(C)
89   if test "X$CC" != "X"; then
90     AC_CACHE_CHECK([for -fgnu89-inline],
91     gnu89_inline_cv_cc,
92     [ gnu89_inline_old_cflags="$CFLAGS"
93       CFLAGS="$CFLAGS -fgnu89-inline"
94       AC_TRY_COMPILE(,, gnu89_inline_cv_cc=yes, gnu89_inline_cv_cc=no)
95       CFLAGS="$gnu89_inline_old_cflags"
96     ])
97     if test $gnu89_inline_cv_cc = yes; then
98       AC_DEFINE([ENABLE_GNU89_INLINE_CC], 1, [Define if gnu89 inlining semantics should be used.])
99     fi
100     AM_CONDITIONAL([ENABLE_GNU89_INLINE_CC], test "x$gnu89_inline_cv_cc" = "xyes")
101   fi
104 dnl Checks for getmntinfo and determines whether it uses statfs or statvfs
105 AC_DEFUN([FS_STATS_TYPE],
106   [AC_CACHE_CHECK([filesystem statistics type], fs_stats_cv_type,
107     [AC_CHECK_FUNC(getmntinfo,
108       [AC_COMPILE_IFELSE(
109         [AC_LANG_PROGRAM([[
110 # include <sys/param.h>
111 # include <sys/mount.h>
112 #if HAVE_SYS_UCRED_H
113 #include <sys/ucred.h>
114 #endif
115 extern int getmntinfo (struct statfs **, int);
117           [])],
118         [fs_stats_cv_type="struct statfs"],
119         [fs_stats_cv_type="struct statvfs"])],
120       [AC_CHECK_FUNC(getmntent,
121         [fs_stats_cv_type="struct statvfs"])]
122     )]
123   )
124   AC_DEFINE_UNQUOTED(FSSTATSTYPE, [$fs_stats_cv_type],
125     [Defined as the filesystem stats type ('statvfs' or 'statfs')])
126   if test $ac_cv_func_getmntinfo = yes; then
127     if test "$fs_stats_cv_type" = "struct statvfs"; then
128       AC_DEFINE([HAVE_GETMNTINFO_STATVFS], 1, [Define if getmntinfo() uses statvfs.])
129     else
130       AC_DEFINE([HAVE_GETMNTINFO_STATFS], 1, [Define if getmntinfo() uses statfs.])
131     fi
132   fi
135 dnl Checks for PATH_MAX and defines it if not present
136 AC_DEFUN([PATH_MAX_DEFINED],
137   [AC_CACHE_CHECK([PATH_MAX defined], path_max_cv_defined,
138     [AC_EGREP_CPP(yes, [[
139 #include <limits.h>
140 #if defined(PATH_MAX)
142 #endif
144       [path_max_cv_defined=yes],
145       [path_max_cv_defined=no])]
146   )
147   if test $path_max_cv_defined = no; then
148     AC_DEFINE([PATH_MAX], 4096, [Define if PATH_MAX is undefined by limits.h.])
149   fi