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