Add GRegex for regular expression matching. (#50075)
[platform/upstream/glib.git] / glib / update-pcre / update.sh
1 #! /bin/sh
2
3 IN="../update-pcre"
4 PCRE=$1
5
6 if [ "x$PCRE" = x -o "x$PCRE" = x--help -o "x$PCRE" = x-h ]; then
7     cat >&2 << EOF
8
9 $0 PCRE-DIR
10
11   Updates the local PCRE copy with a different version of the library,
12   contained in the directory PCRE-DIR.
13
14   This will delete the content of the local pcre directory, copy the
15   necessary files from PCRE-DIR, and generate other needed files, such
16   as Makefile.am
17 EOF
18     exit
19 fi
20
21 if [ ! -f gregex.h ]; then
22     echo "This script should be executed from the directory containing gregex.c." 2> /dev/null
23     exit 1
24 fi
25
26 if [ ! -f $PCRE/Makefile.in -o ! -f $PCRE/pcre_compile.c ]; then
27     echo "'$PCRE' does not contain a valid PCRE version." 2> /dev/null
28     exit 1
29 fi
30
31
32 echo "Deleting old PCRE library"
33 mv pcre/.svn tmp-pcre-svn
34 rm -R pcre 2> /dev/null
35 mkdir pcre
36 cd pcre
37
38 # pcre_chartables.c is generated by dfatables.
39 # We do not want to compile and execute dfatables.c every time, because
40 # this could be a problem (e.g. when cross-compiling), so now generate
41 # the file and then distribuite it with GRegex.
42 echo "Generating pcre_chartables.c"
43 cp -R $PCRE tmp-build
44 cd tmp-build
45 ./configure --enable-utf8 --enable-unicode-properties --disable-cpp > /dev/null
46 make pcre_chartables.c > /dev/null
47 cat > ../pcre_chartables.c << \EOF
48 /* This file is autogenerated by ../update-pcre/update.sh during
49  * the update of the local copy of PCRE.
50  */
51 EOF
52 cat pcre_chartables.c >> ../pcre_chartables.c
53 cd ..
54 rm -R tmp-build
55
56 # Compiled C files.
57 echo "Generating makefiles"
58 all_files=`awk '/^OBJ = /, /^\\s*$/ \
59             { \
60                 sub("^OBJ = ", ""); \
61                 sub(".@OBJEXT@[[:blank:]]*\\\\\\\\", ""); \
62                 sub("\\\\$\\\\(POSIX_OBJ\\\\)", ""); \
63                 print; \
64             }' \
65             $PCRE/Makefile.in`
66
67 # Headers.
68 included_files="pcre.h pcre_internal.h ucp.h ucpinternal.h"
69
70 # Generate Makefile.am.
71 cat $IN/Makefile.am-1 > Makefile.am
72 for name in $all_files; do
73     echo "      $name.c \\" >> Makefile.am
74     if [ $name != pcre_chartables ]; then
75         # pcre_chartables.c is a generated file.
76         cp $PCRE/$name.c .
77     fi
78 done
79 for f in $included_files; do
80     echo "      $f \\" >> Makefile.am
81     cp $PCRE/$f .
82 done
83 cat $IN/Makefile.am-2 >> Makefile.am
84
85 # Generate makefile.msc
86 cat > makefile.msc << EOF
87 !IFDEF DEBUG
88 CRT=-MDd
89 !ELSE
90 CRT=-MD
91 !ENDIF
92
93 CFLAGS = \\
94         -I ..\\.. \\
95         -DHAVE_CONFIG_H \\
96         -DHAVE_LONG_LONG_FORMAT \\
97         -DSUPPORT_UCP \\
98         -DSUPPORT_UTF8 \\
99         -DNEWLINE=10 \\
100         -DMATCH_LIMIT=10000000 \\
101         -DMATCH_LIMIT_RECURSION=10000000 \\
102         -DMAX_NAME_SIZE=32 \\
103         -DMAX_NAME_COUNT=10000 \\
104         -DMAX_DUPLENGTH=30000 \\
105         -DLINK_SIZE=2 \\
106         -DEBCDIC=0 \\
107         -DPOSIX_MALLOC_THRESHOLD=10
108
109 OBJECTS = \\
110 `
111 for f in $all_files; do
112     echo "      $f.obj \\\\"
113 done
114 `
115
116 pcre.lib : \$(OBJECTS)
117         lib -out:pcre.lib \$(OBJECTS)
118
119 .c.obj:
120         \$(CC) \$(CRT) \$(CFLAGS) -Ox -GD -c $<
121 EOF
122
123 echo "Patching PCRE"
124
125 # Copy the license.
126 cp $PCRE/COPYING .
127
128 # Use glib for memory allocation.
129 patch > /dev/null < $IN/memory.patch
130
131 # Copy the modified version of pcre_valid_utf8.c.
132 cp $IN/pcre_valid_utf8.c .
133
134 # Copy the modified version of pcre_ucp_searchfuncs.c that uses glib
135 # for Unicode properties.
136 cp $IN/pcre_ucp_searchfuncs.c .
137 patch > /dev/null < $IN/ucp.patch
138
139 # Remove the digitab array in pcre_compile.c.
140 patch > /dev/null < $IN/digitab.patch
141 sed -i -e 's/(digitab\[\(.*\)\] & ctype_digit)/g_ascii_isdigit(\1)/' pcre_compile.c
142 sed -i -e 's/(digitab\[\(.*\)\] & ctype_xdigit)/g_ascii_isxdigit(\1)/' pcre_compile.c
143
144 # Reduce the number of relocations.
145 $IN/make_utt.py
146 patch > /dev/null < $IN/utt.patch
147 patch > /dev/null < $IN/table-reduction.patch
148
149 # Copy back the old SVN directory.
150 mv ../tmp-pcre-svn .svn
151
152
153 cat << EOF
154
155 Update completed. You now should check that everything is working.
156 Remember to update the regex syntax doc with the new features
157 (docs/reference/glib/regex-syntax.sgml) and to run the tests.
158 EOF
159