version.sh 995 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. #
  3. # determine-version -- report a useful version for releases
  4. #
  5. # Copyright 2008, Aron Griffis <agriffis@n01se.net>
  6. # Copyright 2008, Oracle
  7. # Released under the GNU GPLv2
  8. v="v0.15"
  9. which hg > /dev/null
  10. if [ -d .hg ] && [ $? == 0 ]; then
  11. last=$(hg tags | grep -m1 -o '^v[0-9.]\+')
  12. # now check if the repo has commits since then...
  13. if [[ $(hg id -t) == $last || \
  14. $(hg di -r "$last:." | awk '/^diff/{print $NF}' | sort -u) == .hgtags ]]
  15. then
  16. # check if it's dirty
  17. if [[ $(hg id | cut -d' ' -f1) == *+ ]]; then
  18. v=$last+
  19. else
  20. v=$last
  21. fi
  22. else
  23. # includes dirty flag
  24. v=$last+$(hg id -i)
  25. fi
  26. fi
  27. echo "#ifndef __BUILD_VERSION" > .build-version.h
  28. echo "#define __BUILD_VERSION" >> .build-version.h
  29. echo "#define BTRFS_BUILD_VERSION \"Btrfs $v\"" >> .build-version.h
  30. echo "#endif" >> .build-version.h
  31. diff -q version.h .build-version.h >& /dev/null
  32. if [ $? == 0 ]; then
  33. rm .build-version.h
  34. exit 0
  35. fi
  36. mv .build-version.h version.h