summaryrefslogtreecommitdiff
path: root/glib/update-pcre/update.sh
blob: 960b4d21d65b698d416b63c0dc87f2088b1aed5a (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#! /bin/sh

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

if [ "x$PCRE" = x -o "x$PCRE" = x--help -o "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 -o ! -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 distribuite it with GRegex.
echo "Generating pcre_chartables.c"
cp -R $PCRE tmp-build
cd tmp-build
./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
cd ..
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

# Generate makefile.msc
cat > makefile.msc << EOF
TOP = ..\..\..
!INCLUDE ..\..\build\win32\make.msc

INCLUDES = \\
	-I ..\.. \\
	-I ..
	
DEFINES = \\
	-DPCRE_STATIC \\
	-DHAVE_CONFIG_H \\
	-DHAVE_LONG_LONG_FORMAT \\
	-DSUPPORT_UCP \\
	-DSUPPORT_UTF8 \\
	-DNEWLINE=-1 \\
	-DMATCH_LIMIT=10000000 \\
	-DMATCH_LIMIT_RECURSION=10000000 \\
	-DMAX_NAME_SIZE=32 \\
	-DMAX_NAME_COUNT=10000 \\
	-DMAX_DUPLENGTH=30000 \\
	-DLINK_SIZE=2 \\
	-DEBCDIC=0 \\
	-DPOSIX_MALLOC_THRESHOLD=10

OBJECTS = \\
`
for f in $all_files; do
    echo "	$f.obj \\\\"
done
`

all : pcre.lib

pcre.lib : \$(OBJECTS)
	lib -out:pcre.lib \$(OBJECTS)
EOF

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