diff --git a/.gitignore b/.gitignore index 6972b555e..700198116 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.pc.tmp *-uninstalled.pc /version.h +/_dist autom4te.cache config.cache diff --git a/Makefile b/Makefile index bbba897f3..227010a8e 100644 --- a/Makefile +++ b/Makefile @@ -92,41 +92,22 @@ HTSPREFIX = include htslib_vars.mk -PACKAGE_VERSION = 1.4.1 +PACKAGE_VERSION := $(shell ./version.sh) LIBHTS_SOVERSION = 2 - # $(NUMERIC_VERSION) is for items that must have a numeric X.Y.Z string # even if this is a dirty or untagged Git working tree. -NUMERIC_VERSION = $(PACKAGE_VERSION) - -# If building from a Git repository, replace $(PACKAGE_VERSION) with the Git -# description of the working tree: either a release tag with the same value -# as $(PACKAGE_VERSION) above, or an exact description likely based on a tag. -# Much of this is also GNU Make-specific. If you don't have GNU Make and/or -# are not building from a Git repository, comment out this conditional. -ifneq "$(wildcard .git)" "" -original_version := $(PACKAGE_VERSION) -PACKAGE_VERSION := $(shell git describe --always --dirty) - -# Unless the Git description matches /\d*\.\d*(\.\d*)?/, i.e., is exactly a tag -# with a numeric name, revert $(NUMERIC_VERSION) to the original version number -# written above, but with the patchlevel field bumped to 255. -ifneq "$(subst ..,.,$(subst 0,,$(subst 1,,$(subst 2,,$(subst 3,,$(subst 4,,$(subst 5,,$(subst 6,,$(subst 7,,$(subst 8,,$(subst 9,,$(PACKAGE_VERSION))))))))))))" "." -empty := -NUMERIC_VERSION := $(subst $(empty) ,.,$(wordlist 1,2,$(subst ., ,$(original_version))) 255) -endif +NUMERIC_VERSION := $(shell ./version.sh numeric) # Force version.h to be remade if $(PACKAGE_VERSION) has changed. version.h: $(if $(wildcard version.h),$(if $(findstring "$(PACKAGE_VERSION)",$(shell cat version.h)),,force)) -endif version.h: echo '#define HTS_VERSION "$(PACKAGE_VERSION)"' > $@ -print-version: - @echo $(PACKAGE_VERSION) - +version: + @echo PACKAGE_VERSION = $(PACKAGE_VERSION) + @echo NUMERIC_VERSION = $(NUMERIC_VERSION) .SUFFIXES: .bundle .c .cygdll .dll .o .pico .so @@ -479,6 +460,7 @@ clean: mostlyclean clean-$(SHLIB_FLAVOUR) distclean maintainer-clean: clean -rm -f config.cache config.h config.log config.mk config.status -rm -f TAGS *.pc.tmp *-uninstalled.pc htslib_static.mk + -rm -f _dist clean-so: -rm -f libhts.so libhts.so.* @@ -501,13 +483,54 @@ tags TAGS: # (The wildcards attempt to omit non-exported files (.git*, README.md, # etc) and other detritus that might be in the top-level directory.) distdir: - tar -c *.[ch15] [ILMNRcht]*[ELSbcekmnt] | (cd $(distdir) && tar -x) + @if [ -z "$(distdir)" ]; then echo "Please supply a distdir=DIR argument."; false; fi + tar -c *.[ch15] [ILMNRchtv]*[ELSbcekmnth] | (cd $(distdir) && tar -x) +cd $(distdir) && $(MAKE) distclean + +# Making tarballs for distribution. +# All changes should be committed before running this. +DDIR=htslib-$(PACKAGE_VERSION) +DTAR=$(DDIR).tar.bz2 + +# NB: make sure you run this on a committed branch as uncommitted changes +# will not be copied. +# +# To do: should we scan through the git repository to copy modification dates? +$(DTAR) dist: + -rm -rf _dist + if [ -e .git ]; then \ + mkdir -p _dist/$(DDIR); \ + git archive HEAD . | (cd _dist/$(DDIR) && tar xf -); \ + else \ + tf=`tempfile`; \ + tar cf $$tf .; \ + (mkdir -p _dist/$(DDIR); cd _dist/$(DDIR) && tar xf $$tf; rm $$tf); \ + rm -f _dist/$(DDIR)/*.pc.tmp _dist/$(DDIR)/htslib_static.mk; \ + fi + (cd _dist/$(DDIR) && autoreconf && rm -rf autom4te.cache) + (cd _dist; tar cfj ../$(DTAR) $(DDIR)) + rm -rf _dist + +# Make and extract the distribution tarball followed by configure, make +# and check. We then rebuild the tar ball again to validate it matches +# the original one. This validates our make dist can cope with debris +# left behind from a build and that everything is successfully committed. +distcheck: $(DTAR) + -mkdir _dist + cd _dist && tar xjf ../$(DTAR) + cd _dist/htslib-* && ./configure $${CONFIG_OPTS:-} && $(MAKE) && $(MAKE) check + cd _dist/htslib-* && $(MAKE) distclean && $(MAKE) dist + tar tvf $(DTAR) |awk '{sub("^[^/]*/","",$$6);print $$6,$$3}' | sort > _dist/curr.lst + tar tvf _dist/htslib-*/htslib-*.tar.bz2 |awk '{sub("^[^/]*/","",$$6);print $$6,$$3}' | sort > _dist/sub.lst + diff _dist/*.lst + -rm -rf _dist + + force: -.PHONY: all check clean distclean distdir force +.PHONY: all check clean distclean distdir dist distcheck force .PHONY: install install-pkgconfig installdirs lib-shared lib-static .PHONY: maintainer-clean mostlyclean plugins print-config print-version .PHONY: tags test testclean diff --git a/configure.ac b/configure.ac index ba15331a3..3af05a5e0 100644 --- a/configure.ac +++ b/configure.ac @@ -23,7 +23,7 @@ # DEALINGS IN THE SOFTWARE. dnl Process this file with autoconf to produce a configure script -AC_INIT([HTSlib], m4_esyscmd_s([make print-version]), +AC_INIT([HTSlib], m4_esyscmd_s([./version.sh 2>/dev/null]), [samtools-help@lists.sourceforge.net], [], [http://www.htslib.org/]) AC_PREREQ(2.63) dnl This version introduced 4-argument AC_CHECK_HEADER AC_CONFIG_SRCDIR(hts.c) diff --git a/version.sh b/version.sh new file mode 100755 index 000000000..8655ce025 --- /dev/null +++ b/version.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# Master version, for use in tarballs or non-git source copies +VERSION=1.4.1 + +# If we have a git clone, then check against the current tag +if [ -e .git ] +then + # If we ever get to 10.x this will need to be more liberal + VERSION=`git describe --match '[0-9].[0-9]*' --dirty` +fi + +# Numeric version is for use in .dylib or .so libraries +# +# Follows the same logic from the Makefile commit c2e93911 +# as non-numeric versions get bumped to patch level 255 to indicate +# an unknown value. +if [ "$1" = "numeric" ] +then + v1=`expr "$VERSION" : '\([0-9]*\)'` + v2=`expr "$VERSION" : '[0-9]*.\([0-9]*\)'` + v3=`expr "$VERSION" : '[0-9]*.[0-9]*.\([0-9]*\)'` + if [ -z "`expr "$VERSION" : '^\([0-9.]*\)$'`" ] + then + VERSION="$v1.$v2.255" + else + VERSION="$v1.$v2${v3:+.}$v3" + fi +fi + +echo $VERSION