Create new-version.sh to help with releases, update INSTALL instructions
[platform/upstream/fontconfig.git] / new-version.sh
1 #!/bin/sh
2
3 test=echo
4 if git-status > /dev/null; then
5         :
6 else
7         echo 'Uncommited changes in repository' 1>&2
8         exit 1
9 fi
10
11 version="$1"
12 case "$version" in
13 2.[0-9.]*)
14         ;;
15 *)
16         echo 'Invalid version number:' "$version" 1>&2
17         exit 1
18         ;;
19 esac
20
21 eval `echo $version | 
22         awk -F. '{ printf ("major=%d\nminor=%d\nrevision=%d\n",
23                            $1, $2, $3); }'`
24                            
25 # Update the version numbers
26
27 $test sed -i configure.in "/^AM_INIT_AUTOMAKE/s/2\.[0-9.]*/$version/"
28
29 $test sed -i fontconfig/fontconfig.h \
30         -e "/^#define FC_MAJOR/s/[0-9]*/$major/" \
31         -e "/^#define FC_MINOR/s/[0-9]*/$minor/" \
32         -e "/^#define FC_REVISION/s/[0-9]*/$revision/"
33
34 #
35 # Compute pretty form of new version number
36 #
37 version_note=`echo $version | awk -F. '{ 
38         if ($3 > 90) 
39                 printf ("%d.%d.%d (%d.%d RC%d)\n",
40                         $1, $2, $3, $1, $2 + 1, $3 - 90);
41         else if ($3 == 0)
42                 printf ("%d.%d\n", $1, $2);
43         else
44                 printf ("%d.%d.%d\n", $1, $2, $3); }'`
45                 
46 #
47 # Find previous version in README
48 #
49 last_note=`grep '^2\.[0-9.]*' README |
50         head -1 |
51         sed 's/ (2\.[0-9]* RC[0-9]*)//'`
52 case $last_note in
53 2.*.*)
54         last=$last_note
55         ;;
56 2.*)
57         last="$last_note.0"
58         ;;
59 *)
60         echo 'cannot find previous changelog' 1>&2
61         exit 1
62 esac
63
64 #
65 # Format the current date for the README header
66 #
67 date=`date '+%Y-%m-%d'`
68
69 #
70 # Update the readme file
71
72 if [ $version != $last ]; then
73         #
74         # header
75         #
76         (sed '/^2\.[0-9.]*$/,$d' README | 
77                 sed -e "s/Version.*/Version $version_note/" \
78                     -e "s/200.*/$date/" | awk '
79                     /^[ \t]/ {
80                                 gsub ("^[ \t]*", "");
81                                 gsub ("[ \t]*$", "");
82                                 space=(70 - length) / 2;
83                                 for (i = 0; i < space; i++)
84                                         printf (" ");
85                                 print 
86                                 next
87                               } 
88                               { 
89                                 print 
90                               }'
91         
92         #
93         # changelog
94         #
95         
96         echo $version_note
97         echo
98         git-log --pretty=short $last.. | git-shortlog | cat
99         
100         #
101         # previous changelogs
102         #
103         
104         sed -n '/^2\.[0-9.]*$/,$p' README) > README.tmp ||
105                 (echo "README update failed"; exit 1)
106         
107         $test mv README.tmp README
108 fi
109
110 $test git-commit -m"Bump version to $version" \
111         configure.in \
112         fontconfig/fontconfig.h \
113         README
114
115 # tag the tree
116 $test git-tag -u 096c4dd3 -m"Version $version" $version
117
118 # Make distributed change log
119
120 $test "git-log --stat $last.. > ChangeLog-$version"
121