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