Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
7.4KB

  1. # ===========================================================================
  2. # https://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
  24. # populated:
  25. #
  26. # AC_DEFINE([HAVE_ZONEINFO_RIGHT], [1], [...])
  27. # AC_SUBST([TZDIR_RIGHT])
  28. # AC_DEFINE_UNQUOTED([TZDIR_RIGHT], [/path/to/right/zic/files], [...])
  29. # AC_SUBST([ZONEINFO_UTC_RIGHT])
  30. # AC_DEFINE_UNQUOTED([ZONEINFO_UTC_RIGHT], [$ZONEINFO_UTC_RIGHT], [...])
  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. #serial 4
  41. AC_DEFUN([AX_ZONEINFO_TZFILE_H], [dnl
  42. dnl not totally necessary (yet), as we can simply inspect the tzfiles
  43. dnl ourselves, but it certainly helps
  44. AC_CHECK_HEADER([tzfile.h])
  45. ])dnl AX_ZONEINFO_TZFILE_H
  46. AC_DEFUN([AX_ZONEINFO_CHECK_TZFILE], [dnl
  47. dnl AX_ZONEINFO_CHECK_TZFILE([FILE], [ACTION-IF-VALID], [ACTION-IF-NOT])
  48. dnl secret switch is the 4th argument, which determines the ret code
  49. dnl of the leapcnt check
  50. pushdef([probe], [$1])
  51. pushdef([if_found], [$2])
  52. pushdef([if_not_found], [$3])
  53. AC_REQUIRE([AX_ZONEINFO_TZFILE_H])
  54. if test -z "${ax_tmp_zoneinfo_nested}"; then
  55. AC_MSG_CHECKING([zoneinfo file ]probe[])
  56. fi
  57. AC_LANG_PUSH([C])
  58. AC_RUN_IFELSE([AC_LANG_SOURCE([[
  59. #include <unistd.h>
  60. #include <string.h>
  61. #include <stdio.h>
  62. #include <fcntl.h>
  63. ]]ifelse([$4], [], [], [[
  64. #define CHECK_LEAPCNT ]]$4[[
  65. ]])[[
  66. /* simplified struct */
  67. struct tzhead {
  68. char tzh_magic[4]; /* TZ_MAGIC */
  69. char tzh_version[1]; /* '\0' or '2' as of 2005 */
  70. char tzh_reserved[15]; /* reserved--must be zero */
  71. char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
  72. char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
  73. char tzh_leapcnt[4]; /* coded number of leap seconds */
  74. char tzh_timecnt[4]; /* coded number of transition times */
  75. char tzh_typecnt[4]; /* coded number of local time types */
  76. char tzh_charcnt[4]; /* coded number of abbr. chars */
  77. };
  78. int
  79. main(int argc, char *argv[])
  80. {
  81. struct tzhead foo;
  82. int f;
  83. if (argc <= 1) {
  84. return 0;
  85. } else if ((f = open(argv[1], O_RDONLY, 0644)) < 0) {
  86. return 1;
  87. } else if (read(f, &foo, sizeof(foo)) != sizeof(foo)) {
  88. return 1;
  89. } else if (close(f) < 0) {
  90. return 1;
  91. }
  92. /* inspect the header */
  93. if (memcmp(foo.tzh_magic, "TZif", sizeof(foo.tzh_magic))) {
  94. return 1;
  95. } else if (*foo.tzh_version && *foo.tzh_version != '2') {
  96. return 1;
  97. #if defined CHECK_LEAPCNT
  98. } else if (!foo.tzh_leapcnt[0] && !foo.tzh_leapcnt[1] &&
  99. !foo.tzh_leapcnt[2] && !foo.tzh_leapcnt[3]) {
  100. return CHECK_LEAPCNT;
  101. #endif /* CHECK_LEAPCNT */
  102. }
  103. /* otherwise everything's in order */
  104. return 0;
  105. }
  106. ]])], [## call the whole shebang again with the tzfile
  107. if ./conftest$EXEEXT probe; then
  108. if test -z "${ax_tmp_zoneinfo_nested}"; then
  109. AC_MSG_RESULT([looking good])
  110. fi
  111. []if_found[]
  112. else
  113. if test -z "${ax_tmp_zoneinfo_nested}"; then
  114. AC_MSG_RESULT([looking bad ${ax_tmp_rc}])
  115. fi
  116. []if_not_found[]
  117. fi
  118. ], [
  119. if test -z "${ax_tmp_zoneinfo_nested}"; then
  120. AC_MSG_RESULT([impossible])
  121. fi
  122. []if_not_found[]])
  123. AC_LANG_POP([C])
  124. popdef([probe])
  125. popdef([if_found])
  126. popdef([if_not_found])
  127. ])dnl AX_ZONEINFO_CHECK_TZFILE
  128. AC_DEFUN([AX_ZONEINFO_TZDIR], [dnl
  129. dnl we consider a zoneinfo directory properly populated when it
  130. dnl provides UTC or UCT or Universal or Zulu
  131. pushdef([check_tzdir], [dnl
  132. pushdef([dir], $]1[)dnl
  133. test -n []dir[] && test -d []dir[] dnl
  134. popdef([dir])dnl
  135. ])dnl check_tzdir
  136. dnl try /etc/localtime first, sometimes it's a link into TZDIR
  137. if test -L "/etc/localtime"; then
  138. TZDIR_cand="`readlink /etc/localtime` ${TZDIR_cand}"
  139. fi
  140. dnl oh, how about we try and check if there is a TZDIR already
  141. if check_tzdir(["${TZDIR}"]); then
  142. ## bingo
  143. TZDIR_cand="${TZDIR} ${TZDIR_cand}"
  144. fi
  145. dnl often there's a tzselect util which contains the TZDIR path
  146. AC_PATH_PROG([TZSELECT], [tzselect])
  147. if test -n "${ac_cv_path_TZSELECT}"; then
  148. dnl snarf the value
  149. valtmp="`mktemp`"
  150. strings "${ac_cv_path_TZSELECT}" | \
  151. grep -F 'TZDIR=' > "${valtmp}"
  152. . "${valtmp}"
  153. TZDIR_cand="${TZDIR} ${TZDIR_cand}"
  154. rm -f -- "${valtmp}"
  155. fi
  156. dnl lastly, append the usual suspects
  157. TZDIR_cand="${TZDIR_cand} \
  158. /usr/share/zoneinfo \
  159. /usr/lib/zoneinfo \
  160. /usr/local/etc/zoneinfo \
  161. /usr/share/lib/zoneinfo \
  162. "
  163. dnl go through our candidates
  164. AC_CACHE_CHECK([for TZDIR], [ax_cv_zoneinfo_tzdir], [dnl
  165. ax_tmp_zoneinfo_nested="yes"
  166. for c in ${TZDIR_cand}; do
  167. ax_cv_zoneinfo_utc=""
  168. for f in "UTC" "UCT" "Universal" "Zulu"; do
  169. AX_ZONEINFO_CHECK_TZFILE(["${c}/${f}"], [
  170. dnl ACTION-IF-FOUND
  171. ax_cv_zoneinfo_utc="${c}/${f}"
  172. break
  173. ])
  174. done
  175. if test -n "${ax_cv_zoneinfo_utc}"; then
  176. ax_cv_zoneinfo_tzdir="${c}"
  177. break
  178. fi
  179. done
  180. ax_tmp_zoneinfo_nested=""
  181. ])dnl ax_cv_tzdir
  182. TZDIR="${ax_cv_zoneinfo_tzdir}"
  183. AC_SUBST([TZDIR])
  184. if check_tzdir(["${ax_cv_zoneinfo_tzdir}"]); then
  185. AC_DEFINE([HAVE_ZONEINFO], [1], [dnl
  186. Define when zoneinfo directory has been present during configuration.])
  187. AC_DEFINE_UNQUOTED([TZDIR], ["${ax_cv_zoneinfo_tzdir}"], [
  188. Configuration time zoneinfo directory.])
  189. fi
  190. popdef([check_tzdir])
  191. ])dnl AX_ZONEINFO_TZDIR
  192. AC_DEFUN([AX_ZONEINFO_RIGHT], [dnl
  193. AC_REQUIRE([AX_ZONEINFO_TZDIR])
  194. TZDIR_cand="${TZDIR} \
  195. ${TZDIR}/leapseconds \
  196. ${TZDIR}-leaps \
  197. ${TZDIR}/right \
  198. ${TZDIR}-posix \
  199. ${TZDIR}/posix \
  200. "
  201. dnl go through our candidates
  202. AC_CACHE_CHECK([for leap second file], [ax_cv_zoneinfo_utc_right], [dnl
  203. ax_tmp_zoneinfo_nested="yes"
  204. if test -n "${ax_cv_zoneinfo_utc}"; then
  205. __utc_file="`basename "${ax_cv_zoneinfo_utc}"`"
  206. for c in ${TZDIR_cand}; do
  207. if test -d "${c}"; then
  208. c="${c}/${__utc_file}"
  209. fi
  210. AX_ZONEINFO_CHECK_TZFILE(["${c}"], [
  211. dnl ACTION-IF-FOUND
  212. ax_cv_zoneinfo_utc_right="${c}"
  213. break
  214. ], [:], [2])
  215. done
  216. fi
  217. ax_tmp_zoneinfo_nested=""
  218. ])dnl ax_cv_tzdir
  219. ZONEINFO_UTC_RIGHT="${ax_cv_zoneinfo_utc_right}"
  220. AC_SUBST([ZONEINFO_UTC_RIGHT])
  221. AC_SUBST([TZDIR_RIGHT])
  222. if test -n "${ax_cv_zoneinfo_utc_right}"; then
  223. TZDIR_RIGHT="`dirname ${ax_cv_zoneinfo_utc_right}`"
  224. AC_DEFINE([HAVE_ZONEINFO_RIGHT], [1], [dnl
  225. Define when zoneinfo directory has been present during configuration.])
  226. AC_DEFINE_UNQUOTED([TZDIR_RIGHT],
  227. ["${TZDIR_RIGHT}"], [
  228. Configuration time zoneinfo directory.])
  229. AC_DEFINE_UNQUOTED([ZONEINFO_UTC_RIGHT],
  230. ["${ax_cv_zoneinfo_utc_right}"], [
  231. Leap-second aware UTC zoneinfo file.])
  232. fi
  233. ])dnl AX_ZONEINFO_RIGHT
  234. AC_DEFUN([AX_ZONEINFO], [
  235. AC_REQUIRE([AX_ZONEINFO_TZDIR])
  236. ifelse([$1], [right], [
  237. AC_REQUIRE([AX_ZONEINFO_RIGHT])
  238. ])
  239. AC_ARG_VAR([TZDIR], [Directory with compiled zoneinfo files.])
  240. ])dnl AX_ZONEINFO
  241. dnl ax_zoneinfo.m4 ends here