* Makefile.am: recreated Makefile.am from Makefile.am.in
[findutils.git] / m4 / strftime.m4
blob3f105e986f41ee1fcee91da994de33f14d91f175
1 #serial 5
3 dnl This macro is intended to be used solely in this file.
4 dnl These are the prerequisite macros for GNU's strftime.c replacement.
5 dnl FIXME: the list is far from complete
6 AC_DEFUN(_jm_STRFTIME_PREREQS,
8  dnl strftime.c uses localtime_r if it exists.  Check for it.
9  AC_CHECK_FUNCS(localtime_r)
10  dnl FIXME: add tests for everything in strftime.c: e.g., HAVE_BCOPY,
11  dnl HAVE_TZNAME, HAVE_TZSET, HAVE_TM_ZONE, etc.
14 dnl Determine if the strftime function has all the features of the GNU one.
15 dnl
16 dnl If you use this macro in a package, you should
17 dnl add the following two lines to acconfig.h:
18 dnl   /* Define to gnu_strftime if the replacement function should be used.  */
19 dnl   #undef strftime
20 dnl
21 dnl From Jim Meyering.
22 dnl
23 AC_DEFUN(jm_FUNC_GNU_STRFTIME,
24 [AC_REQUIRE([AC_HEADER_TIME])dnl
26  _jm_STRFTIME_PREREQS
28  AC_REQUIRE([AC_C_CONST])dnl
29  AC_REQUIRE([AC_HEADER_STDC])dnl
30  AC_CHECK_HEADERS(sys/time.h)
31  AC_CACHE_CHECK([for working GNU strftime], jm_cv_func_working_gnu_strftime,
32   [AC_TRY_RUN(
33 changequote(<<, >>)dnl
34 << /* Ulrich Drepper provided parts of the test program.  */
35 #if STDC_HEADERS
36 # include <stdlib.h>
37 #endif
39 #if TIME_WITH_SYS_TIME
40 # include <sys/time.h>
41 # include <time.h>
42 #else
43 # if HAVE_SYS_TIME_H
44 #  include <sys/time.h>
45 # else
46 #  include <time.h>
47 # endif
48 #endif
50 static int
51 compare (const char *fmt, const struct tm *tm, const char *expected)
53   char buf[99];
54   strftime (buf, 99, fmt, tm);
55   if (strcmp (buf, expected))
56     {
57 #ifdef SHOW_FAILURES
58       printf ("fmt: \"%s\", expected \"%s\", got \"%s\"\n",
59               fmt, expected, buf);
60 #endif
61       return 1;
62     }
63   return 0;
66 int
67 main ()
69   int n_fail = 0;
70   struct tm *tm;
71   time_t t = 738367; /* Fri Jan  9 13:06:07 1970 */
72   tm = gmtime (&t);
74   /* This is necessary to make strftime give consistent zone strings and
75      e.g., seconds since the epoch (%s).  */
76   putenv ("TZ=GMT0");
78 #undef CMP
79 #define CMP(Fmt, Expected) n_fail += compare ((Fmt), tm, (Expected))
81   CMP ("%-m", "1");             /* GNU */
82   CMP ("%A", "Friday");
83   CMP ("%^A", "FRIDAY");        /* The ^ is a GNU extension.  */
84   CMP ("%B", "January");
85   CMP ("%^B", "JANUARY");
86   CMP ("%C", "19");             /* POSIX.2 */
87   CMP ("%D", "01/09/70");       /* POSIX.2 */
88   CMP ("%F", "1970-01-09");
89   CMP ("%G", "1970");           /* GNU */
90   CMP ("%H", "13");
91   CMP ("%I", "01");
92   CMP ("%M", "06");
93   CMP ("%M", "06");
94   CMP ("%R", "13:06");          /* POSIX.2 */
95   CMP ("%S", "07");
96   CMP ("%T", "13:06:07");       /* POSIX.2 */
97   CMP ("%U", "01");
98   CMP ("%V", "02");
99   CMP ("%W", "01");
100   CMP ("%X", "13:06:07");
101   CMP ("%Y", "1970");
102   CMP ("%Z", "GMT");
103   CMP ("%_m", " 1");            /* GNU */
104   CMP ("%a", "Fri");
105   CMP ("%^a", "FRI");
106   CMP ("%b", "Jan");
107   CMP ("%^b", "JAN");
108   CMP ("%c", "Fri Jan  9 13:06:07 1970");
109   CMP ("%^c", "FRI JAN  9 13:06:07 1970");
110   CMP ("%d", "09");
111   CMP ("%e", " 9");             /* POSIX.2 */
112   CMP ("%f", "5");              /* POSIX.2 */
113   CMP ("%g", "70");             /* GNU */
114   CMP ("%h", "Jan");            /* POSIX.2 */
115   CMP ("%^h", "JAN");
116   CMP ("%j", "009");
117   CMP ("%k", "13");             /* GNU */
118   CMP ("%l", " 1");             /* GNU */
119   CMP ("%m", "01");
120   CMP ("%n", "\n");             /* POSIX.2 */
121   CMP ("%p", "PM");
122   CMP ("%r", "01:06:07 PM");    /* POSIX.2 */
123   CMP ("%s", "738367");         /* GNU */
124   CMP ("%t", "\t");             /* POSIX.2 */
125   CMP ("%u", "5");              /* POSIX.2 */
126   CMP ("%w", "5");
127   CMP ("%x", "01/09/70");
128   CMP ("%y", "70");
129   CMP ("%z", "+0000");          /* GNU */
131   exit (n_fail ? 1 : 0);
133               >>,
134 changequote([, ])dnl
135              jm_cv_func_working_gnu_strftime=yes,
136              jm_cv_func_working_gnu_strftime=no,
137              dnl When crosscompiling, assume strftime is missing or broken.
138              jm_cv_func_working_gnu_strftime=no)
139   ])
140   if test $jm_cv_func_working_gnu_strftime = no; then
141     LIBOBJS="$LIBOBJS strftime.o"
142     AC_DEFINE_UNQUOTED(strftime, gnu_strftime)
143   fi
146 AC_DEFUN(jm_FUNC_STRFTIME,
148   _jm_STRFTIME_PREREQS
149   AC_REPLACE_FUNCS(strftime)