Fix make-array transforms.
[sbcl.git] / generate-version.sh
1 #!/bin/sh
2 # Not a shell script, but something intended to be sourced from shell scripts
3 git_available_p() {
4     # Check that (1) we have git (2) this is a git tree.
5     if ( which git >/dev/null 2>/dev/null && git describe >/dev/null 2>/dev/null )
6     then
7         echo "ok"
8     else
9         echo ""
10     fi
11 }
12
13 generate_version() {
14     AVAILABLE=`git_available_p`
15     if [ -f version.lisp-expr -a -z "$AVAILABLE" ]
16     then
17         # Relase tarball, leave version.lisp-expr alone.
18         return
19     elif [ -z "$AVAILABLE" ]
20     then
21         echo "Can't run 'git describe' 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
26     fi
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"
35     fi
36     if [ -z "$SBCL_BUILDING_RELEASE_FROM" ]
37     then
38         if [ "`git rev-list HEAD --not origin/master`" = '' ]
39         then
40             # If origin/master contains all the commits on current
41             # branch, use current head as the root instead.
42             version_root="$version_branchname"
43         else
44             version_root="origin/master"
45         fi
46     else
47         version_root="$SBCL_BUILDING_RELEASE_FROM"
48     fi
49     version_base=`git rev-parse "$version_root"`
50     version_tag=`git describe --tags --match="sbcl*" --abbrev=0 $version_base`
51     version_release=`echo $version_tag | sed -e 's/sbcl[_-]//' | sed -e 's/_/\./g'`
52     # Using wc -l instead of --count argument to rev-list because
53     # pre-1.7.2 Gits are still common out in the wilderness.
54     version_n_root=`git rev-list $version_base --not $version_tag | wc -l`
55     version_n_branch=`git rev-list HEAD --not $version_base | wc -l`
56     if [ -z "$NO_GIT_HASH_IN_VERSION" ]
57     then
58         version_hash="-`git rev-parse --short $version_head`"
59     else
60         version_hash=""
61     fi
62     if git diff HEAD --no-ext-diff --quiet --exit-code
63     then
64         version_dirty=""
65     else
66         version_dirty="-dirty"
67     fi
68     # Now that we have all the pieces, put them together.
69     cat >version.lisp-expr <<EOF
70 ;;; This file is auto-generated using generate-version.sh. Every time
71 ;;; you re-run make.sh, this file will be overwritten if you are
72 ;;; working from a Git checkout.
73 EOF
74     if [ "$version_base" = "$version_head" ]
75     then
76         if [ "0" = "$version_n_root" ]
77         then
78             printf "\"%s%s\"\n" \
79                 $version_release $version_dirty >>version.lisp-expr
80         else
81             printf "\"%s.%s%s%s\"\n" \
82                 $version_release $version_n_root \
83                 $version_hash $version_dirty >>version.lisp-expr
84         fi
85     else
86         echo "base=$version_base"
87         echo "head=$version_head"
88         printf "\"%s.%s.%s.%s%s%s\"\n" \
89             $version_release $version_n_root \
90             $version_branchname $version_n_branch \
91             $version_hash $version_dirty >>version.lisp-expr
92     fi
93 }