• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Make and install tzdb code and data.
2# This file is in the public domain, so clarified as of
3# 2009-05-17 by Arthur David Olson.
4# Request POSIX conformance; this must be the first non-comment line.
5.POSIX:
6# By default, builds of code and data assume POSIX.1-2001 or later;
7# this assumption can be relaxed by tailoring the build as described below.
8# On older platforms you may need to scrounge for POSIX conformance.
9# For example, on Solaris 10 (2005) with Sun Studio 12 aka Sun C 5.9 (2007),
10# use 'PATH=/usr/xpg4/bin:$PATH make CC=c99'.
11# Reproducible builds of distribution tarballs also need a copy of the
12# Git repository, and assume the behavior of the following programs
13# (or later versions):
14#	Git 2.7.0 (2016)
15#	GNU Coreutils 6.3 (2006)
16#	GNU Tar 1.14 (2004)
17#	GnuPG 1.4 (2004)
18# Although tzdb does not come with a software bill of materials,
19# you should be able to construct one based on the above information,
20# your platform, and the way you use this Makefile.
21
22# To affect how this Makefile works, you can run a shell script like this:
23#
24#	#!/bin/sh
25#	make CFLAGS='-O2 -DHAVE_GETTEXT=0' "$@"
26#
27# This example script is appropriate for a GNU/Linux system
28# which needs more optimization than default, and which does not want
29# gettext's internationalization of diagnostics.
30#
31# Alternatively, you can simply edit this Makefile to tailor the following
32# macro definitions.
33
34###############################################################################
35# Start of macros that one plausibly might want to tailor.
36
37# Package name for the code distribution.
38PACKAGE=	tzcode
39
40# Version number for the distribution, overridden in the 'tarballs' rule below.
41VERSION=	unknown
42
43# Email address for bug reports.
44BUGEMAIL=	tz@iana.org
45
46# DATAFORM selects the data format.
47# Available formats represent essentially the same data, albeit
48# possibly with minor discrepancies that users are not likely to notice.
49# To get new features and the best data right away, use:
50#	DATAFORM=	vanguard
51# To wait a while before using new features, to give downstream users
52# time to upgrade zic (the default), use:
53#	DATAFORM=	main
54# To wait even longer for new features, use:
55#	DATAFORM=	rearguard
56# Rearguard users might also want "ZFLAGS = -b fat"; see below.
57DATAFORM=		main
58
59# Change the line below for your timezone (after finding the one you want in
60# one of the $(TDATA) source files, or adding it to a source file).
61# Alternatively, if you discover you've got the wrong timezone, you can just
62# 'zic -l -' to remove it, or 'zic -l rightzone' to change it.
63# Use the command
64#	make zonenames
65# to get a list of the values you can use for LOCALTIME.
66
67LOCALTIME=	Factory
68
69# The POSIXRULES macro controls interpretation of POSIX-like TZ
70# settings like TZ='EET-2EEST' that lack DST transition rules.
71# If POSIXRULES is '-', no template is installed; this is the default.
72# Any other value for POSIXRULES is obsolete and should not be relied on, as:
73# * It does not work correctly in popular implementations such as GNU/Linux.
74# * It does not work even in tzcode, except for historical timestamps
75#   that precede the last explicit transition in the POSIXRULES file.
76#   Hence it typically does not work for current and future timestamps.
77# If, despite the above, you want a template for handling these settings,
78# you can change the line below (after finding the timezone you want in the
79# one of the $(TDATA) source files, or adding it to a source file).
80# Alternatively, if you discover you've got the wrong timezone, you can just
81# 'zic -p -' to remove it, or 'zic -p rightzone' to change it.
82# Use the command
83#	make zonenames
84# to get a list of the values you can use for POSIXRULES.
85
86POSIXRULES=	-
87
88# Also see TZDEFRULESTRING below, which takes effect only
89# if POSIXRULES is '-' or if the template file cannot be accessed.
90
91
92# Installation locations.
93#
94# The defaults are suitable for Debian, except that if REDO is
95# posix_right or right_posix then files that Debian puts under
96# /usr/share/zoneinfo/posix and /usr/share/zoneinfo/right are instead
97# put under /usr/share/zoneinfo-posix and /usr/share/zoneinfo-leaps,
98# respectively.  Problems with the Debian approach are discussed in
99# the commentary for the right_posix rule (below).
100
101# Destination directory, which can be used for staging.
102# 'make DESTDIR=/stage install' installs under /stage (e.g., to
103# /stage/etc/localtime instead of to /etc/localtime).  Files under
104# /stage are not intended to work as-is, but can be copied by hand to
105# the root directory later.  If DESTDIR is empty, 'make install' does
106# not stage, but installs directly into production locations.
107DESTDIR =
108
109# Everything is installed into subdirectories of TOPDIR, and used there.
110# TOPDIR should be empty (meaning the root directory),
111# or a directory name that does not end in "/".
112# TOPDIR should be empty or an absolute name unless you're just testing.
113TOPDIR =
114
115# The default local timezone is taken from the file TZDEFAULT.
116TZDEFAULT = $(TOPDIR)/etc/localtime
117
118# The subdirectory containing installed program and data files, and
119# likewise for installed files that can be shared among architectures.
120# These should be relative file names.
121USRDIR = usr
122USRSHAREDIR = $(USRDIR)/share
123
124# "Compiled" timezone information is placed in the "TZDIR" directory
125# (and subdirectories).
126# TZDIR_BASENAME should not contain "/" and should not be ".", ".." or empty.
127TZDIR_BASENAME=	zoneinfo
128TZDIR = $(TOPDIR)/$(USRSHAREDIR)/$(TZDIR_BASENAME)
129
130# The "tzselect" and (if you do "make INSTALL") "date" commands go in:
131BINDIR = $(TOPDIR)/$(USRDIR)/bin
132
133# The "zdump" command goes in:
134ZDUMPDIR = $(BINDIR)
135
136# The "zic" command goes in:
137ZICDIR = $(TOPDIR)/$(USRDIR)/sbin
138
139# Manual pages go in subdirectories of. . .
140MANDIR = $(TOPDIR)/$(USRSHAREDIR)/man
141
142# Library functions are put in an archive in LIBDIR.
143LIBDIR = $(TOPDIR)/$(USRDIR)/lib
144
145
146# Types to try, as an alternative to time_t.
147TIME_T_ALTERNATIVES = $(TIME_T_ALTERNATIVES_HEAD) $(TIME_T_ALTERNATIVES_TAIL)
148TIME_T_ALTERNATIVES_HEAD = int_least64_t.ck
149TIME_T_ALTERNATIVES_TAIL = int_least32_t.ck uint_least32_t.ck \
150  uint_least64_t.ck
151
152# What kind of TZif data files to generate.  (TZif is the binary time
153# zone data format that zic generates; see Internet RFC 9636.)
154# If you want only POSIX time, with time values interpreted as
155# seconds since the epoch (not counting leap seconds), use
156#	REDO=		posix_only
157# below.  If you want only "right" time, with values interpreted
158# as seconds since the epoch (counting leap seconds), use
159#	REDO=		right_only
160# below.  If you want both sets of data available, with leap seconds not
161# counted normally, use
162#	REDO=		posix_right
163# below.  If you want both sets of data available, with leap seconds counted
164# normally, use
165#	REDO=		right_posix
166# below.  POSIX mandates that leap seconds not be counted; for compatibility
167# with it, use "posix_only" or "posix_right".  Use POSIX time on systems with
168# leap smearing; this can work better than unsmeared "right" time with
169# applications that are not leap second aware, and is closer to unsmeared
170# "right" time than unsmeared POSIX time is (e.g., 0.5 vs 1.0 s max error).
171
172REDO=		posix_right
173
174# Whether to put an "Expires" line in the leapseconds file.
175# Use EXPIRES_LINE=1 to put the line in, 0 to omit it.
176# The EXPIRES_LINE value matters only if REDO's value contains "right".
177# If you change EXPIRES_LINE, remove the leapseconds file before running "make".
178# zic's support for the Expires line was introduced in tzdb 2020a,
179# and was modified in tzdb 2021b to generate version 4 TZif files.
180# EXPIRES_LINE defaults to 0 for now so that the leapseconds file
181# can be given to pre-2020a zic implementations and so that TZif files
182# built by newer zic implementations can be read by pre-2021b libraries.
183EXPIRES_LINE=	0
184
185# To install data in text form that has all the information of the TZif data,
186# (optionally incorporating leap second information), use
187#	TZDATA_TEXT=	tzdata.zi leapseconds
188# To install text data without leap second information (e.g., because
189# REDO='posix_only'), use
190#	TZDATA_TEXT=	tzdata.zi
191# To avoid installing text data, use
192#	TZDATA_TEXT=
193
194TZDATA_TEXT=	leapseconds tzdata.zi
195
196# For backward-compatibility links for old zone names, use
197#	BACKWARD=	backward
198# To omit these links, use
199#	BACKWARD=
200
201BACKWARD=	backward
202
203# If you want out-of-scope and often-wrong data from the file 'backzone',
204# but only for entries listed in the backward-compatibility file zone.tab, use
205#	PACKRATDATA=	backzone
206#	PACKRATLIST=	zone.tab
207# If you want all the 'backzone' data, use
208#	PACKRATDATA=	backzone
209#	PACKRATLIST=
210# To omit this data, use
211#	PACKRATDATA=
212#	PACKRATLIST=
213
214PACKRATDATA=
215PACKRATLIST=
216
217# The name of a locale using the UTF-8 encoding, used during self-tests.
218# The tests are skipped if the name does not appear to work on this system.
219
220UTF8_LOCALE=	en_US.utf8
221
222# Non-default libraries needed to link.
223# On some hosts, this should have -lintl unless CFLAGS has -DHAVE_GETTEXT=0.
224LDLIBS=
225
226# Add the following to an uncommented "CFLAGS=" line as needed
227# to override defaults specified in the source code or by the system.
228# "-DFOO" is equivalent to "-DFOO=1".
229#  -DDEPRECATE_TWO_DIGIT_YEARS for optional runtime warnings about strftime
230#	formats that generate only the last two digits of year numbers
231#  -DEPOCH_LOCAL if the 'time' function returns local time not UT
232#  -DEPOCH_OFFSET=N if the 'time' function returns a value N greater
233#	than what POSIX specifies, assuming local time is UT.
234#	For example, N is 252460800 on AmigaOS.
235#  -DHAVE_DECL_ASCTIME_R=0 if <time.h> does not declare asctime_r
236#	on POSIX platforms predating POSIX.1-2024
237#  -DHAVE_DECL_ENVIRON if <unistd.h> declares 'environ'
238#  -DHAVE_DECL_TIMEGM=0 if <time.h> does not declare timegm
239#  -DHAVE_DIRECT_H if mkdir needs <direct.h> (MS-Windows)
240#  -DHAVE__GENERIC=0 if _Generic does not work*
241#  -DHAVE_GETRANDOM if getrandom works (e.g., GNU/Linux),
242#	-DHAVE_GETRANDOM=0 to avoid using getrandom
243#  -DHAVE_GETTEXT if gettext works (e.g., GNU/Linux, FreeBSD, Solaris),
244#	where LDLIBS also needs to contain -lintl on some hosts;
245#	-DHAVE_GETTEXT=0 to avoid using gettext
246#  -DHAVE_INCOMPATIBLE_CTIME_R if your system's time.h declares
247#	ctime_r and asctime_r incompatibly with POSIX.1-2017 and earlier
248#	(Solaris when _POSIX_PTHREAD_SEMANTICS is not defined).
249#  -DHAVE_INTTYPES_H=0 if <inttypes.h> does not work*+
250#  -DHAVE_LINK=0 if your system lacks a link function
251#  -DHAVE_LOCALTIME_R=0 if your system lacks a localtime_r function
252#  -DHAVE_LOCALTIME_RZ=0 if you do not want zdump to use localtime_rz
253#	localtime_rz can make zdump significantly faster, but is nonstandard.
254#  -DHAVE_MALLOC_ERRNO=0 if malloc etc. do not set errno on failure.
255#  -DHAVE_POSIX_DECLS=0 if your system's include files do not declare
256#	functions like 'link' or variables like 'tzname' required by POSIX
257#  -DHAVE_SETENV=0 if your system lacks the setenv function
258#  -DHAVE_SNPRINTF=0 if your system lacks the snprintf function+
259#  -DHAVE_STDCKDINT_H=0 if neither <stdckdint.h> nor substitutes like
260#	__builtin_add_overflow work*
261#  -DHAVE_STDINT_H=0 if <stdint.h> does not work*+
262#  -DHAVE_STRFTIME_L if <time.h> declares locale_t and strftime_l
263#  -DHAVE_STRDUP=0 if your system lacks the strdup function
264#  -DHAVE_STRTOLL=0 if your system lacks the strtoll function+
265#  -DHAVE_SYMLINK=0 if your system lacks the symlink function
266#  -DHAVE_SYS_STAT_H=0 if <sys/stat.h> does not work*
267#  -DHAVE_TZSET=0 if your system lacks a tzset function
268#  -DHAVE_UNISTD_H=0 if <unistd.h> does not work*
269#  -DHAVE_UTMPX_H=0 if <utmpx.h> does not work*
270#  -Dlocale_t=XXX if your system uses XXX instead of locale_t
271#  -DMKTIME_MIGHT_OVERFLOW if mktime might fail due to time_t overflow
272#  -DPORT_TO_C89 if tzcode should also run on mostly-C89 platforms+
273#	Typically it is better to use a later standard.  For example,
274#	with GCC 4.9.4 (2016), prefer '-std=gnu11' to '-DPORT_TO_C89'.
275#	Even with -DPORT_TO_C89, the code needs at least one C99
276#	feature (integers at least 64 bits wide) and maybe more.
277#  -DRESERVE_STD_EXT_IDS if your platform reserves standard identifiers
278#	with external linkage, e.g., applications cannot define 'localtime'.
279#  -Dssize_t=int on hosts like MS-Windows that lack ssize_t
280#  -DSUPPORT_C89=0 if the tzcode library should not support C89 callers
281#	Although -DSUPPORT_C89=0 might work around latent bugs in callers,
282#	it does not conform to POSIX.
283#  -DSUPPORT_POSIX2008 if the library should support older POSIX callers+
284#	However, this might cause problems in POSIX.1-2024-or-later callers.
285#  -DSUPPRESS_TZDIR to not prepend TZDIR to file names; this has
286#	security implications and is not recommended for general use
287#  -DTHREAD_SAFE to make localtime.c thread-safe, as POSIX requires;
288#	not needed by the main-program tz code, which is single-threaded.
289#	Append other compiler flags as needed, e.g., -pthread on GNU/Linux.
290#  -Dtime_tz=\"T\" to use T as the time_t type, rather than the system time_t
291#	This is intended for internal use only; it mangles external names.
292#  -DTZ_DOMAIN=\"foo\" to use "foo" for gettext domain name; default is "tz"
293#  -DTZ_DOMAINDIR=\"/path\" to use "/path" for gettext directory;
294#	the default is system-supplied, typically "/usr/lib/locale"
295#  -DTZDEFRULESTRING=\",date/time,date/time\" to default to the specified
296#	DST transitions for proleptic format TZ strings lacking them,
297#	in the usual case where POSIXRULES is '-'.  If not specified,
298#	TZDEFRULESTRING defaults to US rules for future DST transitions.
299#	This mishandles some past timestamps, as US DST rules have changed.
300#	It also mishandles settings like TZ='EET-2EEST' for eastern Europe,
301#	as Europe and US DST rules differ.
302#  -DTZNAME_MAXIMUM=N to limit time zone abbreviations to N bytes (default 254)
303#  -DUNINIT_TRAP if reading uninitialized storage can cause problems
304#	other than simply getting garbage data
305#  -DUSE_LTZ=0 to build zdump with the system time zone library
306#	Also set TZDOBJS=zdump.o and CHECK_TIME_T_ALTERNATIVES= below.
307#  -DZIC_BLOAT_DEFAULT=\"fat\" to default zic's -b option to "fat", and
308#	similarly for "slim".  Fat TZif files work around incompatibilities
309#	and bugs in some TZif readers, notably older ones that
310#	ignore or otherwise mishandle 64-bit data in TZif files;
311#	however, fat TZif files may trigger bugs in newer TZif readers.
312#	Slim TZif files are more efficient, and are the default.
313#  -DZIC_MAX_ABBR_LEN_WO_WARN=3
314#	(or some other number) to set the maximum time zone abbreviation length
315#	that zic will accept without a warning (the default is 6)
316#  -g to generate symbolic debugging info
317#  -Idir to include from directory 'dir'
318#  -O0 to disable optimization; other -O options to enable more optimization
319#  -Uname to remove any definition of the macro 'name'
320#  $(GCC_DEBUG_FLAGS) if you are using recent GCC and want lots of checking
321#
322# * Options marked "*" can be omitted if your compiler is C23 compatible.
323# * Options marked "+" are obsolescent and are planned to be removed
324#   once the code assumes C99 or later (say in the year 2029)
325#   and POSIX.1-2024 or later (say in the year 2034).
326#
327# Select instrumentation via "make GCC_INSTRUMENT='whatever'".
328GCC_INSTRUMENT = \
329  -fsanitize=undefined -fsanitize-address-use-after-scope \
330  -fsanitize-undefined-trap-on-error -fstack-protector
331# Omit -fanalyzer from GCC_DEBUG_FLAGS, as it makes GCC too slow.
332GCC_DEBUG_FLAGS = -DGCC_LINT -g3 -O3 \
333  $(GCC_INSTRUMENT) \
334  -Wall -Wextra \
335  -Walloc-size-larger-than=100000 -Warray-bounds=2 \
336  -Wbad-function-cast -Wbidi-chars=any,ucn -Wcast-align=strict -Wcast-qual \
337  -Wdate-time \
338  -Wdeclaration-after-statement -Wdouble-promotion \
339  -Wduplicated-branches -Wduplicated-cond -Wflex-array-member-not-at-end \
340  -Wformat=2 -Wformat-overflow=2 -Wformat-signedness -Wformat-truncation \
341  -Wimplicit-fallthrough=5 -Winit-self -Wlogical-op \
342  -Wmissing-declarations -Wmissing-prototypes \
343  -Wmissing-variable-declarations -Wnested-externs \
344  -Wnull-dereference \
345  -Wold-style-definition -Woverlength-strings -Wpointer-arith \
346  -Wshadow -Wshift-overflow=2 -Wstrict-overflow \
347  -Wstrict-prototypes -Wstringop-overflow=4 \
348  -Wstringop-truncation -Wsuggest-attribute=cold \
349  -Wsuggest-attribute=const -Wsuggest-attribute=format \
350  -Wsuggest-attribute=malloc \
351  -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure \
352  -Wtrampolines -Wundef -Wunused-macros -Wuse-after-free=3 \
353  -Wvariadic-macros -Wvla -Wwrite-strings \
354  -Wno-format-nonliteral -Wno-sign-compare -Wno-type-limits
355#
356# If your system has a "GMT offset" field in its "struct tm"s
357# (or if you decide to add such a field in your system's "time.h" file),
358# add the name to a define such as
359#	-DTM_GMTOFF=tm_gmtoff
360# to the end of the "CFLAGS=" line.  If not defined, the code attempts to
361# guess TM_GMTOFF from other macros; define NO_TM_GMTOFF to suppress this.
362# Similarly, if your system has a "zone abbreviation" field, define
363#	-DTM_ZONE=tm_zone
364# and define NO_TM_ZONE to suppress any guessing.
365# Although POSIX.1-2024 requires these fields and they are widely available
366# on GNU/Linux and BSD systems, some older systems lack them.
367#
368# The next batch of options control support for external variables
369# exported by tzcode.  In practice these variables are less useful
370# than TM_GMTOFF and TM_ZONE.  However, most of them are standardized.
371# #
372# # To omit or support the external variable "tzname", add one of:
373# #	-DHAVE_TZNAME=0 # do not support "tzname"
374# #	-DHAVE_TZNAME=1 # support "tzname", which is defined by system library
375# #	-DHAVE_TZNAME=2 # support and define "tzname"
376# # to the "CFLAGS=" line.  Although "tzname" is required by POSIX.1-1988
377# # and later, its contents are unspecified if you use a geographical TZ
378# # and the variable is planned to be removed in a future POSIX edition.
379# # If not defined, the code attempts to guess HAVE_TZNAME from other macros.
380# # Warning: unless time_tz is also defined, HAVE_TZNAME=1 can cause
381# # crashes when combined with some platforms' standard libraries,
382# # presumably due to memory allocation issues.
383# #
384# # To omit or support the external variables "timezone" and "daylight", add
385# #	-DUSG_COMPAT=0 # do not support
386# #	-DUSG_COMPAT=1 # support, and variables are defined by system library
387# #	-DUSG_COMPAT=2 # support and define variables
388# # to the "CFLAGS=" line; "timezone" and "daylight" are inspired by Unix
389# # Systems Group code and are required by POSIX.1-2008 and later (with XSI),
390# # although their contents are unspecified if you use a geographical TZ
391# # and the variables are planned to be removed in a future edition of POSIX.
392# # If not defined, the code attempts to guess USG_COMPAT from other macros.
393# #
394# # To support the external variable "altzone", add
395# #	-DALTZONE=0 # do not support
396# #	-DALTZONE=1 # support "altzone", which is defined by system library
397# #	-DALTZONE=2 # support and define "altzone"
398# # to the end of the "CFLAGS=" line; although "altzone" appeared in
399# # System V Release 3.1 it has not been standardized.
400# # If not defined, the code attempts to guess ALTZONE from other macros.
401#
402# If you want functions that were inspired by early versions of X3J11's work,
403# add
404#	-DSTD_INSPIRED
405# to the end of the "CFLAGS=" line.  This arranges for the following
406# functions to be added to the time conversion library.
407# "offtime" is like "gmtime" except that it accepts a second (long) argument
408# that gives an offset to add to the time_t when converting it.
409# I.e., "offtime" is like calling "localtime_rz" with a fixed-offset zone.
410# "timelocal" is nearly equivalent to "mktime".
411# "timeoff" is like "timegm" except that it accepts a second (long) argument
412# that gives an offset to use when converting to a time_t.
413# I.e., "timeoff" is like calling "mktime_z" with a fixed-offset zone.
414# "posix2time" and "time2posix" are described in an included manual page.
415# X3J11's work does not describe any of these functions.
416# These functions may well disappear in future releases of the time
417# conversion package.
418#
419# If you don't want functions that were inspired by NetBSD, add
420#	-DNETBSD_INSPIRED=0
421# to the end of the "CFLAGS=" line.  Otherwise, the functions
422# "localtime_rz", "mktime_z", "tzalloc", and "tzfree" are added to the
423# time library, and if STD_INSPIRED is also defined to nonzero the functions
424# "posix2time_z" and "time2posix_z" are added as well.
425# The functions ending in "_z" (or "_rz") are like their unsuffixed
426# (or suffixed-by-"_r") counterparts, except with an extra first
427# argument of opaque type timezone_t that specifies the timezone.
428# "tzalloc" allocates a timezone_t value, and "tzfree" frees it.
429#
430# If you want to allocate state structures in localtime, add
431#	-DALL_STATE
432# to the end of the "CFLAGS=" line.  Storage is obtained by calling malloc.
433#
434# NIST-PCTS:151-2, Version 1.4, (1993-12-03) is a test suite put
435# out by the National Institute of Standards and Technology
436# which claims to test C and POSIX conformance.  If you want to pass PCTS, add
437#	-DPCTS
438# to the end of the "CFLAGS=" line.
439#
440# If you want strict compliance with XPG4 as of 1994-04-09, add
441#	-DXPG4_1994_04_09
442# to the end of the "CFLAGS=" line.  This causes "strftime" to always return
443# 53 as a week number (rather than 52 or 53) for January days before
444# January's first Monday when a "%V" format is used and January 1
445# falls on a Friday, Saturday, or Sunday.
446#
447# POSIX says CFLAGS defaults to "-O 1".
448# Uncomment the following line and edit its contents as needed.
449
450#CFLAGS= -O 1
451
452
453# The name of a POSIX-like library archiver, its flags, C compiler,
454# linker flags, and 'make' utility.  Ordinarily the defaults suffice.
455# The commented-out values are the defaults specified by POSIX.1-2024.
456#AR = ar
457#ARFLAGS = -rv
458#CC = c17
459#LDFLAGS =
460#MAKE = make
461
462# Where to fetch leap-seconds.list from.
463leaplist_URI = \
464  https://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list
465# The file is generated by the IERS Earth Orientation Centre, in Paris.
466leaplist_TZ = Europe/Paris
467#
468# To fetch leap-seconds.list from NIST via a less-secure protocol
469# and with less-volatile metadata, use these settings:
470#leaplist_URI = ftp://ftp.boulder.nist.gov/pub/time/leap-seconds.list
471#leaplist_TZ = America/Denver
472
473# The zic command and its arguments.
474
475zic=		./zic
476ZIC=		$(zic) $(ZFLAGS)
477
478# To shrink the size of installed TZif files,
479# append "-r @N" to omit data before N-seconds-after-the-Epoch.
480# To grow the files and work around bugs in older applications,
481# possibly at the expense of introducing bugs in newer ones,
482# append "-b fat"; see ZIC_BLOAT_DEFAULT above.
483# See the zic man page for more about -b and -r.
484ZFLAGS=
485
486# How to use zic to install TZif files.
487
488ZIC_INSTALL=	$(ZIC) -d '$(DESTDIR)$(TZDIR)'
489
490# The name of a POSIX-compliant 'awk' on your system.
491# mawk 1.3.3 and Solaris 10 /usr/bin/awk do not work.
492# Also, it is better (though not essential) if 'awk' supports UTF-8,
493# and unfortunately mawk and busybox awk do not support UTF-8.
494# Try AWK=gawk or AWK=nawk if your awk has the abovementioned problems.
495AWK=		awk
496
497# The full path name of a POSIX-compliant shell, preferably one that supports
498# the Korn shell's 'select' statement as an extension.
499# These days, Bash is the most popular.
500# It should be OK to set this to /bin/sh, on platforms where /bin/sh
501# lacks 'select' or doesn't completely conform to POSIX, but /bin/bash
502# is typically nicer if it works.
503KSHELL=		/bin/bash
504
505# Name of curl <https://curl.haxx.se/>, used for HTML validation
506# and to fetch leap-seconds.list from upstream.
507# Set CURL=: to disable use of the Internet.
508CURL=		curl
509
510# Name of GNU Privacy Guard <https://gnupg.org/>, used to sign distributions.
511GPG=		gpg
512
513# This expensive test requires USE_LTZ.
514# To suppress it, define this macro to be empty.
515CHECK_TIME_T_ALTERNATIVES = check_time_t_alternatives
516
517# SAFE_CHAR is a regular expression that matches a safe character.
518# Some parts of this distribution are limited to safe characters;
519# others can use any UTF-8 character.
520# For now, the safe characters are a safe subset of ASCII.
521# The caller must set the shell variable 'sharp' to the character '#',
522# since Makefile macros cannot contain '#'.
523# TAB_CHAR is a single tab character, in single quotes.
524TAB_CHAR=	'	'
525SAFE_CHARSET1=	$(TAB_CHAR)' !\"'$$sharp'$$%&'\''()*+,./0123456789:;<=>?@'
526SAFE_CHARSET2=	'ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\^_`'
527SAFE_CHARSET3=	'abcdefghijklmnopqrstuvwxyz{|}~'
528SAFE_CHARSET=	$(SAFE_CHARSET1)$(SAFE_CHARSET2)$(SAFE_CHARSET3)
529SAFE_CHAR=	'[]'$(SAFE_CHARSET)'-]'
530
531# These non-alphabetic, non-ASCII printable characters are Latin-1,
532# and so are likely displayable even in editors like XEmacs 21
533# that have limited display capabilities.
534UNUSUAL_OK_LATIN_1 = ¡¢£¤¥¦§¨©«¬®¯°±²³´¶·¸¹»¼½¾¿×÷
535# Non-ASCII non-letters that OK_CHAR allows, as these characters are
536# useful in commentary.
537UNUSUAL_OK_CHARSET= $(UNUSUAL_OK_LATIN_1)
538
539# Put this in a bracket expression to match spaces.
540s = [:space:]
541
542# OK_CHAR matches any character allowed in the distributed files.
543# This is the same as SAFE_CHAR, except that UNUSUAL_OK_CHARSET and
544# multibyte letters are also allowed so that commentary can contain a
545# few safe symbols and people's names and can quote non-English sources.
546# Other non-letters are limited to ASCII renderings for the
547# convenience of maintainers using XEmacs 21.5.34, which by default
548# mishandles Unicode characters U+0100 and greater.
549OK_CHAR=	'[][:alpha:]$(UNUSUAL_OK_CHARSET)'$(SAFE_CHARSET)'-]'
550
551# SAFE_LINE matches a line of safe characters.
552# SAFE_SHARP_LINE is similar, except any OK character can follow '#';
553# this is so that comments can contain non-ASCII characters.
554# OK_LINE matches a line of OK characters.
555SAFE_LINE=	'^'$(SAFE_CHAR)'*$$'
556SAFE_SHARP_LINE='^'$(SAFE_CHAR)'*('$$sharp$(OK_CHAR)'*)?$$'
557OK_LINE=	'^'$(OK_CHAR)'*$$'
558
559# Flags to give 'tar' when making a distribution.
560# Try to use flags appropriate for GNU tar.
561GNUTARFLAGS= --format=pax --pax-option=delete=atime,delete=ctime \
562  --numeric-owner --owner=0 --group=0 \
563  --mode=go+u,go-w --sort=name
564SETUP_TAR= \
565  export LC_ALL=C && \
566  if tar $(GNUTARFLAGS) --version >/dev/null 2>&1; then \
567    TAR='tar $(GNUTARFLAGS)'; \
568  else \
569    TAR=tar; \
570  fi
571
572# Flags to give 'gzip' when making a distribution.
573GZIPFLAGS=	-9n
574
575# When comparing .tzs files, use GNU diff's -F'^TZ=' option if supported.
576# This makes it easier to see which Zone has been affected.
577SETUP_DIFF_TZS = \
578  if diff -u -F'^TZ=' - - <>/dev/null >&0 2>&1; then \
579    DIFF_TZS='diff -u -F^TZ='; \
580  else \
581    DIFF_TZS='diff -u'; \
582  fi
583
584# ':' on typical hosts; 'ranlib' on the ancient hosts that still need ranlib.
585RANLIB=		:
586
587# POSIX prohibits defining or using SHELL.  However, csh users on systems
588# that use the user shell for Makefile commands may need to define SHELL.
589#SHELL=		/bin/sh
590
591# End of macros that one plausibly might want to tailor.
592###############################################################################
593
594
595TZCOBJS=	zic.o
596TZDOBJS=	zdump.o localtime.o strftime.o
597DATEOBJS=	date.o localtime.o strftime.o
598LIBSRCS=	localtime.c asctime.c difftime.c strftime.c
599LIBOBJS=	localtime.o asctime.o difftime.o strftime.o
600HEADERS=	tzfile.h private.h
601NONLIBSRCS=	zic.c zdump.c
602NEWUCBSRCS=	date.c
603SOURCES=	$(HEADERS) $(LIBSRCS) $(NONLIBSRCS) $(NEWUCBSRCS) \
604			tzselect.ksh workman.sh
605MANS=		newctime.3 newstrftime.3 newtzset.3 time2posix.3 \
606			tzfile.5 tzselect.8 zic.8 zdump.8
607MANTXTS=	newctime.3.txt newstrftime.3.txt newtzset.3.txt \
608			time2posix.3.txt \
609			tzfile.5.txt tzselect.8.txt zic.8.txt zdump.8.txt \
610			date.1.txt
611COMMON=		calendars CONTRIBUTING LICENSE Makefile \
612			NEWS README SECURITY theory.html version
613WEB_PAGES=	tz-art.html tz-how-to.html tz-link.html
614CHECK_WEB_PAGES=theory.ck tz-art.ck tz-how-to.ck tz-link.ck
615DOCS=		$(MANS) date.1 $(MANTXTS) $(WEB_PAGES)
616PRIMARY_YDATA=	africa antarctica asia australasia \
617		europe northamerica southamerica
618YDATA=		$(PRIMARY_YDATA) etcetera
619NDATA=		factory
620TDATA_TO_CHECK=	$(YDATA) $(NDATA) backward
621TDATA=		$(YDATA) $(NDATA) $(BACKWARD)
622ZONETABLES=	zone.tab zone1970.tab zonenow.tab
623TABDATA=	iso3166.tab $(TZDATA_TEXT) $(ZONETABLES)
624LEAP_DEPS=	leapseconds.awk leap-seconds.list
625TZDATA_ZI_DEPS=	ziguard.awk zishrink.awk version $(TDATA) \
626		  $(PACKRATDATA) $(PACKRATLIST)
627DSTDATA_ZI_DEPS= ziguard.awk $(TDATA) $(PACKRATDATA) $(PACKRATLIST)
628DATA=		$(TDATA_TO_CHECK) backzone iso3166.tab leap-seconds.list \
629			leapseconds $(ZONETABLES)
630AWK_SCRIPTS=	checklinks.awk checknow.awk checktab.awk leapseconds.awk \
631			ziguard.awk zishrink.awk
632MISC=		$(AWK_SCRIPTS)
633TZS_YEAR=	2050
634TZS_CUTOFF_FLAG=	-c $(TZS_YEAR)
635TZS=		to$(TZS_YEAR).tzs
636TZS_NEW=	to$(TZS_YEAR)new.tzs
637TZS_DEPS=	$(YDATA) localtime.c private.h \
638			strftime.c tzfile.h zdump.c zic.c
639TZDATA_DIST = $(COMMON) $(DATA) $(MISC)
640# EIGHT_YARDS is just a yard short of the whole ENCHILADA.
641EIGHT_YARDS = $(TZDATA_DIST) $(DOCS) $(SOURCES) tzdata.zi
642ENCHILADA = $(EIGHT_YARDS) $(TZS)
643
644# Consult these files when deciding whether to rebuild the 'version' file.
645# This list is not the same as the output of 'git ls-files', since
646# .gitignore is not distributed.
647VERSION_DEPS= \
648		calendars CONTRIBUTING LICENSE Makefile NEWS README SECURITY \
649		africa antarctica asctime.c asia australasia \
650		backward backzone \
651		checklinks.awk checknow.awk checktab.awk \
652		date.1 date.c difftime.c \
653		etcetera europe factory iso3166.tab \
654		leap-seconds.list leapseconds.awk localtime.c \
655		newctime.3 newstrftime.3 newtzset.3 northamerica \
656		private.h southamerica strftime.c theory.html \
657		time2posix.3 tz-art.html tz-how-to.html tz-link.html \
658		tzfile.5 tzfile.h tzselect.8 tzselect.ksh \
659		workman.sh zdump.8 zdump.c zic.8 zic.c \
660		ziguard.awk zishrink.awk \
661		zone.tab zone1970.tab zonenow.tab
662
663all:		tzselect zic zdump libtz.a $(TABDATA) \
664		  vanguard.zi main.zi rearguard.zi
665
666ALL:		all date $(ENCHILADA)
667
668install:	all $(DATA) $(REDO) $(MANS)
669		mkdir -p '$(DESTDIR)$(BINDIR)' \
670			'$(DESTDIR)$(ZDUMPDIR)' '$(DESTDIR)$(ZICDIR)' \
671			'$(DESTDIR)$(LIBDIR)' \
672			'$(DESTDIR)$(MANDIR)/man3' '$(DESTDIR)$(MANDIR)/man5' \
673			'$(DESTDIR)$(MANDIR)/man8'
674		$(ZIC_INSTALL) -l $(LOCALTIME) \
675			-p $(POSIXRULES) \
676			-t '$(DESTDIR)$(TZDEFAULT)'
677		cp -f $(TABDATA) '$(DESTDIR)$(TZDIR)/.'
678		cp tzselect '$(DESTDIR)$(BINDIR)/.'
679		cp zdump '$(DESTDIR)$(ZDUMPDIR)/.'
680		cp zic '$(DESTDIR)$(ZICDIR)/.'
681		cp libtz.a '$(DESTDIR)$(LIBDIR)/.'
682		$(RANLIB) '$(DESTDIR)$(LIBDIR)/libtz.a'
683		cp -f newctime.3 newtzset.3 '$(DESTDIR)$(MANDIR)/man3/.'
684		cp -f tzfile.5 '$(DESTDIR)$(MANDIR)/man5/.'
685		cp -f tzselect.8 zdump.8 zic.8 '$(DESTDIR)$(MANDIR)/man8/.'
686
687INSTALL:	ALL install date.1
688		mkdir -p '$(DESTDIR)$(BINDIR)' '$(DESTDIR)$(MANDIR)/man1'
689		cp date '$(DESTDIR)$(BINDIR)/.'
690		cp -f date.1 '$(DESTDIR)$(MANDIR)/man1/.'
691
692# Calculate version number from git, if available.
693# Otherwise, use $(VERSION) unless it is "unknown" and there is already
694# a 'version' file, in which case reuse the existing 'version' contents
695# and append "-dirty" if the contents do not already end in "-dirty".
696version:	$(VERSION_DEPS)
697		{ (type git) >/dev/null 2>&1 && \
698		  V=$$(git describe --match '[0-9][0-9][0-9][0-9][a-z]*' \
699				--abbrev=7 --dirty) || \
700		  if test '$(VERSION)' = unknown && read -r V <$@; then \
701		    V=$${V%-dirty}-dirty; \
702		  else \
703		    V='$(VERSION)'; \
704		  fi; } && \
705		printf '%s\n' "$$V" >$@.out
706		mv $@.out $@
707
708# These files can be tailored by setting BACKWARD, PACKRATDATA, PACKRATLIST.
709vanguard.zi main.zi rearguard.zi: $(DSTDATA_ZI_DEPS)
710		$(AWK) \
711		  -v DATAFORM=$(@:.zi=) \
712		  -v PACKRATDATA='$(PACKRATDATA)' \
713		  -v PACKRATLIST='$(PACKRATLIST)' \
714		  -f ziguard.awk \
715		  $(TDATA) $(PACKRATDATA) >$@.out
716		mv $@.out $@
717# This file has a version comment that attempts to capture any tailoring
718# via BACKWARD, DATAFORM, PACKRATDATA, PACKRATLIST, and REDO.
719tzdata.zi:	$(DATAFORM).zi version zishrink.awk
720		read -r version <version && \
721		  LC_ALL=C $(AWK) \
722		    -v dataform='$(DATAFORM)' \
723		    -v deps='$(DSTDATA_ZI_DEPS) zishrink.awk' \
724		    -v redo='$(REDO)' \
725		    -v version="$$version" \
726		    -f zishrink.awk \
727		    $(DATAFORM).zi >$@.out
728		mv $@.out $@
729
730tzdir.h:
731		printf '%s\n' >$@.out \
732		  '#ifndef TZDEFAULT' \
733		  '# define TZDEFAULT "$(TZDEFAULT)" /* default zone */' \
734		  '#endif' \
735		  '#ifndef TZDIR' \
736		  '# define TZDIR "$(TZDIR)" /* TZif directory */' \
737		  '#endif'
738		mv $@.out $@
739
740version.h:	version
741		read -r VERSION <version && printf '%s\n' \
742		  'static char const PKGVERSION[]="($(PACKAGE)) ";' \
743		  "static char const TZVERSION[]=\"$$VERSION\";" \
744		  'static char const REPORT_BUGS_TO[]="$(BUGEMAIL)";' \
745		  >$@.out
746		mv $@.out $@
747
748zdump:		$(TZDOBJS)
749		$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(TZDOBJS) $(LDLIBS)
750
751zic:		$(TZCOBJS)
752		$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(TZCOBJS) $(LDLIBS)
753
754leapseconds:	$(LEAP_DEPS)
755		$(AWK) -v EXPIRES_LINE=$(EXPIRES_LINE) \
756		  -f leapseconds.awk leap-seconds.list >$@.out
757		mv $@.out $@
758
759# Awk script to extract a Git-style author from leap-seconds.list comments.
760EXTRACT_AUTHOR = \
761  author_line { sub(/^.[[:space:]]*/, ""); \
762      sub(/:[[:space:]]*/, " <"); \
763      printf "%s>\n", $$0; \
764      success = 1; \
765      exit \
766  } \
767  /Questions or comments to:/ { author_line = 1 } \
768  END { exit !success }
769
770# Fetch leap-seconds.list from upstream.
771fetch-leap-seconds.list:
772		$(CURL) -OR $(leaplist_URI)
773
774# Fetch leap-seconds.list from upstream and commit it to the local repository.
775commit-leap-seconds.list: fetch-leap-seconds.list
776		author=$$($(AWK) '$(EXTRACT_AUTHOR)' leap-seconds.list) && \
777		date=$$(TZ=$(leaplist_TZ) stat -c%y leap-seconds.list) && \
778		git commit --author="$$author" --date="$$date" -m'make $@' \
779		  leap-seconds.list
780
781# Arguments to pass to submakes.
782# They can be overridden by later submake arguments.
783INSTALLARGS = \
784 BACKWARD='$(BACKWARD)' \
785 DESTDIR='$(DESTDIR)' \
786 PACKRATDATA='$(PACKRATDATA)' \
787 PACKRATLIST='$(PACKRATLIST)' \
788 TZDEFAULT='$(TZDEFAULT)' \
789 TZDIR='$(TZDIR)' \
790 ZIC='$(ZIC)'
791
792INSTALL_DATA_DEPS = zic leapseconds tzdata.zi
793
794posix_only: $(INSTALL_DATA_DEPS)
795		$(ZIC_INSTALL) tzdata.zi
796
797right_only: $(INSTALL_DATA_DEPS)
798		$(ZIC_INSTALL) -L leapseconds tzdata.zi
799
800# In earlier versions of this makefile, the other two directories were
801# subdirectories of $(TZDIR).  However, this led to configuration errors.
802# For example, with posix_right under the earlier scheme,
803# TZ='right/Australia/Adelaide' got you localtime with leap seconds,
804# but gmtime without leap seconds, which led to problems with applications
805# like sendmail that subtract gmtime from localtime.
806# Therefore, the other two directories are now siblings of $(TZDIR).
807# You must replace all of $(TZDIR) to switch from not using leap seconds
808# to using them, or vice versa.
809right_posix:	right_only
810		rm -fr '$(DESTDIR)$(TZDIR)-leaps'
811		ln -s '$(TZDIR_BASENAME)' '$(DESTDIR)$(TZDIR)-leaps' || \
812		  $(MAKE) $(INSTALLARGS) TZDIR='$(TZDIR)-leaps' right_only
813		$(MAKE) $(INSTALLARGS) TZDIR='$(TZDIR)-posix' posix_only
814
815posix_right:	posix_only
816		rm -fr '$(DESTDIR)$(TZDIR)-posix'
817		ln -s '$(TZDIR_BASENAME)' '$(DESTDIR)$(TZDIR)-posix' || \
818		  $(MAKE) $(INSTALLARGS) TZDIR='$(TZDIR)-posix' posix_only
819		$(MAKE) $(INSTALLARGS) TZDIR='$(TZDIR)-leaps' right_only
820
821zones:		$(REDO)
822
823# dummy.zd is not a real file; it is mentioned here only so that the
824# top-level 'make' does not have a syntax error.
825ZDS = dummy.zd
826# Rule used only by submakes invoked by the $(TZS_NEW) rule.
827# It is separate so that GNU 'make -j' can run instances in parallel.
828$(ZDS): zdump
829		./zdump -i $(TZS_CUTOFF_FLAG) "$$PWD/$(@:.zd=)" >$@
830
831TZS_NEW_DEPS = tzdata.zi zdump zic
832$(TZS_NEW): $(TZS_NEW_DEPS)
833		rm -fr tzs$(TZS_YEAR).dir
834		mkdir tzs$(TZS_YEAR).dir
835		$(zic) -d tzs$(TZS_YEAR).dir tzdata.zi
836		$(AWK) '/^L/{print "Link\t" $$2 "\t" $$3}' \
837		   tzdata.zi | LC_ALL=C sort >$@.out
838		x=$$($(AWK) '/^Z/{print "tzs$(TZS_YEAR).dir/" $$2 ".zd"}' \
839				tzdata.zi \
840		     | LC_ALL=C sort -t . -k 2,2) && \
841		set x $$x && \
842		shift && \
843		ZDS=$$* && \
844		$(MAKE) TZS_CUTOFF_FLAG="$(TZS_CUTOFF_FLAG)" \
845		  ZDS="$$ZDS" $$ZDS && \
846		sed 's,^TZ=".*\.dir/,TZ=",' $$ZDS >>$@.out
847		rm -fr tzs$(TZS_YEAR).dir
848		mv $@.out $@
849
850# If $(TZS) exists but 'make tzs.ck' fails, a maintainer should inspect the
851# failed output and fix the inconsistency, perhaps by running 'make force_tzs'.
852$(TZS):
853		touch $@
854
855force_tzs:	$(TZS_NEW)
856		cp $(TZS_NEW) $(TZS)
857
858libtz.a:	$(LIBOBJS)
859		rm -f $@
860		$(AR) $(ARFLAGS) $@ $(LIBOBJS)
861		$(RANLIB) $@
862
863date:		$(DATEOBJS)
864		$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(DATEOBJS) $(LDLIBS)
865
866tzselect:	tzselect.ksh version
867		read -r VERSION <version && sed \
868		  -e "s'#!/bin/bash'#!"'$(KSHELL)'\' \
869		  -e s\''\(AWK\)=[^}]*'\''\1=\'\''$(AWK)\'\'\' \
870		  -e s\''\(PKGVERSION\)=.*'\''\1=\'\''($(PACKAGE)) \'\'\' \
871		  -e s\''\(REPORT_BUGS_TO\)=.*'\''\1=\'\''$(BUGEMAIL)\'\'\' \
872		  -e s\''\(TZDIR\)=[^}]*'\''\1=\'\''$(TZDIR)\'\'\' \
873		  -e s\''\(TZVERSION\)=.*'\''\1=\'"'$$VERSION\\''" \
874		  <$@.ksh >$@.out
875		chmod +x $@.out
876		mv $@.out $@
877
878check: check_mild back.ck now.ck
879check_mild: check_web check_zishrink \
880  character-set.ck white-space.ck links.ck mainguard.ck \
881  name-lengths.ck slashed-abbrs.ck sorted.ck \
882  tables.ck ziguard.ck tzs.ck
883
884# True if UTF8_LOCALE does not work;
885# otherwise, false but with LC_ALL set to $(UTF8_LOCALE).
886UTF8_LOCALE_MISSING = \
887  { test ! '$(UTF8_LOCALE)' \
888    || ! printf 'A\304\200B\n' \
889         | LC_ALL='$(UTF8_LOCALE)' grep -q '^A.B$$' >/dev/null 2>&1 \
890    || { export LC_ALL='$(UTF8_LOCALE)'; false; }; }
891
892character-set.ck: $(ENCHILADA)
893	$(UTF8_LOCALE_MISSING) || { \
894		sharp='#' && \
895		! grep -Env $(SAFE_LINE) $(MANS) date.1 $(MANTXTS) \
896			$(MISC) $(SOURCES) $(WEB_PAGES) \
897			CONTRIBUTING LICENSE README SECURITY \
898			version tzdata.zi && \
899		! grep -Env $(SAFE_LINE)'|^UNUSUAL_OK_'$(OK_CHAR)'*$$' \
900			Makefile && \
901		! grep -Env $(SAFE_SHARP_LINE) $(TDATA_TO_CHECK) backzone \
902			leapseconds zone.tab && \
903		! grep -Env $(OK_LINE) $(ENCHILADA); \
904	}
905	touch $@
906
907white-space.ck: $(ENCHILADA)
908	$(UTF8_LOCALE_MISSING) || { \
909		patfmt=' \t|[\f\r\v]' && pat=$$(printf "$$patfmt\\n") && \
910		! grep -En "$$pat|[$s]\$$" \
911		    $(ENCHILADA:leap-seconds.list=); \
912	}
913	touch $@
914
915PRECEDES_FILE_NAME = ^(Zone|Link[$s]+[^$s]+)[$s]+
916FILE_NAME_COMPONENT_TOO_LONG = $(PRECEDES_FILE_NAME)[^$s]*[^/$s]{15}
917
918name-lengths.ck: $(TDATA_TO_CHECK) backzone
919		:;! grep -En '$(FILE_NAME_COMPONENT_TOO_LONG)' \
920			$(TDATA_TO_CHECK) backzone
921		touch $@
922
923mainguard.ck: main.zi
924		test '$(PACKRATLIST)' || \
925		  cat $(TDATA) $(PACKRATDATA) | diff -u - main.zi
926		touch $@
927
928PRECEDES_STDOFF = ^(Zone[$s]+[^$s]+)?[$s]+
929STDOFF = [-+]?[0-9:.]+
930RULELESS_SAVE = (-|$(STDOFF)[sd]?)
931RULELESS_SLASHED_ABBRS = \
932  $(PRECEDES_STDOFF)$(STDOFF)[$s]+$(RULELESS_SAVE)[$s]+[^$s]*/
933
934slashed-abbrs.ck: $(TDATA_TO_CHECK)
935		:;! grep -En '$(RULELESS_SLASHED_ABBRS)' $(TDATA_TO_CHECK)
936		touch $@
937
938CHECK_CC_LIST = { n = split($$1,a,/,/); for (i=2; i<=n; i++) print a[1], a[i]; }
939
940sorted.ck: backward backzone
941		$(AWK) '/^Link/ {printf "%.5d %s\n", g, $$3} !/./ {g++}' \
942		  backward | LC_ALL=C sort -cu
943		$(AWK) '/^Zone.*\// {print $$2}' backzone | LC_ALL=C sort -cu
944		touch $@
945
946back.ck: checklinks.awk $(TDATA_TO_CHECK)
947		$(AWK) \
948		  -v DATAFORM=$(DATAFORM) \
949		  -v backcheck=backward \
950		  -f checklinks.awk $(TDATA_TO_CHECK)
951		touch $@
952
953links.ck: checklinks.awk tzdata.zi
954		$(AWK) \
955		  -v DATAFORM=$(DATAFORM) \
956		  -f checklinks.awk tzdata.zi
957		touch $@
958
959# Check timestamps from now through 28 years from now, to make sure
960# that zonenow.tab contains all sequences of planned timestamps,
961# without any duplicate sequences.  In theory this might require
962# 2800+ years but that would take a long time to check.
963CHECK_NOW_TIMESTAMP = $$(./date +%s)
964CHECK_NOW_FUTURE_YEARS = 28
965CHECK_NOW_FUTURE_SECS = $(CHECK_NOW_FUTURE_YEARS) * 366 * 24 * 60 * 60
966now.ck: checknow.awk date tzdata.zi zdump zic zone1970.tab zonenow.tab
967		rm -fr $@d
968		mkdir $@d
969		./zic -d $@d tzdata.zi
970		now=$(CHECK_NOW_TIMESTAMP) && \
971		  future=$$(($(CHECK_NOW_FUTURE_SECS) + $$now)) && \
972		  ./zdump -i -t $$now,$$future \
973		     $$(find "$$PWD/$@d"/????*/ -type f) \
974		     >$@d/zdump-now.tab && \
975		  ./zdump -i -t 0,$$future \
976		     $$(find "$$PWD/$@d" -name Etc -prune \
977			  -o -type f ! -name '*.tab' -print) \
978		     >$@d/zdump-1970.tab
979		$(AWK) \
980		  -v zdump_table=$@d/zdump-now.tab \
981		  -f checknow.awk zonenow.tab
982		$(AWK) \
983		  'BEGIN {print "-\t-\tUTC"} /^Zone/ {print "-\t-\t" $$2}' \
984		  $(PRIMARY_YDATA) backward factory | \
985		 $(AWK) \
986		   -v zdump_table=$@d/zdump-1970.tab \
987		   -f checknow.awk
988		rm -fr $@d
989		touch $@
990
991tables.ck: checktab.awk $(YDATA) backward zone.tab zone1970.tab
992		for tab in $(ZONETABLES); do \
993		  test "$$tab" = zone.tab && links='$(BACKWARD)' || links=''; \
994		  $(AWK) -f checktab.awk -v zone_table=$$tab $(YDATA) $$links \
995		    || exit; \
996		done
997		touch $@
998
999tzs.ck: $(TZS) $(TZS_NEW)
1000		if test -s $(TZS); then \
1001		  $(SETUP_DIFF_TZS) && $$DIFF_TZS $(TZS) $(TZS_NEW); \
1002		else \
1003		  cp $(TZS_NEW) $(TZS); \
1004		fi
1005		touch $@
1006
1007check_web:	$(CHECK_WEB_PAGES)
1008.SUFFIXES: .ck .html
1009.html.ck:
1010		{ ! ($(CURL) --version) >/dev/null 2>&1 || \
1011		    $(CURL) -sS --url https://validator.w3.org/nu/ -F out=gnu \
1012		          -F file=@$<; } >$@.out && \
1013		  test ! -s $@.out || { cat $@.out; exit 1; }
1014		mv $@.out $@
1015
1016ziguard.ck: rearguard.zi vanguard.zi ziguard.awk
1017		$(AWK) -v DATAFORM=rearguard -f ziguard.awk vanguard.zi | \
1018		  diff -u rearguard.zi -
1019		$(AWK) -v DATAFORM=vanguard -f ziguard.awk rearguard.zi | \
1020		  diff -u vanguard.zi -
1021		touch $@
1022
1023# Check that zishrink.awk does not alter the data, and that ziguard.awk
1024# preserves main-format data.
1025check_zishrink: zishrink-posix.ck zishrink-right.ck
1026zishrink-posix.ck zishrink-right.ck: \
1027  zic leapseconds $(PACKRATDATA) $(PACKRATLIST) \
1028  $(TDATA) $(DATAFORM).zi tzdata.zi
1029		rm -fr $@d t-$@d shrunk-$@d
1030		mkdir $@d t-$@d shrunk-$@d
1031		case $@ in \
1032		  *right*) leap='-L leapseconds';; \
1033		  *) leap=;; \
1034		esac && \
1035		  $(ZIC) $$leap -d $@d $(DATAFORM).zi && \
1036		  $(ZIC) $$leap -d shrunk-$@d tzdata.zi && \
1037		  case $(DATAFORM),$(PACKRATLIST) in \
1038		    main,) \
1039		      $(ZIC) $$leap -d t-$@d $(TDATA) && \
1040		      $(AWK) '/^Rule/' $(TDATA) | \
1041			$(ZIC) $$leap -d t-$@d - $(PACKRATDATA) && \
1042		      diff -r $@d t-$@d;; \
1043		  esac
1044		diff -r $@d shrunk-$@d
1045		rm -fr $@d t-$@d shrunk-$@d
1046		touch $@
1047
1048clean_misc:
1049		rm -fr *.ckd *.dir
1050		rm -f *.ck *.core *.o *.out *.t core core.* \
1051		  date tzdir.h tzselect version.h zdump zic libtz.a
1052clean:		clean_misc
1053		rm -fr tzdb-*/
1054		rm -f *.zi $(TZS_NEW)
1055
1056maintainer-clean: clean
1057		@echo 'This command is intended for maintainers to use; it'
1058		@echo 'deletes files that may need special tools to rebuild.'
1059		rm -f leapseconds version $(MANTXTS) $(TZS) *.asc *.tar.*
1060
1061names:
1062		@echo $(ENCHILADA)
1063
1064public: check public.ck $(CHECK_TIME_T_ALTERNATIVES) \
1065		tarballs signatures
1066
1067date.1.txt:	date.1
1068newctime.3.txt:	newctime.3
1069newstrftime.3.txt: newstrftime.3
1070newtzset.3.txt:	newtzset.3
1071time2posix.3.txt: time2posix.3
1072tzfile.5.txt:	tzfile.5
1073tzselect.8.txt:	tzselect.8
1074zdump.8.txt:	zdump.8
1075zic.8.txt:	zic.8
1076
1077$(MANTXTS):	workman.sh
1078		LC_ALL=C sh workman.sh $(@:.txt=) >$@.out
1079		mv $@.out $@
1080
1081# Set file timestamps deterministically if possible,
1082# so that tarballs containing the timestamps are reproducible.
1083#
1084# '$(SET_TIMESTAMP_N) N DEST A B C ...' sets the timestamp of the
1085# file DEST to the maximum of the timestamps of the files A B C ...,
1086# plus N if GNU ls and touch are available.
1087SET_TIMESTAMP_N = sh -c '\
1088  n=$$0 dest=$$1; shift; \
1089  <"$$dest" && \
1090  if test $$n != 0 && \
1091     lsout=$$(ls -nt --time-style="+%s" "$$@" 2>/dev/null); then \
1092    set x $$lsout && \
1093    timestamp=$$(($$7 + $$n)) && \
1094    echo "+ touch -md @$$timestamp $$dest" && \
1095    touch -md @$$timestamp "$$dest"; \
1096  else \
1097    newest=$$(ls -t "$$@" | sed 1q) && \
1098    echo "+ touch -mr $$newest $$dest" && \
1099    touch -mr "$$newest" "$$dest"; \
1100  fi'
1101# If DEST depends on A B C ... in this Makefile, callers should use
1102# $(SET_TIMESTAMP_DEP) DEST A B C ..., for the benefit of any
1103# downstream 'make' that considers equal timestamps to be out of date.
1104# POSIX allows this 'make' behavior, and HP-UX 'make' does it.
1105# If all that matters is that the timestamp be reproducible
1106# and plausible, use $(SET_TIMESTAMP).
1107SET_TIMESTAMP = $(SET_TIMESTAMP_N) 0
1108SET_TIMESTAMP_DEP = $(SET_TIMESTAMP_N) 1
1109
1110# Set the timestamps to those of the git repository, if available,
1111# and if the files have not changed since then.
1112# This uses GNU 'ls --time-style=+%s', which outputs the seconds count,
1113# and GNU 'touch -d@N FILE', where N is the number of seconds since 1970.
1114# If git or GNU is absent, don't bother to sync with git timestamps.
1115# Also, set the timestamp of each prebuilt file like 'leapseconds'
1116# to be the maximum of the files it depends on.
1117set-timestamps.out: $(EIGHT_YARDS)
1118		rm -f $@
1119		if (type git) >/dev/null 2>&1 && \
1120		   files=$$(git ls-files $(EIGHT_YARDS)) && \
1121		   touch -md @1 test.out; then \
1122		  rm -f test.out && \
1123		  for file in $$files; do \
1124		    if git diff --quiet HEAD $$file; then \
1125		      time=$$(TZ=UTC0 git log -1 \
1126			--format='tformat:%cd' \
1127			--date='format-local:%Y-%m-%dT%H:%M:%SZ' \
1128			$$file) && \
1129		      echo "+ touch -md $$time $$file" && \
1130		      touch -md $$time $$file; \
1131		    else \
1132		      echo >&2 "$$file: warning: does not match repository"; \
1133		    fi || exit; \
1134		  done; \
1135		fi
1136		$(SET_TIMESTAMP_DEP) leapseconds $(LEAP_DEPS)
1137		for file in $(MANTXTS); do \
1138		  $(SET_TIMESTAMP_DEP) $$file $${file%.txt} workman.sh || \
1139		    exit; \
1140		done
1141		$(SET_TIMESTAMP_DEP) version $(VERSION_DEPS)
1142		$(SET_TIMESTAMP_DEP) tzdata.zi $(TZDATA_ZI_DEPS)
1143		touch $@
1144set-tzs-timestamp.out: $(TZS)
1145		$(SET_TIMESTAMP_DEP) $(TZS) $(TZS_DEPS)
1146		touch $@
1147
1148# The zics below ensure that each data file can stand on its own.
1149# We also do an all-files run to catch links to links.
1150
1151public.ck: $(VERSION_DEPS)
1152		rm -fr $@d
1153		mkdir $@d
1154		ln $(VERSION_DEPS) $@d
1155		cd $@d \
1156		  && $(MAKE) CFLAGS='$(GCC_DEBUG_FLAGS)' TZDIR='$(TZDIR)' ALL
1157		for i in $(TDATA_TO_CHECK) \
1158		    tzdata.zi vanguard.zi main.zi rearguard.zi; \
1159		do \
1160		  $@d/zic -v -d $@d/zoneinfo $@d/$$i || exit; \
1161		done
1162		$@d/zic -v -d $@d/zoneinfo-all $(TDATA_TO_CHECK)
1163		:
1164		: Also check 'backzone' syntax.
1165		rm $@d/main.zi
1166		cd $@d && $(MAKE) PACKRATDATA=backzone main.zi
1167		$@d/zic -d $@d/zoneinfo main.zi
1168		rm $@d/main.zi
1169		cd $@d && \
1170		  $(MAKE) PACKRATDATA=backzone PACKRATLIST=zone.tab main.zi
1171		$@d/zic -d $@d/zoneinfo main.zi
1172		:
1173		rm -fr $@d
1174		touch $@
1175
1176# Check that the code works under various alternative
1177# implementations of time_t.
1178check_time_t_alternatives: $(TIME_T_ALTERNATIVES)
1179$(TIME_T_ALTERNATIVES_TAIL): $(TIME_T_ALTERNATIVES_HEAD)
1180$(TIME_T_ALTERNATIVES): $(VERSION_DEPS)
1181		rm -fr $@d
1182		mkdir $@d
1183		ln $(VERSION_DEPS) $@d
1184		case $@ in \
1185		  *32_t*) range=-2147483648,2147483648;; \
1186		  u*) range=0,4294967296;; \
1187		  *) range=-4294967296,4294967296;; \
1188		esac && \
1189		wd=$$PWD && \
1190		zones=$$($(AWK) '/^[^#]/ { print $$3 }' <zone1970.tab) && \
1191		if test $@ = $(TIME_T_ALTERNATIVES_HEAD); then \
1192		  range_target=; \
1193		else \
1194		  range_target=to$$range.tzs; \
1195		fi && \
1196		(cd $@d && \
1197		  $(MAKE) TOPDIR="$$wd/$@d" \
1198		    CFLAGS='$(CFLAGS) -Dtime_tz='"'$(@:.ck=)'" \
1199		    REDO='$(REDO)' \
1200		    D="$$wd/$@d" \
1201		    TZS_YEAR="$$range" TZS_CUTOFF_FLAG="-t $$range" \
1202		    install $$range_target) && \
1203		test $@ = $(TIME_T_ALTERNATIVES_HEAD) || { \
1204		  (cd $(TIME_T_ALTERNATIVES_HEAD)d && \
1205		    $(MAKE) TOPDIR="$$wd/$@d" \
1206		      TZS_YEAR="$$range" TZS_CUTOFF_FLAG="-t $$range" \
1207		      D="$$wd/$@d" \
1208		      to$$range.tzs) && \
1209		  $(SETUP_DIFF_TZS) && \
1210		  $$DIFF_TZS $(TIME_T_ALTERNATIVES_HEAD)d/to$$range.tzs \
1211			  $@d/to$$range.tzs && \
1212		  if diff -q Makefile Makefile 2>/dev/null; then \
1213		    quiet_option='-q'; \
1214		  else \
1215		    quiet_option=''; \
1216		  fi && \
1217		    diff $$quiet_option -r $(TIME_T_ALTERNATIVES_HEAD)d/etc \
1218					   $@d/etc && \
1219		    diff $$quiet_option -r \
1220		      $(TIME_T_ALTERNATIVES_HEAD)d/usr/share \
1221		      $@d/usr/share; \
1222		}
1223		touch $@
1224
1225TRADITIONAL_ASC = \
1226  tzcode$(VERSION).tar.gz.asc.t \
1227  tzdata$(VERSION).tar.gz.asc.t
1228REARGUARD_ASC = \
1229  tzdata$(VERSION)-rearguard.tar.gz.asc.t
1230ALL_ASC = $(TRADITIONAL_ASC) $(REARGUARD_ASC) \
1231  tzdb-$(VERSION).tar.lz.asc.t
1232
1233tarballs rearguard_tarballs tailored_tarballs traditional_tarballs \
1234signatures rearguard_signatures traditional_signatures: \
1235  version set-timestamps.out rearguard.zi vanguard.zi
1236		read -r VERSION <version && \
1237		$(MAKE) AWK='$(AWK)' VERSION="$$VERSION" $@_version
1238
1239# These *_version rules are intended for use if VERSION is set by some
1240# other means.  Ordinarily these rules are used only by the above
1241# non-_version rules, which set VERSION on the 'make' command line.
1242tarballs_version: traditional_tarballs_version rearguard_tarballs_version \
1243  tzdb-$(VERSION).tar.lz.t
1244rearguard_tarballs_version: \
1245  tzdata$(VERSION)-rearguard.tar.gz.t
1246traditional_tarballs_version: \
1247  tzcode$(VERSION).tar.gz.t tzdata$(VERSION).tar.gz.t
1248tailored_tarballs_version: \
1249  tzdata$(VERSION)-tailored.tar.gz.t
1250signatures_version: $(ALL_ASC)
1251rearguard_signatures_version: $(REARGUARD_ASC)
1252traditional_signatures_version: $(TRADITIONAL_ASC)
1253
1254tzcode$(VERSION).tar.gz.t: set-timestamps.out
1255		$(SETUP_TAR) && \
1256		$$TAR -cf - \
1257		    $(COMMON) $(DOCS) $(SOURCES) | \
1258		  gzip $(GZIPFLAGS) >$(@:.t=)
1259		$(SET_TIMESTAMP) $(@:.t=) $(COMMON) $(DOCS) $(SOURCES)
1260		touch $@
1261
1262tzdata$(VERSION).tar.gz.t: set-timestamps.out
1263		$(SETUP_TAR) && \
1264		$$TAR -cf - $(TZDATA_DIST) | \
1265		  gzip $(GZIPFLAGS) >$(@:.t=)
1266		$(SET_TIMESTAMP) $(@:.t=) $(TZDATA_DIST)
1267		touch $@
1268
1269# Create empty files with a reproducible timestamp.
1270CREATE_EMPTY = TZ=UTC0 touch -mt 202010122253.00
1271
1272# The obsolescent *rearguard* targets and related macros are present
1273# for backwards compatibility with tz releases 2018e through 2022a.
1274# They should go away eventually.  To build rearguard tarballs you
1275# can instead use 'make DATAFORM=rearguard tailored_tarballs'.
1276tzdata$(VERSION)-rearguard.tar.gz.t: rearguard.zi set-timestamps.out
1277		rm -fr $@.dir
1278		mkdir $@.dir
1279		ln $(TZDATA_DIST) $@.dir
1280		cd $@.dir && rm -f $(TDATA) $(PACKRATDATA) version
1281		for f in $(TDATA) $(PACKRATDATA); do \
1282		  rearf=$@.dir/$$f; \
1283		  $(AWK) -v DATAFORM=rearguard -f ziguard.awk $$f >$$rearf && \
1284		  $(SET_TIMESTAMP_DEP) $$rearf ziguard.awk $$f || exit; \
1285		done
1286		sed '1s/$$/-rearguard/' <version >$@.dir/version
1287		: The dummy pacificnew pacifies TZUpdater 2.3.1 and earlier.
1288		$(CREATE_EMPTY) $@.dir/pacificnew
1289		touch -mr version $@.dir/version
1290		$(SETUP_TAR) && \
1291		  (cd $@.dir && \
1292		   $$TAR -cf - \
1293			$(TZDATA_DIST) pacificnew | \
1294		     gzip $(GZIPFLAGS)) >$(@:.t=)
1295		$(SET_TIMESTAMP) $(@:.t=) \
1296		  $$(cd $@.dir && \
1297		       ls $(TZDATA_DIST) pacificnew | sed 's,^,$@.dir/,')
1298		touch $@
1299
1300# Create a tailored tarball suitable for TZUpdater and compatible tools.
1301# For example, 'make DATAFORM=vanguard tailored_tarballs' makes a tarball
1302# useful for testing whether TZUpdater supports vanguard form.
1303# The generated tarball is not byte-for-byte equivalent to a hand-tailored
1304# traditional tarball, as data entries are put into 'etcetera' even if they
1305# came from some other source file.  However, the effect should be the same
1306# for ordinary use, which reads all the source files.
1307tzdata$(VERSION)-tailored.tar.gz.t: set-timestamps.out
1308		rm -fr $@.dir
1309		mkdir $@.dir
1310		: The dummy pacificnew pacifies TZUpdater 2.3.1 and earlier.
1311		if test $(DATAFORM) = vanguard; then \
1312		  pacificnew=; \
1313		else \
1314		  pacificnew=pacificnew; \
1315		fi && \
1316		cd $@.dir && \
1317		  $(CREATE_EMPTY) $(PRIMARY_YDATA) $(NDATA) backward \
1318		  $$pacificnew
1319		(sed '/^#/!d' tzdata.zi && echo && cat $(DATAFORM).zi) \
1320		  >$@.dir/etcetera
1321		touch -mr tzdata.zi $@.dir/etcetera
1322		sed -n \
1323		  -e '/^# *version  *\(.*\)/h' \
1324		  -e '/^# *ddeps  */H' \
1325		  -e '$$!d' \
1326		  -e 'g' \
1327		  -e 's/^# *version  *//' \
1328		  -e 's/\n# *ddeps  */-/' \
1329		  -e 's/ /-/g' \
1330		  -e 'p' \
1331		  <tzdata.zi >$@.dir/version
1332		touch -mr version $@.dir/version
1333		links= && \
1334		  for file in $(TZDATA_DIST); do \
1335		    test -f $@.dir/$$file || links="$$links $$file"; \
1336		  done && \
1337		  ln $$links $@.dir
1338		$(SETUP_TAR) && \
1339		  (cd $@.dir && \
1340		   $$TAR -cf - *) | gzip $(GZIPFLAGS) >$(@:.t=)
1341		$(SET_TIMESTAMP) $(@:.t=) \
1342		  $$(cd $@.dir && ls * | sed 's,^,$@.dir/,')
1343		touch $@
1344
1345tzdb-$(VERSION).tar.lz.t: set-timestamps.out set-tzs-timestamp.out
1346		rm -fr tzdb-$(VERSION)
1347		mkdir tzdb-$(VERSION)
1348		ln $(ENCHILADA) tzdb-$(VERSION)
1349		$(SET_TIMESTAMP) tzdb-$(VERSION) tzdb-$(VERSION)/*
1350		$(SETUP_TAR) && \
1351		  $$TAR -cf - tzdb-$(VERSION) | lzip -9 >$(@:.t=)
1352		$(SET_TIMESTAMP) $(@:.t=) tzdb-$(VERSION)
1353		touch $@
1354
1355tzcode$(VERSION).tar.gz.asc.t: tzcode$(VERSION).tar.gz.t
1356tzdata$(VERSION).tar.gz.asc.t: tzdata$(VERSION).tar.gz.t
1357tzdata$(VERSION)-rearguard.tar.gz.asc.t: tzdata$(VERSION)-rearguard.tar.gz.t
1358tzdb-$(VERSION).tar.lz.asc.t: tzdb-$(VERSION).tar.lz.t
1359$(ALL_ASC):
1360		$(GPG) --armor --detach-sign $(?:.t=)
1361		$(SET_TIMESTAMP) $(@:.t=) $(?:.t=)
1362		touch $@
1363
1364TYPECHECK_CFLAGS = $(CFLAGS) -DTYPECHECK -D__time_t_defined -D_TIME_T
1365typecheck: long-long.ck unsigned.ck
1366long-long.ck unsigned.ck: $(VERSION_DEPS)
1367		rm -fr $@d
1368		mkdir $@d
1369		ln $(VERSION_DEPS) $@d
1370		cd $@d && \
1371		  case $@ in \
1372		    long-long.*) i="long long";; \
1373		    unsigned.* ) i="unsigned" ;; \
1374		  esac && \
1375		  $(MAKE) \
1376		    CFLAGS="$(TYPECHECK_CFLAGS) \"-Dtime_t=$$i\"" \
1377		    TOPDIR="$$PWD" \
1378		    install
1379		$@d/zdump -i -c 1970,1971 Europe/Rome
1380		touch $@
1381
1382zonenames:	tzdata.zi
1383		@$(AWK) '/^Z/ { print $$2 } /^L/ { print $$3 }' tzdata.zi
1384
1385asctime.o:	private.h
1386date.o:		private.h
1387difftime.o:	private.h
1388localtime.o:	private.h tzdir.h tzfile.h
1389strftime.o:	localtime.c private.h tzdir.h tzfile.h
1390zdump.o:	private.h version.h
1391zic.o:		private.h tzdir.h tzfile.h version.h
1392
1393.PHONY: ALL INSTALL all
1394.PHONY: check check_mild check_time_t_alternatives
1395.PHONY: check_web check_zishrink
1396.PHONY: clean clean_misc commit-leap-seconds.list dummy.zd
1397.PHONY: fetch-leap-seconds.list force_tzs
1398.PHONY: install maintainer-clean names
1399.PHONY: posix_only posix_right public
1400.PHONY: rearguard_signatures rearguard_signatures_version
1401.PHONY: rearguard_tarballs rearguard_tarballs_version
1402.PHONY: right_only right_posix signatures signatures_version
1403.PHONY: tarballs tarballs_version
1404.PHONY: traditional_signatures traditional_signatures_version
1405.PHONY: traditional_tarballs traditional_tarballs_version
1406.PHONY: tailored_tarballs tailored_tarballs_version
1407.PHONY: typecheck
1408.PHONY: zonenames zones
1409.PHONY: $(ZDS)
1410