Makefile revision 1.34
1# This file is in the public domain, so clarified as of
2# 2009-05-17 by Arthur David Olson.
3
4# Package name for the code distribution.
5PACKAGE=	tzcode
6
7# Version number for the distribution, overridden in the 'tarballs' rule below.
8VERSION=	2016g
9
10# Email address for bug reports.
11BUGEMAIL=	tz@iana.org
12
13# Change the line below for your time zone (after finding the zone you want in
14# the time zone files, or adding it to a time zone file).
15# Alternately, if you discover you've got the wrong time zone, you can just
16#	zic -l rightzone
17# to correct things.
18# Use the command
19#	make zonenames
20# to get a list of the values you can use for LOCALTIME.
21
22LOCALTIME=	GMT
23
24# If you want something other than Eastern United States time as a template
25# for handling POSIX-style time zone environment variables,
26# change the line below (after finding the zone you want in the
27# time zone files, or adding it to a time zone file).
28# (When a POSIX-style environment variable is handled, the rules in the
29# template file are used to determine "spring forward" and "fall back" days and
30# times; the environment variable itself specifies UT offsets of standard and
31# summer time.)
32# Alternately, if you discover you've got the wrong time zone, you can just
33#	zic -p rightzone
34# to correct things.
35# Use the command
36#	make zonenames
37# to get a list of the values you can use for POSIXRULES.
38# If you want POSIX compatibility, use "America/New_York".
39
40POSIXRULES=	America/New_York
41
42# Also see TZDEFRULESTRING below, which takes effect only
43# if the time zone files cannot be accessed.
44
45# Everything gets put in subdirectories of. . .
46
47TOPDIR=		/usr/local
48
49# "Compiled" time zone information is placed in the "TZDIR" directory
50# (and subdirectories).
51# Use an absolute path name for TZDIR unless you're just testing the software.
52
53TZDIR_BASENAME=	zoneinfo
54TZDIR=		$(TOPDIR)/etc/$(TZDIR_BASENAME)
55
56# Types to try, as an alternative to time_t.  int64_t should be first.
57TIME_T_ALTERNATIVES= int64_t int32_t uint32_t uint64_t
58
59# The "tzselect", "zic", and "zdump" commands get installed in. . .
60
61ETCDIR=		$(TOPDIR)/etc
62
63# If you "make INSTALL", the "date" command gets installed in. . .
64
65BINDIR=		$(TOPDIR)/bin
66
67# Manual pages go in subdirectories of. . .
68
69MANDIR=		$(TOPDIR)/man
70
71# Library functions are put in an archive in LIBDIR.
72
73LIBDIR=		$(TOPDIR)/lib
74
75# If you always want time values interpreted as "seconds since the epoch
76# (not counting leap seconds)", use
77#	REDO=		posix_only
78# below.  If you always want right time values interpreted as "seconds since
79# the epoch" (counting leap seconds)", use
80#	REDO=		right_only
81# below.  If you want both sets of data available, with leap seconds not
82# counted normally, use
83#	REDO=		posix_right
84# below.  If you want both sets of data available, with leap seconds counted
85# normally, use
86#	REDO=		right_posix
87# below.  POSIX mandates that leap seconds not be counted; for compatibility
88# with it, use "posix_only" or "posix_right".
89
90REDO=		posix_right
91
92# If you want out-of-scope and often-wrong data from the file 'backzone', use
93#	PACKRATDATA=	backzone
94# To omit this data, use
95#	PACKRATDATA=
96
97PACKRATDATA=
98
99# Since "." may not be in PATH...
100
101YEARISTYPE=	./yearistype
102
103# Non-default libraries needed to link.
104# Add -lintl if you want to use 'gettext' on Solaris.
105LDLIBS=
106
107# Add the following to the end of the "CFLAGS=" line as needed.
108#  -DBIG_BANG=-9999999LL if the Big Bang occurred at time -9999999 (see zic.c)
109#  -DHAVE_DECL_ASCTIME_R=0 if <time.h> does not declare asctime_r
110#  -DHAVE_DIRECT_H if mkdir needs <direct.h> (MS-Windows)
111#  -DHAVE_DOS_FILE_NAMES if file names have drive specifiers etc. (MS-DOS)
112#  -DHAVE_GETTEXT=1 if 'gettext' works (GNU, Linux, Solaris); also see LDLIBS
113#  -DHAVE_INCOMPATIBLE_CTIME_R=1 if your system's time.h declares
114#	ctime_r and asctime_r incompatibly with the POSIX standard (Solaris 8).
115#  -DHAVE_INTTYPES_H=1 if you have a pre-C99 compiler with "inttypes.h"
116#  -DHAVE_LINK=0 if your system lacks a link function
117#  -DHAVE_LOCALTIME_R=0 if your system lacks a localtime_r function
118#  -DHAVE_LOCALTIME_RZ=0 if you do not want zdump to use localtime_rz
119#	This defaults to 1 if a working localtime_rz seems to be available.
120#	localtime_rz can make zdump significantly faster, but is nonstandard.
121#  -DHAVE_POSIX_DECLS=0 if your system's include files do not declare
122#	functions like 'link' or variables like 'tzname' required by POSIX
123#  -DHAVE_STDINT_H=1 if you have a pre-C99 compiler with "stdint.h"
124#  -DHAVE_STRFTIME_L=1 if <time.h> declares locale_t and strftime_l
125#	This defaults to 0 if _POSIX_VERSION < 200809, 1 otherwise.
126#  -DHAVE_STRDUP=0 if your system lacks the strdup function
127#  -DHAVE_SYMLINK=0 if your system lacks the symlink function
128#  -DHAVE_SYS_STAT_H=0 if your compiler lacks a "sys/stat.h"
129#  -DHAVE_SYS_WAIT_H=0 if your compiler lacks a "sys/wait.h"
130#  -DHAVE_TZSET=0 if your system lacks a tzset function
131#  -DHAVE_UNISTD_H=0 if your compiler lacks a "unistd.h" (Microsoft C++ 7?)
132#  -DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU=1
133#	if you do not want run time warnings about formats that may cause
134#	year 2000 grief
135#  -Dssize_t=long on ancient hosts that lack ssize_t
136#  -DTHREAD_SAFE=1 to make localtime.c thread-safe, as POSIX requires;
137#	not needed by the main-program tz code, which is single-threaded.
138#	Append other compiler flags as needed, e.g., -pthread on GNU/Linux.
139#  -Dtime_tz=\"T\" to use T as the time_t type, rather than the system time_t
140#  -DTZ_DOMAIN=\"foo\" to use "foo" for gettext domain name; default is "tz"
141#  -DTZ_DOMAINDIR=\"/path\" to use "/path" for gettext directory;
142#	the default is system-supplied, typically "/usr/lib/locale"
143#  -DTZDEFRULESTRING=\",date/time,date/time\" to default to the specified
144#  -DUNINIT_TRAP=1 if reading uninitialized storage can cause problems
145#	other than simply getting garbage data
146#  -DUSE_LTZ=0 to build zdump with the system time zone library
147#	Also set TZDOBJS=zdump.o and CHECK_TIME_T_ALTERNATIVES= below.
148#  -DNO_ERROR_IN_DST_GAP=1
149#	if you want mktime() not to return an error in the DST gap.
150#  -DZIC_MAX_ABBR_LEN_WO_WARN=3
151#	(or some other number) to set the maximum time zone abbreviation length
152#	that zic will accept without a warning (the default is 6)
153#  $(GCC_DEBUG_FLAGS) if you are using recent GCC and want lots of checking
154GCC_DEBUG_FLAGS = -Dlint -g3 -O3 -fno-common -fstrict-aliasing \
155	-Wall -Wextra \
156	-Wbad-function-cast -Wcast-align -Wdate-time \
157	-Wdeclaration-after-statement \
158	-Wdouble-promotion \
159	-Wformat=2 -Winit-self -Wjump-misses-init \
160	-Wlogical-op -Wmissing-prototypes -Wnested-externs \
161	-Wold-style-definition -Woverlength-strings -Wpointer-arith \
162	-Wshadow -Wstrict-prototypes -Wsuggest-attribute=const \
163	-Wsuggest-attribute=format -Wsuggest-attribute=noreturn \
164	-Wsuggest-attribute=pure -Wtrampolines \
165	-Wunused -Wwrite-strings \
166	-Wno-address -Wno-format-nonliteral -Wno-sign-compare \
167	-Wno-type-limits -Wno-unused-parameter
168#
169# If you want to use System V compatibility code, add
170#	-DUSG_COMPAT
171# to the end of the "CFLAGS=" line.  This arrange for "timezone" and "daylight"
172# variables to be kept up-to-date by the time conversion functions.  Neither
173# "timezone" nor "daylight" is described in X3J11's work.
174#
175# If your system has a "GMT offset" field in its "struct tm"s
176# (or if you decide to add such a field in your system's "time.h" file),
177# add the name to a define such as
178#	-DTM_GMTOFF=tm_gmtoff
179# to the end of the "CFLAGS=" line.  If not defined, the code attempts to
180# guess TM_GMTOFF from other macros; define NO_TM_GMTOFF to suppress this.
181# Similarly, if your system has a "zone abbreviation" field, define
182#	-DTM_ZONE=tm_zone
183# and define NO_TM_ZONE to suppress any guessing.  These two fields are not
184# required by POSIX, but are widely available on GNU/Linux and BSD systems.
185#
186# If you want functions that were inspired by early versions of X3J11's work,
187# add
188#	-DSTD_INSPIRED
189# to the end of the "CFLAGS=" line.  This arranges for the functions
190# "tzsetwall", "offtime", "timelocal", "timegm", "timeoff",
191# "posix2time", and "time2posix" to be added to the time conversion library.
192# "tzsetwall" is like "tzset" except that it arranges for local wall clock
193# time (rather than the time specified in the TZ environment variable)
194# to be used.
195# "offtime" is like "gmtime" except that it accepts a second (long) argument
196# that gives an offset to add to the time_t when converting it.
197# "timelocal" is equivalent to "mktime".
198# "timegm" is like "timelocal" except that it turns a struct tm into
199# a time_t using UT (rather than local time as "timelocal" does).
200# "timeoff" is like "timegm" except that it accepts a second (long) argument
201# that gives an offset to use when converting to a time_t.
202# "posix2time" and "time2posix" are described in an included manual page.
203# X3J11's work does not describe any of these functions.
204# Sun has provided "tzsetwall", "timelocal", and "timegm" in SunOS 4.0.
205# These functions may well disappear in future releases of the time
206# conversion package.
207#
208# If you don't want functions that were inspired by NetBSD, add
209#	-DNETBSD_INSPIRED=0
210# to the end of the "CFLAGS=" line.  Otherwise, the functions
211# "localtime_rz", "mktime_z", "tzalloc", and "tzfree" are added to the
212# time library, and if STD_INSPIRED is also defined the functions
213# "posix2time_z" and "time2posix_z" are added as well.
214# The functions ending in "_z" (or "_rz") are like their unsuffixed
215# (or suffixed-by-"_r") counterparts, except with an extra first
216# argument of opaque type timezone_t that specifies the time zone.
217# "tzalloc" allocates a timezone_t value, and "tzfree" frees it.
218#
219# If you want to allocate state structures in localtime, add
220#	-DALL_STATE
221# to the end of the "CFLAGS=" line.  Storage is obtained by calling malloc.
222#
223# If you want an "altzone" variable (a la System V Release 3.1), add
224#	-DALTZONE
225# to the end of the "CFLAGS=" line.
226# This variable is not described in X3J11's work.
227#
228# NIST-PCTS:151-2, Version 1.4, (1993-12-03) is a test suite put
229# out by the National Institute of Standards and Technology
230# which claims to test C and Posix conformance.  If you want to pass PCTS, add
231#	-DPCTS
232# to the end of the "CFLAGS=" line.
233#
234# If you want strict compliance with XPG4 as of 1994-04-09, add
235#	-DXPG4_1994_04_09
236# to the end of the "CFLAGS=" line.  This causes "strftime" to always return
237# 53 as a week number (rather than 52 or 53) for those days in January that
238# before the first Monday in January when a "%V" format is used and January 1
239# falls on a Friday, Saturday, or Sunday.
240
241CFLAGS=
242
243# Linker flags.  Default to $(LFLAGS) for backwards compatibility
244# to release 2012h and earlier.
245
246LDFLAGS=	$(LFLAGS)
247
248# For leap seconds, this Makefile uses LEAPSECONDS='-L leapseconds' in
249# submake command lines.  The default is no leap seconds.
250
251LEAPSECONDS=
252
253# The zic command and its arguments.
254
255zic=		./zic
256ZIC=		$(zic) $(ZFLAGS)
257
258ZFLAGS=
259
260# How to use zic to install tz binary files.
261
262ZIC_INSTALL=	$(ZIC) -y $(YEARISTYPE) -d $(DESTDIR)$(TZDIR) $(LEAPSECONDS)
263
264# The name of a Posix-compliant 'awk' on your system.
265AWK=		awk
266
267# The full path name of a Posix-compliant shell, preferably one that supports
268# the Korn shell's 'select' statement as an extension.
269# These days, Bash is the most popular.
270# It should be OK to set this to /bin/sh, on platforms where /bin/sh
271# lacks 'select' or doesn't completely conform to Posix, but /bin/bash
272# is typically nicer if it works.
273KSHELL=		/bin/bash
274
275# The path where SGML DTDs are kept and the catalog file(s) to use when
276# validating.  The default should work on both Debian and Red Hat.
277SGML_TOPDIR= /usr
278SGML_DTDDIR= $(SGML_TOPDIR)/share/xml/w3c-sgml-lib/schema/dtd
279SGML_SEARCH_PATH= $(SGML_DTDDIR)/REC-html401-19991224
280SGML_CATALOG_FILES= \
281  $(SGML_TOPDIR)/share/doc/w3-recs/html/www.w3.org/TR/1999/REC-html401-19991224/HTML4.cat:$(SGML_TOPDIR)/share/sgml/html/4.01/HTML4.cat
282
283# The name, arguments and environment of a program to validate your web pages.
284# See <http://openjade.sourceforge.net/doc/> for a validator, and
285# <https://validator.w3.org/source/> for a validation library.
286VALIDATE = nsgmls
287VALIDATE_FLAGS = -s -B -wall -wno-unused-param
288VALIDATE_ENV = \
289  SGML_CATALOG_FILES=$(SGML_CATALOG_FILES) \
290  SGML_SEARCH_PATH=$(SGML_SEARCH_PATH) \
291  SP_CHARSET_FIXED=YES \
292  SP_ENCODING=UTF-8
293
294# This expensive test requires USE_LTZ.
295# To suppress it, define this macro to be empty.
296CHECK_TIME_T_ALTERNATIVES = check_time_t_alternatives
297
298# SAFE_CHAR is a regular expression that matches a safe character.
299# Some parts of this distribution are limited to safe characters;
300# others can use any UTF-8 character.
301# For now, the safe characters are a safe subset of ASCII.
302# The caller must set the shell variable 'sharp' to the character '#',
303# since Makefile macros cannot contain '#'.
304# TAB_CHAR is a single tab character, in single quotes.
305TAB_CHAR=	'	'
306SAFE_CHARSET1=	$(TAB_CHAR)' !\"'$$sharp'$$%&'\''()*+,./0123456789:;<=>?@'
307SAFE_CHARSET2=	'ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\^_`'
308SAFE_CHARSET3=	'abcdefghijklmnopqrstuvwxyz{|}~'
309SAFE_CHARSET=	$(SAFE_CHARSET1)$(SAFE_CHARSET2)$(SAFE_CHARSET3)
310SAFE_CHAR=	'[]'$(SAFE_CHARSET)'-]'
311
312# OK_CHAR matches any character allowed in the distributed files.
313# This is the same as SAFE_CHAR, except that multibyte letters are
314# also allowed so that commentary can contain people's names and quote
315# non-English sources.  For non-letters the sources are limited to
316# ASCII renderings for the convenience of maintainers whose text editors
317# mishandle UTF-8 by default (e.g., XEmacs 21.4.22).
318OK_CHAR=	'[][:alpha:]'$(SAFE_CHARSET)'-]'
319
320# SAFE_LINE matches a line of safe characters.
321# SAFE_SHARP_LINE is similar, except any OK character can follow '#';
322# this is so that comments can contain non-ASCII characters.
323# OK_LINE matches a line of OK characters.
324SAFE_LINE=	'^'$(SAFE_CHAR)'*$$'
325SAFE_SHARP_LINE='^'$(SAFE_CHAR)'*('$$sharp$(OK_CHAR)'*)?$$'
326OK_LINE=	'^'$(OK_CHAR)'*$$'
327
328# Flags to give 'tar' when making a distribution.
329# Try to use flags appropriate for GNU tar.
330GNUTARFLAGS= --numeric-owner --owner=0 --group=0 --mode=go+u,go-w --sort=name
331TARFLAGS=	`if tar $(GNUTARFLAGS) --version >/dev/null 2>&1; \
332		 then echo $(GNUTARFLAGS); \
333		 else :; \
334		 fi`
335
336# Flags to give 'gzip' when making a distribution.
337GZIPFLAGS=	-9 ${GZIP_N_FLAG}
338
339###############################################################################
340
341#MAKE=		make
342
343cc=		cc
344CC=		$(cc) -DTZDIR=\"$(TZDIR)\"
345
346AR=		ar
347
348# ':' on typical hosts; 'ranlib' on the ancient hosts that still need ranlib.
349RANLIB=		:
350
351TZCOBJS=	zic.o
352TZDOBJS=	zdump.o localtime.o asctime.o
353DATEOBJS=	date.o localtime.o strftime.o asctime.o
354LIBSRCS=	localtime.c asctime.c difftime.c
355LIBOBJS=	localtime.o asctime.o difftime.o
356HEADERS=	tzfile.h private.h
357NONLIBSRCS=	zic.c zdump.c
358NEWUCBSRCS=	date.c strftime.c
359SOURCES=	$(HEADERS) $(LIBSRCS) $(NONLIBSRCS) $(NEWUCBSRCS) \
360			tzselect.ksh version workman.sh
361MANS=		newctime.3 newstrftime.3 newtzset.3 time2posix.3 \
362			tzfile.5 tzselect.8 zic.8 zdump.8
363MANTXTS=	newctime.3.txt newstrftime.3.txt newtzset.3.txt \
364			time2posix.3.txt \
365			tzfile.5.txt tzselect.8.txt zic.8.txt zdump.8.txt \
366			date.1.txt
367COMMON=		CONTRIBUTING LICENSE Makefile NEWS README Theory
368WEB_PAGES=	tz-art.htm tz-how-to.html tz-link.htm
369DOCS=		$(MANS) date.1 $(MANTXTS) $(WEB_PAGES)
370PRIMARY_YDATA=	africa antarctica asia australasia \
371		europe northamerica southamerica
372YDATA=		$(PRIMARY_YDATA) pacificnew etcetera backward
373NDATA=		systemv factory
374TDATA=		$(YDATA) $(NDATA)
375ZONETABLES=	zone1970.tab zone.tab
376TABDATA=	iso3166.tab leapseconds $(ZONETABLES)
377LEAP_DEPS=	leapseconds.awk leap-seconds.list
378DATA=		$(YDATA) $(NDATA) backzone $(TABDATA) \
379			leap-seconds.list yearistype.sh
380AWK_SCRIPTS=	checklinks.awk checktab.awk leapseconds.awk
381MISC=		$(AWK_SCRIPTS) zoneinfo2tdf.pl
382TZS_YEAR=	2050
383TZS=		to$(TZS_YEAR).tzs
384TZS_NEW=	to$(TZS_YEAR)new.tzs
385TZS_DEPS=	$(PRIMARY_YDATA) asctime.c localtime.c \
386			private.h tzfile.h zdump.c zic.c
387ENCHILADA=	$(COMMON) $(DOCS) $(SOURCES) $(DATA) $(MISC) $(TZS)
388
389# Consult these files when deciding whether to rebuild the 'version' file.
390# This list is not the same as the output of 'git ls-files', since
391# .gitignore is not distributed.
392VERSION_DEPS= \
393		CONTRIBUTING LICENSE Makefile NEWS README Theory \
394		africa antarctica asctime.c asia australasia \
395		backward backzone \
396		checklinks.awk checktab.awk \
397		date.1 date.c difftime.c \
398		etcetera europe factory iso3166.tab \
399		leap-seconds.list leapseconds.awk localtime.c \
400		newctime.3 newstrftime.3 newtzset.3 northamerica \
401		pacificnew private.h \
402		southamerica strftime.c systemv \
403		time2posix.3 tz-art.htm tz-how-to.html tz-link.htm \
404		tzfile.5 tzfile.h tzselect.8 tzselect.ksh \
405		workman.sh yearistype.sh \
406		zdump.8 zdump.c zic.8 zic.c \
407		zone.tab zone1970.tab zoneinfo2tdf.pl
408
409# And for the benefit of csh users on systems that assume the user
410# shell should be used to handle commands in Makefiles. . .
411
412SHELL=		/bin/sh
413
414all:		tzselect yearistype zic zdump libtz.a $(TABDATA)
415
416ALL:		all date $(ENCHILADA)
417
418install:	all $(DATA) $(REDO) $(MANS)
419		mkdir -p $(DESTDIR)$(ETCDIR) $(DESTDIR)$(TZDIR) \
420			$(DESTDIR)$(LIBDIR) \
421			$(DESTDIR)$(MANDIR)/man3 $(DESTDIR)$(MANDIR)/man5 \
422			$(DESTDIR)$(MANDIR)/man8
423		$(ZIC_INSTALL) -l $(LOCALTIME) -p $(POSIXRULES)
424		cp -f iso3166.tab $(ZONETABLES) $(DESTDIR)$(TZDIR)/.
425		cp tzselect zic zdump $(DESTDIR)$(ETCDIR)/.
426		cp libtz.a $(DESTDIR)$(LIBDIR)/.
427		$(RANLIB) $(DESTDIR)$(LIBDIR)/libtz.a
428		cp -f newctime.3 newtzset.3 $(DESTDIR)$(MANDIR)/man3/.
429		cp -f tzfile.5 $(DESTDIR)$(MANDIR)/man5/.
430		cp -f tzselect.8 zdump.8 zic.8 $(DESTDIR)$(MANDIR)/man8/.
431
432INSTALL:	ALL install date.1
433		mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1
434		cp date $(DESTDIR)$(BINDIR)/.
435		cp -f date.1 $(DESTDIR)$(MANDIR)/man1/.
436
437version:	$(VERSION_DEPS)
438		{ V=$$(git describe --match '[0-9][0-9][0-9][0-9][a-z]*' \
439				--abbrev=7 --dirty) || \
440		  V=$(VERSION); } && \
441		printf '%s\n' "$$V" >$@
442
443version.h:	version
444		(echo 'static char const PKGVERSION[]="($(PACKAGE)) ";' && \
445		 printf 'static char const TZVERSION[]="%s";\n' \
446		   "$$(cat version)" && \
447		 echo 'static char const REPORT_BUGS_TO[]="$(BUGEMAIL)";') >$@
448
449zdump:		$(TZDOBJS)
450		$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(TZDOBJS) $(LDLIBS)
451
452zic:		$(TZCOBJS)
453		$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(TZCOBJS) $(LDLIBS)
454
455yearistype:	yearistype.sh
456		cp yearistype.sh yearistype
457		chmod +x yearistype
458
459leapseconds:	$(LEAP_DEPS)
460		$(AWK) -f leapseconds.awk leap-seconds.list >$@
461
462# Arguments to pass to submakes of install_data.
463# They can be overridden by later submake arguments.
464INSTALLARGS = \
465 DESTDIR=$(DESTDIR) \
466 LEAPSECONDS='$(LEAPSECONDS)' \
467 PACKRATDATA='$(PACKRATDATA)' \
468 TZDIR=$(TZDIR) \
469 YEARISTYPE=$(YEARISTYPE) \
470 ZIC='$(ZIC)'
471
472# 'make install_data' installs one set of tz binary files.
473# It can be tailored by setting LEAPSECONDS, PACKRATDATA, etc.
474install_data:	zic leapseconds yearistype $(PACKRATDATA) $(TDATA)
475		$(ZIC_INSTALL) $(TDATA)
476		$(AWK) '/^Rule/' $(TDATA) | $(ZIC_INSTALL) - $(PACKRATDATA)
477
478posix_only:
479		$(MAKE) $(INSTALLARGS) LEAPSECONDS= install_data
480
481right_only:
482		$(MAKE) $(INSTALLARGS) LEAPSECONDS='-L leapseconds' \
483			install_data
484
485# In earlier versions of this makefile, the other two directories were
486# subdirectories of $(TZDIR).  However, this led to configuration errors.
487# For example, with posix_right under the earlier scheme,
488# TZ='right/Australia/Adelaide' got you localtime with leap seconds,
489# but gmtime without leap seconds, which led to problems with applications
490# like sendmail that subtract gmtime from localtime.
491# Therefore, the other two directories are now siblings of $(TZDIR).
492# You must replace all of $(TZDIR) to switch from not using leap seconds
493# to using them, or vice versa.
494right_posix:	right_only
495		rm -fr $(DESTDIR)$(TZDIR)-leaps
496		ln -s $(TZDIR_BASENAME) $(DESTDIR)$(TZDIR)-leaps || \
497		  $(MAKE) $(INSTALLARGS) TZDIR=$(TZDIR)-leaps right_only
498		$(MAKE) $(INSTALLARGS) TZDIR=$(TZDIR)-posix posix_only
499
500posix_right:	posix_only
501		rm -fr $(DESTDIR)$(TZDIR)-posix
502		ln -s $(TZDIR_BASENAME) $(DESTDIR)$(TZDIR)-posix || \
503		  $(MAKE) $(INSTALLARGS) TZDIR=$(TZDIR)-posix posix_only
504		$(MAKE) $(INSTALLARGS) TZDIR=$(TZDIR)-leaps right_only
505
506# This obsolescent rule is present for backwards compatibility with
507# tz releases 2014g through 2015g.  It should go away eventually.
508posix_packrat:
509		$(MAKE) $(INSTALLARGS) PACKRATDATA=backzone posix_only
510
511zones:		$(REDO)
512
513$(TZS_NEW):	$(TDATA) zdump zic
514		mkdir -p tzs.dir
515		$(zic) -d tzs.dir $(TDATA)
516		$(AWK) '/^Link/{print $$1 "\t" $$2 "\t" $$3}' \
517		   $(TDATA) | LC_ALL=C sort >$@.out
518		zones=$$($(AWK) -v wd="$$(pwd)" \
519				'/^Zone/{print wd "/tzs.dir/" $$2}' $(TDATA) \
520			 | LC_ALL=C sort) && \
521		./zdump -i -c $(TZS_YEAR) $$zones >>$@.out
522		sed 's,^TZ=".*tzs\.dir/,TZ=",' $@.out >$@
523		rm -fr tzs.dir $@.out
524
525# If $(TZS) does not already exist (e.g., old-format tarballs), create it.
526# If it exists but 'make check_tzs' fails, a maintainer should inspect the
527# failed output and fix the inconsistency, perhaps by running 'make force_tzs'.
528$(TZS):
529		$(MAKE) force_tzs
530
531force_tzs:	$(TZS_NEW)
532		cp $(TZS_NEW) $(TZS)
533
534libtz.a:	$(LIBOBJS)
535		$(AR) ru $@ $(LIBOBJS)
536		$(RANLIB) $@
537
538date:		$(DATEOBJS)
539		$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(DATEOBJS) $(LDLIBS)
540
541tzselect:	tzselect.ksh version
542		sed \
543			-e 's|#!/bin/bash|#!$(KSHELL)|g' \
544			-e 's|AWK=[^}]*|AWK=$(AWK)|g' \
545			-e 's|\(PKGVERSION\)=.*|\1='\''($(PACKAGE)) '\''|' \
546			-e 's|\(REPORT_BUGS_TO\)=.*|\1=$(BUGEMAIL)|' \
547			-e 's|TZDIR=[^}]*|TZDIR=$(TZDIR)|' \
548			-e 's|\(TZVERSION\)=.*|\1='"$$(cat version)"'|' \
549			<$@.ksh >$@
550		chmod +x $@
551
552check:		check_character_set check_white_space check_links check_sorted \
553		  check_tables check_tzs check_web
554
555check_character_set: $(ENCHILADA)
556		LC_ALL=en_US.utf8 && export LC_ALL && \
557		sharp='#' && \
558		! grep -Env $(SAFE_LINE) Makefile $(MANS) date.1 $(MANTXTS) \
559			$(MISC) $(SOURCES) $(WEB_PAGES) && \
560		! grep -Env $(SAFE_SHARP_LINE) $(TDATA) backzone \
561			leapseconds yearistype.sh zone.tab && \
562		! grep -Env $(OK_LINE) $(ENCHILADA)
563
564check_white_space: $(ENCHILADA)
565		! grep -En ' '$(TAB_CHAR)"|$$(printf '[\f\r\v]')" $(ENCHILADA)
566		! grep -n '[[:space:]]$$' $(ENCHILADA)
567
568CHECK_CC_LIST = { n = split($$1,a,/,/); for (i=2; i<=n; i++) print a[1], a[i]; }
569
570check_sorted: backward backzone iso3166.tab zone.tab zone1970.tab
571		$(AWK) '/^Link/ {print $$3}' backward | LC_ALL=C sort -cu
572		$(AWK) '/^Zone/ {print $$2}' backzone | LC_ALL=C sort -cu
573		$(AWK) '/^[^#]/ {print $$1}' iso3166.tab | LC_ALL=C sort -cu
574		$(AWK) '/^[^#]/ {print $$1}' zone.tab | LC_ALL=C sort -c
575		$(AWK) '/^[^#]/ {print substr($$0, 1, 2)}' zone1970.tab | \
576		  LC_ALL=C sort -c
577		$(AWK) '/^[^#]/ $(CHECK_CC_LIST)' zone1970.tab | \
578		  LC_ALL=C sort -cu
579
580check_links:	checklinks.awk $(TDATA)
581		$(AWK) -f checklinks.awk $(TDATA)
582
583check_tables:	checktab.awk $(PRIMARY_YDATA) $(ZONETABLES)
584		for tab in $(ZONETABLES); do \
585		  $(AWK) -f checktab.awk -v zone_table=$$tab $(PRIMARY_YDATA) \
586		    || exit; \
587		done
588
589check_tzs:	$(TZS) $(TZS_NEW)
590		diff -u $(TZS) $(TZS_NEW)
591
592check_web:	$(WEB_PAGES)
593		$(VALIDATE_ENV) $(VALIDATE) $(VALIDATE_FLAGS) $(WEB_PAGES)
594
595clean_misc:
596		rm -f core *.o *.out \
597		  date tzselect version.h zdump zic yearistype libtz.a
598clean:		clean_misc
599		rm -fr *.dir tzdb-*/ $(TZS_NEW)
600
601maintainer-clean: clean
602		@echo 'This command is intended for maintainers to use; it'
603		@echo 'deletes files that may need special tools to rebuild.'
604		rm -f leapseconds version $(MANTXTS) $(TZS) *.asc *.tar.*
605
606names:
607		@echo $(ENCHILADA)
608
609public:		check check_public $(CHECK_TIME_T_ALTERNATIVES) \
610		tarballs signatures
611
612date.1.txt:	date.1
613newctime.3.txt:	newctime.3
614newstrftime.3.txt: newstrftime.3
615newtzset.3.txt:	newtzset.3
616time2posix.3.txt: time2posix.3
617tzfile.5.txt:	tzfile.5
618tzselect.8.txt:	tzselect.8
619zdump.8.txt:	zdump.8
620zic.8.txt:	zic.8
621
622$(MANTXTS):	workman.sh
623		LC_ALL=C sh workman.sh `expr $@ : '\(.*\)\.txt$$'` >$@
624
625# Set the time stamps to those of the git repository, if available,
626# and if the files have not changed since then.
627# This uses GNU 'touch' syntax 'touch -d@N FILE',
628# where N is the number of seconds since 1970.
629# If git or GNU 'touch' is absent, don't bother to sync with git timestamps.
630# Also, set the timestamp of each prebuilt file like 'leapseconds'
631# to be the maximum of the files it depends on.
632set-timestamps.out: $(ENCHILADA)
633		rm -f $@
634		if files=`git ls-files $(ENCHILADA)` && \
635		   touch -md @1 test.out; then \
636		  rm -f test.out && \
637		  for file in $$files; do \
638		    if git diff --quiet $$file; then \
639		      time=`git log -1 --format='tformat:%ct' $$file` && \
640		      touch -cmd @$$time $$file; \
641		    else \
642		      echo >&2 "$$file: warning: does not match repository"; \
643		    fi || exit; \
644		  done; \
645		fi
646		touch -cmr `ls -t $(LEAP_DEPS) | sed 1q` leapseconds
647		for file in `ls $(MANTXTS) | sed 's/\.txt$$//'`; do \
648		  touch -cmr `ls -t $$file workman.sh | sed 1q` $$file.txt || \
649		    exit; \
650		done
651		touch -cmr $$(ls -t $(TZS_DEPS) | sed 1q) $(TZS)
652		touch -cmr $$(ls -t $(VERSION_DEPS) | sed 1q) version
653		touch $@
654
655# The zics below ensure that each data file can stand on its own.
656# We also do an all-files run to catch links to links.
657
658check_public:
659		$(MAKE) maintainer-clean
660		$(MAKE) "CFLAGS=$(GCC_DEBUG_FLAGS)" ALL
661		mkdir -p public.dir
662		for i in $(TDATA) ; do \
663		  $(zic) -v -d public.dir $$i 2>&1 || exit; \
664		done
665		$(zic) -v -d public.dir $(TDATA)
666		rm -fr public.dir
667
668# Check that the code works under various alternative
669# implementations of time_t.
670check_time_t_alternatives:
671		if diff -q Makefile Makefile 2>/dev/null; then \
672		  quiet_option='-q'; \
673		else \
674		  quiet_option=''; \
675		fi && \
676		zones=`$(AWK) '/^[^#]/ { print $$3 }' <zone1970.tab` && \
677		for type in $(TIME_T_ALTERNATIVES); do \
678		  mkdir -p time_t.dir/$$type && \
679		  $(MAKE) clean_misc && \
680		  $(MAKE) TOPDIR=$$(pwd)/time_t.dir/$$type \
681		    CFLAGS='$(CFLAGS) -Dtime_tz='"'$$type'" \
682		    REDO='$(REDO)' \
683		    install && \
684		  diff $$quiet_option -r \
685		    time_t.dir/int64_t/etc/zoneinfo \
686		    time_t.dir/$$type/etc/zoneinfo && \
687		  case $$type in \
688		  int32_t) range=-2147483648,2147483647;; \
689		  uint32_t) range=0,4294967296;; \
690		  int64_t) continue;; \
691		  *u*) range=0,10000000000;; \
692		  *) range=-10000000000,10000000000;; \
693		  esac && \
694		  echo checking $$type zones ... && \
695		  time_t.dir/int64_t/etc/zdump -V -t $$range $$zones \
696		      >time_t.dir/int64_t.out && \
697		  time_t.dir/$$type/etc/zdump -V -t $$range $$zones \
698		      >time_t.dir/$$type.out && \
699		  diff -u time_t.dir/int64_t.out time_t.dir/$$type.out \
700		    || exit; \
701		done
702		rm -fr time_t.dir
703
704tarballs signatures: version
705		$(MAKE) VERSION="$$(cat version)" $@_version
706
707tarballs_version: tzcode$(VERSION).tar.gz tzdata$(VERSION).tar.gz \
708		tzdb-$(VERSION).tar.lz
709
710tzcode$(VERSION).tar.gz: set-timestamps.out
711		LC_ALL=C && export LC_ALL && \
712		tar $(TARFLAGS) -cf - \
713		    $(COMMON) $(DOCS) $(SOURCES) | \
714		  ${TOOL_GZIP} $(GZIPFLAGS) > $@
715
716tzdata$(VERSION).tar.gz: set-timestamps.out
717		LC_ALL=C && export LC_ALL && \
718		tar $(TARFLAGS) -cf - $(COMMON) $(DATA) $(MISC) | \
719		  ${TOOL_GZIP} $(GZIPFLAGS) > $@
720
721tzdb-$(VERSION).tar.lz: set-timestamps.out
722		rm -fr tzdb-$(VERSION)
723		mkdir tzdb-$(VERSION)
724		ln $(ENCHILADA) tzdb-$(VERSION)
725		touch -cmr $$(ls -t tzdb-$(VERSION)/* | sed 1q) tzdb-$(VERSION)
726		LC_ALL=C && export LC_ALL && \
727		tar $(TARFLAGS) -cf - tzdb-$(VERSION) | lzip -9 > $@
728
729signatures_version: tzcode$(VERSION).tar.gz.asc tzdata$(VERSION).tar.gz.asc \
730		tzdb-$(VERSION).tar.lz.asc
731
732tzcode$(VERSION).tar.gz.asc: tzcode$(VERSION).tar.gz
733		gpg --armor --detach-sign $?
734
735tzdata$(VERSION).tar.gz.asc: tzdata$(VERSION).tar.gz
736		gpg --armor --detach-sign $?
737
738tzdb-$(VERSION).tar.lz.asc: tzdb-$(VERSION).tar.lz
739		gpg --armor --detach-sign $?
740
741typecheck:
742		$(MAKE) clean
743		for i in "long long" unsigned; \
744		do \
745			$(MAKE) CFLAGS="-DTYPECHECK -D__time_t_defined -D_TIME_T \"-Dtime_t=$$i\"" ; \
746			./zdump -v Europe/Rome ; \
747			$(MAKE) clean ; \
748		done
749
750zonenames:	$(TDATA)
751		@$(AWK) '/^Zone/ { print $$2 } /^Link/ { print $$3 }' $(TDATA)
752
753asctime.o:	private.h tzfile.h
754date.o:		private.h
755difftime.o:	private.h
756localtime.o:	private.h tzfile.h
757strftime.o:	private.h tzfile.h
758zdump.o:	version.h
759zic.o:		private.h tzfile.h version.h
760
761.KEEP_STATE:
762
763.PHONY: ALL INSTALL all
764.PHONY: check check_character_set check_links
765.PHONY: check_public check_sorted check_tables
766.PHONY: check_time_t_alternatives check_tzs check_web check_white_space
767.PHONY: clean clean_misc force_tzs
768.PHONY: install install_data maintainer-clean names
769.PHONY: posix_only posix_packrat posix_right
770.PHONY: public right_only right_posix signatures signatures_version
771.PHONY: tarballs tarballs_version typecheck
772.PHONY: zonenames zones
773