summaryrefslogtreecommitdiff
path: root/dist/s_sql_upgrade
blob: e515442ce71cf67ea3022ee7f5d7c302fbbabc6b (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
#!/bin/sh
#
# This script needs to be run when upgrading the version of SQLite, it
# automates the process as much as possible
#
# The first step is to replace the files in the sql/sqlite directory with those
# from the latest release.
# Once that is done - run this script, review the changes, and push to the
# central server.

sqldir=../lang/sql/sqlite

copy_if_changes()
{
	f1="$1"
	f2="$2"
	cmp $f1 $f2 > /dev/null 2>&1 ||
	(rm -f $f1 && cp $f2 $f1)
	rm -f $f2
}

# Check or recheck-and-apply each patch
try_patches()
{
	doit=$1
	for f in $sqldir/../adapter/sqlite-patches/[0-9][0-9]_*.patch ; do
		msgs=$( patch -d $sqldir -p0 --dry-run --force < $f 2>&1 )
		if test $? -ne 0 ;  then
			echo "Patch $f would fail:"
			echo "$msgs" | sed -e 's/^/	/'
			echo "Exiting."
			exit 1
		else
			if test $doit = 1 ; then
				echo "Applying patch $f"
				patch -d $sqldir -p0 --force --quiet < $f
			fi
		fi
	done
}

# echo "Testing patch files for the sqlite source tree."
# try_patches 0

# Update the SQLite Makefile to refer to the replaced source files.
MAKEFILE_NAME=$sqldir/Makefile.in
for f in ../lang/sql/adapter/*.[ch]; do
	short_f=`basename $f`
	sed -e "s/\$(TOP)\/src\/$short_f/\$(TOP)\/..\/adapter\/$short_f/g" $MAKEFILE_NAME > $MAKEFILE_NAME.tmp
	copy_if_changes $MAKEFILE_NAME $MAKEFILE_NAME.tmp
done
# Update the include path so that headers in sql/adapter dir can be found.
sed -e '/^TCC/s/-I\. -I${TOP}\/src/& -I${TOP}\/..\/adapter -I${TOP}\/ext\/fts3/' $MAKEFILE_NAME > $MAKEFILE_NAME.tmp
copy_if_changes $MAKEFILE_NAME $MAKEFILE_NAME.tmp

# We will be building from a different directory level, update the makefile
# accordingly.
sed -e 's/TOP = \.\.\/sqlite/TOP = \.\.\/\.\.\/sql\/sqlite/' $sqldir/Makefile.linux-gcc > $sqldir/Makefile.linux-gcc.tmp
copy_if_changes $sqldir/Makefile.linux-gcc $sqldir/Makefile.linux-gcc.tmp

echo "Applying patch files to the sqlite source tree."
try_patches 1

# Remove files from the SQLite source tree that have been replaced by db.
( cd $sqldir/../adapter &&
for f in *c *h ; do
	rm -f ../sqlite/src/$f
done
)