The m4/timegm.m4 macro makes use of lib/mktime.c in unexpected ways: It uses it to define a function mktime_internal().
It sits in the wrong .m4 file, leading to maintenance bugs like the one I just found. Additionally, it has a bug: It tests for a __mktime_internal function in libc and then goes on to invoke mktime_internal. Obviously leading to a link error on all platforms that have __mktime_internal (currently only BeOS). What this code really intends to be is a module that provides an mktime_internal() function. This patch fixes it. This patch has also the effect that lib/mktime.c will be compiled on platforms that have a working mktime() and a working timegm() function. If you don't like this, just specify --conditional-dependencies. 2011-05-22 Bruno Haible <br...@clisp.org> New module 'mktime-internal'. * modules/mktime-internal: New file. * m4/timegm.m4 (gl_PREREQ_TIMEGM): Move contents to ... * m4/mktime.m4 (gl_FUNC_MKTIME_INTERNAL): New macro. Define mktime_internal as a C macro if libc has __mktime_internal. * modules/timegm (Depends-on): Add mktime-internal. Remove mktime. Add conditions. * MODULES.html.sh (Date and time <time.h>): Add mktime-internal. =========================== modules/mktime-internal =========================== Description: mktime_internal() function: convert broken-down time to linear time. Files: lib/mktime-internal.h lib/mktime.c Depends-on: mktime configure.ac: gl_FUNC_MKTIME_INTERNAL Makefile.am: Include: "mktime-internal.h" License: LGPLv2+ Maintainer: Bruno Haible, Paul Eggert =============================================================================== --- MODULES.html.sh.orig Sun May 22 16:33:39 2011 +++ MODULES.html.sh Sun May 22 16:12:26 2011 @@ -1834,6 +1834,7 @@ func_echo "$element" func_begin_table + func_module mktime-internal func_module parse-datetime func_module timegm func_module tzset --- m4/mktime.m4.orig Sun May 22 16:33:39 2011 +++ m4/mktime.m4 Sun May 22 16:18:49 2011 @@ -1,4 +1,4 @@ -# serial 19 +# serial 20 dnl Copyright (C) 2002-2003, 2005-2007, 2009-2011 Free Software Foundation, dnl Inc. dnl This file is free software; the Free Software Foundation @@ -234,6 +234,23 @@ fi ]) +AC_DEFUN([gl_FUNC_MKTIME_INTERNAL], [ + AC_REQUIRE([gl_FUNC_MKTIME]) + if test $REPLACE_MKTIME = 0; then + dnl BeOS has __mktime_internal in libc, but other platforms don't. + AC_CHECK_FUNC([__mktime_internal], + [AC_DEFINE([mktime_internal], [__mktime_internal], + [Define to the real name of the mktime_internal function.]) + ], + [dnl mktime works but it doesn't export __mktime_internal, + dnl so we need to substitute our own mktime implementation. + REPLACE_MKTIME=1 + AC_LIBOBJ([mktime]) + gl_PREREQ_MKTIME + ]) + fi +]) + # Prerequisites of lib/mktime.c. AC_DEFUN([gl_PREREQ_MKTIME], [ --- m4/timegm.m4.orig Sun May 22 16:33:39 2011 +++ m4/timegm.m4 Sun May 22 16:31:49 2011 @@ -26,13 +26,5 @@ # Prerequisites of lib/timegm.c. AC_DEFUN([gl_PREREQ_TIMEGM], [ - AC_REQUIRE([gl_FUNC_MKTIME]) - if test $ac_cv_func_working_mktime = yes; then - AC_CHECK_FUNC([__mktime_internal], , - [# mktime works but it doesn't export __mktime_internal, - # so we need to substitute our own mktime implementation. - AC_LIBOBJ([mktime]) - REPLACE_MKTIME=1 - gl_PREREQ_MKTIME]) - fi + : ]) --- modules/timegm.orig Sun May 22 16:33:39 2011 +++ modules/timegm Sun May 22 16:06:04 2011 @@ -7,9 +7,9 @@ m4/timegm.m4 Depends-on: -mktime time -time_r +mktime-internal [test $HAVE_TIMEGM = 0 || test $REPLACE_TIMEGM = 1] +time_r [test $HAVE_TIMEGM = 0 || test $REPLACE_TIMEGM = 1] configure.ac: gl_FUNC_TIMEGM -- In memoriam Richard Friedmann <http://de.wikipedia.org/wiki/Richard_Friedmann>