po: Update German man pages translation
[dpkg.git] / m4 / dpkg-funcs.m4
blobe5f302b9c577609bdec9bb0d58d59d4919a3bf3d
1 # serial 1
2 # Copyright © 2005 Scott James Remnant <scott@netsplit.com>
3 # Copyright © 2008-2009,2015 Guillem Jover <guillem@debian.org>
5 # DPKG_FUNC_VA_COPY
6 # -----------------
7 # Define HAVE_VA_COPY if we have va_copy.
8 AC_DEFUN([DPKG_FUNC_VA_COPY], [
9   AC_CACHE_CHECK([for va_copy], [dpkg_cv_va_copy], [
10     AC_COMPILE_IFELSE([
11       AC_LANG_PROGRAM([[
12 #include <stdarg.h>
13       ]], [[
14 va_list v1, v2;
15 va_copy(v1, v2);
16       ]])
17     ], [
18       dpkg_cv_va_copy=yes
19     ], [
20       dpkg_cv_va_copy=no
21     ])
22   ])
23   AS_IF([test "x$dpkg_cv_va_copy" = "xyes"], [
24     AC_DEFINE([HAVE_VA_COPY], [1], [Define to 1 if the 'va_copy' macro exists])
25   ])
26 ])# DPKG_FUNC_VA_COPY
28 # DPKG_FUNC_FSYNC_DIR
29 # -------------------
30 # Define HAVE_FSYNC_DIR if we can fsync(2) directories.
31 AC_DEFUN([DPKG_FUNC_FSYNC_DIR], [
32   AC_CACHE_CHECK([whether fsync works on directories], [dpkg_cv_fsync_dir], [
33     AC_RUN_IFELSE([
34       AC_LANG_PROGRAM([[
35 #include <sys/types.h>
36 #include <stddef.h>
37 #include <dirent.h>
38 #include <unistd.h>
39 ]], [[
40         int fd;
41         DIR *dir = opendir(".");
42         if (dir == NULL)
43                 return 1;
44         fd = dirfd(dir);
45         if (fd < 0)
46                 return 1;
47         if (fsync(fd) < 0)
48                 return 1;
49         closedir(dir);
50       ]])
51     ], [
52       dpkg_cv_fsync_dir=yes
53     ], [
54       dpkg_cv_fsync_dir=no
55     ], [
56       dpkg_cv_fsync_dir=maybe
57     ])
59     AS_IF([test "x$dpkg_cv_fsync_dir" = "xmaybe"], [
60       AS_CASE([$host_os],
61         [aix*], [
62           # On AIX fsync(3) requires writable file descriptors, which
63           # opendir(3) does not provide, but even then fsync(3) nor
64           # fsync_range(3) always work on directories anyway.
65           dpkg_cv_fsync_dir=no
66         ], [
67           # On other systems we assume this works.
68           dpkg_cv_fsync_dir=yes
69         ]
70       )
71     ])
72   ])
73   AS_IF([test "x$dpkg_cv_fsync_dir" = "xyes"], [
74     AC_DEFINE([HAVE_FSYNC_DIR], [1],
75               [Define to 1 if the 'fsync' function works on directories])
76   ])
79 # DPKG_FUNC_C99_SNPRINTF
80 # -----------------------
81 # Define HAVE_C99_SNPRINTF if we have C99 snprintf family semantics
82 AC_DEFUN([DPKG_FUNC_C99_SNPRINTF], [
83   AC_CACHE_CHECK([for C99 snprintf functions], [dpkg_cv_c99_snprintf], [
84     AC_RUN_IFELSE([
85       AC_LANG_PROGRAM([[
86 #include <stdarg.h>
87 #include <stdio.h>
88 #include <string.h>
89 int test_vsnprintf(const char *fmt, ...)
91         int n;
92         va_list args;
94         va_start(args, fmt);
95         n = vsnprintf(NULL, 0, fmt, args);
96         va_end(args);
98         return n;
100 ]], [[
101         int n;
103         n = snprintf(NULL, 0, "format %s %d", "string", 10);
104         if (n != strlen("format string 10"))
105                 return 1;
107         n = test_vsnprintf("format %s %d", "string", 10);
108         if (n != strlen("format string 10"))
109                 return 1;
110       ]])
111     ], [
112       dpkg_cv_c99_snprintf=yes
113     ], [
114       dpkg_cv_c99_snprintf=no
115     ], [
116       dpkg_cv_c99_snprintf=maybe
117     ])
119     AS_IF([test "x$dpkg_cv_c99_snprintf" = "xmaybe"], [
120       AC_COMPILE_IFELSE([
121         AC_LANG_SOURCE([[
122 #define _GNU_SOURCE 1
123 #include <unistd.h>
124 #if !defined(_XOPEN_VERSION) || _XOPEN_VERSION < 600
125 #error "snprintf() has conflicting semantics with C99 on SUSv2 and earlier"
126 #endif
127         ]])
128       ], [
129         dpkg_cv_c99_snprintf=yes
130       ], [
131         dpkg_cv_c99_snprintf=no
132       ])
133     ])
134   ])
135   AS_IF([test "x$dpkg_cv_c99_snprintf" = "xyes"], [
136     AC_DEFINE([HAVE_C99_SNPRINTF], [1],
137       [Define to 1 if the 'snprintf' family is C99 conformant])
138   ])
139   AM_CONDITIONAL([HAVE_C99_SNPRINTF], [test "x$dpkg_cv_c99_snprintf" = "xyes"])
140 ])# DPKG_FUNC_C99_SNPRINTF
142 # DPKG_USE_MMAP
143 # -------------
144 # Define USE_MMAP if mmap() is available and it was requested
145 AC_DEFUN([DPKG_USE_MMAP], [
146   AC_ARG_ENABLE([mmap],
147     [AS_HELP_STRING([--enable-mmap],
148       [enable usage of unrealiable mmap if available])],
149     [], [enable_mmap=no])
151   AS_IF([test "x$enable_mmap" = "xyes"], [
152     AC_CHECK_FUNCS([mmap])
153     AC_DEFINE([USE_MMAP], [1], [Use unreliable mmap support])
154   ])
157 # DPKG_USE_DISK_PREALLOCATE
158 # -------------------------
159 # Define USE_DISK_PREALLOCATE if disk size pre-allocation is available
160 # and it was requested.
161 AC_DEFUN([DPKG_USE_DISK_PREALLOCATE], [
162   AC_ARG_ENABLE([disk-preallocate],
163     [AS_HELP_STRING([--enable-disk-preallocate],
164       [enable usage of disk size pre-allocation])],
165     [], [enable_disk_preallocate=no])
167   AS_IF([test "x$enable_disk_preallocate" = "xyes"], [
168     AC_DEFINE([USE_DISK_PREALLOCATE], [1], [Use disk size pre-allocation])
169   ])
172 # DPKG_CHECK_PROGNAME
173 # -------------------
174 # Check for system implementations of program name tracking.
175 AC_DEFUN([DPKG_CHECK_PROGNAME], [
176   AC_MSG_CHECKING([for program_invocation_short_name])
177   AC_LINK_IFELSE([
178     AC_LANG_PROGRAM(
179       [[#include <errno.h>]],
180       [[const char *p = program_invocation_short_name;]])
181   ], [
182     AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
183       [Define to 1 if you have program_invocation_short_name])
184     AC_MSG_RESULT([yes])
185   ], [
186     AC_MSG_RESULT([no])
187   ])
189   AC_MSG_CHECKING([for __progname])
190   AC_LINK_IFELSE([
191     AC_LANG_PROGRAM(
192       [[extern char *__progname;]],
193       [[printf("%s", __progname);]])
194   ], [
195     AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
196     AC_MSG_RESULT([yes])
197   ], [
198     AC_MSG_RESULT([no])
199   ])
200 ]) # DPKG_CHECK_PROGNAME
202 # DPKG_CHECK_COMPAT_FUNCS(LIST)
203 # -----------------------
204 # Check each function and define an automake conditional
205 AC_DEFUN([DPKG_CHECK_COMPAT_FUNCS], [
206   AC_CHECK_FUNCS([$1])
207   m4_foreach_w([ac_func], [$1], [
208     AM_CONDITIONAL([HAVE_]AS_TR_CPP(ac_func),
209       [test "x$ac_cv_func_[]AS_TR_SH(ac_func)" = "xyes"])
210   ])
211 ]) # DPKG_CHECK_COMPAT_FUNCS