Stop saying 'can't open-code test of unknown type'.
[sbcl.git] / generate-version.sh
blob6d1fe9996db5dd4b71af2a8a1e1103376a827cb0
1 #!/bin/sh
3 git_available_p() {
4 # Check that (1) we have git (2) this is a git tree.
5 if ( command -v git >/dev/null && git describe >/dev/null 2>/dev/null && \
6 test -f `git rev-parse --show-toplevel`/run-sbcl.sh)
7 then
8 echo "ok"
9 else
10 echo ""
14 AVAILABLE=`git_available_p`
15 if [ -f version.lisp-expr -a -z "$AVAILABLE" ]
16 then
17 # Release tarball, leave version.lisp-expr alone.
18 exit 0
19 elif [ -z "$AVAILABLE" ]
20 then
21 echo "Can't 'git describe' SBCL source and version.lisp-expr is missing." >&2
22 echo "To fix this, either install git or create a fake version.lisp-expr file." >&2
23 echo "You can create a fake version.lisp-expr file like this:" >&2
24 echo " \$ echo '\"1.0.99.999\"' > version.lisp-expr" >&2
25 exit 1
27 # Build it.
28 version_head=`git rev-parse HEAD`
29 if grep -q "ref: refs/heads/.*" .git/HEAD > /dev/null 2>&1
30 then
31 version_branchname=`cut -d / -f 3- < .git/HEAD`
32 else
33 # Detached head.
34 version_branchname="HEAD"
36 if [ -z "$SBCL_BUILDING_RELEASE_FROM" ]
37 then
38 version_root=`git merge-base HEAD origin/master`
39 else
40 version_root="$SBCL_BUILDING_RELEASE_FROM"
42 version_base=`git rev-parse "$version_root"`
43 version_tag=`git describe --tags --match="sbcl*" --abbrev=0 $version_base`
44 version_release=`echo $version_tag | sed -e 's/sbcl[_-]//' | sed -e 's/_/\./g'`
45 # Using wc -l instead of --count argument to rev-list because
46 # pre-1.7.2 Gits are still common out in the wilderness.
47 version_n_root=`git rev-list $version_base --not $version_tag | wc -l | sed -e 's/[ \t]//g'`
48 version_n_branch=`git rev-list HEAD --not $version_base | wc -l | sed -e 's/[ \t]//g'`
49 if [ -z "$NO_GIT_HASH_IN_VERSION" ]
50 then
51 version_hash="-`git rev-parse --short $version_head`"
52 else
53 version_hash=""
55 if git diff HEAD --no-ext-diff --quiet --exit-code
56 then
57 version_dirty=""
58 else
59 version_dirty="-WIP"
61 # Now that we have all the pieces, put them together.
62 cat >version.lisp-expr <<EOF
63 ;;; This file is auto-generated using generate-version.sh. Every time
64 ;;; you re-run make.sh, this file will be overwritten if you are
65 ;;; working from a Git checkout.
66 EOF
67 if [ "$version_base" = "$version_head" ]
68 then
69 if [ "0" = "$version_n_root" ]
70 then
71 printf "\"%s%s\"\n" \
72 $version_release $version_dirty >>version.lisp-expr
73 else
74 printf "\"%s.%s%s%s\"\n" \
75 $version_release $version_n_root \
76 $version_hash $version_dirty >>version.lisp-expr
78 else
79 echo "base=$version_base"
80 echo "head=$version_head"
81 printf "\"%s.%s.%s.%s%s%s\"\n" \
82 $version_release $version_n_root \
83 $version_branchname $version_n_branch \
84 $version_hash $version_dirty >>version.lisp-expr