Makefile revision 1.27
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 numbers of the code and data distributions.
8VERSION=	2015b
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.  If you want just POSIX-compatible time values, but with
88# out-of-scope and often-wrong data from the file 'backzone', use
89#	REDO=		posix_packrat
90# POSIX mandates that leap seconds not be counted; for compatibility with it,
91# use "posix_only", "posix_right", or "posix_packrat".
92
93REDO=		posix_right
94
95# Since "." may not be in PATH...
96
97YEARISTYPE=	./yearistype
98
99# Non-default libraries needed to link.
100# Add -lintl if you want to use 'gettext' on Solaris.
101LDLIBS=
102
103# Add the following to the end of the "CFLAGS=" line as needed.
104#  -DBIG_BANG=-9999999LL if the Big Bang occurred at time -9999999 (see zic.c)
105#  -DHAVE_ADJTIME=0 if 'adjtime' does not exist (SVR0?)
106#  -DHAVE_DOS_FILE_NAMES if file names have drive specifiers etc. (MS-DOS)
107#  -DHAVE_GETTEXT=1 if 'gettext' works (GNU, Linux, Solaris); also see LDLIBS
108#  -DHAVE_INCOMPATIBLE_CTIME_R=1 if your system's time.h declares
109#	ctime_r and asctime_r incompatibly with the POSIX standard (Solaris 8).
110#  -DHAVE_INTTYPES_H=1 if you have a pre-C99 compiler with "inttypes.h"
111#  -DHAVE_LINK=0 if your system lacks a link function
112#  -DHAVE_LOCALTIME_R=0 if your system lacks a localtime_r function
113#  -DHAVE_LOCALTIME_RZ=0 if you do not want zdump to use localtime_rz
114#	This defaults to 1 if a working localtime_rz seems to be available.
115#	localtime_rz can make zdump significantly faster, but is nonstandard.
116#  -DHAVE_SETTIMEOFDAY=0 if settimeofday does not exist (SVR0?)
117#  -DHAVE_SETTIMEOFDAY=1 if settimeofday has just 1 arg (SVR4)
118#  -DHAVE_SETTIMEOFDAY=2 if settimeofday uses 2nd arg (4.3BSD)
119#  -DHAVE_SETTIMEOFDAY=3 if settimeofday ignores 2nd arg (4.4BSD)
120#  -DHAVE_STDINT_H=1 if you have a pre-C99 compiler with "stdint.h"
121#  -DHAVE_STRFTIME_L=1 if <time.h> declares locale_t and strftime_l
122#	This defaults to 0 if _POSIX_VERSION < 200809, 1 otherwise.
123#  -DHAVE_SYMLINK=0 if your system lacks the symlink function
124#  -DHAVE_SYS_STAT_H=0 if your compiler lacks a "sys/stat.h"
125#  -DHAVE_SYS_WAIT_H=0 if your compiler lacks a "sys/wait.h"
126#  -DHAVE_TZSET=0 if your system lacks a tzset function
127#  -DHAVE_UNISTD_H=0 if your compiler lacks a "unistd.h" (Microsoft C++ 7?)
128#  -DHAVE_UTMPX_H=1 if your compiler has a "utmpx.h"
129#  -DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU=1
130#	if you do not want run time warnings about formats that may cause
131#	year 2000 grief
132#  -Dssize_t=long on ancient hosts that lack ssize_t
133#  -DTHREAD_SAFE=1 to make localtime.c thread-safe, as POSIX requires;
134#	not needed by the main-program tz code, which is single-threaded.
135#	Append other compiler flags as needed, e.g., -pthread on GNU/Linux.
136#  -Dtime_tz=\"T\" to use T as the time_t type, rather than the system time_t
137#  -DTZ_DOMAIN=\"foo\" to use "foo" for gettext domain name; default is "tz"
138#  -DTZ_DOMAINDIR=\"/path\" to use "/path" for gettext directory;
139#	the default is system-supplied, typically "/usr/lib/locale"
140#  -DTZDEFRULESTRING=\",date/time,date/time\" to default to the specified
141#  -DUNINIT_TRAP=1 if reading uninitialized storage can cause problems
142#	other than simply getting garbage data
143#  -DUSE_LTZ=0 to build zdump with the system time zone library
144#	Also set TZDOBJS=zdump.o and CHECK_TIME_T_ALTERNATIVES= below.
145#  -DNO_ERROR_IN_DST_GAP=1
146#	if you want mktime() not to return an error in the DST gap.
147#  -DZIC_MAX_ABBR_LEN_WO_WARN=3
148#	(or some other number) to set the maximum time zone abbreviation length
149#	that zic will accept without a warning (the default is 6)
150#  $(GCC_DEBUG_FLAGS) if you are using GCC and want lots of checking
151GCC_DEBUG_FLAGS = -Dlint -g3 -O3 -fno-common -fstrict-aliasing \
152	-Wall -Wextra \
153	-Wbad-function-cast -Wcast-align -Wcast-qual \
154	-Wdeclaration-after-statement \
155	-Wformat=2 -Winit-self -Wjump-misses-init \
156	-Wmissing-declarations -Wmissing-noreturn -Wmissing-prototypes \
157	-Wnested-externs -Wno-address -Wno-cast-qual \
158	-Wno-format-nonliteral -Wno-sign-compare -Wno-sign-conversion \
159	-Wno-type-limits \
160	-Wno-unused-parameter -Woverlength-strings -Wpointer-arith \
161	-Wshadow -Wstrict-prototypes -Wsuggest-attribute=const \
162	-Wsuggest-attribute=format -Wsuggest-attribute=noreturn \
163	-Wsuggest-attribute=pure -Wtrampolines \
164	-Wwrite-strings
165#
166# If you want to use System V compatibility code, add
167#	-DUSG_COMPAT
168# to the end of the "CFLAGS=" line.  This arrange for "timezone" and "daylight"
169# variables to be kept up-to-date by the time conversion functions.  Neither
170# "timezone" nor "daylight" is described in X3J11's work.
171#
172# If your system has a "GMT offset" field in its "struct tm"s
173# (or if you decide to add such a field in your system's "time.h" file),
174# add the name to a define such as
175#	-DTM_GMTOFF=tm_gmtoff
176# to the end of the "CFLAGS=" line.  If not defined, the code attempts to
177# guess TM_GMTOFF from other macros; define NO_TM_GMTOFF to suppress this.
178# Similarly, if your system has a "zone abbreviation" field, define
179#	-DTM_ZONE=tm_zone
180# and define NO_TM_ZONE to suppress any guessing.  These two fields are not
181# required by POSIX, but are widely available on GNU/Linux and BSD systems.
182#
183# If you want functions that were inspired by early versions of X3J11's work,
184# add
185#	-DSTD_INSPIRED
186# to the end of the "CFLAGS=" line.  This arranges for the functions
187# "tzsetwall", "offtime", "timelocal", "timegm", "timeoff",
188# "posix2time", and "time2posix" to be added to the time conversion library.
189# "tzsetwall" is like "tzset" except that it arranges for local wall clock
190# time (rather than the time specified in the TZ environment variable)
191# to be used.
192# "offtime" is like "gmtime" except that it accepts a second (long) argument
193# that gives an offset to add to the time_t when converting it.
194# "timelocal" is equivalent to "mktime".
195# "timegm" is like "timelocal" except that it turns a struct tm into
196# a time_t using UT (rather than local time as "timelocal" does).
197# "timeoff" is like "timegm" except that it accepts a second (long) argument
198# that gives an offset to use when converting to a time_t.
199# "posix2time" and "time2posix" are described in an included manual page.
200# X3J11's work does not describe any of these functions.
201# Sun has provided "tzsetwall", "timelocal", and "timegm" in SunOS 4.0.
202# These functions may well disappear in future releases of the time
203# conversion package.
204#
205# If you don't want functions that were inspired by NetBSD, add
206#	-DNETBSD_INSPIRED=0
207# to the end of the "CFLAGS=" line.  Otherwise, the functions
208# "localtime_rz", "mktime_z", "tzalloc", and "tzfree" are added to the
209# time library, and if STD_INSPIRED is also defined the functions
210# "posix2time_z" and "time2posix_z" are added as well.
211# The functions ending in "_z" (or "_rz") are like their unsuffixed
212# (or suffixed-by-"_r") counterparts, except with an extra first
213# argument of opaque type timezone_t that specifies the time zone.
214# "tzalloc" allocates a timezone_t value, and "tzfree" frees it.
215#
216# If you want to allocate state structures in localtime, add
217#	-DALL_STATE
218# to the end of the "CFLAGS=" line.  Storage is obtained by calling malloc.
219#
220# If you want an "altzone" variable (a la System V Release 3.1), add
221#	-DALTZONE
222# to the end of the "CFLAGS=" line.
223# This variable is not described in X3J11's work.
224#
225# NIST-PCTS:151-2, Version 1.4, (1993-12-03) is a test suite put
226# out by the National Institute of Standards and Technology
227# which claims to test C and Posix conformance.  If you want to pass PCTS, add
228#	-DPCTS
229# to the end of the "CFLAGS=" line.
230#
231# If you want strict compliance with XPG4 as of 1994-04-09, add
232#	-DXPG4_1994_04_09
233# to the end of the "CFLAGS=" line.  This causes "strftime" to always return
234# 53 as a week number (rather than 52 or 53) for those days in January that
235# before the first Monday in January when a "%V" format is used and January 1
236# falls on a Friday, Saturday, or Sunday.
237
238CFLAGS=
239
240# Linker flags.  Default to $(LFLAGS) for backwards compatibility
241# to tzcode2012h and earlier.
242
243LDFLAGS=	$(LFLAGS)
244
245zic=		./zic
246ZIC=		$(zic) $(ZFLAGS)
247
248ZFLAGS=
249
250# The name of a Posix-compliant 'awk' on your system.
251AWK=		awk
252
253# The full path name of a Posix-compliant shell, preferably one that supports
254# the Korn shell's 'select' statement as an extension.
255# These days, Bash is the most popular.
256# It should be OK to set this to /bin/sh, on platforms where /bin/sh
257# lacks 'select' or doesn't completely conform to Posix, but /bin/bash
258# is typically nicer if it works.
259KSHELL=		/bin/bash
260
261# The path where SGML DTDs are kept and the catalog file(s) to use when
262# validating.  The default is appropriate for Ubuntu 13.10.
263SGML_TOPDIR= /usr
264SGML_DTDDIR= $(SGML_TOPDIR)/share/xml/w3c-sgml-lib/schema/dtd
265SGML_SEARCH_PATH= $(SGML_DTDDIR)/REC-html401-19991224
266SGML_CATALOG_FILES= \
267  $(SGML_TOPDIR)/share/doc/w3-recs/html/www.w3.org/TR/1999/REC-html401-19991224/HTML4.cat
268
269# The name, arguments and environment of a program to validate your web pages.
270# See <http://www.jclark.com/sp/> for a validator, and
271# <http://validator.w3.org/source/> for a validation library.
272VALIDATE = nsgmls
273VALIDATE_FLAGS = -s -B -wall -wno-unused-param
274VALIDATE_ENV = \
275  SGML_CATALOG_FILES=$(SGML_CATALOG_FILES) \
276  SGML_SEARCH_PATH=$(SGML_SEARCH_PATH) \
277  SP_CHARSET_FIXED=YES \
278  SP_ENCODING=UTF-8
279
280# This expensive test requires USE_LTZ.
281# To suppress it, define this macro to be empty.
282CHECK_TIME_T_ALTERNATIVES = check_time_t_alternatives
283
284# SAFE_CHAR is a regular expression that matches a safe character.
285# Some parts of this distribution are limited to safe characters;
286# others can use any UTF-8 character.
287# For now, the safe characters are a safe subset of ASCII.
288# The caller must set the shell variable 'sharp' to the character '#',
289# since Makefile macros cannot contain '#'.
290# TAB_CHAR is a single tab character, in single quotes.
291TAB_CHAR=	'	'
292SAFE_CHARSET1=	$(TAB_CHAR)' !\"'$$sharp'$$%&'\''()*+,./0123456789:;<=>?@'
293SAFE_CHARSET2=	'ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\^_`'
294SAFE_CHARSET3=	'abcdefghijklmnopqrstuvwxyz{|}~'
295SAFE_CHARSET=	]$(SAFE_CHARSET1)$(SAFE_CHARSET2)$(SAFE_CHARSET3)-
296SAFE_CHAR=	'['$(SAFE_CHARSET)']'
297# NONSYM_CHAR is a regular expression that matches any character
298# except for a small number of symbols, where we prefer to stick with
299# ASCII renderings for the convenience of maintainers whose text editors
300# mishandle UTF-8 by default (e.g., XEmacs 21.4.22).
301NONSYM_CHAR=	'[^–—°′″≈≠≤≥±−×÷∞←→↔·•§¶«»‘’‚‛“”„‟‹›「」『』〝〞〟]'
302
303# SAFE_LINE matches a line of safe characters.
304# SAFE_SHARP_LINE is similar, except any character can follow '#';
305# this is so that comments can contain non-ASCII characters.
306# NONSYM_LINE matches a line of non-symbols.
307# VALID_LINE matches a line of any validly-encoded characters.
308SAFE_LINE=	'^'$(SAFE_CHAR)'*$$'
309SAFE_SHARP_LINE='^'$(SAFE_CHAR)'*('$$sharp$(NONSYM_CHAR)'*)?$$'
310NONSYM_LINE=	'^'$(NONSYM_CHAR)'*$$'
311VALID_LINE=	'^.*$$'
312
313# Flags to give 'tar' when making a distribution.
314# Try to use flags appropriate for GNU tar.
315GNUTARFLAGS=	--numeric-owner --owner=0 --group=0 --mode=go+u,go-w
316TARFLAGS=	`if tar $(GNUTARFLAGS) --version >/dev/null 2>&1; \
317		 then echo $(GNUTARFLAGS); \
318		 else :; \
319		 fi`
320
321# Flags to give 'gzip' when making a distribution.
322GZIPFLAGS=	-9 ${GZIP_N_FLAG}
323
324###############################################################################
325
326cc=		cc
327CC=		$(cc) -DTZDIR=\"$(TZDIR)\"
328
329AR=		ar
330
331# ':' on typical hosts; 'ranlib' on the ancient hosts that still need ranlib.
332RANLIB=		:
333
334TZCOBJS=	zic.o scheck.o ialloc.o
335TZDOBJS=	zdump.o localtime.o asctime.o
336DATEOBJS=	date.o localtime.o strftime.o asctime.o
337LIBSRCS=	localtime.c asctime.c difftime.c
338LIBOBJS=	localtime.o asctime.o difftime.o
339HEADERS=	tzfile.h private.h
340NONLIBSRCS=	zic.c zdump.c scheck.c ialloc.c
341NEWUCBSRCS=	date.c strftime.c
342SOURCES=	$(HEADERS) $(LIBSRCS) $(NONLIBSRCS) $(NEWUCBSRCS) \
343			tzselect.ksh workman.sh
344MANS=		newctime.3 newstrftime.3 newtzset.3 time2posix.3 \
345			tzfile.5 tzselect.8 zic.8 zdump.8
346MANTXTS=	newctime.3.txt newstrftime.3.txt newtzset.3.txt \
347			time2posix.3.txt \
348			tzfile.5.txt tzselect.8.txt zic.8.txt zdump.8.txt \
349			date.1.txt
350COMMON=		CONTRIBUTING Makefile NEWS README Theory
351WEB_PAGES=	tz-art.htm tz-link.htm
352DOCS=		$(MANS) date.1 $(MANTXTS) $(WEB_PAGES)
353PRIMARY_YDATA=	africa antarctica asia australasia \
354		europe northamerica southamerica
355YDATA=		$(PRIMARY_YDATA) pacificnew etcetera backward
356NDATA=		systemv factory
357TDATA=		$(YDATA) $(NDATA)
358ZONETABLES=	zone1970.tab zone.tab
359TABDATA=	iso3166.tab leapseconds $(ZONETABLES)
360LEAP_DEPS=	leapseconds.awk leap-seconds.list
361DATA=		$(YDATA) $(NDATA) backzone $(TABDATA) \
362			leap-seconds.list yearistype.sh
363AWK_SCRIPTS=	checklinks.awk checktab.awk leapseconds.awk
364MISC=		$(AWK_SCRIPTS) zoneinfo2tdf.pl
365ENCHILADA=	$(COMMON) $(DOCS) $(SOURCES) $(DATA) $(MISC)
366
367# And for the benefit of csh users on systems that assume the user
368# shell should be used to handle commands in Makefiles. . .
369
370SHELL=		/bin/sh
371
372all:		tzselect zic zdump libtz.a $(TABDATA)
373
374ALL:		all date
375
376install:	all $(DATA) $(REDO) $(MANS)
377		mkdir -p $(DESTDIR)$(ETCDIR) $(DESTDIR)$(TZDIR) \
378			$(DESTDIR)$(LIBDIR) \
379			$(DESTDIR)$(MANDIR)/man3 $(DESTDIR)$(MANDIR)/man5 \
380			$(DESTDIR)$(MANDIR)/man8
381		$(ZIC) -y $(YEARISTYPE) \
382			-d $(DESTDIR)$(TZDIR) -l $(LOCALTIME) -p $(POSIXRULES)
383		cp -f iso3166.tab $(ZONETABLES) $(DESTDIR)$(TZDIR)/.
384		cp tzselect zic zdump $(DESTDIR)$(ETCDIR)/.
385		cp libtz.a $(DESTDIR)$(LIBDIR)/.
386		$(RANLIB) $(DESTDIR)$(LIBDIR)/libtz.a
387		cp -f newctime.3 newtzset.3 $(DESTDIR)$(MANDIR)/man3/.
388		cp -f tzfile.5 $(DESTDIR)$(MANDIR)/man5/.
389		cp -f tzselect.8 zdump.8 zic.8 $(DESTDIR)$(MANDIR)/man8/.
390
391INSTALL:	ALL install date.1
392		mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1
393		cp date $(DESTDIR)$(BINDIR)/.
394		cp -f date.1 $(DESTDIR)$(MANDIR)/man1/.
395
396version.h:
397		(echo 'static char const PKGVERSION[]="($(PACKAGE)) ";' && \
398		 echo 'static char const TZVERSION[]="$(VERSION)";' && \
399		 echo 'static char const REPORT_BUGS_TO[]="$(BUGEMAIL)";') >$@
400
401zdump:		$(TZDOBJS)
402		$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(TZDOBJS) $(LDLIBS)
403
404zic:		$(TZCOBJS) yearistype
405		$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(TZCOBJS) $(LDLIBS)
406
407yearistype:	yearistype.sh
408		cp yearistype.sh yearistype
409		chmod +x yearistype
410
411leapseconds:	$(LEAP_DEPS)
412		$(AWK) -f leapseconds.awk leap-seconds.list >$@
413
414posix_only:	zic $(TDATA)
415		$(ZIC) -y $(YEARISTYPE) -d $(DESTDIR)$(TZDIR) \
416			-L /dev/null $(TDATA)
417
418right_only:	zic leapseconds $(TDATA)
419		$(ZIC) -y $(YEARISTYPE) -d $(DESTDIR)$(TZDIR) \
420			-L leapseconds $(TDATA)
421
422# In earlier versions of this makefile, the other two directories were
423# subdirectories of $(TZDIR).  However, this led to configuration errors.
424# For example, with posix_right under the earlier scheme,
425# TZ='right/Australia/Adelaide' got you localtime with leap seconds,
426# but gmtime without leap seconds, which led to problems with applications
427# like sendmail that subtract gmtime from localtime.
428# Therefore, the other two directories are now siblings of $(TZDIR).
429# You must replace all of $(TZDIR) to switch from not using leap seconds
430# to using them, or vice versa.
431right_posix:	right_only leapseconds
432		rm -fr $(DESTDIR)$(TZDIR)-leaps
433		ln -s $(TZDIR_BASENAME) $(DESTDIR)$(TZDIR)-leaps || \
434		  $(ZIC) -y $(YEARISTYPE) -d $(DESTDIR)$(TZDIR)-leaps \
435			-L leapseconds $(TDATA)
436		$(ZIC) -y $(YEARISTYPE) -d $(DESTDIR)$(TZDIR)-posix \
437			-L /dev/null $(TDATA)
438
439posix_right:	posix_only leapseconds
440		rm -fr $(DESTDIR)$(TZDIR)-posix
441		ln -s $(TZDIR_BASENAME) $(DESTDIR)$(TZDIR)-posix || \
442		  $(ZIC) -y $(YEARISTYPE) -d $(DESTDIR)$(TZDIR)-posix \
443			-L /dev/null $(TDATA)
444		$(ZIC) -y $(YEARISTYPE) -d $(DESTDIR)$(TZDIR)-leaps \
445			-L leapseconds $(TDATA)
446
447posix_packrat:	posix_only backzone
448		$(AWK) '/^Rule/' $(TDATA) | \
449		  $(ZIC) -y $(YEARISTYPE) -d $(DESTDIR)$(TZDIR) \
450			-L /dev/null - backzone
451
452zones:		$(REDO)
453
454libtz.a:	$(LIBOBJS)
455		$(AR) ru $@ $(LIBOBJS)
456		$(RANLIB) $@
457
458date:		$(DATEOBJS)
459		$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(DATEOBJS) $(LDLIBS)
460
461tzselect:	tzselect.ksh
462		sed \
463			-e 's|#!/bin/bash|#!$(KSHELL)|g' \
464			-e 's|AWK=[^}]*|AWK=$(AWK)|g' \
465			-e 's|\(PKGVERSION\)=.*|\1='\''($(PACKAGE)) '\''|' \
466			-e 's|\(REPORT_BUGS_TO\)=.*|\1=$(BUGEMAIL)|' \
467			-e 's|TZDIR=[^}]*|TZDIR=$(TZDIR)|' \
468			-e 's|\(TZVERSION\)=.*|\1=$(VERSION)|' \
469			<$? >$@
470		chmod +x $@
471
472check:		check_character_set check_white_space check_links check_sorted \
473		  check_tables check_web
474
475check_character_set: $(ENCHILADA)
476		LC_ALL=en_US.utf8 && export LC_ALL && \
477		sharp='#' && \
478		! grep -Env $(SAFE_LINE) $(MANS) date.1 $(MANTXTS) \
479			$(MISC) $(SOURCES) $(WEB_PAGES) && \
480		! grep -Env $(SAFE_SHARP_LINE) $(TDATA) backzone \
481			iso3166.tab leapseconds yearistype.sh zone.tab && \
482		test $$(grep -Ecv $(SAFE_SHARP_LINE) Makefile) -eq 1 && \
483		! grep -Env $(NONSYM_LINE) CONTRIBUTING NEWS README Theory \
484			$(MANS) date.1 zone1970.tab && \
485		! grep -Env $(VALID_LINE) $(ENCHILADA)
486
487check_white_space: $(ENCHILADA)
488		! grep -En ' '$(TAB_CHAR)"|$$(printf '[\f\r\v]')" $(ENCHILADA)
489		! grep -n '[[:space:]]$$' $(ENCHILADA)
490
491CHECK_CC_LIST = { n = split($$1,a,/,/); for (i=2; i<=n; i++) print a[1], a[i]; }
492
493check_sorted: backward backzone iso3166.tab zone.tab zone1970.tab
494		$(AWK) '/^Link/ {print $$3}' backward | LC_ALL=C sort -cu
495		$(AWK) '/^Zone/ {print $$2}' backzone | LC_ALL=C sort -cu
496		$(AWK) '/^[^#]/ {print $$1}' iso3166.tab | LC_ALL=C sort -cu
497		$(AWK) '/^[^#]/ {print $$1}' zone.tab | LC_ALL=C sort -c
498		$(AWK) '/^[^#]/ {print substr($$0, 1, 2)}' zone1970.tab | \
499		  LC_ALL=C sort -c
500		$(AWK) '/^[^#]/ $(CHECK_CC_LIST)' zone1970.tab | \
501		  LC_ALL=C sort -cu
502
503check_links:	checklinks.awk $(TDATA)
504		$(AWK) -f checklinks.awk $(TDATA)
505
506check_tables:	checktab.awk $(PRIMARY_YDATA) $(ZONETABLES)
507		for tab in $(ZONETABLES); do \
508		  $(AWK) -f checktab.awk -v zone_table=$$tab $(PRIMARY_YDATA) \
509		    || exit; \
510		done
511
512check_web:	$(WEB_PAGES)
513		$(VALIDATE_ENV) $(VALIDATE) $(VALIDATE_FLAGS) $(WEB_PAGES)
514
515clean_misc:
516		rm -f core *.o *.out \
517		  date tzselect version.h zdump zic yearistype libtz.a
518clean:		clean_misc
519		rm -fr tzpublic
520
521maintainer-clean: clean
522		@echo 'This command is intended for maintainers to use; it'
523		@echo 'deletes files that may need special tools to rebuild.'
524		rm -f leapseconds $(MANTXTS) *.asc *.tar.gz
525
526names:
527		@echo $(ENCHILADA)
528
529public:		check check_public $(CHECK_TIME_T_ALTERNATIVES) \
530		tarballs signatures
531
532date.1.txt:	date.1
533newctime.3.txt:	newctime.3
534newstrftime.3.txt: newstrftime.3
535newtzset.3.txt:	newtzset.3
536time2posix.3.txt: time2posix.3
537tzfile.5.txt:	tzfile.5
538tzselect.8.txt:	tzselect.8
539zdump.8.txt:	zdump.8
540zic.8.txt:	zic.8
541
542$(MANTXTS):	workman.sh
543		LC_ALL=C sh workman.sh `expr $@ : '\(.*\)\.txt$$'` >$@
544
545# Set the time stamps to those of the git repository, if available,
546# and if the files have not changed since then.
547# This uses GNU 'touch' syntax 'touch -d@N FILE',
548# where N is the number of seconds since 1970.
549# If git or GNU 'touch' is absent, don't bother to sync with git timestamps.
550# Also, set the timestamp of each prebuilt file like 'leapseconds'
551# to be the maximum of the files it depends on.
552set-timestamps.out: $(ENCHILADA)
553		rm -f $@
554		if files=`git ls-files $(ENCHILADA)` && \
555		   touch -md @1 test.out; then \
556		  rm -f test.out && \
557		  for file in $$files; do \
558		    if git diff --quiet $$file; then \
559		      time=`git log -1 --format='tformat:%ct' $$file` && \
560		      touch -cmd @$$time $$file; \
561		    else \
562		      echo >&2 "$$file: warning: does not match repository"; \
563		    fi || exit; \
564		  done; \
565		fi
566		touch -cmr `ls -t $(LEAP_DEPS) | sed 1q` leapseconds
567		for file in `ls $(MANTXTS) | sed 's/\.txt$$//'`; do \
568		  touch -cmr `ls -t $$file workman.sh | sed 1q` $$file.txt || \
569		    exit; \
570		done
571		touch $@
572
573# The zics below ensure that each data file can stand on its own.
574# We also do an all-files run to catch links to links.
575
576check_public:	$(ENCHILADA)
577		make maintainer-clean
578		make "CFLAGS=$(GCC_DEBUG_FLAGS)" $(ENCHILADA) all
579		mkdir tzpublic
580		for i in $(TDATA) ; do \
581		  $(zic) -v -d tzpublic $$i 2>&1 || exit; \
582		done
583		$(zic) -v -d tzpublic $(TDATA)
584		rm -fr tzpublic
585
586# Check that the code works under various alternative
587# implementations of time_t.
588check_time_t_alternatives:
589		if diff -q Makefile Makefile 2>/dev/null; then \
590		  quiet_option='-q'; \
591		else \
592		  quiet_option=''; \
593		fi && \
594		zones=`$(AWK) '/^[^#]/ { print $$3 }' <zone1970.tab` && \
595		for type in $(TIME_T_ALTERNATIVES); do \
596		  mkdir -p tzpublic/$$type && \
597		  make clean_misc && \
598		  make TOPDIR=`pwd`/tzpublic/$$type \
599		    CFLAGS='$(CFLAGS) -Dtime_tz='"'$$type'" \
600		    REDO='$(REDO)' \
601		    install && \
602		  diff $$quiet_option -r \
603		    tzpublic/int64_t/etc/zoneinfo \
604		    tzpublic/$$type/etc/zoneinfo && \
605		  case $$type in \
606		  int32_t) range=-2147483648,2147483647;; \
607		  uint32_t) range=0,4294967296;; \
608		  int64_t) continue;; \
609		  *u*) range=0,10000000000;; \
610		  *) range=-10000000000,10000000000;; \
611		  esac && \
612		  echo checking $$type zones ... && \
613		  tzpublic/int64_t/etc/zdump -V -t $$range $$zones \
614		      >tzpublic/int64_t.out && \
615		  tzpublic/$$type/etc/zdump -V -t $$range $$zones \
616		      >tzpublic/$$type.out && \
617		  diff -u tzpublic/int64_t.out tzpublic/$$type.out \
618		    || exit; \
619		done
620		rm -fr tzpublic
621
622tarballs:	tzcode$(VERSION).tar.gz tzdata$(VERSION).tar.gz
623
624tzcode$(VERSION).tar.gz: set-timestamps.out
625		LC_ALL=C && export LC_ALL && \
626		tar $(TARFLAGS) -cf - \
627		    $(COMMON) $(DOCS) $(SOURCES) | \
628		  ${TOOL_GZIP} $(GZIPFLAGS) > $@
629
630tzdata$(VERSION).tar.gz: set-timestamps.out
631		LC_ALL=C && export LC_ALL && \
632		tar $(TARFLAGS) -cf - $(COMMON) $(DATA) $(MISC) | \
633		  ${TOOL_GZIP} $(GZIPFLAGS) > $@
634
635signatures:	tzcode$(VERSION).tar.gz.asc tzdata$(VERSION).tar.gz.asc
636
637tzcode$(VERSION).tar.gz.asc: tzcode$(VERSION).tar.gz
638		gpg --armor --detach-sign $?
639
640tzdata$(VERSION).tar.gz.asc: tzdata$(VERSION).tar.gz
641		gpg --armor --detach-sign $?
642
643typecheck:
644		make clean
645		for i in "long long" unsigned; \
646		do \
647			make CFLAGS="-DTYPECHECK -D__time_t_defined -D_TIME_T \"-Dtime_t=$$i\"" ; \
648			./zdump -v Europe/Rome ; \
649			make clean ; \
650		done
651
652zonenames:	$(TDATA)
653		@$(AWK) '/^Zone/ { print $$2 } /^Link/ { print $$3 }' $(TDATA)
654
655asctime.o:	private.h tzfile.h
656date.o:		private.h
657difftime.o:	private.h
658ialloc.o:	private.h
659localtime.o:	private.h tzfile.h
660scheck.o:	private.h
661strftime.o:	private.h tzfile.h
662zdump.o:	version.h
663zic.o:		private.h tzfile.h version.h
664
665.KEEP_STATE:
666
667.PHONY: ALL INSTALL all
668.PHONY: check check_character_set check_links
669.PHONY: check_public check_sorted check_tables
670.PHONY: check_time_t_alternatives check_web check_white_space clean clean_misc
671.PHONY: install maintainer-clean names posix_packrat posix_only posix_right
672.PHONY: public right_only right_posix signatures tarballs typecheck
673.PHONY: zonenames zones
674