summaryrefslogtreecommitdiff
path: root/glib/update-pcre/update.sh
blob: 69d7f8aa755425134c204c48824dd7462353aefe (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#! /bin/sh

set -e

IN="../update-pcre"
PCRE=$1

if [ "x$PCRE" = x ] || [ "x$PCRE" = x--help ] || [ "x$PCRE" = x-h ]; then
    cat >&2 << EOF

$0 PCRE-DIR

  Updates the local PCRE copy with a different version of the library,
  contained in the directory PCRE-DIR.

  This will delete the content of the local pcre directory, copy the
  necessary files from PCRE-DIR, and generate other needed files, such
  as Makefile.am
EOF
    exit
fi

if [ ! -f gregex.h ]; then
    echo "This script should be executed from the directory containing gregex.c." 2> /dev/null
    exit 1
fi

if [ ! -f "${PCRE}/Makefile.in" ] || [ ! -f "${PCRE}/pcre_compile.c" ]; then
    echo "'${PCRE}' does not contain a valid PCRE version." 2> /dev/null
    exit 1
fi


echo "Deleting old PCRE library"
mv pcre/.svn tmp-pcre-svn
rm -R pcre 2> /dev/null
mkdir pcre
cd pcre

# pcre_chartables.c is generated by dfatables.
# We do not want to compile and execute dfatables.c every time, because
# this could be a problem (e.g. when cross-compiling), so now generate
# the file and then distribute it with GRegex.
echo "Generating pcre_chartables.c"
cp -R "${PCRE}" tmp-build
(
cd tmp-build || exit 1
./configure --enable-utf8 --enable-unicode-properties --disable-cpp > /dev/null
make pcre_chartables.c > /dev/null
cat > ../pcre_chartables.c << \EOF
/* This file is autogenerated by ../update-pcre/update.sh during
 * the update of the local copy of PCRE.
 */
EOF
cat pcre_chartables.c >> ../pcre_chartables.c
)
rm -R tmp-build

# Compiled C files.
echo "Generating makefiles"
all_files=$(awk '/^OBJ = /, /^\\s*$/ ' \
                '{' \
                    'sub("^OBJ = ", "");' \
                    'sub(".@OBJEXT@[[:blank:]]*\\\\\\\\", "");' \
                    'sub("\\\\$\\\\(POSIX_OBJ\\\\)", "");' \
                    'print;' \
                '}' \
            "${PCRE}/Makefile.in")

# Headers.
included_files="pcre.h pcre_internal.h ucp.h ucpinternal.h"

# Generate Makefile.am.
cat $IN/Makefile.am-1 > Makefile.am
for name in $all_files; do
    echo "	$name.c \\" >> Makefile.am
    if [ "${name}" != pcre_chartables ]; then
        # pcre_chartables.c is a generated file.
        cp "${PCRE}/${name}.c" .
    fi
done
for f in $included_files; do
    echo "	$f \\" >> Makefile.am
    cp "${PCRE}/${f}" .
done
cat $IN/Makefile.am-2 >> Makefile.am

echo "Patching PCRE"

# Copy the license.
cp "${PCRE}/COPYING" .

# Use glib for memory allocation.
patch > /dev/null < $IN/memory.patch

# Copy the modified version of pcre_valid_utf8.c.
cp $IN/pcre_valid_utf8.c .

# Copy the modified version of pcre_ucp_searchfuncs.c that uses glib
# for Unicode properties.
cp $IN/pcre_ucp_searchfuncs.c .
patch > /dev/null < $IN/ucp.patch

# Remove the digitab array in pcre_compile.c.
patch > /dev/null < $IN/digitab.patch
sed -i -e 's/(digitab\[\(.*\)\] & ctype_digit)/g_ascii_isdigit(\1)/' pcre_compile.c
sed -i -e 's/(digitab\[\(.*\)\] & ctype_xdigit)/g_ascii_isxdigit(\1)/' pcre_compile.c

# Reduce the number of relocations.
python $IN/make_utt.py
patch > /dev/null < $IN/utt.patch
patch > /dev/null < $IN/table-reduction.patch

# Copy back the old SVN directory.
mv ../tmp-pcre-svn .svn


cat << EOF

Update completed. You now should check that everything is working.
Remember to update the regex syntax doc with the new features
(docs/reference/glib/regex-syntax.sgml) and to run the tests.
EOF