diff --git a/.gitignore b/.gitignore index b0920a2a..940d7d51 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,5 @@ include/clixon_config.h lib/src/build.c lib/clixon/clixon.h + +build-root/*.tar.xz diff --git a/Makefile.in b/Makefile.in index 97e1f57b..4ad5ff70 100644 --- a/Makefile.in +++ b/Makefile.in @@ -108,9 +108,43 @@ distclean: rm -f Makefile TAGS config.status config.log *~ .depend rm -rf Makefile autom4te.cache rm -rf clixon.conf.cpp clixon.mk + rm -f build-root/*.tar.xz for i in $(SUBDIRS) doc example docker; \ do (cd $$i && $(MAKE) $(MFLAGS) $@); done +export BR=$(CURDIR)/build-root + +$(BR)/scripts/.version: +ifneq ("$(wildcard /etc/redhat-release)","") + $(shell $(BR)/scripts/version rpm-string > $(BR)/scripts/.version) +else + $(shell $(BR)/scripts/version > $(BR)/scripts/.version) +endif + +DIST_FILE = $(BR)/clixon-$(shell extras/scripts/version).tar +DIST_SUBDIR = clixon-$(shell extras/scripts/version | cut -f1 -d-) + +dist: + @if git rev-parse 2> /dev/null ; then \ + git archive \ + --prefix=$(DIST_SUBDIR)/ \ + --format=tar \ + -o $(DIST_FILE) \ + HEAD ; \ + git describe > $(BR)/.version ; \ + else \ + (cd .. ; tar -cf $(DIST_FILE) $(DIST_SUBDIR) --exclude=*.tar) ; \ + extras/scripts/version > $(BR)/.version ; \ + fi + @tar --append \ + --file $(DIST_FILE) \ + --transform='s,.*/.version,$(DIST_SUBDIR)/extras/scripts/.version,' \ + $(BR)/.version + @$(RM) $(BR)/.version $(DIST_FILE).xz + @xz -v --threads=0 $(DIST_FILE) + @$(RM) $(BR)/clixon-latest.tar.xz + @ln -rs $(DIST_FILE).xz $(BR)/clixon-latest.tar.xz + docker: for i in docker; \ do (cd $$i && $(MAKE) $(MFLAGS) $@); done diff --git a/build-root/scripts/version b/build-root/scripts/version new file mode 120000 index 00000000..0144b7ee --- /dev/null +++ b/build-root/scripts/version @@ -0,0 +1 @@ +../../extras/scripts/version \ No newline at end of file diff --git a/extras/scripts/version b/extras/scripts/version new file mode 100755 index 00000000..d52ca207 --- /dev/null +++ b/extras/scripts/version @@ -0,0 +1,53 @@ +#!/bin/bash +# +# Obtained from VPP - https://wiki.fd.io/view/VPP +# + +path=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P ) + +cd "$path" + +if [ -f .version ]; then + vstring=$(cat .version) +else + vstring=$(git describe) + if [ $? != 0 ]; then + exit 1 + fi +fi + +TAG=$(echo ${vstring} | cut -d- -f1 | sed -e 's/^[vR]//') +ADD=$(echo ${vstring} | cut -s -d- -f2) + +git rev-parse 2> /dev/null +if [ $? == 0 ]; then + CMT=$(git describe --dirty | cut -s -d- -f3,4) +else + CMT=$(echo ${vstring} | cut -s -d- -f3,4) +fi +CMTR=$(echo $CMT | sed 's/-/_/') + +if [ -n "${BUILD_NUMBER}" ]; then + BLD="~b${BUILD_NUMBER}" +fi + +if [ "$1" = "rpm-version" ]; then + echo ${TAG} + exit +fi + +if [ "$1" = "rpm-release" ]; then + [ -z "${ADD}" ] && echo release && exit + echo ${ADD}${CMTR:+~${CMTR}}${BLD} + exit +fi + + if [ -n "${ADD}" ]; then + if [ "$1" = "rpm-string" ]; then + echo ${TAG}-${ADD}${CMTR:+~${CMTR}}${BLD} + else + echo ${TAG}-${ADD}${CMT:+~${CMT}}${BLD} + fi + else + echo ${TAG}-release +fi