summaryrefslogtreecommitdiff
path: root/tools/update-patchv
blob: ea04c310908c90231226d5b38b0128f3d7f1d7cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh

# Run this script from the top or tools directory to update some files
# before a patch is built.

set -e

LC_ALL=C
export LC_ALL

if [ $# -ne 1 ]; then
  echo >&2 "Usage: $0 <patchnumber>"
  exit 1
fi

dir=`pwd`
[ -d src ] || [ "`basename "$dir"`" != tools ] || cd ..

replace()
{
  if [ ! -h "$2" ] && [ -r "$2" ] && [ -w "$2" ]; then
    err=`perl -pi -e "$1" "$2" 2>&1 >/dev/null`
    if [ -n "$err" ]; then
      printf >&2 "Error from perl:\n%s\n" "$err"
      exit 2
    fi
  else
    printf >&2 "Error: %s is not a readable/writable file\n" "$2"
    exit 2
  fi
}

vers="`perl -pe 's/^(\d+\.\d+\.\d+).*/\1/' VERSION`"
if [ -z "$vers" ]; then
  echo >&2 "Error: could not get the current MPFR version"
  exit 2
fi

full="${vers}-p$1"
echo $full > VERSION

replace "s/(?<=#define MPFR_VERSION_STRING ).*/\"$full\"/" src/mpfr.h
replace "s/(?<=return \").*\"/$full\"/" src/version.c
replace "s/(?<=#if ).*/0/" tests/tversion.c

echo "MPFR version successfully updated."