Skip to content
Snippets Groups Projects
Commit f6ca38cf authored by Assaf Gordon's avatar Assaf Gordon
Browse files

Second attemp at automatic versioning system.

Handles missing ".git" repository, and GitHub's "Download as ZIP" builds
parent a5cfc589
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@
SHELL := /bin/bash -e
VERSION_FILE=./src/utils/version/version_git.h
RELEASED_VERSION_FILE=./src/utils/version/version_release.txt
# define our object and binary directories
......@@ -78,7 +79,7 @@ UTIL_SUBDIRS = $(SRC_DIR)/utils/bedFile \
BUILT_OBJECTS = $(OBJ_DIR)/*.o
all: print_banner $(OBJ_DIR) $(BIN_DIR) $(UTIL_SUBDIRS) $(SUBDIRS)
all: print_banner $(OBJ_DIR) $(BIN_DIR) autoversion $(UTIL_SUBDIRS) $(SUBDIRS)
@echo "- Building main bedtools binary."
@$(CXX) $(CXXFLAGS) -c src/bedtools.cpp -o obj/bedtools.o -I$(UTIL_DIR)/version/
@$(CXX) $(LDFLAGS) $(CXXFLAGS) -o $(BIN_DIR)/bedtools $(BUILT_OBJECTS) -L$(UTIL_DIR)/BamTools/lib/ -lbamtools $(LIBS)
......@@ -127,15 +128,75 @@ test: all
.PHONY: test
#.PHONY: gitversion
version:
@( BEDTOOLS_VERSION="" ; \
[ -e "$(VERSION_FILE)" ] && BEDTOOLS_VERSION=$$(grep "define VERSION_GIT " "$(VERSION_FILE)" | cut -f3 -d" " | sed 's/"//g') ; \
GIT_VERSION=$$(git describe --always --tags --dirty) ; \
echo "BEDTOOLS_VERSION = $$BEDTOOLS_VERSION" ; \
echo "GIT_VERSION = $$GIT_VERSION" ; \
if [ "$${GIT_VERSION}" != "$${BEDTOOLS_VERSION}" ] ; then \
mkdir -p ./src/utils/version ; \
## For BEDTools developers (not users):
## When you want to release (and tag) a new version, run:
## $ make setversion VERSION=v2.17.2
## This will:
## 1. Update the "/src/utils/version/version_release.txt" file
## 2. Commit the file
## 3. Git-Tag the commit with the latest version
##
.PHONY: setversion
setversion:
ifeq "$(VERSION)" ""
$(error please set VERSION variable to the new version (e.g "make setversion VERSION=v2.17.2"))
endif
@echo "# This file was auto-generated by running \"make setversion VERSION=$(VERSION)\"" > "$(RELEASED_VERSION_FILE)"
@echo "# on $$(date) ." >> "$(RELEASED_VERSION_FILE)"
@echo "# Please do not edit or commit this file manually." >> "$(RELEASED_VERSION_FILE)"
@echo "#" >> "$(RELEASED_VERSION_FILE)"
@echo "$(VERSION)" >> $(RELEASED_VERSION_FILE)
@git add $(RELEASED_VERSION_FILE)
@git commit -q -m "Setting Release-Version $(VERSION)"
@git tag "$(VERSION)"
@echo "Version updated to $(VERSION)."
@echo ""
@echo "Don't forget to push the commits AND the tags:"
@echo " git push --all --tags"
@echo ""
## Automatic version detection
##
## What's going on here?
## 1. If there's a ".git" repository - use the version from the repository.
## ignore any released-version file. git repository is authorative.
##
## 2, If there's no ".git" repository,
## get the "released" version number from the release-version file.
##
## 2.1. If the current directory looks like "arq5x-bedtools-XXXXXXX",
## assume "-XXXXXX" is the last revision number (and the user
## probably downloaded the ZIP from github).
## Append the revision number to the released version string.
##
## 3. Compare the detected version (from steps 1,2) to the current string
## in ./src/utils/version/version_git.h .
## If they differ, update the header file - will cause a recompilation
## of version.o .
##
.PHONY: autoversion
autoversion:
@( \
if [ -d "./git" ] && $$(which git) ; then \
DETECTED_VERSION=$$(git describe --always --tags --dirty) ; \
else \
DETECTED_VERSION=$$(grep -v "^#" "$(RELEASED_VERSION_FILE)") ; \
if basename $$(pwd) | grep -q "^[[:alnum:]]*-bedtools-[[:alnum:]]*$$" ; then \
DETECTED_VERSION=$${DETECTED_VERSION}-zip-$$(basename "$$(pwd)" | sed 's/^[[:alnum:]]*-bedtools-//') ; \
fi ; \
fi ; \
\
CURRENT_VERSION="" ; \
[ -e "$(VERSION_FILE)" ] && CURRENT_VERSION=$$(grep "define VERSION_GIT " "$(VERSION_FILE)" | cut -f3 -d" " | sed 's/"//g') ; \
\
echo "DETECTED_VERSION = $$DETECTED_VERSION" ; \
echo "CURRENT_VERSION = $$CURRENT_VERSION" ; \
if [ "$${DETECTED_VERSION}" != "$${CURRENT_VERSION}" ] ; then \
echo "Updating version file." ; \
printf "#ifndef VERSION_GIT_H\n#define VERSION_GIT_H\n\n#define VERSION_GIT \"$${GIT_VERSION}\"\n\n#endif /* VERSION_GIT_H */\n" > $(VERSION_FILE) ; \
echo "#ifndef VERSION_GIT_H" > $(VERSION_FILE) ; \
echo "#define VERSION_GIT_H" >> $(VERSION_FILE) ; \
echo "#define VERSION_GIT \"$${DETECTED_VERSION}\"" >> $(VERSION_FILE) ; \
echo "#endif /* VERSION_GIT_H */" >> $(VERSION_FILE) ; \
fi )
#ifndef VERSION_GIT_H
#define VERSION_GIT_H
#define VERSION_GIT "v2.16.0"
#endif /* VERSION_GIT_H */
# This file was auto-generated by running "make setversion VERSION=v2.16.0.tagTest"
# on Fri Mar 9 13:50:40 EST 2012 .
# Please do not edit or commit this file manually.
#
v2.16.0.tagTest
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment