Implement make dist target

Add dist target to create project tarball. It uses a script called
version, that was obtained from vpp source code to produce a version
string using `git describe` that is incremental based on last annotated
tag available.
This commit is contained in:
Renato Botelho do Couto 2017-12-05 04:00:54 -06:00
parent 3dd4903f88
commit e7b1c0c38c
4 changed files with 90 additions and 0 deletions

2
.gitignore vendored
View file

@ -43,3 +43,5 @@ include/clixon_config.h
lib/src/build.c
lib/clixon/clixon.h
build-root/*.tar.xz

View file

@ -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

1
build-root/scripts/version Symbolic link
View file

@ -0,0 +1 @@
../../extras/scripts/version

53
extras/scripts/version Executable file
View file

@ -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