From 66c1b59ea170032f54441fed39a3ed255070c400 Mon Sep 17 00:00:00 2001
From: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Date: Tue, 13 Nov 2018 16:58:13 +0000
Subject: Most library versions are now also checked

All the libraries that define their version string as a macro in their
headers are now also checked in `reproduce/src/make/initialize.mk'.

Also, the CFITSIO tarball now follows the same versioning style as the rest
of the tarballs: a script is added to convert the version string into what
is included in the tarball.
---
 reproduce/src/make/dependencies.mk | 65 +++++++++++++++++++---------------
 reproduce/src/make/initialize.mk   | 72 ++++++++++++++++++++++++++------------
 2 files changed, 87 insertions(+), 50 deletions(-)

(limited to 'reproduce/src')

diff --git a/reproduce/src/make/dependencies.mk b/reproduce/src/make/dependencies.mk
index fdc30a1..1a0a5d1 100644
--- a/reproduce/src/make/dependencies.mk
+++ b/reproduce/src/make/dependencies.mk
@@ -72,25 +72,31 @@ LD_LIBRARY_PATH := $(ildir):$(LD_LIBRARY_PATH)
 # --------
 #
 # All the necessary tarballs are defined and prepared with this rule.
-tarballs = $(foreach t, bash-$(bash-version).tar.gz                 \
-	                cfitsio$(cfitsio-version).tar.gz            \
-                        cmake-$(cmake-version).tar.gz               \
-                        coreutils-$(coreutils-version).tar.xz       \
-                        curl-$(curl-version).tar.gz                 \
-	                gawk-$(gawk-version).tar.gz                 \
-	                ghostscript-$(ghostscript-version).tar.gz   \
-	                git-$(git-version).tar.xz                   \
-	                gnuastro-$(gnuastro-version).tar.lz         \
-	                grep-$(grep-version).tar.xz                 \
-	                gsl-$(gsl-version).tar.gz                   \
-	                jpegsrc.$(libjpeg-version).tar.gz           \
-                        tiff-$(libtiff-version).tar.gz              \
-	                libtool-$(libtool-version).tar.gz           \
-                        libgit2-$(libgit2-version).tar.gz           \
-	                sed-$(sed-version).tar.xz                   \
-	                make-$(make-version).tar.gz                 \
-	                wcslib-$(wcslib-version).tar.bz2            \
-                        zlib-$(zlib-version).tar.gz                 \
+#
+# Note that we want the tarballs to follow the convention of NAME-VERSION
+# before the `tar.XX' prefix. For those programs that don't follow this
+# convention, but include the name/version in their tarball names with
+# another format, we'll do the modification before the download so the
+# downloaded file has our desired format.
+tarballs = $(foreach t, bash-$(bash-version).tar.gz                   \
+	                cfitsio-$(cfitsio-version).tar.gz             \
+                        cmake-$(cmake-version).tar.gz                 \
+                        coreutils-$(coreutils-version).tar.xz         \
+                        curl-$(curl-version).tar.gz                   \
+	                gawk-$(gawk-version).tar.gz                   \
+	                ghostscript-$(ghostscript-version).tar.gz     \
+	                git-$(git-version).tar.xz                     \
+	                gnuastro-$(gnuastro-version).tar.lz           \
+	                grep-$(grep-version).tar.xz                   \
+	                gsl-$(gsl-version).tar.gz                     \
+	                jpegsrc.$(libjpeg-version).tar.gz             \
+                        tiff-$(libtiff-version).tar.gz                \
+	                libtool-$(libtool-version).tar.gz             \
+                        libgit2-$(libgit2-version).tar.gz             \
+	                sed-$(sed-version).tar.xz                     \
+	                make-$(make-version).tar.gz                   \
+	                wcslib-$(wcslib-version).tar.bz2              \
+                        zlib-$(zlib-version).tar.gz                   \
                       , $(tdir)/$(t) )
 $(tarballs): $(tdir)/%:
 	if [ -f $(DEPENDENCIES-DIR)/$* ]; then
