@@ -583,11 +583,19 @@ INSTALL: ALL install date.1
583583 cp date ' $(DESTDIR)$(BINDIR)/.'
584584 cp -f date.1 ' $(DESTDIR)$(MANDIR)/man1/.'
585585
586+ # Calculate version number from git, if available.
587+ # Otherwise, use $(VERSION) unless it is "unknown" and there is already
588+ # a 'version' file, in which case reuse the existing 'version' contents
589+ # and append "-dirty" if the contents do not already end in "-dirty".
586590version: $( VERSION_DEPS)
587591 { (type git) > /dev/null 2>&1 && \
588592 V=` git describe --match ' [0-9][0-9][0-9][0-9][a-z]*' \
589593 --abbrev=7 --dirty` || \
590- V=' $(VERSION)' ; } && \
594+ if test ' $(VERSION)' = unknown && V=` cat $@ ` ; then \
595+ case $$ V in * -dirty);; * ) V=$$ V-dirty;; esac ; \
596+ else \
597+ V=' $(VERSION)' ; \
598+ fi ; } && \
591599 printf ' %s\n' " $$ V" > $@ .out
592600 mv $@ .out $@
593601
@@ -872,11 +880,34 @@ $(MANTXTS): workman.sh
872880 LC_ALL=C sh workman.sh ` expr $@ : ' \(.*\)\.txt$$' ` >$@ .out
873881 mv $@ .out $@
874882
883+ # Set file timestamps deterministically if possible,
884+ # so that tarballs containing the timestamps are reproducible.
885+ #
886+ # ' $(SET_TIMESTAMP_N) N DEST A B C ...' sets the timestamp of the
887+ # file DEST to the maximum of the timestamps of the files A B C ...,
888+ # plus N if GNU ls and touch are available.
889+ SET_TIMESTAMP_N = sh -c ' \
890+ n=$$0 dest=$$1; shift; \
891+ touch -cmr `ls -t "$$@" | sed 1q` "$$dest" && \
892+ if test $$n != 0 && \
893+ lsout=`ls -n --time-style="+%s" "$$dest" 2>/dev/null`; then \
894+ set x $$lsout && \
895+ touch -cmd @`expr $$7 + $$n` "$$dest"; \
896+ else :; fi'
897+ # If DEST depends on A B C ... in this Makefile, callers should use
898+ # $( SET_TIMESTAMP_DEP) DEST A B C ..., for the benefit of any
899+ # downstream ' make' that considers equal timestamps to be out of date.
900+ # POSIX allows this ' make' behavior, and HP-UX ' make' does it.
901+ # If all that matters is that the timestamp be reproducible
902+ # and plausible, use $( SET_TIMESTAMP) .
903+ SET_TIMESTAMP = $( SET_TIMESTAMP_N) 0
904+ SET_TIMESTAMP_DEP = $( SET_TIMESTAMP_N) 1
905+
875906# Set the timestamps to those of the git repository, if available,
876907# and if the files have not changed since then.
877- # This uses GNU ' touch ' syntax ' touch -d@N FILE ' ,
878- # where N is the number of seconds since 1970.
879- # If git or GNU ' touch ' is absent, don' t bother to sync with git timestamps.
908+ # This uses GNU ' ls --time-style=+%s ' , which outputs the seconds count ,
909+ # and GNU ' touch -d@N FILE ' , where N is the number of seconds since 1970.
910+ # If git or GNU is absent, don' t bother to sync with git timestamps.
880911# Also, set the timestamp of each prebuilt file like ' leapseconds'
881912# to be the maximum of the files it depends on.
882913set-timestamps.out: $(EIGHT_YARDS)
@@ -894,16 +925,16 @@ set-timestamps.out: $(EIGHT_YARDS)
894925 fi || exit; \
895926 done; \
896927 fi
897- touch -cmr `ls -t $(LEAP_DEPS) | sed 1q` leapseconds
928+ $(SET_TIMESTAMP_DEP) leapseconds $(LEAP_DEPS)
898929 for file in `ls $(MANTXTS) | sed ' s/\. txt$$ //' `; do \
899- touch -cmr `ls -t $$file workman.sh | sed 1q` $$file.txt || \
930+ $(SET_TIMESTAMP_DEP) $$file.txt $$file workman.sh || \
900931 exit; \
901932 done
902- touch -cmr `ls -t $(TZDATA_ZI_DEPS) | sed 1q` tzdata.zi
903- touch -cmr `ls -t $(VERSION_DEPS) | sed 1q` version
933+ $(SET_TIMESTAMP_DEP) version $(VERSION_DEPS)
934+ $(SET_TIMESTAMP_DEP) tzdata.zi $(TZDATA_ZI_DEPS)
904935 touch $@
905936set-tzs-timestamp.out: $(TZS)
906- touch -cmr `ls -t $(TZS_DEPS) | sed 1q` $(TZS)
937+ $(SET_TIMESTAMP_DEP) $(TZS) $(TZS_DEPS )
907938 touch $@
908939
909940# The zics below ensure that each data file can stand on its own.
@@ -981,7 +1012,7 @@ tarballs rearguard_tarballs traditional_tarballs \
9811012signatures rearguard_signatures traditional_signatures: \
9821013 version set-timestamps.out rearguard.zi
9831014 VERSION=`cat version` && \
984- $(MAKE) VERSION="$$VERSION" $@_version
1015+ $(MAKE) AWK= ' $( AWK ) ' VERSION="$$VERSION" $@_version
9851016
9861017# These *_version rules are intended for use if VERSION is set by some
9871018# other means. Ordinarily these rules are used only by the above
@@ -1018,7 +1049,7 @@ tzdata$(VERSION)-rearguard.tar.gz: rearguard.zi set-timestamps.out
10181049 for f in $(TDATA) $(PACKRATDATA); do \
10191050 rearf=tzdata$(VERSION)-rearguard.dir/$$f; \
10201051 $(AWK) -v DATAFORM=rearguard -f ziguard.awk $$f >$$rearf && \
1021- touch -cmr `ls -t ziguard.awk $$f` $$rearf || exit; \
1052+ $(SET_TIMESTAMP_DEP) $$rearf ziguard.awk $$f || exit; \
10221053 done
10231054 sed ' 1s/$$ /-rearguard/' \
10241055 <version >tzdata$(VERSION)-rearguard.dir/version
@@ -1037,7 +1068,7 @@ tzdb-$(VERSION).tar.lz: set-timestamps.out set-tzs-timestamp.out
10371068 rm -fr tzdb-$(VERSION)
10381069 mkdir tzdb-$(VERSION)
10391070 ln $(ENCHILADA) tzdb-$(VERSION)
1040- touch -cmr `ls -t tzdb-$(VERSION)/* | sed 1q` tzdb-$(VERSION)
1071+ $(SET_TIMESTAMP) tzdb-$(VERSION) tzdb-$(VERSION)/*
10411072 LC_ALL=C && export LC_ALL && \
10421073 tar $(TARFLAGS) -cf - tzdb-$(VERSION) | lzip -9 >[email protected] 10431074@@ -1079,8 +1110,6 @@ strftime.o: private.h tzfile.h
10791110zdump.o: version.h
10801111zic.o: private.h tzfile.h version.h
10811112
1082- .KEEP_STATE:
1083-
10841113.PHONY: ALL INSTALL all
10851114.PHONY: check check_time_t_alternatives
10861115.PHONY: check_web check_zishrink
0 commit comments