Mercurial > octave
changeset 24077:e483dcb5777d
build the source distribution archives reproducibly
* Makefile.am (GZIP_ENV): Override default for a deterministic gzip.
(SOURCE_MTIME): Define to the value printed by get-source-mtime.sh.
(TAR_OPTIONS): Define to GNU tar options for making deterministic archives
and export for tar to inherit by default.
* build-aux/get-source-mtime.sh: New script.
* build-aux/module.mk (EXTRA_DIST): Include it in the list.
* m4/acinclude.m4 (OCTAVE_PROG_TAR_REPRODUCIBLE): New macro.
* configure.ac: Use it.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Thu, 21 Sep 2017 14:19:10 -0700 |
parents | 1b7e49a72c62 |
children | 08093b89c08a |
files | Makefile.am build-aux/get-source-mtime.sh build-aux/module.mk configure.ac m4/acinclude.m4 |
diffstat | 5 files changed, 91 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile.am Tue Oct 11 15:20:35 2016 +0200 +++ b/Makefile.am Thu Sep 21 14:19:10 2017 -0700 @@ -26,6 +26,7 @@ export SED export SHELL export PERL +export TAR_OPTIONS version := ${OCTAVE_VERSION} api_version := ${OCTAVE_API_VERSION} @@ -80,6 +81,13 @@ OCTAVE_GUI_LINK_DEPS = @OCTAVE_GUI_LINK_DEPS@ OCTAVE_GUI_LINK_OPTS = @OCTAVE_GUI_LINK_OPTS@ +# Options used for creating the source distribution. + +GZIP_ENV = --best --no-name +SOURCE_MTIME := \ + $(shell $(SHELL) $(top_srcdir)/build-aux/get-source-mtime.sh "$(srcdir)") +TAR_OPTIONS = $(REPRODUCIBLE_TAR_FLAGS) --mtime=@$(SOURCE_MTIME) + # The arguments passed to configure. CONFIG_SUBDIRS = @subdirs@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build-aux/get-source-mtime.sh Thu Sep 21 14:19:10 2017 -0700 @@ -0,0 +1,55 @@ +#! /bin/sh +# +# Copyright (C) 2017 Mike Miller +# +# This file is part of Octave. +# +# Octave is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Octave is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Octave; see the file COPYING. If not, see +# <http://www.gnu.org/licenses/>. + +# Generate a timestamp that best represents the last modification time +# of this source tree. The time value is printed on stdout in units of +# time_t. If a reasonable representation of the source tree last +# modification time can't be determined, then the current system time is +# printed instead. A valid time_t value is always printed on stdout. + +set -e + +PERL=${PERL:-perl} +SED=${SED:-sed} + +if [ $# -ne 1 ]; then + echo "usage: get-source-mtime.sh SRCDIR" 1>&2 + exit 1 +fi + +srcdir="$1" + +if [ x"$SOURCE_DATE_EPOCH" != x ]; then + # Allow the source modification time to be overridden by SOURCE_DATE_EPOCH + t=$SOURCE_DATE_EPOCH +elif [ -d $srcdir/.hg ]; then + t=$( cd $srcdir && hg log --rev . --template '{date|hgdate}' ) + t=$( echo $t | $SED -n 's/^\([0-9]\+\) .*/\1/p' ) +elif [ -f $srcdir/HG-ID ]; then + t=$( $PERL -e '@s = stat($ARGV[0]); print($s[9]) if @s;' $srcdir/HG-ID ) +elif [ -f $srcdir/configure ]; then + t=$( $PERL -e '@s = stat($ARGV[0]); print($s[9]) if @s;' $srcdir/configure ) +fi + +if [ x"$t" = x ]; then + t=$( date +%s ) +fi + +echo $t
--- a/build-aux/module.mk Tue Oct 11 15:20:35 2016 +0200 +++ b/build-aux/module.mk Thu Sep 21 14:19:10 2017 -0700 @@ -5,6 +5,7 @@ %reldir%/check-subst-vars.in.sh \ %reldir%/find-defun-files.sh \ %reldir%/find-files-with-tests.sh \ + %reldir%/get-source-mtime.sh \ %reldir%/mk-hg-id.sh \ %reldir%/mk-octave-config-h.sh \ %reldir%/mk-opts.pl \
--- a/configure.ac Tue Oct 11 15:20:35 2016 +0200 +++ b/configure.ac Thu Sep 21 14:19:10 2017 -0700 @@ -203,6 +203,8 @@ OCTAVE_PROG_TEXI2DVI OCTAVE_PROG_TEXI2PDF +OCTAVE_PROG_TAR_REPRODUCIBLE + ## Programs used when installing Octave. AC_PROG_LN_S AC_PROG_MKDIR_P
--- a/m4/acinclude.m4 Tue Oct 11 15:20:35 2016 +0200 +++ b/m4/acinclude.m4 Thu Sep 21 14:19:10 2017 -0700 @@ -2582,6 +2582,31 @@ AC_MSG_RESULT([$SED]) ]) dnl +dnl Check for options that can be passed to tar to make archives reproducible. +dnl +AC_DEFUN([OCTAVE_PROG_TAR_REPRODUCIBLE], [ + AC_MSG_CHECKING([for options to make reproducible archives with GNU tar]) +dnl This uses Automake's logic for finding GNU tar under various names + for octave_tar in tar gnutar gtar :; do + $octave_tar --version >/dev/null 2>&1 && break + done +dnl If we have a valid GNU tar program, see if it supports sets of options + if test x"$octave_tar" != x:; then + octave_tar_flags= + echo > conftest.txt + for octave_tar_flag in --owner=0 --group=0 --numeric-owner --sort=name; do + $octave_tar -cf conftest.tar $octave_tar_flags $octave_tar_flag conftest.txt 2>/dev/null + if test $? -eq 0; then + octave_tar_flags="${octave_tar_flags:+$octave_tar_flags }$octave_tar_flag" + fi + done + rm -f conftest.tar conftest.txt + REPRODUCIBLE_TAR_FLAGS="$octave_tar_flags" + fi + AC_SUBST(REPRODUCIBLE_TAR_FLAGS) + AC_MSG_RESULT([$REPRODUCIBLE_TAR_FLAGS]) +]) +dnl dnl Check for texi2dvi. dnl AC_DEFUN([OCTAVE_PROG_TEXI2DVI], [