Makefile revision 1.58
11.41Schristos# Make and install tzdb code and data.
21.1Smlelstv# This file is in the public domain, so clarified as of
31.1Smlelstv# 2009-05-17 by Arthur David Olson.
41.56Schristos# Request POSIX conformance; this must be the first non-comment line.
51.56Schristos.POSIX:
61.58Schristos# On older platforms you may need to scrounge for POSIX conformance.
71.58Schristos# For example, on Solaris 10 (2005) with Sun Studio 12 aka Sun C 5.9 (2007),
81.58Schristos# use 'PATH=/usr/xpg4/bin:$PATH make CC=c99'.
91.56Schristos
101.56Schristos# To affect how this Makefile works, you can run a shell script like this:
111.56Schristos#
121.56Schristos#	#!/bin/sh
131.58Schristos#	make CC='gcc -std=gnu23' "$@"
141.56Schristos#
151.58Schristos# This example script is appropriate for a circa 2024 GNU/Linux system
161.58Schristos# where a non-default setting enables this package's optional use of C23.
171.56Schristos#
181.56Schristos# Alternatively, you can simply edit this Makefile to tailor the following
191.56Schristos# macro definitions.
201.56Schristos
211.56Schristos###############################################################################
221.56Schristos# Start of macros that one plausibly might want to tailor.
231.1Smlelstv
241.10Schristos# Package name for the code distribution.
251.10SchristosPACKAGE=	tzcode
261.10Schristos
271.34Schristos# Version number for the distribution, overridden in the 'tarballs' rule below.
281.35SchristosVERSION=	unknown
291.9Schristos
301.9Schristos# Email address for bug reports.
311.9SchristosBUGEMAIL=	tz@iana.org
321.6Schristos
331.43Schristos# DATAFORM selects the data format.
341.43Schristos# Available formats represent essentially the same data, albeit
351.43Schristos# possibly with minor discrepancies that users are not likely to notice.
361.43Schristos# To get new features and the best data right away, use:
371.40Schristos#	DATAFORM=	vanguard
381.40Schristos# To wait a while before using new features, to give downstream users
391.40Schristos# time to upgrade zic (the default), use:
401.40Schristos#	DATAFORM=	main
411.40Schristos# To wait even longer for new features, use:
421.40Schristos#	DATAFORM=	rearguard
431.46Schristos# Rearguard users might also want "ZFLAGS = -b fat"; see below.
441.40SchristosDATAFORM=		main
451.40Schristos
461.41Schristos# Change the line below for your timezone (after finding the one you want in
471.41Schristos# one of the $(TDATA) source files, or adding it to a source file).
481.41Schristos# Alternatively, if you discover you've got the wrong timezone, you can just
491.46Schristos# 'zic -l -' to remove it, or 'zic -l rightzone' to change it.
501.1Smlelstv# Use the command
511.1Smlelstv#	make zonenames
521.1Smlelstv# to get a list of the values you can use for LOCALTIME.
531.1Smlelstv
541.51SchristosLOCALTIME=	Factory
551.1Smlelstv
561.58Schristos# The POSIXRULES macro controls interpretation of POSIX-like TZ
571.55Schristos# settings like TZ='EET-2EEST' that lack DST transition rules.
581.46Schristos# If POSIXRULES is '-', no template is installed; this is the default.
591.46Schristos# Any other value for POSIXRULES is obsolete and should not be relied on, as:
601.44Schristos# * It does not work correctly in popular implementations such as GNU/Linux.
611.49Schristos# * It does not work even in tzcode, except for historical timestamps
621.49Schristos#   that precede the last explicit transition in the POSIXRULES file.
631.49Schristos#   Hence it typically does not work for current and future timestamps.
641.46Schristos# If, despite the above, you want a template for handling these settings,
651.46Schristos# you can change the line below (after finding the timezone you want in the
661.46Schristos# one of the $(TDATA) source files, or adding it to a source file).
671.46Schristos# Alternatively, if you discover you've got the wrong timezone, you can just
681.46Schristos# 'zic -p -' to remove it, or 'zic -p rightzone' to change it.
691.46Schristos# Use the command
701.46Schristos#	make zonenames
711.46Schristos# to get a list of the values you can use for POSIXRULES.
721.1Smlelstv
731.46SchristosPOSIXRULES=	-
741.1Smlelstv
751.1Smlelstv# Also see TZDEFRULESTRING below, which takes effect only
761.55Schristos# if POSIXRULES is '-' or if the template file cannot be accessed.
771.1Smlelstv
781.1Smlelstv
791.39Schristos# Installation locations.
801.39Schristos#
811.39Schristos# The defaults are suitable for Debian, except that if REDO is
821.39Schristos# posix_right or right_posix then files that Debian puts under
831.39Schristos# /usr/share/zoneinfo/posix and /usr/share/zoneinfo/right are instead
841.39Schristos# put under /usr/share/zoneinfo-posix and /usr/share/zoneinfo-leaps,
851.39Schristos# respectively.  Problems with the Debian approach are discussed in
861.39Schristos# the commentary for the right_posix rule (below).
871.39Schristos
881.39Schristos# Destination directory, which can be used for staging.
891.39Schristos# 'make DESTDIR=/stage install' installs under /stage (e.g., to
901.39Schristos# /stage/etc/localtime instead of to /etc/localtime).  Files under
911.39Schristos# /stage are not intended to work as-is, but can be copied by hand to
921.39Schristos# the root directory later.  If DESTDIR is empty, 'make install' does
931.39Schristos# not stage, but installs directly into production locations.
941.39SchristosDESTDIR =
951.39Schristos
961.39Schristos# Everything is installed into subdirectories of TOPDIR, and used there.
971.39Schristos# TOPDIR should be empty (meaning the root directory),
981.39Schristos# or a directory name that does not end in "/".
991.39Schristos# TOPDIR should be empty or an absolute name unless you're just testing.
1001.39SchristosTOPDIR =
1011.39Schristos
1021.41Schristos# The default local timezone is taken from the file TZDEFAULT.
1031.39SchristosTZDEFAULT = $(TOPDIR)/etc/localtime
1041.39Schristos
1051.39Schristos# The subdirectory containing installed program and data files, and
1061.39Schristos# likewise for installed files that can be shared among architectures.
1071.39Schristos# These should be relative file names.
1081.39SchristosUSRDIR = usr
1091.39SchristosUSRSHAREDIR = $(USRDIR)/share
1101.1Smlelstv
1111.41Schristos# "Compiled" timezone information is placed in the "TZDIR" directory
1121.1Smlelstv# (and subdirectories).
1131.38Schristos# TZDIR_BASENAME should not contain "/" and should not be ".", ".." or empty.
1141.15SchristosTZDIR_BASENAME=	zoneinfo
1151.39SchristosTZDIR = $(TOPDIR)/$(USRSHAREDIR)/$(TZDIR_BASENAME)
1161.1Smlelstv
1171.39Schristos# The "tzselect" and (if you do "make INSTALL") "date" commands go in:
1181.39SchristosBINDIR = $(TOPDIR)/$(USRDIR)/bin
1191.1Smlelstv
1201.39Schristos# The "zdump" command goes in:
1211.39SchristosZDUMPDIR = $(BINDIR)
1221.1Smlelstv
1231.39Schristos# The "zic" command goes in:
1241.39SchristosZICDIR = $(TOPDIR)/$(USRDIR)/sbin
1251.1Smlelstv
1261.1Smlelstv# Manual pages go in subdirectories of. . .
1271.39SchristosMANDIR = $(TOPDIR)/$(USRSHAREDIR)/man
1281.1Smlelstv
1291.39Schristos# Library functions are put in an archive in LIBDIR.
1301.39SchristosLIBDIR = $(TOPDIR)/$(USRDIR)/lib
1311.1Smlelstv
1321.1Smlelstv
1331.41Schristos# Types to try, as an alternative to time_t.
1341.41SchristosTIME_T_ALTERNATIVES = $(TIME_T_ALTERNATIVES_HEAD) $(TIME_T_ALTERNATIVES_TAIL)
1351.58SchristosTIME_T_ALTERNATIVES_HEAD = int_least64_t.ck
1361.58SchristosTIME_T_ALTERNATIVES_TAIL = int_least32_t.ck uint_least32_t.ck \
1371.58Schristos  uint_least64_t.ck
1381.1Smlelstv
1391.43Schristos# What kind of TZif data files to generate.  (TZif is the binary time
1401.43Schristos# zone data format that zic generates; see Internet RFC 8536.)
1411.37Schristos# If you want only POSIX time, with time values interpreted as
1421.37Schristos# seconds since the epoch (not counting leap seconds), use
1431.1Smlelstv#	REDO=		posix_only
1441.38Schristos# below.  If you want only "right" time, with values interpreted
1451.37Schristos# as seconds since the epoch (counting leap seconds), use
1461.1Smlelstv#	REDO=		right_only
1471.1Smlelstv# below.  If you want both sets of data available, with leap seconds not
1481.1Smlelstv# counted normally, use
1491.1Smlelstv#	REDO=		posix_right
1501.1Smlelstv# below.  If you want both sets of data available, with leap seconds counted
1511.1Smlelstv# normally, use
1521.1Smlelstv#	REDO=		right_posix
1531.32Schristos# below.  POSIX mandates that leap seconds not be counted; for compatibility
1541.37Schristos# with it, use "posix_only" or "posix_right".  Use POSIX time on systems with
1551.37Schristos# leap smearing; this can work better than unsmeared "right" time with
1561.37Schristos# applications that are not leap second aware, and is closer to unsmeared
1571.37Schristos# "right" time than unsmeared POSIX time is (e.g., 0.5 vs 1.0 s max error).
1581.1Smlelstv
1591.1SmlelstvREDO=		posix_right
1601.1Smlelstv
1611.45Schristos# Whether to put an "Expires" line in the leapseconds file.
1621.45Schristos# Use EXPIRES_LINE=1 to put the line in, 0 to omit it.
1631.45Schristos# The EXPIRES_LINE value matters only if REDO's value contains "right".
1641.45Schristos# If you change EXPIRES_LINE, remove the leapseconds file before running "make".
1651.45Schristos# zic's support for the Expires line was introduced in tzdb 2020a,
1661.49Schristos# and was modified in tzdb 2021b to generate version 4 TZif files.
1671.49Schristos# EXPIRES_LINE defaults to 0 for now so that the leapseconds file
1681.49Schristos# can be given to pre-2020a zic implementations and so that TZif files
1691.49Schristos# built by newer zic implementations can be read by pre-2021b libraries.
1701.45SchristosEXPIRES_LINE=	0
1711.45Schristos
1721.41Schristos# To install data in text form that has all the information of the TZif data,
1731.38Schristos# (optionally incorporating leap second information), use
1741.38Schristos#	TZDATA_TEXT=	tzdata.zi leapseconds
1751.38Schristos# To install text data without leap second information (e.g., because
1761.38Schristos# REDO='posix_only'), use
1771.38Schristos#	TZDATA_TEXT=	tzdata.zi
1781.38Schristos# To avoid installing text data, use
1791.38Schristos#	TZDATA_TEXT=
1801.38Schristos
1811.38SchristosTZDATA_TEXT=	leapseconds tzdata.zi
1821.38Schristos
1831.38Schristos# For backward-compatibility links for old zone names, use
1841.39Schristos#	BACKWARD=	backward
1851.38Schristos# To omit these links, use
1861.38Schristos#	BACKWARD=
1871.38Schristos
1881.39SchristosBACKWARD=	backward
1891.38Schristos
1901.51Schristos# If you want out-of-scope and often-wrong data from the file 'backzone',
1911.51Schristos# but only for entries listed in the backward-compatibility file zone.tab, use
1921.32Schristos#	PACKRATDATA=	backzone
1931.51Schristos#	PACKRATLIST=	zone.tab
1941.51Schristos# If you want all the 'backzone' data, use
1951.51Schristos#	PACKRATDATA=	backzone
1961.51Schristos#	PACKRATLIST=
1971.32Schristos# To omit this data, use
1981.32Schristos#	PACKRATDATA=
1991.51Schristos#	PACKRATLIST=
2001.32Schristos
2011.32SchristosPACKRATDATA=
2021.51SchristosPACKRATLIST=
2031.32Schristos
2041.38Schristos# The name of a locale using the UTF-8 encoding, used during self-tests.
2051.38Schristos# The tests are skipped if the name does not appear to work on this system.
2061.38Schristos
2071.38SchristosUTF8_LOCALE=	en_US.utf8
2081.38Schristos
2091.1Smlelstv# Non-default libraries needed to link.
2101.54Schristos# On some hosts, this should have -lintl unless CFLAGS has -DHAVE_GETTEXT=0.
2111.1SmlelstvLDLIBS=
2121.1Smlelstv
2131.56Schristos# Add the following to an uncommented "CFLAGS=" line as needed
2141.56Schristos# to override defaults specified in the source code or by the system.
2151.56Schristos# "-DFOO" is equivalent to "-DFOO=1".
2161.38Schristos#  -DDEPRECATE_TWO_DIGIT_YEARS for optional runtime warnings about strftime
2171.38Schristos#	formats that generate only the last two digits of year numbers
2181.38Schristos#  -DEPOCH_LOCAL if the 'time' function returns local time not UT
2191.38Schristos#  -DEPOCH_OFFSET=N if the 'time' function returns a value N greater
2201.38Schristos#	than what POSIX specifies, assuming local time is UT.
2211.38Schristos#	For example, N is 252460800 on AmigaOS.
2221.32Schristos#  -DHAVE_DECL_ASCTIME_R=0 if <time.h> does not declare asctime_r
2231.58Schristos#	on POSIX platforms predating POSIX.1-2024
2241.38Schristos#  -DHAVE_DECL_ENVIRON if <unistd.h> declares 'environ'
2251.54Schristos#  -DHAVE_DECL_TIMEGM=0 if <time.h> does not declare timegm
2261.32Schristos#  -DHAVE_DIRECT_H if mkdir needs <direct.h> (MS-Windows)
2271.55Schristos#  -DHAVE__GENERIC=0 if _Generic does not work*
2281.54Schristos#  -DHAVE_GETRANDOM if getrandom works (e.g., GNU/Linux),
2291.54Schristos#	-DHAVE_GETRANDOM=0 to avoid using getrandom
2301.54Schristos#  -DHAVE_GETTEXT if gettext works (e.g., GNU/Linux, FreeBSD, Solaris),
2311.54Schristos#	where LDLIBS also needs to contain -lintl on some hosts;
2321.54Schristos#	-DHAVE_GETTEXT=0 to avoid using gettext
2331.38Schristos#  -DHAVE_INCOMPATIBLE_CTIME_R if your system's time.h declares
2341.58Schristos#	ctime_r and asctime_r incompatibly with POSIX.1-2017 and earlier
2351.35Schristos#	(Solaris when _POSIX_PTHREAD_SEMANTICS is not defined).
2361.55Schristos#  -DHAVE_INTTYPES_H=0 if <inttypes.h> does not work*+
2371.16Schristos#  -DHAVE_LINK=0 if your system lacks a link function
2381.23Schristos#  -DHAVE_LOCALTIME_R=0 if your system lacks a localtime_r function
2391.23Schristos#  -DHAVE_LOCALTIME_RZ=0 if you do not want zdump to use localtime_rz
2401.23Schristos#	localtime_rz can make zdump significantly faster, but is nonstandard.
2411.49Schristos#  -DHAVE_MALLOC_ERRNO=0 if malloc etc. do not set errno on failure.
2421.32Schristos#  -DHAVE_POSIX_DECLS=0 if your system's include files do not declare
2431.32Schristos#	functions like 'link' or variables like 'tzname' required by POSIX
2441.53Schristos#  -DHAVE_SETENV=0 if your system lacks the setenv function
2451.55Schristos#  -DHAVE_SNPRINTF=0 if your system lacks the snprintf function+
2461.54Schristos#  -DHAVE_STDCKDINT_H=0 if neither <stdckdint.h> nor substitutes like
2471.54Schristos#	__builtin_add_overflow work*
2481.55Schristos#  -DHAVE_STDINT_H=0 if <stdint.h> does not work*+
2491.38Schristos#  -DHAVE_STRFTIME_L if <time.h> declares locale_t and strftime_l
2501.28Schristos#  -DHAVE_STRDUP=0 if your system lacks the strdup function
2511.55Schristos#  -DHAVE_STRTOLL=0 if your system lacks the strtoll function+
2521.1Smlelstv#  -DHAVE_SYMLINK=0 if your system lacks the symlink function
2531.54Schristos#  -DHAVE_SYS_STAT_H=0 if <sys/stat.h> does not work*
2541.23Schristos#  -DHAVE_TZSET=0 if your system lacks a tzset function
2551.54Schristos#  -DHAVE_UNISTD_H=0 if <unistd.h> does not work*
2561.54Schristos#  -DHAVE_UTMPX_H=0 if <utmpx.h> does not work*
2571.38Schristos#  -Dlocale_t=XXX if your system uses XXX instead of locale_t
2581.56Schristos#  -DPORT_TO_C89 if tzcode should also run on mostly-C89 platforms+
2591.56Schristos#	Typically it is better to use a later standard.  For example,
2601.56Schristos#	with GCC 4.9.4 (2016), prefer '-std=gnu11' to '-DPORT_TO_C89'.
2611.56Schristos#	Even with -DPORT_TO_C89, the code needs at least one C99
2621.56Schristos#	feature (integers at least 64 bits wide) and maybe more.
2631.40Schristos#  -DRESERVE_STD_EXT_IDS if your platform reserves standard identifiers
2641.40Schristos#	with external linkage, e.g., applications cannot define 'localtime'.
2651.38Schristos#  -Dssize_t=long on hosts like MS-Windows that lack ssize_t
2661.58Schristos#  -DSUPPORT_C89=0 if the tzcode library should not support C89 callers
2671.58Schristos#	Although -DSUPPORT_C89=0 might work around latent bugs in callers,
2681.58Schristos#	it does not conform to POSIX.
2691.58Schristos#  -DSUPPORT_POSIX2008 if the library should support older POSIX callers+
2701.58Schristos#	However, this might cause problems in POSIX.1-2024-or-later callers.
2711.40Schristos#  -DSUPPRESS_TZDIR to not prepend TZDIR to file names; this has
2721.40Schristos#	security implications and is not recommended for general use
2731.38Schristos#  -DTHREAD_SAFE to make localtime.c thread-safe, as POSIX requires;
2741.23Schristos#	not needed by the main-program tz code, which is single-threaded.
2751.23Schristos#	Append other compiler flags as needed, e.g., -pthread on GNU/Linux.
2761.14Schristos#  -Dtime_tz=\"T\" to use T as the time_t type, rather than the system time_t
2771.38Schristos#	This is intended for internal use only; it mangles external names.
2781.1Smlelstv#  -DTZ_DOMAIN=\"foo\" to use "foo" for gettext domain name; default is "tz"
2791.22Schristos#  -DTZ_DOMAINDIR=\"/path\" to use "/path" for gettext directory;
2801.1Smlelstv#	the default is system-supplied, typically "/usr/lib/locale"
2811.14Schristos#  -DTZDEFRULESTRING=\",date/time,date/time\" to default to the specified
2821.58Schristos#	DST transitions for proleptic format TZ strings lacking them,
2831.55Schristos#	in the usual case where POSIXRULES is '-'.  If not specified,
2841.55Schristos#	TZDEFRULESTRING defaults to US rules for future DST transitions.
2851.55Schristos#	This mishandles some past timestamps, as US DST rules have changed.
2861.55Schristos#	It also mishandles settings like TZ='EET-2EEST' for eastern Europe,
2871.55Schristos#	as Europe and US DST rules differ.
2881.55Schristos#  -DTZNAME_MAXIMUM=N to limit time zone abbreviations to N bytes (default 255)
2891.38Schristos#  -DUNINIT_TRAP if reading uninitialized storage can cause problems
2901.23Schristos#	other than simply getting garbage data
2911.23Schristos#  -DUSE_LTZ=0 to build zdump with the system time zone library
2921.23Schristos#	Also set TZDOBJS=zdump.o and CHECK_TIME_T_ALTERNATIVES= below.
2931.46Schristos#  -DZIC_BLOAT_DEFAULT=\"fat\" to default zic's -b option to "fat", and
2941.46Schristos#	similarly for "slim".  Fat TZif files work around incompatibilities
2951.53Schristos#	and bugs in some TZif readers, notably older ones that
2961.53Schristos#	ignore or otherwise mishandle 64-bit data in TZif files;
2971.53Schristos#	however, fat TZif files may trigger bugs in newer TZif readers.
2981.53Schristos#	Slim TZif files are more efficient, and are the default.
2991.1Smlelstv#  -DZIC_MAX_ABBR_LEN_WO_WARN=3
3001.1Smlelstv#	(or some other number) to set the maximum time zone abbreviation length
3011.1Smlelstv#	that zic will accept without a warning (the default is 6)
3021.56Schristos#  -g to generate symbolic debugging info
3031.56Schristos#  -Idir to include from directory 'dir'
3041.56Schristos#  -O0 to disable optimization; other -O options to enable more optimization
3051.56Schristos#  -Uname to remove any definition of the macro 'name'
3061.30Schristos#  $(GCC_DEBUG_FLAGS) if you are using recent GCC and want lots of checking
3071.53Schristos#
3081.53Schristos# * Options marked "*" can be omitted if your compiler is C23 compatible.
3091.55Schristos# * Options marked "+" are obsolescent and are planned to be removed
3101.58Schristos#   once the code assumes C99 or later (say in the year 2029)
3111.58Schristos#   and POSIX.1-2024 or later (say in the year 2034).
3121.53Schristos#
3131.38Schristos# Select instrumentation via "make GCC_INSTRUMENT='whatever'".
3141.38SchristosGCC_INSTRUMENT = \
3151.38Schristos  -fsanitize=undefined -fsanitize-address-use-after-scope \
3161.38Schristos  -fsanitize-undefined-trap-on-error -fstack-protector
3171.49Schristos# Omit -fanalyzer from GCC_DEBUG_FLAGS, as it makes GCC too slow.
3181.58SchristosGCC_DEBUG_FLAGS = -DGCC_LINT -g3 -O3 \
3191.38Schristos  $(GCC_INSTRUMENT) \
3201.38Schristos  -Wall -Wextra \
3211.38Schristos  -Walloc-size-larger-than=100000 -Warray-bounds=2 \
3221.51Schristos  -Wbad-function-cast -Wbidi-chars=any,ucn -Wcast-align=strict -Wdate-time \
3231.38Schristos  -Wdeclaration-after-statement -Wdouble-promotion \
3241.58Schristos  -Wduplicated-branches -Wduplicated-cond -Wflex-array-member-not-at-end \
3251.38Schristos  -Wformat=2 -Wformat-overflow=2 -Wformat-signedness -Wformat-truncation \
3261.54Schristos  -Wimplicit-fallthrough=5 -Winit-self -Wlogical-op \
3271.58Schristos  -Wmissing-declarations -Wmissing-prototypes \
3281.58Schristos  -Wmissing-variable-declarations -Wnested-externs \
3291.49Schristos  -Wnull-dereference \
3301.38Schristos  -Wold-style-definition -Woverlength-strings -Wpointer-arith \
3311.49Schristos  -Wshadow -Wshift-overflow=2 -Wstrict-overflow \
3321.49Schristos  -Wstrict-prototypes -Wstringop-overflow=4 \
3331.40Schristos  -Wstringop-truncation -Wsuggest-attribute=cold \
3341.38Schristos  -Wsuggest-attribute=const -Wsuggest-attribute=format \
3351.40Schristos  -Wsuggest-attribute=malloc \
3361.38Schristos  -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure \
3371.58Schristos  -Wtrampolines -Wundef -Wunused-macros -Wuse-after-free=3 \
3381.38Schristos  -Wvariadic-macros -Wvla -Wwrite-strings \
3391.58Schristos  -Wno-format-nonliteral -Wno-sign-compare
3401.1Smlelstv#
3411.1Smlelstv# If your system has a "GMT offset" field in its "struct tm"s
3421.1Smlelstv# (or if you decide to add such a field in your system's "time.h" file),
3431.1Smlelstv# add the name to a define such as
3441.1Smlelstv#	-DTM_GMTOFF=tm_gmtoff
3451.23Schristos# to the end of the "CFLAGS=" line.  If not defined, the code attempts to
3461.23Schristos# guess TM_GMTOFF from other macros; define NO_TM_GMTOFF to suppress this.
3471.23Schristos# Similarly, if your system has a "zone abbreviation" field, define
3481.1Smlelstv#	-DTM_ZONE=tm_zone
3491.57Schristos# and define NO_TM_ZONE to suppress any guessing.
3501.58Schristos# Although POSIX.1-2024 requires these fields and they are widely available
3511.58Schristos# on GNU/Linux and BSD systems, some older systems lack them.
3521.1Smlelstv#
3531.38Schristos# The next batch of options control support for external variables
3541.38Schristos# exported by tzcode.  In practice these variables are less useful
3551.38Schristos# than TM_GMTOFF and TM_ZONE.  However, most of them are standardized.
3561.38Schristos# #
3571.38Schristos# # To omit or support the external variable "tzname", add one of:
3581.45Schristos# #	-DHAVE_TZNAME=0 # do not support "tzname"
3591.45Schristos# #	-DHAVE_TZNAME=1 # support "tzname", which is defined by system library
3601.45Schristos# #	-DHAVE_TZNAME=2 # support and define "tzname"
3611.58Schristos# # to the "CFLAGS=" line.  Although "tzname" is required by POSIX.1-1988
3621.58Schristos# # and later, its contents are unspecified if you use a geographical TZ
3631.58Schristos# # and the variable is planned to be removed in a future POSIX edition.
3641.38Schristos# # If not defined, the code attempts to guess HAVE_TZNAME from other macros.
3651.38Schristos# # Warning: unless time_tz is also defined, HAVE_TZNAME=1 can cause
3661.38Schristos# # crashes when combined with some platforms' standard libraries,
3671.38Schristos# # presumably due to memory allocation issues.
3681.38Schristos# #
3691.38Schristos# # To omit or support the external variables "timezone" and "daylight", add
3701.45Schristos# #	-DUSG_COMPAT=0 # do not support
3711.45Schristos# #	-DUSG_COMPAT=1 # support, and variables are defined by system library
3721.45Schristos# #	-DUSG_COMPAT=2 # support and define variables
3731.57Schristos# # to the "CFLAGS=" line; "timezone" and "daylight" are inspired by Unix
3741.58Schristos# # Systems Group code and are required by POSIX.1-2008 and later (with XSI),
3751.58Schristos# # although their contents are unspecified if you use a geographical TZ
3761.58Schristos# # and the variables are planned to be removed in a future edition of POSIX.
3771.38Schristos# # If not defined, the code attempts to guess USG_COMPAT from other macros.
3781.38Schristos# #
3791.38Schristos# # To support the external variable "altzone", add
3801.45Schristos# #	-DALTZONE=0 # do not support
3811.45Schristos# #	-DALTZONE=1 # support "altzone", which is defined by system library
3821.45Schristos# #	-DALTZONE=2 # support and define "altzone"
3831.38Schristos# # to the end of the "CFLAGS=" line; although "altzone" appeared in
3841.38Schristos# # System V Release 3.1 it has not been standardized.
3851.45Schristos# # If not defined, the code attempts to guess ALTZONE from other macros.
3861.38Schristos#
3871.1Smlelstv# If you want functions that were inspired by early versions of X3J11's work,
3881.1Smlelstv# add
3891.1Smlelstv#	-DSTD_INSPIRED
3901.54Schristos# to the end of the "CFLAGS=" line.  This arranges for the following
3911.54Schristos# functions to be added to the time conversion library.
3921.1Smlelstv# "offtime" is like "gmtime" except that it accepts a second (long) argument
3931.1Smlelstv# that gives an offset to add to the time_t when converting it.
3941.56Schristos# I.e., "offtime" is like calling "localtime_rz" with a fixed-offset zone.
3951.56Schristos# "timelocal" is nearly equivalent to "mktime".
3961.1Smlelstv# "timeoff" is like "timegm" except that it accepts a second (long) argument
3971.1Smlelstv# that gives an offset to use when converting to a time_t.
3981.56Schristos# I.e., "timeoff" is like calling "mktime_z" with a fixed-offset zone.
3991.1Smlelstv# "posix2time" and "time2posix" are described in an included manual page.
4001.1Smlelstv# X3J11's work does not describe any of these functions.
4011.1Smlelstv# These functions may well disappear in future releases of the time
4021.1Smlelstv# conversion package.
4031.1Smlelstv#
4041.23Schristos# If you don't want functions that were inspired by NetBSD, add
4051.23Schristos#	-DNETBSD_INSPIRED=0
4061.23Schristos# to the end of the "CFLAGS=" line.  Otherwise, the functions
4071.23Schristos# "localtime_rz", "mktime_z", "tzalloc", and "tzfree" are added to the
4081.55Schristos# time library, and if STD_INSPIRED is also defined to nonzero the functions
4091.23Schristos# "posix2time_z" and "time2posix_z" are added as well.
4101.23Schristos# The functions ending in "_z" (or "_rz") are like their unsuffixed
4111.23Schristos# (or suffixed-by-"_r") counterparts, except with an extra first
4121.41Schristos# argument of opaque type timezone_t that specifies the timezone.
4131.23Schristos# "tzalloc" allocates a timezone_t value, and "tzfree" frees it.
4141.23Schristos#
4151.1Smlelstv# If you want to allocate state structures in localtime, add
4161.1Smlelstv#	-DALL_STATE
4171.1Smlelstv# to the end of the "CFLAGS=" line.  Storage is obtained by calling malloc.
4181.1Smlelstv#
4191.1Smlelstv# NIST-PCTS:151-2, Version 1.4, (1993-12-03) is a test suite put
4201.1Smlelstv# out by the National Institute of Standards and Technology
4211.56Schristos# which claims to test C and POSIX conformance.  If you want to pass PCTS, add
4221.1Smlelstv#	-DPCTS
4231.1Smlelstv# to the end of the "CFLAGS=" line.
4241.1Smlelstv#
4251.1Smlelstv# If you want strict compliance with XPG4 as of 1994-04-09, add
4261.1Smlelstv#	-DXPG4_1994_04_09
4271.1Smlelstv# to the end of the "CFLAGS=" line.  This causes "strftime" to always return
4281.38Schristos# 53 as a week number (rather than 52 or 53) for January days before
4291.38Schristos# January's first Monday when a "%V" format is used and January 1
4301.1Smlelstv# falls on a Friday, Saturday, or Sunday.
4311.56Schristos#
4321.56Schristos# POSIX says CFLAGS defaults to "-O 1".
4331.56Schristos# Uncomment the following line and edit its contents as needed.
4341.1Smlelstv
4351.56Schristos#CFLAGS= -O 1
4361.1Smlelstv
4371.9Schristos
4381.56Schristos# The name of a POSIX-like library archiver, its flags, C compiler,
4391.56Schristos# linker flags, and 'make' utility.  Ordinarily the defaults suffice.
4401.58Schristos# The commented-out values are the defaults specified by POSIX.1-2024.
4411.56Schristos#AR = ar
4421.56Schristos#ARFLAGS = -rv
4431.56Schristos#CC = c17
4441.56Schristos#LDFLAGS =
4451.56Schristos#MAKE = make
4461.1Smlelstv
4471.57Schristos# Where to fetch leap-seconds.list from.
4481.57Schristosleaplist_URI = \
4491.57Schristos  https://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list
4501.57Schristos# The file is generated by the IERS Earth Orientation Centre, in Paris.
4511.57Schristosleaplist_TZ = Europe/Paris
4521.57Schristos
4531.32Schristos# The zic command and its arguments.
4541.32Schristos
4551.1Smlelstvzic=		./zic
4561.1SmlelstvZIC=		$(zic) $(ZFLAGS)
4571.1Smlelstv
4581.43Schristos# To shrink the size of installed TZif files,
4591.43Schristos# append "-r @N" to omit data before N-seconds-after-the-Epoch.
4601.53Schristos# To grow the files and work around bugs in older applications,
4611.53Schristos# possibly at the expense of introducing bugs in newer ones,
4621.53Schristos# append "-b fat"; see ZIC_BLOAT_DEFAULT above.
4631.44Schristos# See the zic man page for more about -b and -r.
4641.15SchristosZFLAGS=
4651.15Schristos
4661.41Schristos# How to use zic to install TZif files.
4671.32Schristos
4681.58SchristosZIC_INSTALL=	$(ZIC) -d '$(DESTDIR)$(TZDIR)'
4691.32Schristos
4701.56Schristos# The name of a POSIX-compliant 'awk' on your system.
4711.50Schristos# mawk 1.3.3 and Solaris 10 /usr/bin/awk do not work.
4721.50Schristos# Also, it is better (though not essential) if 'awk' supports UTF-8,
4731.50Schristos# and unfortunately mawk and busybox awk do not support UTF-8.
4741.50Schristos# Try AWK=gawk or AWK=nawk if your awk has the abovementioned problems.
4751.9SchristosAWK=		awk
4761.9Schristos
4771.56Schristos# The full path name of a POSIX-compliant shell, preferably one that supports
4781.16Schristos# the Korn shell's 'select' statement as an extension.
4791.16Schristos# These days, Bash is the most popular.
4801.16Schristos# It should be OK to set this to /bin/sh, on platforms where /bin/sh
4811.56Schristos# lacks 'select' or doesn't completely conform to POSIX, but /bin/bash
4821.16Schristos# is typically nicer if it works.
4831.9SchristosKSHELL=		/bin/bash
4841.1Smlelstv
4851.57Schristos# Name of curl <https://curl.haxx.se/>, used for HTML validation
4861.57Schristos# and to fetch leap-seconds.list from upstream.
4871.58Schristos# Set CURL=: to disable use of the Internet.
4881.42SchristosCURL=		curl
4891.42Schristos
4901.44Schristos# Name of GNU Privacy Guard <https://gnupg.org/>, used to sign distributions.
4911.44SchristosGPG=		gpg
4921.44Schristos
4931.23Schristos# This expensive test requires USE_LTZ.
4941.23Schristos# To suppress it, define this macro to be empty.
4951.23SchristosCHECK_TIME_T_ALTERNATIVES = check_time_t_alternatives
4961.23Schristos
4971.22Schristos# SAFE_CHAR is a regular expression that matches a safe character.
4981.22Schristos# Some parts of this distribution are limited to safe characters;
4991.22Schristos# others can use any UTF-8 character.
5001.22Schristos# For now, the safe characters are a safe subset of ASCII.
5011.9Schristos# The caller must set the shell variable 'sharp' to the character '#',
5021.9Schristos# since Makefile macros cannot contain '#'.
5031.9Schristos# TAB_CHAR is a single tab character, in single quotes.
5041.9SchristosTAB_CHAR=	'	'
5051.22SchristosSAFE_CHARSET1=	$(TAB_CHAR)' !\"'$$sharp'$$%&'\''()*+,./0123456789:;<=>?@'
5061.22SchristosSAFE_CHARSET2=	'ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\^_`'
5071.22SchristosSAFE_CHARSET3=	'abcdefghijklmnopqrstuvwxyz{|}~'
5081.29SchristosSAFE_CHARSET=	$(SAFE_CHARSET1)$(SAFE_CHARSET2)$(SAFE_CHARSET3)
5091.29SchristosSAFE_CHAR=	'[]'$(SAFE_CHARSET)'-]'
5101.29Schristos
5111.55Schristos# These non-alphabetic, non-ASCII printable characters are Latin-1,
5121.55Schristos# and so are likely displayable even in editors like XEmacs 21
5131.55Schristos# that have limited display capabilities.
5141.55SchristosUNUSUAL_OK_LATIN_1 = ¡¢£¤¥¦§¨©«¬®¯°±²³´¶·¸¹»¼½¾¿×÷
5151.40Schristos# Non-ASCII non-letters that OK_CHAR allows, as these characters are
5161.41Schristos# useful in commentary.
5171.55SchristosUNUSUAL_OK_CHARSET= $(UNUSUAL_OK_LATIN_1)
5181.40Schristos
5191.51Schristos# Put this in a bracket expression to match spaces.
5201.51Schristoss = [:space:]
5211.51Schristos
5221.29Schristos# OK_CHAR matches any character allowed in the distributed files.
5231.40Schristos# This is the same as SAFE_CHAR, except that UNUSUAL_OK_CHARSET and
5241.40Schristos# multibyte letters are also allowed so that commentary can contain a
5251.40Schristos# few safe symbols and people's names and can quote non-English sources.
5261.40Schristos# Other non-letters are limited to ASCII renderings for the
5271.40Schristos# convenience of maintainers using XEmacs 21.5.34, which by default
5281.40Schristos# mishandles Unicode characters U+0100 and greater.
5291.40SchristosOK_CHAR=	'[][:alpha:]$(UNUSUAL_OK_CHARSET)'$(SAFE_CHARSET)'-]'
5301.22Schristos
5311.22Schristos# SAFE_LINE matches a line of safe characters.
5321.29Schristos# SAFE_SHARP_LINE is similar, except any OK character can follow '#';
5331.22Schristos# this is so that comments can contain non-ASCII characters.
5341.29Schristos# OK_LINE matches a line of OK characters.
5351.22SchristosSAFE_LINE=	'^'$(SAFE_CHAR)'*$$'
5361.29SchristosSAFE_SHARP_LINE='^'$(SAFE_CHAR)'*('$$sharp$(OK_CHAR)'*)?$$'
5371.29SchristosOK_LINE=	'^'$(OK_CHAR)'*$$'
5381.9Schristos
5391.6Schristos# Flags to give 'tar' when making a distribution.
5401.6Schristos# Try to use flags appropriate for GNU tar.
5411.58SchristosGNUTARFLAGS= --format=pax --pax-option=delete=atime,delete=ctime \
5421.50Schristos  --numeric-owner --owner=0 --group=0 \
5431.50Schristos  --mode=go+u,go-w --sort=name
5441.58SchristosSETUP_TAR= \
5451.58Schristos  export LC_ALL=C && \
5461.58Schristos  if tar $(GNUTARFLAGS) --version >/dev/null 2>&1; then \
5471.58Schristos    TAR='tar $(GNUTARFLAGS)'; \
5481.58Schristos  else \
5491.58Schristos    TAR=tar; \
5501.58Schristos  fi
5511.6Schristos
5521.6Schristos# Flags to give 'gzip' when making a distribution.
5531.38SchristosGZIPFLAGS=	-9n
5541.6Schristos
5551.54Schristos# When comparing .tzs files, use GNU diff's -F'^TZ=' option if supported.
5561.54Schristos# This makes it easier to see which Zone has been affected.
5571.58SchristosSETUP_DIFF_TZS = \
5581.58Schristos  if diff -u -F'^TZ=' - - <>/dev/null >&0 2>&1; then \
5591.58Schristos    DIFF_TZS='diff -u -F^TZ='; \
5601.58Schristos  else \
5611.58Schristos    DIFF_TZS='diff -u'; \
5621.58Schristos  fi
5631.54Schristos
5641.56Schristos# ':' on typical hosts; 'ranlib' on the ancient hosts that still need ranlib.
5651.56SchristosRANLIB=		:
5661.1Smlelstv
5671.56Schristos# POSIX prohibits defining or using SHELL.  However, csh users on systems
5681.56Schristos# that use the user shell for Makefile commands may need to define SHELL.
5691.56Schristos#SHELL=		/bin/sh
5701.29Schristos
5711.56Schristos# End of macros that one plausibly might want to tailor.
5721.56Schristos###############################################################################
5731.1Smlelstv
5741.16Schristos
5751.28SchristosTZCOBJS=	zic.o
5761.58SchristosTZDOBJS=	zdump.o localtime.o strftime.o
5771.58SchristosDATEOBJS=	date.o localtime.o strftime.o
5781.45SchristosLIBSRCS=	localtime.c asctime.c difftime.c strftime.c
5791.45SchristosLIBOBJS=	localtime.o asctime.o difftime.o strftime.o
5801.1SmlelstvHEADERS=	tzfile.h private.h
5811.28SchristosNONLIBSRCS=	zic.c zdump.c
5821.45SchristosNEWUCBSRCS=	date.c
5831.23SchristosSOURCES=	$(HEADERS) $(LIBSRCS) $(NONLIBSRCS) $(NEWUCBSRCS) \
5841.35Schristos			tzselect.ksh workman.sh
5851.1SmlelstvMANS=		newctime.3 newstrftime.3 newtzset.3 time2posix.3 \
5861.1Smlelstv			tzfile.5 tzselect.8 zic.8 zdump.8
5871.16SchristosMANTXTS=	newctime.3.txt newstrftime.3.txt newtzset.3.txt \
5881.16Schristos			time2posix.3.txt \
5891.16Schristos			tzfile.5.txt tzselect.8.txt zic.8.txt zdump.8.txt \
5901.16Schristos			date.1.txt
5911.38SchristosCOMMON=		calendars CONTRIBUTING LICENSE Makefile \
5921.49Schristos			NEWS README SECURITY theory.html version
5931.39SchristosWEB_PAGES=	tz-art.html tz-how-to.html tz-link.html
5941.58SchristosCHECK_WEB_PAGES=theory.ck tz-art.ck tz-how-to.ck tz-link.ck
5951.23SchristosDOCS=		$(MANS) date.1 $(MANTXTS) $(WEB_PAGES)
5961.1SmlelstvPRIMARY_YDATA=	africa antarctica asia australasia \
5971.1Smlelstv		europe northamerica southamerica
5981.39SchristosYDATA=		$(PRIMARY_YDATA) etcetera
5991.46SchristosNDATA=		factory
6001.46SchristosTDATA_TO_CHECK=	$(YDATA) $(NDATA) backward
6011.39SchristosTDATA=		$(YDATA) $(NDATA) $(BACKWARD)
6021.56SchristosZONETABLES=	zone.tab zone1970.tab zonenow.tab
6031.38SchristosTABDATA=	iso3166.tab $(TZDATA_TEXT) $(ZONETABLES)
6041.16SchristosLEAP_DEPS=	leapseconds.awk leap-seconds.list
6051.51SchristosTZDATA_ZI_DEPS=	ziguard.awk zishrink.awk version $(TDATA) \
6061.51Schristos		  $(PACKRATDATA) $(PACKRATLIST)
6071.51SchristosDSTDATA_ZI_DEPS= ziguard.awk $(TDATA) $(PACKRATDATA) $(PACKRATLIST)
6081.39SchristosDATA=		$(TDATA_TO_CHECK) backzone iso3166.tab leap-seconds.list \
6091.46Schristos			leapseconds $(ZONETABLES)
6101.56SchristosAWK_SCRIPTS=	checklinks.awk checknow.awk checktab.awk leapseconds.awk \
6111.40Schristos			ziguard.awk zishrink.awk
6121.52SchristosMISC=		$(AWK_SCRIPTS)
6131.34SchristosTZS_YEAR=	2050
6141.41SchristosTZS_CUTOFF_FLAG=	-c $(TZS_YEAR)
6151.34SchristosTZS=		to$(TZS_YEAR).tzs
6161.34SchristosTZS_NEW=	to$(TZS_YEAR)new.tzs
6171.49SchristosTZS_DEPS=	$(YDATA) asctime.c localtime.c \
6181.34Schristos			private.h tzfile.h zdump.c zic.c
6191.51SchristosTZDATA_DIST = $(COMMON) $(DATA) $(MISC)
6201.41Schristos# EIGHT_YARDS is just a yard short of the whole ENCHILADA.
6211.51SchristosEIGHT_YARDS = $(TZDATA_DIST) $(DOCS) $(SOURCES) tzdata.zi
6221.41SchristosENCHILADA = $(EIGHT_YARDS) $(TZS)
6231.34Schristos
6241.34Schristos# Consult these files when deciding whether to rebuild the 'version' file.
6251.34Schristos# This list is not the same as the output of 'git ls-files', since
6261.34Schristos# .gitignore is not distributed.
6271.34SchristosVERSION_DEPS= \
6281.49Schristos		calendars CONTRIBUTING LICENSE Makefile NEWS README SECURITY \
6291.34Schristos		africa antarctica asctime.c asia australasia \
6301.34Schristos		backward backzone \
6311.56Schristos		checklinks.awk checknow.awk checktab.awk \
6321.34Schristos		date.1 date.c difftime.c \
6331.34Schristos		etcetera europe factory iso3166.tab \
6341.34Schristos		leap-seconds.list leapseconds.awk localtime.c \
6351.34Schristos		newctime.3 newstrftime.3 newtzset.3 northamerica \
6361.46Schristos		private.h southamerica strftime.c theory.html \
6371.39Schristos		time2posix.3 tz-art.html tz-how-to.html tz-link.html \
6381.34Schristos		tzfile.5 tzfile.h tzselect.8 tzselect.ksh \
6391.46Schristos		workman.sh zdump.8 zdump.c zic.8 zic.c \
6401.40Schristos		ziguard.awk zishrink.awk \
6411.56Schristos		zone.tab zone1970.tab zonenow.tab
6421.1Smlelstv
6431.46Schristosall:		tzselect zic zdump libtz.a $(TABDATA) \
6441.40Schristos		  vanguard.zi main.zi rearguard.zi
6451.1Smlelstv
6461.29SchristosALL:		all date $(ENCHILADA)
6471.1Smlelstv
6481.16Schristosinstall:	all $(DATA) $(REDO) $(MANS)
6491.39Schristos		mkdir -p '$(DESTDIR)$(BINDIR)' \
6501.39Schristos			'$(DESTDIR)$(ZDUMPDIR)' '$(DESTDIR)$(ZICDIR)' \
6511.39Schristos			'$(DESTDIR)$(LIBDIR)' \
6521.39Schristos			'$(DESTDIR)$(MANDIR)/man3' '$(DESTDIR)$(MANDIR)/man5' \
6531.39Schristos			'$(DESTDIR)$(MANDIR)/man8'
6541.44Schristos		$(ZIC_INSTALL) -l $(LOCALTIME) \
6551.58Schristos			-p $(POSIXRULES) \
6561.39Schristos			-t '$(DESTDIR)$(TZDEFAULT)'
6571.39Schristos		cp -f $(TABDATA) '$(DESTDIR)$(TZDIR)/.'
6581.39Schristos		cp tzselect '$(DESTDIR)$(BINDIR)/.'
6591.39Schristos		cp zdump '$(DESTDIR)$(ZDUMPDIR)/.'
6601.39Schristos		cp zic '$(DESTDIR)$(ZICDIR)/.'
6611.39Schristos		cp libtz.a '$(DESTDIR)$(LIBDIR)/.'
6621.39Schristos		$(RANLIB) '$(DESTDIR)$(LIBDIR)/libtz.a'
6631.39Schristos		cp -f newctime.3 newtzset.3 '$(DESTDIR)$(MANDIR)/man3/.'
6641.39Schristos		cp -f tzfile.5 '$(DESTDIR)$(MANDIR)/man5/.'
6651.39Schristos		cp -f tzselect.8 zdump.8 zic.8 '$(DESTDIR)$(MANDIR)/man8/.'
6661.1Smlelstv
6671.1SmlelstvINSTALL:	ALL install date.1
6681.39Schristos		mkdir -p '$(DESTDIR)$(BINDIR)' '$(DESTDIR)$(MANDIR)/man1'
6691.39Schristos		cp date '$(DESTDIR)$(BINDIR)/.'
6701.39Schristos		cp -f date.1 '$(DESTDIR)$(MANDIR)/man1/.'
6711.1Smlelstv
6721.48Schristos# Calculate version number from git, if available.
6731.48Schristos# Otherwise, use $(VERSION) unless it is "unknown" and there is already
6741.48Schristos# a 'version' file, in which case reuse the existing 'version' contents
6751.48Schristos# and append "-dirty" if the contents do not already end in "-dirty".
6761.34Schristosversion:	$(VERSION_DEPS)
6771.35Schristos		{ (type git) >/dev/null 2>&1 && \
6781.58Schristos		  V=$$(git describe --match '[0-9][0-9][0-9][0-9][a-z]*' \
6791.58Schristos				--abbrev=7 --dirty) || \
6801.58Schristos		  if test '$(VERSION)' = unknown && read -r V <$@; then \
6811.58Schristos		    V=$${V%-dirty}-dirty; \
6821.48Schristos		  else \
6831.48Schristos		    V='$(VERSION)'; \
6841.48Schristos		  fi; } && \
6851.35Schristos		printf '%s\n' "$$V" >$@.out
6861.35Schristos		mv $@.out $@
6871.34Schristos
6881.51Schristos# These files can be tailored by setting BACKWARD, PACKRATDATA, PACKRATLIST.
6891.40Schristosvanguard.zi main.zi rearguard.zi: $(DSTDATA_ZI_DEPS)
6901.51Schristos		$(AWK) \
6911.58Schristos		  -v DATAFORM=$(@:.zi=) \
6921.51Schristos		  -v PACKRATDATA='$(PACKRATDATA)' \
6931.51Schristos		  -v PACKRATLIST='$(PACKRATLIST)' \
6941.51Schristos		  -f ziguard.awk \
6951.40Schristos		  $(TDATA) $(PACKRATDATA) >$@.out
6961.40Schristos		mv $@.out $@
6971.41Schristos# This file has a version comment that attempts to capture any tailoring
6981.51Schristos# via BACKWARD, DATAFORM, PACKRATDATA, PACKRATLIST, and REDO.
6991.41Schristostzdata.zi:	$(DATAFORM).zi version zishrink.awk
7001.58Schristos		read -r version <version && \
7011.41Schristos		  LC_ALL=C $(AWK) \
7021.41Schristos		    -v dataform='$(DATAFORM)' \
7031.41Schristos		    -v deps='$(DSTDATA_ZI_DEPS) zishrink.awk' \
7041.41Schristos		    -v redo='$(REDO)' \
7051.41Schristos		    -v version="$$version" \
7061.41Schristos		    -f zishrink.awk \
7071.40Schristos		    $(DATAFORM).zi >$@.out
7081.38Schristos		mv $@.out $@
7091.38Schristos
7101.56Schristostzdir.h:
7111.56Schristos		printf '%s\n' >$@.out \
7121.56Schristos		  '#ifndef TZDEFAULT' \
7131.56Schristos		  '# define TZDEFAULT "$(TZDEFAULT)" /* default zone */' \
7141.56Schristos		  '#endif' \
7151.56Schristos		  '#ifndef TZDIR' \
7161.56Schristos		  '# define TZDIR "$(TZDIR)" /* TZif directory */' \
7171.56Schristos		  '#endif'
7181.56Schristos		mv $@.out $@
7191.56Schristos
7201.34Schristosversion.h:	version
7211.58Schristos		read -r VERSION <version && printf '%s\n' \
7221.35Schristos		  'static char const PKGVERSION[]="($(PACKAGE)) ";' \
7231.35Schristos		  "static char const TZVERSION[]=\"$$VERSION\";" \
7241.35Schristos		  'static char const REPORT_BUGS_TO[]="$(BUGEMAIL)";' \
7251.35Schristos		  >$@.out
7261.35Schristos		mv $@.out $@
7271.6Schristos
7281.1Smlelstvzdump:		$(TZDOBJS)
7291.9Schristos		$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(TZDOBJS) $(LDLIBS)
7301.1Smlelstv
7311.32Schristoszic:		$(TZCOBJS)
7321.9Schristos		$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(TZCOBJS) $(LDLIBS)
7331.1Smlelstv
7341.16Schristosleapseconds:	$(LEAP_DEPS)
7351.45Schristos		$(AWK) -v EXPIRES_LINE=$(EXPIRES_LINE) \
7361.45Schristos		  -f leapseconds.awk leap-seconds.list >$@.out
7371.35Schristos		mv $@.out $@
7381.15Schristos
7391.57Schristos# Awk script to extract a Git-style author from leap-seconds.list comments.
7401.57SchristosEXTRACT_AUTHOR = \
7411.57Schristos  author_line { sub(/^.[[:space:]]*/, ""); \
7421.57Schristos      sub(/:[[:space:]]*/, " <"); \
7431.57Schristos      printf "%s>\n", $$0; \
7441.57Schristos      success = 1; \
7451.57Schristos      exit \
7461.57Schristos  } \
7471.57Schristos  /Questions or comments to:/ { author_line = 1 } \
7481.57Schristos  END { exit !success }
7491.57Schristos
7501.57Schristos# Fetch leap-seconds.list from upstream.
7511.57Schristosfetch-leap-seconds.list:
7521.57Schristos		$(CURL) -OR $(leaplist_URI)
7531.57Schristos
7541.57Schristos# Fetch leap-seconds.list from upstream and commit it to the local repository.
7551.57Schristoscommit-leap-seconds.list: fetch-leap-seconds.list
7561.57Schristos		author=$$($(AWK) '$(EXTRACT_AUTHOR)' leap-seconds.list) && \
7571.57Schristos		date=$$(TZ=$(leaplist_TZ) stat -c%y leap-seconds.list) && \
7581.57Schristos		git commit --author="$$author" --date="$$date" -m'make $@' \
7591.57Schristos		  leap-seconds.list
7601.57Schristos
7611.58Schristos# Arguments to pass to submakes.
7621.32Schristos# They can be overridden by later submake arguments.
7631.32SchristosINSTALLARGS = \
7641.39Schristos BACKWARD='$(BACKWARD)' \
7651.39Schristos DESTDIR='$(DESTDIR)' \
7661.32Schristos PACKRATDATA='$(PACKRATDATA)' \
7671.51Schristos PACKRATLIST='$(PACKRATLIST)' \
7681.39Schristos TZDEFAULT='$(TZDEFAULT)' \
7691.39Schristos TZDIR='$(TZDIR)' \
7701.32Schristos ZIC='$(ZIC)'
7711.32Schristos
7721.46SchristosINSTALL_DATA_DEPS = zic leapseconds tzdata.zi
7731.41Schristos
7741.58Schristosposix_only: $(INSTALL_DATA_DEPS)
7751.38Schristos		$(ZIC_INSTALL) tzdata.zi
7761.32Schristos
7771.41Schristosright_only: $(INSTALL_DATA_DEPS)
7781.58Schristos		$(ZIC_INSTALL) -L leapseconds tzdata.zi
7791.1Smlelstv
7801.1Smlelstv# In earlier versions of this makefile, the other two directories were
7811.1Smlelstv# subdirectories of $(TZDIR).  However, this led to configuration errors.
7821.1Smlelstv# For example, with posix_right under the earlier scheme,
7831.1Smlelstv# TZ='right/Australia/Adelaide' got you localtime with leap seconds,
7841.1Smlelstv# but gmtime without leap seconds, which led to problems with applications
7851.1Smlelstv# like sendmail that subtract gmtime from localtime.
7861.1Smlelstv# Therefore, the other two directories are now siblings of $(TZDIR).
7871.1Smlelstv# You must replace all of $(TZDIR) to switch from not using leap seconds
7881.1Smlelstv# to using them, or vice versa.
7891.32Schristosright_posix:	right_only
7901.39Schristos		rm -fr '$(DESTDIR)$(TZDIR)-leaps'
7911.39Schristos		ln -s '$(TZDIR_BASENAME)' '$(DESTDIR)$(TZDIR)-leaps' || \
7921.39Schristos		  $(MAKE) $(INSTALLARGS) TZDIR='$(TZDIR)-leaps' right_only
7931.39Schristos		$(MAKE) $(INSTALLARGS) TZDIR='$(TZDIR)-posix' posix_only
7941.15Schristos
7951.32Schristosposix_right:	posix_only
7961.39Schristos		rm -fr '$(DESTDIR)$(TZDIR)-posix'
7971.39Schristos		ln -s '$(TZDIR_BASENAME)' '$(DESTDIR)$(TZDIR)-posix' || \
7981.39Schristos		  $(MAKE) $(INSTALLARGS) TZDIR='$(TZDIR)-posix' posix_only
7991.39Schristos		$(MAKE) $(INSTALLARGS) TZDIR='$(TZDIR)-leaps' right_only
8001.32Schristos
8011.1Smlelstvzones:		$(REDO)
8021.1Smlelstv
8031.40Schristos# dummy.zd is not a real file; it is mentioned here only so that the
8041.40Schristos# top-level 'make' does not have a syntax error.
8051.40SchristosZDS = dummy.zd
8061.40Schristos# Rule used only by submakes invoked by the $(TZS_NEW) rule.
8071.40Schristos# It is separate so that GNU 'make -j' can run instances in parallel.
8081.40Schristos$(ZDS): zdump
8091.58Schristos		./zdump -i $(TZS_CUTOFF_FLAG) "$$PWD/$(@:.zd=)" >$@
8101.40Schristos
8111.41SchristosTZS_NEW_DEPS = tzdata.zi zdump zic
8121.41Schristos$(TZS_NEW): $(TZS_NEW_DEPS)
8131.41Schristos		rm -fr tzs$(TZS_YEAR).dir
8141.41Schristos		mkdir tzs$(TZS_YEAR).dir
8151.41Schristos		$(zic) -d tzs$(TZS_YEAR).dir tzdata.zi
8161.38Schristos		$(AWK) '/^L/{print "Link\t" $$2 "\t" $$3}' \
8171.38Schristos		   tzdata.zi | LC_ALL=C sort >$@.out
8181.58Schristos		x=$$($(AWK) '/^Z/{print "tzs$(TZS_YEAR).dir/" $$2 ".zd"}' \
8191.41Schristos				tzdata.zi \
8201.58Schristos		     | LC_ALL=C sort -t . -k 2,2) && \
8211.41Schristos		set x $$x && \
8221.40Schristos		shift && \
8231.40Schristos		ZDS=$$* && \
8241.58Schristos		$(MAKE) TZS_CUTOFF_FLAG="$(TZS_CUTOFF_FLAG)" \
8251.41Schristos		  ZDS="$$ZDS" $$ZDS && \
8261.41Schristos		sed 's,^TZ=".*\.dir/,TZ=",' $$ZDS >>$@.out
8271.41Schristos		rm -fr tzs$(TZS_YEAR).dir
8281.40Schristos		mv $@.out $@
8291.34Schristos
8301.58Schristos# If $(TZS) exists but 'make tzs.ck' fails, a maintainer should inspect the
8311.34Schristos# failed output and fix the inconsistency, perhaps by running 'make force_tzs'.
8321.34Schristos$(TZS):
8331.41Schristos		touch $@
8341.34Schristos
8351.34Schristosforce_tzs:	$(TZS_NEW)
8361.34Schristos		cp $(TZS_NEW) $(TZS)
8371.34Schristos
8381.16Schristoslibtz.a:	$(LIBOBJS)
8391.37Schristos		rm -f $@
8401.56Schristos		$(AR) $(ARFLAGS) $@ $(LIBOBJS)
8411.16Schristos		$(RANLIB) $@
8421.1Smlelstv
8431.1Smlelstvdate:		$(DATEOBJS)
8441.9Schristos		$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(DATEOBJS) $(LDLIBS)
8451.1Smlelstv
8461.34Schristostzselect:	tzselect.ksh version
8471.58Schristos		read -r VERSION <version && sed \
8481.56Schristos		  -e "s'#!/bin/bash'#!"'$(KSHELL)'\' \
8491.56Schristos		  -e s\''\(AWK\)=[^}]*'\''\1=\'\''$(AWK)\'\'\' \
8501.56Schristos		  -e s\''\(PKGVERSION\)=.*'\''\1=\'\''($(PACKAGE)) \'\'\' \
8511.56Schristos		  -e s\''\(REPORT_BUGS_TO\)=.*'\''\1=\'\''$(BUGEMAIL)\'\'\' \
8521.56Schristos		  -e s\''\(TZDIR\)=[^}]*'\''\1=\'\''$(TZDIR)\'\'\' \
8531.56Schristos		  -e s\''\(TZVERSION\)=.*'\''\1=\'"'$$VERSION\\''" \
8541.56Schristos		  <$@.ksh >$@.out
8551.35Schristos		chmod +x $@.out
8561.35Schristos		mv $@.out $@
8571.1Smlelstv
8581.58Schristoscheck: check_mild back.ck
8591.58Schristoscheck_mild: check_web check_zishrink \
8601.58Schristos  character-set.ck white-space.ck links.ck mainguard.ck \
8611.58Schristos  name-lengths.ck now.ck slashed-abbrs.ck sorted.ck \
8621.58Schristos  tables.ck ziguard.ck tzs.ck
8631.9Schristos
8641.56Schristos# True if UTF8_LOCALE does not work;
8651.56Schristos# otherwise, false but with LC_ALL set to $(UTF8_LOCALE).
8661.56SchristosUTF8_LOCALE_MISSING = \
8671.56Schristos  { test ! '$(UTF8_LOCALE)' \
8681.56Schristos    || ! printf 'A\304\200B\n' \
8691.56Schristos         | LC_ALL='$(UTF8_LOCALE)' grep -q '^A.B$$' >/dev/null 2>&1 \
8701.58Schristos    || { export LC_ALL='$(UTF8_LOCALE)'; false; }; }
8711.56Schristos
8721.58Schristoscharacter-set.ck: $(ENCHILADA)
8731.56Schristos	$(UTF8_LOCALE_MISSING) || { \
8741.22Schristos		sharp='#' && \
8751.35Schristos		! grep -Env $(SAFE_LINE) $(MANS) date.1 $(MANTXTS) \
8761.35Schristos			$(MISC) $(SOURCES) $(WEB_PAGES) \
8771.49Schristos			CONTRIBUTING LICENSE README SECURITY \
8781.38Schristos			version tzdata.zi && \
8791.41Schristos		! grep -Env $(SAFE_LINE)'|^UNUSUAL_OK_'$(OK_CHAR)'*$$' \
8801.40Schristos			Makefile && \
8811.39Schristos		! grep -Env $(SAFE_SHARP_LINE) $(TDATA_TO_CHECK) backzone \
8821.46Schristos			leapseconds zone.tab && \
8831.38Schristos		! grep -Env $(OK_LINE) $(ENCHILADA); \
8841.38Schristos	}
8851.41Schristos	touch $@
8861.22Schristos
8871.58Schristoswhite-space.ck: $(ENCHILADA)
8881.56Schristos	$(UTF8_LOCALE_MISSING) || { \
8891.58Schristos		enchilada='$(ENCHILADA)' && \
8901.58Schristos		patfmt=' \t|[\f\r\v]' && pat=$$(printf "$$patfmt\\n") && \
8911.56Schristos		! grep -En "$$pat|[$s]\$$" \
8921.58Schristos		    $${enchilada%leap-seconds.list*} \
8931.58Schristos		    $${enchilada#*leap-seconds.list}; \
8941.56Schristos	}
8951.56Schristos	touch $@
8961.23Schristos
8971.51SchristosPRECEDES_FILE_NAME = ^(Zone|Link[$s]+[^$s]+)[$s]+
8981.51SchristosFILE_NAME_COMPONENT_TOO_LONG = $(PRECEDES_FILE_NAME)[^$s]*[^/$s]{15}
8991.38Schristos
9001.58Schristosname-lengths.ck: $(TDATA_TO_CHECK) backzone
9011.58Schristos		:;! grep -En '$(FILE_NAME_COMPONENT_TOO_LONG)' \
9021.39Schristos			$(TDATA_TO_CHECK) backzone
9031.41Schristos		touch $@
9041.38Schristos
9051.58Schristosmainguard.ck: main.zi
9061.58Schristos		test '$(PACKRATLIST)' || \
9071.58Schristos		  cat $(TDATA) $(PACKRATDATA) | diff -u - main.zi
9081.58Schristos		touch $@
9091.58Schristos
9101.51SchristosPRECEDES_STDOFF = ^(Zone[$s]+[^$s]+)?[$s]+
9111.51SchristosSTDOFF = [-+]?[0-9:.]+
9121.51SchristosRULELESS_SAVE = (-|$(STDOFF)[sd]?)
9131.51SchristosRULELESS_SLASHED_ABBRS = \
9141.51Schristos  $(PRECEDES_STDOFF)$(STDOFF)[$s]+$(RULELESS_SAVE)[$s]+[^$s]*/
9151.51Schristos
9161.58Schristosslashed-abbrs.ck: $(TDATA_TO_CHECK)
9171.58Schristos		:;! grep -En '$(RULELESS_SLASHED_ABBRS)' $(TDATA_TO_CHECK)
9181.51Schristos		touch $@
9191.51Schristos
9201.23SchristosCHECK_CC_LIST = { n = split($$1,a,/,/); for (i=2; i<=n; i++) print a[1], a[i]; }
9211.23Schristos
9221.58Schristossorted.ck: backward backzone
9231.54Schristos		$(AWK) '/^Link/ {printf "%.5d %s\n", g, $$3} !/./ {g++}' \
9241.53Schristos		  backward | LC_ALL=C sort -cu
9251.58Schristos		$(AWK) '/^Zone.*\// {print $$2}' backzone | LC_ALL=C sort -cu
9261.41Schristos		touch $@
9271.23Schristos
9281.58Schristosback.ck: checklinks.awk $(TDATA_TO_CHECK)
9291.53Schristos		$(AWK) \
9301.53Schristos		  -v DATAFORM=$(DATAFORM) \
9311.53Schristos		  -v backcheck=backward \
9321.53Schristos		  -f checklinks.awk $(TDATA_TO_CHECK)
9331.54Schristos		touch $@
9341.54Schristos
9351.58Schristoslinks.ck: checklinks.awk tzdata.zi
9361.53Schristos		$(AWK) \
9371.53Schristos		  -v DATAFORM=$(DATAFORM) \
9381.53Schristos		  -f checklinks.awk tzdata.zi
9391.41Schristos		touch $@
9401.26Schristos
9411.56Schristos# Check timestamps from now through 28 years from now, to make sure
9421.56Schristos# that zonenow.tab contains all sequences of planned timestamps,
9431.56Schristos# without any duplicate sequences.  In theory this might require
9441.58Schristos# 2800+ years but that would take a long time to check.
9451.58SchristosCHECK_NOW_TIMESTAMP = $$(./date +%s)
9461.56SchristosCHECK_NOW_FUTURE_YEARS = 28
9471.58SchristosCHECK_NOW_FUTURE_SECS = $(CHECK_NOW_FUTURE_YEARS) * 366 * 24 * 60 * 60
9481.58Schristosnow.ck: checknow.awk date tzdata.zi zdump zic zone1970.tab zonenow.tab
9491.58Schristos		rm -fr $@d
9501.58Schristos		mkdir $@d
9511.58Schristos		./zic -d $@d tzdata.zi
9521.56Schristos		now=$(CHECK_NOW_TIMESTAMP) && \
9531.58Schristos		  future=$$(($(CHECK_NOW_FUTURE_SECS) + $$now)) && \
9541.56Schristos		  ./zdump -i -t $$now,$$future \
9551.58Schristos		     $$(find "$$PWD/$@d"/????*/ -type f) \
9561.58Schristos		     >$@d/zdump-now.tab && \
9571.58Schristos		  ./zdump -i -t 0,$$future \
9581.58Schristos		     $$(find "$$PWD/$@d" -name Etc -prune \
9591.58Schristos			  -o -type f ! -name '*.tab' -print) \
9601.58Schristos		     >$@d/zdump-1970.tab
9611.56Schristos		$(AWK) \
9621.58Schristos		  -v zdump_table=$@d/zdump-now.tab \
9631.56Schristos		  -f checknow.awk zonenow.tab
9641.58Schristos		$(AWK) \
9651.58Schristos		  'BEGIN {print "-\t-\tUTC"} /^Zone/ {print "-\t-\t" $$2}' \
9661.58Schristos		  $(PRIMARY_YDATA) backward factory | \
9671.58Schristos		 $(AWK) \
9681.58Schristos		   -v zdump_table=$@d/zdump-1970.tab \
9691.58Schristos		   -f checknow.awk
9701.58Schristos		rm -fr $@d
9711.56Schristos		touch $@
9721.56Schristos
9731.58Schristostables.ck: checktab.awk $(YDATA) backward zone.tab zone1970.tab
9741.22Schristos		for tab in $(ZONETABLES); do \
9751.49Schristos		  test "$$tab" = zone.tab && links='$(BACKWARD)' || links=''; \
9761.49Schristos		  $(AWK) -f checktab.awk -v zone_table=$$tab $(YDATA) $$links \
9771.22Schristos		    || exit; \
9781.22Schristos		done
9791.41Schristos		touch $@
9801.1Smlelstv
9811.58Schristostzs.ck: $(TZS) $(TZS_NEW)
9821.41Schristos		if test -s $(TZS); then \
9831.58Schristos		  $(SETUP_DIFF_TZS) && $$DIFF_TZS $(TZS) $(TZS_NEW); \
9841.41Schristos		else \
9851.41Schristos		  cp $(TZS_NEW) $(TZS); \
9861.41Schristos		fi
9871.41Schristos		touch $@
9881.34Schristos
9891.42Schristoscheck_web:	$(CHECK_WEB_PAGES)
9901.58Schristos.SUFFIXES: .ck .html
9911.58Schristos.html.ck:
9921.58Schristos		{ ! ($(CURL) --version) >/dev/null 2>&1 || \
9931.58Schristos		    $(CURL) -sS --url https://validator.w3.org/nu/ -F out=gnu \
9941.58Schristos		          -F file=@$<; } >$@.out && \
9951.42Schristos		  test ! -s $@.out || { cat $@.out; exit 1; }
9961.42Schristos		mv $@.out $@
9971.38Schristos
9981.58Schristosziguard.ck: rearguard.zi vanguard.zi ziguard.awk
9991.51Schristos		$(AWK) -v DATAFORM=rearguard -f ziguard.awk vanguard.zi | \
10001.51Schristos		  diff -u rearguard.zi -
10011.51Schristos		$(AWK) -v DATAFORM=vanguard -f ziguard.awk rearguard.zi | \
10021.51Schristos		  diff -u vanguard.zi -
10031.51Schristos		touch $@
10041.51Schristos
10051.40Schristos# Check that zishrink.awk does not alter the data, and that ziguard.awk
10061.40Schristos# preserves main-format data.
10071.58Schristoscheck_zishrink: zishrink-posix.ck zishrink-right.ck
10081.58Schristoszishrink-posix.ck zishrink-right.ck: \
10091.51Schristos  zic leapseconds $(PACKRATDATA) $(PACKRATLIST) \
10101.51Schristos  $(TDATA) $(DATAFORM).zi tzdata.zi
10111.58Schristos		rm -fr $@d t-$@d shrunk-$@d
10121.58Schristos		mkdir $@d t-$@d shrunk-$@d
10131.41Schristos		case $@ in \
10141.58Schristos		  *right*) leap='-L leapseconds';; \
10151.41Schristos		  *) leap=;; \
10161.41Schristos		esac && \
10171.58Schristos		  $(ZIC) $$leap -d $@d $(DATAFORM).zi && \
10181.58Schristos		  $(ZIC) $$leap -d shrunk-$@d tzdata.zi && \
10191.51Schristos		  case $(DATAFORM),$(PACKRATLIST) in \
10201.51Schristos		    main,) \
10211.58Schristos		      $(ZIC) $$leap -d t-$@d $(TDATA) && \
10221.40Schristos		      $(AWK) '/^Rule/' $(TDATA) | \
10231.58Schristos			$(ZIC) $$leap -d t-$@d - $(PACKRATDATA) && \
10241.58Schristos		      diff -r $@d t-$@d;; \
10251.41Schristos		  esac
10261.58Schristos		diff -r $@d shrunk-$@d
10271.58Schristos		rm -fr $@d t-$@d shrunk-$@d
10281.41Schristos		touch $@
10291.1Smlelstv
10301.14Schristosclean_misc:
10311.58Schristos		rm -fr *.ckd *.dir
10321.58Schristos		rm -f *.ck *.core *.o *.out core core.* \
10331.56Schristos		  date tzdir.h tzselect version.h zdump zic libtz.a
10341.14Schristosclean:		clean_misc
10351.58Schristos		rm -fr tzdb-*/
10361.43Schristos		rm -f *.zi $(TZS_NEW)
10371.1Smlelstv
10381.1Smlelstvmaintainer-clean: clean
10391.1Smlelstv		@echo 'This command is intended for maintainers to use; it'
10401.1Smlelstv		@echo 'deletes files that may need special tools to rebuild.'
10411.34Schristos		rm -f leapseconds version $(MANTXTS) $(TZS) *.asc *.tar.*
10421.1Smlelstv
10431.1Smlelstvnames:
10441.1Smlelstv		@echo $(ENCHILADA)
10451.1Smlelstv
10461.58Schristospublic: check public.ck $(CHECK_TIME_T_ALTERNATIVES) \
10471.16Schristos		tarballs signatures
10481.16Schristos
10491.16Schristosdate.1.txt:	date.1
10501.16Schristosnewctime.3.txt:	newctime.3
10511.16Schristosnewstrftime.3.txt: newstrftime.3
10521.16Schristosnewtzset.3.txt:	newtzset.3
10531.16Schristostime2posix.3.txt: time2posix.3
10541.16Schristostzfile.5.txt:	tzfile.5
10551.16Schristostzselect.8.txt:	tzselect.8
10561.16Schristoszdump.8.txt:	zdump.8
10571.16Schristoszic.8.txt:	zic.8
10581.16Schristos
10591.16Schristos$(MANTXTS):	workman.sh
10601.58Schristos		LC_ALL=C sh workman.sh $(@:.txt=) >$@.out
10611.35Schristos		mv $@.out $@
10621.9Schristos
10631.48Schristos# Set file timestamps deterministically if possible,
10641.48Schristos# so that tarballs containing the timestamps are reproducible.
10651.48Schristos#
10661.48Schristos# '$(SET_TIMESTAMP_N) N DEST A B C ...' sets the timestamp of the
10671.48Schristos# file DEST to the maximum of the timestamps of the files A B C ...,
10681.48Schristos# plus N if GNU ls and touch are available.
10691.48SchristosSET_TIMESTAMP_N = sh -c '\
10701.48Schristos  n=$$0 dest=$$1; shift; \
10711.56Schristos  <"$$dest" && \
10721.48Schristos  if test $$n != 0 && \
10731.58Schristos     lsout=$$(ls -nt --time-style="+%s" "$$@" 2>/dev/null); then \
10741.48Schristos    set x $$lsout && \
10751.58Schristos    timestamp=$$(($$7 + $$n)) && \
10761.56Schristos    echo "+ touch -md @$$timestamp $$dest" && \
10771.56Schristos    touch -md @$$timestamp "$$dest"; \
10781.56Schristos  else \
10791.58Schristos    newest=$$(ls -t "$$@" | sed 1q) && \
10801.56Schristos    echo "+ touch -mr $$newest $$dest" && \
10811.56Schristos    touch -mr "$$newest" "$$dest"; \
10821.56Schristos  fi'
10831.48Schristos# If DEST depends on A B C ... in this Makefile, callers should use
10841.48Schristos# $(SET_TIMESTAMP_DEP) DEST A B C ..., for the benefit of any
10851.48Schristos# downstream 'make' that considers equal timestamps to be out of date.
10861.48Schristos# POSIX allows this 'make' behavior, and HP-UX 'make' does it.
10871.48Schristos# If all that matters is that the timestamp be reproducible
10881.48Schristos# and plausible, use $(SET_TIMESTAMP).
10891.48SchristosSET_TIMESTAMP = $(SET_TIMESTAMP_N) 0
10901.48SchristosSET_TIMESTAMP_DEP = $(SET_TIMESTAMP_N) 1
10911.48Schristos
10921.41Schristos# Set the timestamps to those of the git repository, if available,
10931.6Schristos# and if the files have not changed since then.
10941.48Schristos# This uses GNU 'ls --time-style=+%s', which outputs the seconds count,
10951.48Schristos# and GNU 'touch -d@N FILE', where N is the number of seconds since 1970.
10961.48Schristos# If git or GNU is absent, don't bother to sync with git timestamps.
10971.16Schristos# Also, set the timestamp of each prebuilt file like 'leapseconds'
10981.16Schristos# to be the maximum of the files it depends on.
10991.41Schristosset-timestamps.out: $(EIGHT_YARDS)
11001.16Schristos		rm -f $@
11011.35Schristos		if (type git) >/dev/null 2>&1 && \
11021.58Schristos		   files=$$(git ls-files $(EIGHT_YARDS)) && \
11031.16Schristos		   touch -md @1 test.out; then \
11041.16Schristos		  rm -f test.out && \
11051.16Schristos		  for file in $$files; do \
11061.16Schristos		    if git diff --quiet $$file; then \
11071.58Schristos		      time=$$(TZ=UTC0 git log -1 \
11081.56Schristos			--format='tformat:%cd' \
11091.56Schristos			--date='format:%Y-%m-%dT%H:%M:%SZ' \
11101.58Schristos			$$file) && \
11111.56Schristos		      echo "+ touch -md $$time $$file" && \
11121.56Schristos		      touch -md $$time $$file; \
11131.16Schristos		    else \
11141.16Schristos		      echo >&2 "$$file: warning: does not match repository"; \
11151.16Schristos		    fi || exit; \
11161.16Schristos		  done; \
11171.16Schristos		fi
11181.48Schristos		$(SET_TIMESTAMP_DEP) leapseconds $(LEAP_DEPS)
11191.58Schristos		for file in $(MANTXTS); do \
11201.58Schristos		  $(SET_TIMESTAMP_DEP) $$file $${file%.txt} workman.sh || \
11211.16Schristos		    exit; \
11221.6Schristos		done
11231.48Schristos		$(SET_TIMESTAMP_DEP) version $(VERSION_DEPS)
11241.48Schristos		$(SET_TIMESTAMP_DEP) tzdata.zi $(TZDATA_ZI_DEPS)
11251.41Schristos		touch $@
11261.41Schristosset-tzs-timestamp.out: $(TZS)
11271.48Schristos		$(SET_TIMESTAMP_DEP) $(TZS) $(TZS_DEPS)
11281.16Schristos		touch $@
11291.6Schristos
11301.1Smlelstv# The zics below ensure that each data file can stand on its own.
11311.1Smlelstv# We also do an all-files run to catch links to links.
11321.1Smlelstv
11331.58Schristospublic.ck: $(VERSION_DEPS)
11341.58Schristos		rm -fr $@d
11351.58Schristos		mkdir $@d
11361.58Schristos		ln $(VERSION_DEPS) $@d
11371.58Schristos		cd $@d \
11381.56Schristos		  && $(MAKE) CFLAGS='$(GCC_DEBUG_FLAGS)' TZDIR='$(TZDIR)' ALL
11391.58Schristos		for i in $(TDATA_TO_CHECK) \
11401.58Schristos		    tzdata.zi vanguard.zi main.zi rearguard.zi; \
11411.48Schristos		do \
11421.58Schristos		  $@d/zic -v -d $@d/zoneinfo $@d/$$i || exit; \
11431.9Schristos		done
11441.58Schristos		$@d/zic -v -d $@d/zoneinfo-all $(TDATA_TO_CHECK)
11451.49Schristos		:
11461.49Schristos		: Also check 'backzone' syntax.
11471.58Schristos		rm $@d/main.zi
11481.58Schristos		cd $@d && $(MAKE) PACKRATDATA=backzone main.zi
11491.58Schristos		$@d/zic -d $@d/zoneinfo main.zi
11501.58Schristos		rm $@d/main.zi
11511.58Schristos		cd $@d && \
11521.51Schristos		  $(MAKE) PACKRATDATA=backzone PACKRATLIST=zone.tab main.zi
11531.58Schristos		$@d/zic -d $@d/zoneinfo main.zi
11541.49Schristos		:
11551.58Schristos		rm -fr $@d
11561.41Schristos		touch $@
11571.9Schristos
11581.14Schristos# Check that the code works under various alternative
11591.14Schristos# implementations of time_t.
11601.41Schristoscheck_time_t_alternatives: $(TIME_T_ALTERNATIVES)
11611.41Schristos$(TIME_T_ALTERNATIVES_TAIL): $(TIME_T_ALTERNATIVES_HEAD)
11621.41Schristos$(TIME_T_ALTERNATIVES): $(VERSION_DEPS)
11631.58Schristos		rm -fr $@d
11641.58Schristos		mkdir $@d
11651.58Schristos		ln $(VERSION_DEPS) $@d
11661.41Schristos		case $@ in \
11671.58Schristos		  *32_t*) range=-2147483648,2147483648;; \
11681.41Schristos		  u*) range=0,4294967296;; \
11691.41Schristos		  *) range=-4294967296,4294967296;; \
11701.41Schristos		esac && \
11711.58Schristos		wd=$$PWD && \
11721.58Schristos		zones=$$($(AWK) '/^[^#]/ { print $$3 }' <zone1970.tab) && \
11731.41Schristos		if test $@ = $(TIME_T_ALTERNATIVES_HEAD); then \
11741.41Schristos		  range_target=; \
11751.23Schristos		else \
11761.41Schristos		  range_target=to$$range.tzs; \
11771.23Schristos		fi && \
11781.58Schristos		(cd $@d && \
11791.58Schristos		  $(MAKE) TOPDIR="$$wd/$@d" \
11801.58Schristos		    CFLAGS='$(CFLAGS) -Dtime_tz='"'$(@:.ck=)'" \
11811.23Schristos		    REDO='$(REDO)' \
11821.58Schristos		    D="$$wd/$@d" \
11831.41Schristos		    TZS_YEAR="$$range" TZS_CUTOFF_FLAG="-t $$range" \
11841.41Schristos		    install $$range_target) && \
11851.41Schristos		test $@ = $(TIME_T_ALTERNATIVES_HEAD) || { \
11861.58Schristos		  (cd $(TIME_T_ALTERNATIVES_HEAD)d && \
11871.58Schristos		    $(MAKE) TOPDIR="$$wd/$@d" \
11881.41Schristos		      TZS_YEAR="$$range" TZS_CUTOFF_FLAG="-t $$range" \
11891.58Schristos		      D="$$wd/$@d" \
11901.41Schristos		      to$$range.tzs) && \
11911.58Schristos		  $(SETUP_DIFF_TZS) && \
11921.58Schristos		  $$DIFF_TZS $(TIME_T_ALTERNATIVES_HEAD)d/to$$range.tzs \
11931.58Schristos			  $@d/to$$range.tzs && \
11941.41Schristos		  if diff -q Makefile Makefile 2>/dev/null; then \
11951.41Schristos		    quiet_option='-q'; \
11961.41Schristos		  else \
11971.41Schristos		    quiet_option=''; \
11981.41Schristos		  fi && \
11991.58Schristos		    diff $$quiet_option -r $(TIME_T_ALTERNATIVES_HEAD)d/etc \
12001.58Schristos					   $@d/etc && \
12011.41Schristos		    diff $$quiet_option -r \
12021.58Schristos		      $(TIME_T_ALTERNATIVES_HEAD)d/usr/share \
12031.58Schristos		      $@d/usr/share; \
12041.41Schristos		}
12051.41Schristos		touch $@
12061.34Schristos
12071.40SchristosTRADITIONAL_ASC = \
12081.40Schristos  tzcode$(VERSION).tar.gz.asc \
12091.40Schristos  tzdata$(VERSION).tar.gz.asc
12101.41SchristosREARGUARD_ASC = \
12111.41Schristos  tzdata$(VERSION)-rearguard.tar.gz.asc
12121.41SchristosALL_ASC = $(TRADITIONAL_ASC) $(REARGUARD_ASC) \
12131.40Schristos  tzdb-$(VERSION).tar.lz.asc
12141.40Schristos
12151.51Schristostarballs rearguard_tarballs tailored_tarballs traditional_tarballs \
12161.41Schristossignatures rearguard_signatures traditional_signatures: \
12171.51Schristos  version set-timestamps.out rearguard.zi vanguard.zi
12181.58Schristos		read -r VERSION <version && \
12191.48Schristos		$(MAKE) AWK='$(AWK)' VERSION="$$VERSION" $@_version
12201.35Schristos
12211.40Schristos# These *_version rules are intended for use if VERSION is set by some
12221.40Schristos# other means.  Ordinarily these rules are used only by the above
12231.40Schristos# non-_version rules, which set VERSION on the 'make' command line.
12241.41Schristostarballs_version: traditional_tarballs_version rearguard_tarballs_version \
12251.40Schristos  tzdb-$(VERSION).tar.lz
12261.41Schristosrearguard_tarballs_version: \
12271.41Schristos  tzdata$(VERSION)-rearguard.tar.gz
12281.38Schristostraditional_tarballs_version: \
12291.38Schristos  tzcode$(VERSION).tar.gz tzdata$(VERSION).tar.gz
12301.51Schristostailored_tarballs_version: \
12311.51Schristos  tzdata$(VERSION)-tailored.tar.gz
12321.40Schristossignatures_version: $(ALL_ASC)
12331.41Schristosrearguard_signatures_version: $(REARGUARD_ASC)
12341.40Schristostraditional_signatures_version: $(TRADITIONAL_ASC)
12351.9Schristos
12361.16Schristostzcode$(VERSION).tar.gz: set-timestamps.out
12371.58Schristos		$(SETUP_TAR) && \
12381.58Schristos		$$TAR -cf - \
12391.23Schristos		    $(COMMON) $(DOCS) $(SOURCES) | \
12401.38Schristos		  gzip $(GZIPFLAGS) >$@.out
12411.35Schristos		mv $@.out $@
12421.10Schristos
12431.16Schristostzdata$(VERSION).tar.gz: set-timestamps.out
12441.58Schristos		$(SETUP_TAR) && \
12451.58Schristos		$$TAR -cf - $(TZDATA_DIST) | \
12461.38Schristos		  gzip $(GZIPFLAGS) >$@.out
12471.35Schristos		mv $@.out $@
12481.9Schristos
12491.51Schristos# Create empty files with a reproducible timestamp.
12501.51SchristosCREATE_EMPTY = TZ=UTC0 touch -mt 202010122253.00
12511.51Schristos
12521.51Schristos# The obsolescent *rearguard* targets and related macros are present
12531.51Schristos# for backwards compatibility with tz releases 2018e through 2022a.
12541.51Schristos# They should go away eventually.  To build rearguard tarballs you
12551.51Schristos# can instead use 'make DATAFORM=rearguard tailored_tarballs'.
12561.40Schristostzdata$(VERSION)-rearguard.tar.gz: rearguard.zi set-timestamps.out
12571.51Schristos		rm -fr $@.dir
12581.51Schristos		mkdir $@.dir
12591.51Schristos		ln $(TZDATA_DIST) $@.dir
12601.51Schristos		cd $@.dir && rm -f $(TDATA) $(PACKRATDATA) version
12611.40Schristos		for f in $(TDATA) $(PACKRATDATA); do \
12621.51Schristos		  rearf=$@.dir/$$f; \
12631.40Schristos		  $(AWK) -v DATAFORM=rearguard -f ziguard.awk $$f >$$rearf && \
12641.48Schristos		  $(SET_TIMESTAMP_DEP) $$rearf ziguard.awk $$f || exit; \
12651.40Schristos		done
12661.51Schristos		sed '1s/$$/-rearguard/' <version >$@.dir/version
12671.47Schristos		: The dummy pacificnew pacifies TZUpdater 2.3.1 and earlier.
12681.51Schristos		$(CREATE_EMPTY) $@.dir/pacificnew
12691.56Schristos		touch -mr version $@.dir/version
12701.58Schristos		$(SETUP_TAR) && \
12711.51Schristos		  (cd $@.dir && \
12721.58Schristos		   $$TAR -cf - \
12731.51Schristos			$(TZDATA_DIST) pacificnew | \
12741.40Schristos		     gzip $(GZIPFLAGS)) >$@.out
12751.40Schristos		mv $@.out $@
12761.40Schristos
12771.51Schristos# Create a tailored tarball suitable for TZUpdater and compatible tools.
12781.51Schristos# For example, 'make DATAFORM=vanguard tailored_tarballs' makes a tarball
12791.51Schristos# useful for testing whether TZUpdater supports vanguard form.
12801.51Schristos# The generated tarball is not byte-for-byte equivalent to a hand-tailored
12811.51Schristos# traditional tarball, as data entries are put into 'etcetera' even if they
12821.51Schristos# came from some other source file.  However, the effect should be the same
12831.51Schristos# for ordinary use, which reads all the source files.
12841.51Schristostzdata$(VERSION)-tailored.tar.gz: set-timestamps.out
12851.51Schristos		rm -fr $@.dir
12861.51Schristos		mkdir $@.dir
12871.51Schristos		: The dummy pacificnew pacifies TZUpdater 2.3.1 and earlier.
12881.58Schristos		if test $(DATAFORM) = vanguard; then \
12891.58Schristos		  pacificnew=; \
12901.58Schristos		else \
12911.58Schristos		  pacificnew=pacificnew; \
12921.58Schristos		fi && \
12931.51Schristos		cd $@.dir && \
12941.51Schristos		  $(CREATE_EMPTY) $(PRIMARY_YDATA) $(NDATA) backward \
12951.58Schristos		  $$pacificnew
12961.51Schristos		(grep '^#' tzdata.zi && echo && cat $(DATAFORM).zi) \
12971.51Schristos		  >$@.dir/etcetera
12981.56Schristos		touch -mr tzdata.zi $@.dir/etcetera
12991.51Schristos		sed -n \
13001.51Schristos		  -e '/^# *version  *\(.*\)/h' \
13011.51Schristos		  -e '/^# *ddeps  */H' \
13021.51Schristos		  -e '$$!d' \
13031.51Schristos		  -e 'g' \
13041.51Schristos		  -e 's/^# *version  *//' \
13051.51Schristos		  -e 's/\n# *ddeps  */-/' \
13061.51Schristos		  -e 's/ /-/g' \
13071.51Schristos		  -e 'p' \
13081.51Schristos		  <tzdata.zi >$@.dir/version
13091.56Schristos		touch -mr version $@.dir/version
13101.51Schristos		links= && \
13111.51Schristos		  for file in $(TZDATA_DIST); do \
13121.51Schristos		    test -f $@.dir/$$file || links="$$links $$file"; \
13131.51Schristos		  done && \
13141.51Schristos		  ln $$links $@.dir
13151.58Schristos		$(SETUP_TAR) && \
13161.51Schristos		  (cd $@.dir && \
13171.58Schristos		   $$TAR -cf - * | gzip $(GZIPFLAGS)) >$@.out
13181.51Schristos		mv $@.out $@
13191.51Schristos
13201.41Schristostzdb-$(VERSION).tar.lz: set-timestamps.out set-tzs-timestamp.out
13211.34Schristos		rm -fr tzdb-$(VERSION)
13221.34Schristos		mkdir tzdb-$(VERSION)
13231.34Schristos		ln $(ENCHILADA) tzdb-$(VERSION)
13241.48Schristos		$(SET_TIMESTAMP) tzdb-$(VERSION) tzdb-$(VERSION)/*
13251.58Schristos		$(SETUP_TAR) && \
13261.58Schristos		$$TAR -cf - tzdb-$(VERSION) | lzip -9 >$@.out
13271.35Schristos		mv $@.out $@
13281.9Schristos
13291.9Schristostzcode$(VERSION).tar.gz.asc: tzcode$(VERSION).tar.gz
13301.9Schristostzdata$(VERSION).tar.gz.asc: tzdata$(VERSION).tar.gz
13311.40Schristostzdata$(VERSION)-rearguard.tar.gz.asc: tzdata$(VERSION)-rearguard.tar.gz
13321.34Schristostzdb-$(VERSION).tar.lz.asc: tzdb-$(VERSION).tar.lz
13331.40Schristos$(ALL_ASC):
13341.44Schristos		$(GPG) --armor --detach-sign $?
13351.34Schristos
13361.41SchristosTYPECHECK_CFLAGS = $(CFLAGS) -DTYPECHECK -D__time_t_defined -D_TIME_T
13371.58Schristostypecheck: long-long.ck unsigned.ck
13381.58Schristoslong-long.ck unsigned.ck: $(VERSION_DEPS)
13391.58Schristos		rm -fr $@d
13401.58Schristos		mkdir $@d
13411.58Schristos		ln $(VERSION_DEPS) $@d
13421.58Schristos		cd $@d && \
13431.41Schristos		  case $@ in \
13441.58Schristos		    long-long.*) i="long long";; \
13451.58Schristos		    unsigned.* ) i="unsigned" ;; \
13461.41Schristos		  esac && \
13471.41Schristos		  $(MAKE) \
13481.41Schristos		    CFLAGS="$(TYPECHECK_CFLAGS) \"-Dtime_t=$$i\"" \
13491.58Schristos		    TOPDIR="$$PWD" \
13501.41Schristos		    install
13511.58Schristos		$@d/zdump -i -c 1970,1971 Europe/Rome
13521.41Schristos		touch $@
13531.1Smlelstv
13541.38Schristoszonenames:	tzdata.zi
13551.38Schristos		@$(AWK) '/^Z/ { print $$2 } /^L/ { print $$3 }' tzdata.zi
13561.1Smlelstv
13571.1Smlelstvasctime.o:	private.h tzfile.h
13581.1Smlelstvdate.o:		private.h
13591.1Smlelstvdifftime.o:	private.h
13601.56Schristoslocaltime.o:	private.h tzfile.h tzdir.h
13611.23Schristosstrftime.o:	private.h tzfile.h
13621.6Schristoszdump.o:	version.h
13631.56Schristoszic.o:		private.h tzfile.h tzdir.h version.h
13641.1Smlelstv
13651.22Schristos.PHONY: ALL INSTALL all
13661.54Schristos.PHONY: check check_mild check_time_t_alternatives
13671.42Schristos.PHONY: check_web check_zishrink
13681.57Schristos.PHONY: clean clean_misc commit-leap-seconds.list dummy.zd
13691.57Schristos.PHONY: fetch-leap-seconds.list force_tzs
13701.58Schristos.PHONY: install maintainer-clean names
13711.51Schristos.PHONY: posix_only posix_right public
13721.41Schristos.PHONY: rearguard_signatures rearguard_signatures_version
13731.41Schristos.PHONY: rearguard_tarballs rearguard_tarballs_version
13741.41Schristos.PHONY: right_only right_posix signatures signatures_version
13751.40Schristos.PHONY: tarballs tarballs_version
13761.40Schristos.PHONY: traditional_signatures traditional_signatures_version
13771.40Schristos.PHONY: traditional_tarballs traditional_tarballs_version
13781.51Schristos.PHONY: tailored_tarballs tailored_tarballs_version
13791.40Schristos.PHONY: typecheck
13801.22Schristos.PHONY: zonenames zones
13811.40Schristos.PHONY: $(ZDS)
1382