@@ -98,13 +104,21 @@ $(tarballs): $(tdir)/%:
 	else
           # Remove all numbers, `-' and `.' from the tarball name so we can
           # search more easily only with the program name.
-	  n=$$(echo $* | sed -e's/[0-9\-]/ /g' -e's/\./ /g'         \
+	  n=$$(echo $* | sed -e's/[0-9\-]/ /g' -e's/\./ /g'           \
 	               | awk '{print $$1}' )
 
           # Set the top download link of the requested tarball.
 	  mergenames=1
 	  if   [ $$n = bash        ]; then w=http://ftp.gnu.org/gnu/bash
-	  elif [ $$n = cfitsio     ]; then w=https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c
+	  elif [ $$n = cfitsio     ]; then
+	    mergenames=0
+	    v=$$(echo $(cfitsio-version) | sed -e's/\.//'             \
+	              | awk '{l=length($1);                           \
+	                      printf (l==4 ? "%d\n"                   \
+	                              : (l==3 ? "%d0\n"               \
+	                                 : (l==2 ? "%d00\n"           \
+                                            : "%d000\n") ), $$1)}')
+	    w=https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio$$v.tar.gz
 	  elif [ $$n = cmake       ]; then w=https://cmake.org/files/v3.12
 	  elif [ $$n = coreutils   ]; then w=http://ftp.gnu.org/gnu/coreutils
 	  elif [ $$n = curl        ]; then w=https://curl.haxx.se/download
@@ -142,12 +156,7 @@ $(tarballs): $(tdir)/%:
 	  else                           tarballurl=$$w
 	  fi
 	  echo "Downloading $$tarballurl"
-	  if [ $$mergenames = 1 ]; then
-	    $(DOWNLOADER) $@ $$tarballurl
-	  else
-	    $(DOWNLOADER) $@_tmp $$tarballurl
-	    mv $@_tmp $@
-	  fi
+	  $(DOWNLOADER) $@ $$tarballurl
 	fi
 
 
@@ -182,7 +191,7 @@ cbuild = cd $(ddir); rm -rf $(2); tar xf $(tdir)/$(1); cd $(2);      \
 
 # Libraries
 # ---------
-$(ildir)/libcfitsio.a: $(tdir)/cfitsio$(cfitsio-version).tar.gz         \
+$(ildir)/libcfitsio.a: $(tdir)/cfitsio-$(cfitsio-version).tar.gz         \
                        $(ildir)/libcurl.a                               \
                        $(ibdir)/ls
 	$(call gbuild,$(subst $(tdir),,$<), cfitsio, static,            \
diff --git a/reproduce/src/make/initialize.mk b/reproduce/src/make/initialize.mk
index b8d71c6..563462f 100644
--- a/reproduce/src/make/initialize.mk
+++ b/reproduce/src/make/initialize.mk
@@ -147,16 +147,28 @@ distclean: clean
 
 # Check the version of programs which write their version
 # -------------------------------------------------------
-vercheck = prog="$(strip $(1))";                                          \
-	   ver="$(strip $(2))";                                           \
-	   name="$(strip $(3))";                                          \
-	   macro="$(strip $(4))";                                         \
-	   v=$$($$prog --version | awk '/'$$ver'/{print "y"}');           \
-	   if [ x$$v != xy ]; then                                        \
-	     echo; echo "PIPELINE ERROR: Not running $$name $$ver"; echo; \
-	     exit 1;                                                      \
-	   fi;                                                            \
-	   echo "\newcommand{\\$$macro}{$$ver}" >> $@
+pvcheck = prog="$(strip $(1))";                                          \
+	  ver="$(strip $(2))";                                           \
+	  name="$(strip $(3))";                                          \
+	  macro="$(strip $(4))";                                         \
+	  v=$$($$prog --version | awk '/'$$ver'/{print "y"}');           \
+	  if [ x$$v != xy ]; then                                        \
+	    echo; echo "PIPELINE ERROR: Not running $$name $$ver"; echo; \
+	    exit 1;                                                      \
+	  fi;                                                            \
+	  echo "\newcommand{\\$$macro}{$$ver}" >> $@
+
+lvcheck = idir=$(BDIR)/dependencies/installed/include;                   \
+	  f="$$idir/$(strip $(1))";                                      \
+	  ver="$(strip $(2))";                                           \
+	  name="$(strip $(3))";                                          \
+	  macro="$(strip $(4))";                                         \
+	  v=$$(awk '$$1=="\#define" && /'$$ver'/ {print "y"}' $$f);      \
+	  if [ x$$v != xy ]; then                                        \
+	    echo; echo "PIPELINE ERROR: Not linking with $$name $$ver";  \
+	    echo; exit 1;                                                \
+	  fi;                                                            \
+	  echo "\newcommand{\\$$macro}{$$ver}" >> $@
 
 
 
@@ -175,17 +187,33 @@ $(mtexdir)/initialize.tex: | $(mtexdir)
 	echo "\newcommand{\pipelineversion}{$$v}"  > $@
 	@echo "\newcommand{\bdir}{$(BDIR)}"       >> $@
 
-        # Versions of programs (same order as `dependency-versions.mk').
-	$(call vercheck, bash, $(bash-version), GNU Bash, bashversion)
-	$(call vercheck, cmake, $(cmake-version), CMake, cmakeversion)
-	$(call vercheck, ls, $(coreutils-version), GNU Coreutils,       \
+        # Versions of programs (same order as 'dependency-versions.mk').
+	$(call pvcheck, bash, $(bash-version), GNU Bash, bashversion)
+	$(call pvcheck, cmake, $(cmake-version), CMake, cmakeversion)
+	$(call pvcheck, ls, $(coreutils-version), GNU Coreutils,       \
                          coreutilsversion)
-	$(call vercheck, awk, $(gawk-version), GNU AWK, gawkversion)
-	$(call vercheck, gs, $(ghostscript-version), GPL Ghostscript,   \
-	                 ghostscriptversion)
-	$(call vercheck, git, $(git-version), Git, gitversion)
-	$(call vercheck, astnoisechisel, $(gnuastro-version), Gnuastro, \
+	$(call pvcheck, awk, $(gawk-version), GNU AWK, gawkversion)
+	$(call pvcheck, gs, $(ghostscript-version), GPL Ghostscript,   \
+	                    ghostscriptversion)
+	$(call pvcheck, git, $(git-version), Git, gitversion)
+	$(call pvcheck, astnoisechisel, $(gnuastro-version), Gnuastro, \
                          gnuastroversion)
-	$(call vercheck, grep, $(grep-version), GNU Grep, grepversion)
-	$(call vercheck, make, $(make-version), GNU Make, makeversion)
-	$(call vercheck, sed, $(sed-version), GNU SED, sedversion)
+	$(call pvcheck, grep, $(grep-version), GNU Grep, grepversion)
+	$(call pvcheck, libtool, $(libtool-version), GNU Libtool,      \
+	                libtoolversion)
+	$(call pvcheck, make, $(make-version), GNU Make, makeversion)
+	$(call pvcheck, sed, $(sed-version), GNU SED, sedversion)
+
+        # Versions of libraries.
+	$(call lvcheck, fitsio.h, $(cfitsio-version), CFITSIO, cfitsioversion)
+        ########## Curl library not yet checked.
+	$(call lvcheck, gsl/gsl_version.h, $(gsl-version),  \
+	                GNU Scientific Library (GSL), gslversion)
+        ########## libjpeg not  yet checked.
+	$(call lvcheck, git2/version.h, $(libgit2-version), Libgit2, \
+	                libgitwoversion)
+	$(call lvcheck, tiffvers.h, $(libtiff-version), Libtiff, \
+	                libtiffversion)
+	$(call lvcheck, wcslib/wcsconfig.h, $(wcslib-version), WCSLIB, \
+	                wcslibversion)
+	$(call lvcheck, zlib.h, $(zlib-version), zlib, zlibversion)
-- 
cgit v1.2.1