dpkg (1.18.25) stretch; urgency=medium
[dpkg] / m4 / dpkg-funcs.m4
CommitLineData
1479465f
GJ
1# Copyright © 2005 Scott James Remnant <scott@netsplit.com>
2# Copyright © 2008-2009,2015 Guillem Jover <guillem@debian.org>
3
4# DPKG_FUNC_VA_COPY
5# -----------------
6# Define HAVE_VA_COPY if we have va_copy.
7AC_DEFUN([DPKG_FUNC_VA_COPY], [
8 AC_CACHE_CHECK([for va_copy], [dpkg_cv_va_copy], [
9 AC_COMPILE_IFELSE([
10 AC_LANG_PROGRAM([[
11#include <stdarg.h>
12 ]], [[
13va_list v1, v2;
14va_copy(v1, v2);
15 ]])
16 ], [
17 dpkg_cv_va_copy=yes
18 ], [
19 dpkg_cv_va_copy=no
20 ])
21 ])
22 AS_IF([test "x$dpkg_cv_va_copy" = "xyes"], [
23 AC_DEFINE([HAVE_VA_COPY], [1], [Define to 1 if the 'va_copy' macro exists])
24 ])
25])# DPKG_FUNC_VA_COPY
26
27# DPKG_FUNC_C99_SNPRINTF
28# -----------------------
29# Define HAVE_C99_SNPRINTF if we have C99 snprintf family semantics
30AC_DEFUN([DPKG_FUNC_C99_SNPRINTF], [
31 AC_CACHE_CHECK([for C99 snprintf functions], [dpkg_cv_c99_snprintf], [
32 AC_RUN_IFELSE([
33 AC_LANG_SOURCE([[
34#include <stdarg.h>
35#include <stdio.h>
36#include <string.h>
37int test_vsnprintf(const char *fmt, ...)
38{
39 int n;
40 va_list args;
41
42 va_start(args, fmt);
43 n = vsnprintf(NULL, 0, fmt, args);
44 va_end(args);
45
46 return n;
47}
48int main()
49{
50 int n;
51
52 n = snprintf(NULL, 0, "format %s %d", "string", 10);
53 if (n != strlen("format string 10"))
54 return 1;
55
56 n = test_vsnprintf("format %s %d", "string", 10);
57 if (n != strlen("format string 10"))
58 return 1;
59
60 return 0;
61}
62 ]])
63 ], [
64 dpkg_cv_c99_snprintf=yes
65 ], [
66 dpkg_cv_c99_snprintf=no
67 ], [
68 dpkg_cv_c99_snprintf=maybe
69 ])
70
71 AS_IF([test "x$dpkg_cv_c99_snprintf" = "xmaybe"], [
72 AC_COMPILE_IFELSE([
73 AC_LANG_SOURCE([[
74#define _GNU_SOURCE 1
75#include <unistd.h>
76#if !defined(_XOPEN_VERSION) || _XOPEN_VERSION < 600
77#error "snprintf() has conflicting semantics with C99 on SUSv2 and earlier"
78#endif
79 ]])
80 ], [
81 dpkg_cv_c99_snprintf=yes
82 ], [
83 dpkg_cv_c99_snprintf=no
84 ])
85 ])
86 ])
87 AS_IF([test "x$dpkg_cv_c99_snprintf" = "xyes"], [
88 AC_DEFINE([HAVE_C99_SNPRINTF], [1],
89 [Define to 1 if the 'snprintf' family is C99 conformant])
90 ])
91 AM_CONDITIONAL([HAVE_C99_SNPRINTF], [test "x$dpkg_cv_c99_snprintf" = "xyes"])
92])# DPKG_FUNC_C99_SNPRINTF
93
94# DPKG_USE_MMAP
95# -------------
96# Define USE_MMAP if mmap() is available and it was requested
97AC_DEFUN([DPKG_USE_MMAP], [
98 AC_ARG_ENABLE([mmap],
99 [AS_HELP_STRING([--enable-mmap],
100 [enable usage of unrealiable mmap if available])],
101 [], [enable_mmap=no])
102
103 AS_IF([test "x$enable_mmap" = "xyes"], [
104 AC_CHECK_FUNCS([mmap])
105 AC_DEFINE([USE_MMAP], [1], [Use unreliable mmap support])
106 ])
107])
108
109# DPKG_USE_DISK_PREALLOCATE
110# -------------------------
111# Define USE_DISK_PREALLOCATE if disk size pre-allocation is available
112# and it was requested.
113AC_DEFUN([DPKG_USE_DISK_PREALLOCATE], [
114 AC_ARG_ENABLE([disk-preallocate],
115 [AS_HELP_STRING([--enable-disk-preallocate],
116 [enable usage of disk size pre-allocation])],
117 [], [enable_disk_preallocate=no])
118
119 AS_IF([test "x$enable_disk_preallocate" = "xyes"], [
120 AC_DEFINE([USE_DISK_PREALLOCATE], [1], [Use disk size pre-allocation])
121 ])
122])
123
124# DPKG_CHECK_PROGNAME
125# -------------------
126# Check for system implementations of program name tracking.
127AC_DEFUN([DPKG_CHECK_PROGNAME], [
128 AC_MSG_CHECKING([for program_invocation_short_name])
129 AC_LINK_IFELSE([
130 AC_LANG_PROGRAM(
131 [[#include <errno.h>]],
132 [[const char *p = program_invocation_short_name;]])
133 ], [
134 AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
135 [Define to 1 if you have program_invocation_short_name])
136 AC_MSG_RESULT([yes])
137 ], [
138 AC_MSG_RESULT([no])
139 ])
140
141 AC_MSG_CHECKING([for __progname])
142 AC_LINK_IFELSE([
143 AC_LANG_PROGRAM(
144 [[extern char *__progname;]],
145 [[printf("%s", __progname);]])
146 ], [
147 AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
148 AC_MSG_RESULT([yes])
149 ], [
150 AC_MSG_RESULT([no])
151 ])
152]) # DPKG_CHECK_PROGNAME
153
154# DPKG_CHECK_COMPAT_FUNCS(LIST)
155# -----------------------
156# Check each function and define an automake conditional
157AC_DEFUN([DPKG_CHECK_COMPAT_FUNCS], [
158 AC_CHECK_FUNCS([$1])
159 m4_foreach_w([ac_func], [$1], [
160 AM_CONDITIONAL([HAVE_]AS_TR_CPP(ac_func),
161 [test "x$ac_cv_func_[]AS_TR_SH(ac_func)" = "xyes"])
162 ])
163]) # DPKG_CHECK_COMPAT_FUNCS