"Fossies" - the Fresh Open Source Software Archive

Member "dateutils-0.4.6/m4/ax_zoneinfo.m4" (19 Mar 2019, 7688 Bytes) of package /linux/privat/dateutils-0.4.6.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # ===========================================================================
    2 #      http://www.gnu.org/software/autoconf-archive/ax_zoneinfo.html
    3 # ===========================================================================
    4 #
    5 # SYNOPSIS
    6 #
    7 #   AX_ZONEINFO([options...])
    8 #
    9 # DESCRIPTION
   10 #
   11 #   This macro finds compiled zoneinfo files.  If successful it will define
   12 #   HAVE_ZONEINFO per:
   13 #
   14 #     AC_DEFINE([HAVE_ZONEINFO], [1], [...])
   15 #
   16 #   and have the variable TZDIR point to the zoneinfo directory as per
   17 #
   18 #     AC_SUBST([TZDIR])
   19 #     AC_DEFINE_UNQUOTED([TZDIR], [/path/to/zic/files], [...])
   20 #
   21 #   Optionally, OPTIONS can be `right' to trigger further tests that will
   22 #   determine if leap second fix-ups are available.  If so the variables
   23 #   HAVE_ZONEINFO_RIGHT, ZONEINFO_UTC_RIGHT and TZDIR_RIGHT will be populated:
   24 #
   25 #     AC_DEFINE([HAVE_ZONEINFO_RIGHT], [1], [...])
   26 #     AC_SUBST([TZDIR_RIGHT])
   27 #     AC_DEFINE_UNQUOTED([TZDIR_RIGHT], [/path/to/right/zic/files], [...])
   28 #     AC_SUBST([ZONEINFO_UTC_RIGHT])
   29 #     AC_DEFINE_UNQUOTED([ZONEINFO_UTC_RIGHT], [$ZONEINFO_UTC_RIGHT], [...])
   30 #
   31 #
   32 # LICENSE
   33 #
   34 #   Copyright (c) 2012 Sebastian Freundt <freundt@fresse.org>
   35 #
   36 #   Copying and distribution of this file, with or without modification, are
   37 #   permitted in any medium without royalty provided the copyright notice
   38 #   and this notice are preserved. This file is offered as-is, without any
   39 #   warranty.
   40 
   41 #serial 1
   42 
   43 AC_DEFUN([AX_ZONEINFO_TZFILE_H], [dnl
   44 	dnl not totally necessary (yet), as we can simply inspect the tzfiles
   45 	dnl ourselves, but it certainly helps
   46 	AC_CHECK_HEADER([tzfile.h])
   47 ])dnl AX_ZONEINFO_TZFILE_H
   48 
   49 AC_DEFUN([AX_ZONEINFO_CHECK_TZFILE], [dnl
   50 	dnl AX_ZONEINFO_CHECK_TZFILE([FILE], [ACTION-IF-VALID], [ACTION-IF-NOT])
   51 	dnl secret switch is the 4th argument, which determines the ret code
   52 	dnl of the leapcnt check
   53 	pushdef([probe], [$1])
   54 	pushdef([if_found], [$2])
   55 	pushdef([if_not_found], [$3])
   56 
   57 	AC_REQUIRE([AX_ZONEINFO_TZFILE_H])
   58 
   59 	if test -z "${ax_tmp_zoneinfo_nested}"; then
   60 		AC_MSG_CHECKING([zoneinfo file ]probe[])
   61 	fi
   62 
   63 	AC_LANG_PUSH([C])
   64 	AC_RUN_IFELSE([AC_LANG_SOURCE([[
   65 #include <unistd.h>
   66 #include <string.h>
   67 #include <stdio.h>
   68 #include <fcntl.h>
   69 
   70 ]]ifelse([$4], [], [], [[
   71 #define CHECK_LEAPCNT	]]$4[[
   72 ]])[[
   73 
   74 /* simplified struct */
   75 struct tzhead {
   76 	char	tzh_magic[4];		/* TZ_MAGIC */
   77 	char	tzh_version[1];		/* '\0' or '2' as of 2005 */
   78 	char	tzh_reserved[15];	/* reserved--must be zero */
   79 	char	tzh_ttisgmtcnt[4];	/* coded number of trans. time flags */
   80 	char	tzh_ttisstdcnt[4];	/* coded number of trans. time flags */
   81 	char	tzh_leapcnt[4];		/* coded number of leap seconds */
   82 	char	tzh_timecnt[4];		/* coded number of transition times */
   83 	char	tzh_typecnt[4];		/* coded number of local time types */
   84 	char	tzh_charcnt[4];		/* coded number of abbr. chars */
   85 };
   86 
   87 int
   88 main(int argc, char *argv[])
   89 {
   90 	struct tzhead foo;
   91 	int f;
   92 
   93 	if (argc <= 1) {
   94 		return 0;
   95 	} else if ((f = open(argv[1], O_RDONLY, 0644)) < 0) {
   96 		return 1;
   97 	} else if (read(f, &foo, sizeof(foo)) != sizeof(foo)) {
   98 		return 1;
   99 	} else if (close(f) < 0) {
  100 		return 1;
  101 	}
  102 
  103 	/* inspect the header */
  104 	if (memcmp(foo.tzh_magic, "TZif", sizeof(foo.tzh_magic))) {
  105 		return 1;
  106 	} else if (*foo.tzh_version && *foo.tzh_version != '2') {
  107 		return 1;
  108 #if defined CHECK_LEAPCNT
  109 	} else if (!foo.tzh_leapcnt[0] && !foo.tzh_leapcnt[1] &&
  110 		   !foo.tzh_leapcnt[2] && !foo.tzh_leapcnt[3]) {
  111 		return CHECK_LEAPCNT;
  112 #endif  /* CHECK_LEAPCNT */
  113 	}
  114 
  115 	/* otherwise everything's in order */
  116 	return 0;
  117 }
  118 ]])], [## call the whole shebang again with the tzfile
  119 		if ./conftest$EXEEXT probe; then
  120 			if test -z "${ax_tmp_zoneinfo_nested}"; then
  121 				AC_MSG_RESULT([looking good])
  122 			fi
  123 			[]if_found[]
  124 		else
  125 			if test -z "${ax_tmp_zoneinfo_nested}"; then
  126 				AC_MSG_RESULT([looking bad ${ax_tmp_rc}])
  127 			fi
  128 			[]if_not_found[]
  129 		fi
  130 ], [
  131 		if test -z "${ax_tmp_zoneinfo_nested}"; then
  132 			AC_MSG_RESULT([impossible])
  133 		fi
  134 		[]if_not_found[]])
  135 	AC_LANG_POP([C])
  136 
  137 	popdef([probe])
  138 	popdef([if_found])
  139 	popdef([if_not_found])
  140 ])dnl AX_ZONEINFO_CHECK_TZFILE
  141 
  142 AC_DEFUN([AX_ZONEINFO_TZDIR], [dnl
  143 	dnl we consider a zoneinfo directory properly populated when it
  144 	dnl provides UTC or UCT or Universal or Zulu
  145 
  146 	pushdef([check_tzdir], [dnl
  147 		pushdef([dir], $]1[)dnl
  148 		test -n []dir[] && test -d []dir[] dnl
  149 		popdef([dir])dnl
  150 	])dnl check_tzdir
  151 
  152 	dnl try /etc/localtime first, sometimes it's a link into TZDIR
  153 	if test -L "/etc/localtime"; then
  154 		TZDIR_cand="`readlink /etc/localtime` ${TZDIR_cand}"
  155 	fi
  156 
  157 	dnl oh, how about we try and check if there is a TZDIR already
  158 	if check_tzdir(["${TZDIR}"]); then
  159 		## bingo
  160 		TZDIR_cand="${TZDIR} ${TZDIR_cand}"
  161 	fi
  162 
  163 	dnl often there's a tzselect util which contains the TZDIR path
  164 	AC_PATH_PROG([TZSELECT], [tzselect])
  165 	if test -n "${ac_cv_path_TZSELECT}"; then
  166 		dnl snarf the value
  167 		valtmp="`mktemp`"
  168 		strings "${ac_cv_path_TZSELECT}" | \
  169 			grep -F 'TZDIR=' > "${valtmp}"
  170 		. "${valtmp}"
  171 		TZDIR_cand="${TZDIR} ${TZDIR_cand}"
  172 		rm -f -- "${valtmp}"
  173 	fi
  174 
  175 	dnl lastly, append the usual suspects
  176 	TZDIR_cand="${TZDIR_cand} \
  177 /usr/share/zoneinfo \
  178 /usr/lib/zoneinfo \
  179 /usr/local/etc/zoneinfo \
  180 /usr/share/lib/zoneinfo \
  181 "
  182 
  183 	dnl go through our candidates
  184 	AC_CACHE_CHECK([for TZDIR], [ax_cv_zoneinfo_tzdir], [dnl
  185 		ax_tmp_zoneinfo_nested="yes"
  186 		for c in ${TZDIR_cand}; do
  187 			ax_cv_zoneinfo_utc=""
  188 			for f in "UTC" "UCT" "Universal" "Zulu"; do
  189 				AX_ZONEINFO_CHECK_TZFILE(["${c}/${f}"], [
  190 					dnl ACTION-IF-FOUND
  191 					ax_cv_zoneinfo_utc="${c}/${f}"
  192 					break
  193 				])
  194 			done
  195 			if test -n "${ax_cv_zoneinfo_utc}"; then
  196 				ax_cv_zoneinfo_tzdir="${c}"
  197 				break
  198 			fi
  199 		done
  200 		ax_tmp_zoneinfo_nested=""
  201 	])dnl ax_cv_tzdir
  202 
  203 	TZDIR="${ax_cv_zoneinfo_tzdir}"
  204 	AC_SUBST([TZDIR])
  205 
  206 	if check_tzdir(["${ax_cv_zoneinfo_tzdir}"]); then
  207 		AC_DEFINE([HAVE_ZONEINFO], [1], [dnl
  208 Define when zoneinfo directory has been present during configuration.])
  209 		AC_DEFINE_UNQUOTED([TZDIR], ["${ax_cv_zoneinfo_tzdir}"], [
  210 Configuration time zoneinfo directory.])
  211 	fi
  212 
  213 	if test -n "${ax_cv_zoneinfo_utc}"; then
  214 		AC_DEFINE_UNQUOTED([ZONEINFO_UTC],
  215 			["${ax_cv_zoneinfo_utc}"], [
  216 Leap-second UNAWARE UTC zoneinfo file.])
  217 	fi
  218 
  219 	popdef([check_tzdir])
  220 ])dnl AX_ZONEINFO_TZDIR
  221 
  222 AC_DEFUN([AX_ZONEINFO_RIGHT], [dnl
  223 	AC_REQUIRE([AX_ZONEINFO_TZDIR])
  224 
  225 	TZDIR_cand="${TZDIR} \
  226 ${TZDIR}/leapseconds \
  227 ${TZDIR}-leaps \
  228 ${TZDIR}/right \
  229 ${TZDIR}-posix \
  230 ${TZDIR}/posix \
  231 "
  232 
  233 	dnl go through our candidates
  234 	AC_CACHE_CHECK([for leap second file], [ax_cv_zoneinfo_utc_right], [dnl
  235 		ax_tmp_zoneinfo_nested="yes"
  236 		if test -n "${ax_cv_zoneinfo_utc}"; then
  237 			__utc_file="`basename "${ax_cv_zoneinfo_utc}"`"
  238 			for c in ${TZDIR_cand}; do
  239 				if test -d "${c}"; then
  240 					c="${c}/${__utc_file}"
  241 				fi
  242 				AX_ZONEINFO_CHECK_TZFILE(["${c}"], [
  243 					dnl ACTION-IF-FOUND
  244 					ax_cv_zoneinfo_utc_right="${c}"
  245 					break
  246 				], [:], [2])
  247 			done
  248 		fi
  249 		ax_tmp_zoneinfo_nested=""
  250 	])dnl ax_cv_tzdir
  251 
  252 	ZONEINFO_UTC_RIGHT="${ax_cv_zoneinfo_utc_right}"
  253 	AC_SUBST([ZONEINFO_UTC_RIGHT])
  254 	AC_SUBST([TZDIR_RIGHT])
  255 
  256 	if test -n "${ax_cv_zoneinfo_utc_right}"; then
  257 		TZDIR_RIGHT="`dirname ${ax_cv_zoneinfo_utc_right}`"
  258 
  259 		AC_DEFINE([HAVE_ZONEINFO_RIGHT], [1], [dnl
  260 Define when zoneinfo directory has been present during configuration.])
  261 		AC_DEFINE_UNQUOTED([TZDIR_RIGHT],
  262 			["${TZDIR_RIGHT}"], [
  263 Configuration time zoneinfo directory.])
  264 		AC_DEFINE_UNQUOTED([ZONEINFO_UTC_RIGHT],
  265 			["${ax_cv_zoneinfo_utc_right}"], [
  266 Leap-second aware UTC zoneinfo file.])
  267 	fi
  268 ])dnl AX_ZONEINFO_RIGHT
  269 
  270 AC_DEFUN([AX_ZONEINFO], [
  271 	AC_REQUIRE([AX_ZONEINFO_TZDIR])
  272 
  273 	ifelse([$1], [right], [
  274 		AC_REQUIRE([AX_ZONEINFO_RIGHT])
  275 	])
  276 
  277 	AC_ARG_VAR([TZDIR], [Directory with compiled zoneinfo files.])
  278 ])dnl AX_ZONEINFO
  279 
  280 dnl ax_zoneinfo.m4 ends here