summaryrefslogtreecommitdiff
path: root/m4/dpkg-funcs.m4
blob: e087bbdcae69b16271052a636c94b0f04993077c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
# Copyright © 2005 Scott James Remnant <scott@netsplit.com>
# Copyright © 2008, 2009 Guillem Jover <guillem@debian.org>

# DPKG_FUNC_VA_COPY
# -----------------
# Define HAVE_VA_COPY if we have va_copy, fail if they can't be assigned
AC_DEFUN([DPKG_FUNC_VA_COPY],
[AC_CACHE_CHECK([for va_copy], [dpkg_cv_va_copy],
	[AC_RUN_IFELSE([AC_LANG_SOURCE(
[[#include <stdarg.h>
int main()
{
va_list v1, v2;
va_copy (v1, v2);
exit (0);
}
	]])],
	[dpkg_cv_va_copy=yes],
	[dpkg_cv_va_copy=no],
	[dpkg_cv_va_copy=no])])
AS_IF([test "x$dpkg_cv_va_copy" = "xyes"],
	[AC_DEFINE([HAVE_VA_COPY], 1,
	           [Define to 1 if the 'va_copy' macro exists])])
])# DPKG_FUNC_VA_COPY

# DPKG_FUNC_C99_SNPRINTF
# -----------------------
# Define HAVE_C99_SNPRINTF if we have C99 snprintf family semantics
AC_DEFUN([DPKG_FUNC_C99_SNPRINTF],
[AC_CACHE_CHECK([for C99 snprintf functions], [dpkg_cv_c99_snprintf],
	[AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
int test_vsnprintf(const char *fmt, ...)
{
	int n;
	va_list args;

	va_start(args, fmt);
	n = vsnprintf(NULL, 0, fmt, args);
	va_end(args);

	return n;
}
int main()
{
	int n;

	n = snprintf(NULL, 0, "format %s %d", "string", 10);
	if (n != strlen("format string 10"))
		return 1;

	n = test_vsnprintf("format %s %d", "string", 10);
	if (n != strlen("format string 10"))
		return 1;

	return 0;
}
	]])],
	[dpkg_cv_c99_snprintf=yes],
	[dpkg_cv_c99_snprintf=no],
	[dpkg_cv_c99_snprintf=no])])
AS_IF([test "x$dpkg_cv_c99_snprintf" = "xyes"],
	[AC_DEFINE([HAVE_C99_SNPRINTF], 1,
	           [Define to 1 if the 'snprintf' family is C99 conformant])],
	)
AM_CONDITIONAL(HAVE_C99_SNPRINTF, [test "x$dpkg_cv_c99_snprintf" = "xyes"])
])# DPKG_FUNC_C99_SNPRINTF

# DPKG_MMAP
# ---------
# Define USE_MMAP if mmap() is available and it was requested
AC_DEFUN([DPKG_MMAP],
[
  AC_ARG_ENABLE([mmap],
    AS_HELP_STRING([--enable-mmap],
                   [enable usage of unrealiable mmap if available]),
    [],
    [enable_mmap=no])

  AS_IF([test "x$enable_mmap" = "xyes"], [
    AC_CHECK_FUNCS([mmap])
    AC_DEFINE(USE_MMAP, 1, [Use unreliable mmap support])
  ])
])

# DPKG_CHECK_PROGNAME
# -------------------
# Check for system implementations of program name tracking.
AC_DEFUN([DPKG_CHECK_PROGNAME],
[
  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])])

  AC_MSG_CHECKING([for __progname])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
                 [[extern char *__progname;
                   const char *p = __progname;]])],
                 [AC_DEFINE([HAVE___PROGNAME], [1],
                            [Define to 1 if you have __progname])
                  AC_MSG_RESULT([yes])],
                 [AC_MSG_RESULT([no])])
]) # DPKG_CHECK_PROGNAME

# DPKG_CHECK_COMPAT_FUNCS(LIST)
# -----------------------
# Check each function and define an automake conditional
AC_DEFUN([DPKG_CHECK_COMPAT_FUNCS],
[
  AC_CHECK_FUNCS([$1])
  m4_foreach_w([ac_func], [$1], [
    AM_CONDITIONAL(HAVE_[]AS_TR_CPP(ac_func),
                   [test "x$ac_cv_func_[]AS_TR_SH(ac_func)" = "xyes"])
  ])
]) # DPKG_CHECK_COMPAT_FUNCS