• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2002-2004, 2006-2018 Free Software Foundation, Inc.
2# This file is free software; the Free Software Foundation
3# gives unlimited permission to copy and/or distribute it,
4# with or without modifications, as long as this notice is preserved.
5
6# Test whether the *printf family of functions supports the %F format
7# directive. (ISO C99, POSIX:2001)
8# Result is gl_cv_func_printf_directive_f.
9
10printf_directive_f_test = '''
11#include <stdio.h>
12#include <string.h>
13static char buf[100];
14static double zero = 0.0;
15int main ()
16{
17  int result = 0;
18  if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
19      || strcmp (buf, "1234567.000000 33") != 0)
20    result |= 1;
21  if (sprintf (buf, "%F", 1.0 / zero) < 0
22      || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
23    result |= 2;
24  /* This catches a Cygwin 1.5.x bug.  */
25  if (sprintf (buf, "%.F", 1234.0) < 0
26      || strcmp (buf, "1234") != 0)
27    result |= 4;
28  return result;
29}
30'''
31
32if not meson.is_cross_build() or meson.has_exe_wrapper()
33  run_result = cc.run(printf_directive_f_test,
34      name : 'printf supports the \'F\' directive')
35  gl_cv_func_printf_directive_f = run_result.compiled() and run_result.returncode() == 0
36else
37  if host_system in ['linux', 'android']
38    gl_cv_func_printf_directive_f = true
39  elif (host_system.startswith ('freebsd1') or
40        host_system.startswith ('freebsd2') or
41        host_system.startswith ('freebsd3') or
42        host_system.startswith ('freebsd4') or
43        host_system.startswith ('freebsd5'))
44    gl_cv_func_printf_directive_f = false
45  elif (host_system.startswith ('freebsd') or
46        host_system.startswith ('kfreebsd'))
47    gl_cv_func_printf_directive_f = true
48  elif (host_system.startswith ('darwin1') or
49        host_system.startswith ('darwin2') or
50        host_system.startswith ('darwin3') or
51        host_system.startswith ('darwin4') or
52        host_system.startswith ('darwin5') or
53        host_system.startswith ('darwin6'))
54    gl_cv_func_printf_directive_f = false
55  elif host_system.startswith ('darwin')
56    gl_cv_func_printf_directive_f = true
57# Split the check from the main if statement, ensure that
58# some meson versions (old ones, presumable) won't try
59# to evaluate host_system[9] when it's shorter than that
60  elif host_system.startswith ('solaris2.')
61    if (host_system[9] == '1' and
62        '0123456789'.contains (host_system[10])) or
63       ('23456789'.contains (host_system[9]) == '1' and
64        '0123456789'.contains (host_system[10]))
65      gl_cv_func_printf_directive_f = true
66    elif host_system.startswith ('solaris')
67      gl_cv_func_printf_directive_f = false
68    endif
69  elif host_system.startswith ('solaris')
70    gl_cv_func_printf_directive_f = false
71  elif host_system == 'windows'
72    # Guess yes on MSVC, no on mingw.
73    if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
74      gl_cv_func_printf_directive_f = true
75    else
76      gl_cv_func_printf_directive_f = false
77    endif
78  else
79    gl_cv_func_printf_directive_f = false
80  endif
81endif
82