updated to clean up compiler issues with how functions were used from basis namespace;
[feisty_meow.git] / scripts / generator / next_version.sh
1 #!/bin/bash
2
3 # increments the build version number.
4
5 mkdir -p "$TEMPORARIES_DIR"
6
7 export PARAMETER_FILE
8 if [ ! -z "$BUILD_PARAMETER_FILE" ]; then
9   # define our version of the build parameter file.  this should be set
10   # beforehand so we override the default parameter file for clam.
11   PARAMETER_FILE="$BUILD_PARAMETER_FILE"
12 fi
13 if [ -z "$PARAMETER_FILE" ]; then
14   # last ditch attempt to get one that will work.
15   PARAMETER_FILE="$FEISTY_MEOW_DIR/build.ini"
16 fi
17
18 chmod u+w "$PARAMETER_FILE"
19
20 new_buildini="$(mktemp "$TEMPORARIES_DIR/buildini.XXXXXX")"
21 # whack the file just in case.
22 rm -f "$new_buildini"
23 echo -n "" >"$new_buildini"
24
25 # pick a weird separator that we hope never to see.
26 IFS='~'
27
28 found_version=""
29 skip_line=""
30
31 major_string=
32 minor_string=
33 revision_string=
34
35 while read line_found; do
36   if [ $? != 0 ]; then break; fi
37 #echo line found is $line_found
38   if [ ! -z "$skip_line" ]; then
39     # we were told to skip this line to fix win32.
40     skip_line=""
41     continue
42   fi
43
44   # these checks don't care about whether we've seen other stuff yet.
45   if [ -z "$major_string" ]; then
46     if [ ! -z "$(echo $line_found | sed -n -e 's/^ *major *=.*$/yep/p')" ]; then
47       major_string=$(echo $line_found | sed -e 's/.*=\(.*\)$/\1/' )
48     fi
49   fi
50   if [ -z "$minor_string" ]; then
51     if [ ! -z "$(echo $line_found | sed -n -e 's/^ *minor *=.*$/yep/p')" ]; then
52       minor_string=$(echo $line_found | sed -e 's/.*=\(.*\)$/\1/' )
53     fi
54   fi
55
56   # we process the revision string line specially.
57   if [ -z "$found_version" ]; then
58         if [ "$line_found" == "#[version]" ]; then
59           # repair our special escape that makes this a valid ini file and
60           # gnu make include file.
61           echo -e "#\\\\\n[version]" >>"$new_buildini"
62           found_version="yes"
63       continue
64         elif [ "$line_found" == "#" ]; then
65           # retarded win32 case.
66           echo -e "#\\\\\n[version]" >>"$new_buildini"
67           found_version="yes"
68           skip_line="yes"
69       continue
70         fi
71   elif [ -z "$revision_string" ]; then
72     if [ ! -z "$(echo $line_found | sed -n -e 's/^ *revision *=.*$/yep/p')" ]; then
73       revision_string=$(echo $line_found | sed -e 's/.*=\(.*\)$/\1/' )
74 #echo second part is $revision_string 
75       revision_string=$(expr $revision_string + 1)
76       echo "revision=$revision_string" >>"$new_buildini"
77       # don't print the line normally also.
78       continue
79     fi
80   fi
81
82   # send the line with no special processing.
83   echo "$line_found" >>"$new_buildini"
84
85 done <"$PARAMETER_FILE"
86
87 # if we created something with contents, let's use it.
88 if [ -s "$new_buildini" ]; then
89   cp "$new_buildini" "$PARAMETER_FILE"
90 fi
91
92 echo "New build version is: $major_string.$minor_string.$revision_string"
93
94 # don't leave the temporary version files floating around.
95 rm -f "$new_buildini"
96