root/gs2-extensions/tdb/trunk/enable_tdb.sh @ 30257

Revision 30257, 9.3 KB (checked in by jmt12, 5 years ago)

Correcting and optimizing for GS3 (which needs fewer paths to be included)

  • Property svn:executable set to *
Line 
1#!/bin/bash
2# Used to merge in the code needed to add TDB support to Greenstone. The script
3# is responsible for updating both Makefile.in and source code files. You can
4# later run 'disable_tdb.sh' to undo these changes.
5# @author John Thompson, University of Waikato, NZ
6
7echo
8echo '===== Merging TDB support code into Greenstone ====='
9echo
10
11# Test that GSDLHOME is set otherwise we won't be able to find the required files
12if [ "${GSDLHOME}x" == "x" ]
13then
14    echo 'Error! GSDLHOME not set. Please source setup.bash before running.'
15    echo
16    exit 0
17fi
18if [ "${GSDLOS}x" == "x" ]
19then
20    echo 'Error! GSDLOS not set. Please source setup.bash before running.'
21    echo
22    exit 0
23fi
24
25# Black magic to determine the actual name of the extension folder (in case I
26# change from tdb-edit to tdb in the future (writing in hindsight))
27EXTDIR="${PWD}"
28EXTNAME="${PWD##*/}"
29
30# - Symlink the source file into place
31printf ' * Symlinking TDB source files into place... '
32if [ -f "${GSDLHOME}/common-src/src/lib/tdbclass.h" ]
33then
34    echo 'already present'
35else
36    ln -f -s "${EXTDIR}/src/lib/tdbclass.h" "${GSDLHOME}/common-src/src/lib/tdbclass.h"
37    ln -f -s "${EXTDIR}/src/lib/tdbclass.cpp" "${GSDLHOME}/common-src/src/lib/tdbclass.cpp"
38    echo 'Done!'
39fi
40
41# - Makefile.in
42printf ' * Enabling TDB support in common function library... '
43MAKEFILE="${GSDLHOME}/common-src/src/lib/Makefile.in"
44# - I have no idea why this is commented out in the Makefile
45sed -i 's:#GSDL_DIR = ../../..:GSDL_DIR = ../../..:' "${MAKEFILE}"
46grep -q 'DUSE_TDB' "${MAKEFILE}"
47if [ $? -eq 1 ]
48then
49    # - Test for extension support in the makefile
50    grep -q 'EXT_DEFINES' "${MAKEFILE}"
51    if [ $? -eq 1 ]
52    then
53    # - No Extension variables yet - add them in with TDB parts
54    sed -i 's:AR = ar:# Support for adding in extension classes\nEXT_DEFINES = -DUSE_TDB\nEXT_INCLUDES = -I'${EXTDIR}'/'${GSDLOS}'/include\nEXT_SOURCES = tdbclass.cpp\nEXT_OBJECTS = tdbclass.o\n\n&:' "${MAKEFILE}"
55    sed -i 's:DEFS = @DEFS@ .*:& $(EXT_DEFINES):' "${MAKEFILE}"
56    sed -i 's:INCLUDES = -I. .*:& $(EXT_INCLUDES):' "${MAKEFILE}"
57    sed -i 's:unitool.cpp:& \\\n        $(EXT_SOURCES):' "${MAKEFILE}"
58    sed -i 's:unitool.o:& \\\n        $(EXT_OBJECTS):' "${MAKEFILE}"
59    else
60    # - Extension support already present - add TDB parts
61    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' "${MAKEFILE}"
62    sed -i 's:EXT_INCLUDES =.*:& -I'${EXTDIR}'/'${GSDLOS}'/include:' "${MAKEFILE}"
63    sed -i 's:EXT_SOURCES =.*:& tdbclass.cpp:' "${MAKEFILE}"
64    sed -i 's:EXT_OBJECTS =.*:& tdbclass.o:' "${MAKEFILE}"
65    fi
66    echo 'Done!'
67else
68    echo 'already enabled'
69fi
70grep -q 'DUSE_TDB' "${MAKEFILE}"
71if [ $? -eq 1 ]
72then
73  echo "Error! Update of ${MAKEFILE} failed."
74  exit
75fi
76
77# No runtime support needed for Greenstone3 - that's done via JNI
78if [ "${GSDL3HOME}x" == "x" ]
79then
80    printf ' * Enabling TDB support in collection server... '
81    # - Makefile.in
82    MAKEFILE="${GSDLHOME}/runtime-src/src/colservr/Makefile.in"
83    grep -q 'DUSE_TDB' "${MAKEFILE}"
84    if [ $? -eq 1 ]
85    then
86    # - Test for extension support in the makefile
87    grep -q 'EXT_DEFINES' "${MAKEFILE}"
88    if [ $? -eq 1 ]
89    then
90        sed -i 's:AR = ar:# Support for adding in extension classes\nEXT_DEFINES = -DUSE_TDB\nEXT_INCLUDES = -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib\n\n&:' "${MAKEFILE}"
91        sed -i 's:DEFS = @DEFS@:& $(EXT_DEFINES):' "${MAKEFILE}"
92        sed -i 's:INCLUDES = -I. -I$(GSDL_DIR):& $(EXT_INCLUDES):' "${MAKEFILE}"
93    else
94        sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' "${MAKEFILE}"
95        sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib:' "${MAKEFILE}"
96    fi
97    echo 'Done!'
98    else
99    echo 'already enabled'
100    fi
101    grep -q 'DUSE_TDB' "${MAKEFILE}"
102    if [ $? -eq 1 ]
103    then
104    echo "Error! Update of ${MAKEFILE} failed."
105    exit
106    fi
107
108    # - collectset.cpp
109    SRCFILE="${GSDLHOME}/runtime-src/src/colservr/collectset.cpp"
110    grep -q 'tdbclass.h' "${SRCFILE}"
111    if [ $? -eq 1 ]
112    then
113    grep -q '@EXTENSION HEADERS@' "${SRCFILE}"
114    if [ $? -eq 1 ]
115    then
116        sed -i 's:collectset\:\:collectset (text_t& gsdlhome, text_t& collecthome):// @EXTENSION HEADERS@\n#include "tdbclass.h //TDB\n\n&:' "${SRCFILE}"
117        sed -i 's:    // Use GDBM if the infodb type is empty or not one of the values above:    // @EXTENSION DATASOURCES@\n    if (infodbtype == "tdb") {db_ptr = new tdbclass(gsdlhome);} //TDB\n    if (infodbtype == "tdbserver") {db_ptr = new tdbclass(gsdlhome);} //TDBServer\n\n&:' "${SRCFILE}"
118    else
119        sed -i 's:// @EXTENSION HEADERS@:&\n#include "tdbclass.h" //TDB:' "${SRCFILE}"
120        sed -i 's:// @EXTENSION DATASOURCES@:&\n    if (infodbtype == "tdb") {db_ptr = new tdbclass(gsdlhome);} //TDB\n    if (infodbtype == "tdbserver") {db_ptr = new tdbclass(gsdlhome);} //TDBServer:' "${SRCFILE}"
121    fi
122    fi
123    grep -q 'tdbclass.h' "${SRCFILE}"
124    if [ $? -eq 1 ]
125    then
126    echo "Error! Update of ${SRCFILE} failed."
127    exit
128    fi
129
130    # - collectserver.cpp
131    # There are now sanity tests in collectserver to ensure appropriate indexer
132    # and infodbtype are compiled into colservr.  While not fatal to leave this
133    # as is, it does cause vast amounts of error messages in (Apache) logs
134    SRCFILE="${GSDLHOME}/runtime-src/src/colservr/collectserver.cpp"
135    grep -q 'TDB' "${SRCFILE}"
136    if [ $? -eq 1 ]
137    then
138    grep -q '@EXTENSION DATASOURCES@' "${SRCFILE}"
139    if [ $? -eq 1 ]
140    then
141        sed -i 's:  if (infodbtype=="gdbm") {:  // @EXTENSION DATASOURCES@\n  if (infodbtype == "tdb") { return; } // TDB Do nothing\n  if (infodbtype == "tdbserver") { return; } // TDBServer Do nothing\n\n&:' "${SRCFILE}"
142    else
143        sed -i 's:  // @EXTENSION DATASOURCES@:&\n  if (infodbtype == "tdb") { return; } // TDB Do nothing\n  if (infodbtype == "tdbserver") { return; } // TDBServer Do nothing:' "${SRCFILE}"
144    fi
145    fi
146    grep -q 'TDB' "${SRCFILE}"
147    if [ $? -eq 1 ]
148    then
149    echo "Error! Update of ${SRCFILE} failed."
150    exit
151    fi
152
153    printf ' * Enabling TDB support in Greenstone receptionist... '
154    # - Makefile.in
155    MAKEFILE="${GSDLHOME}/runtime-src/src/recpt/Makefile.in"
156    grep -q 'DUSE_TDB' "${MAKEFILE}"
157    if [ $? -eq 1 ]
158    then
159    grep -q 'EXT_DEFINES' "${MAKEFILE}"
160    if [ $? -eq 1 ]
161    then
162        sed -i 's:AR = ar:# Support for adding in extension classes\nEXT_DEFINES = -DUSE_TDB\nEXT_INCLUDES = -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib\nEXT_LDFLAGS = -L$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/lib\nEXT_LIBS = -ltdb\n\n&:' "${MAKEFILE}"
163        sed -i 's:DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DHAVE_CONFIG_H:& $(EXT_DEFINES):' "${MAKEFILE}"
164        sed -i 's:INCLUDES = -I. -I$(GSDL_DIR):& $(EXT_INCLUDES):' "${MAKEFILE}"
165        sed -i 's:LDFLAGS = @LDFLAGS@ @ARCH_DEP_FLAGS@:& $(EXT_LDFLAGS):' "${MAKEFILE}"
166        sed -i 's:LIBS = @LIBS@ $(GDBM_LIBS):& $(EXT_LIBS):' "${MAKEFILE}"
167    else
168        sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' "${MAKEFILE}"
169        sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib:' "${MAKEFILE}"
170        sed -i 's:EXT_LDFLAGS =.*:& -L$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/lib:' "${MAKEFILE}"
171        sed -i 's:EXT_LIBS =.*:& -ltdb:' "${MAKEFILE}"
172    fi
173    echo 'Done!'
174    else
175    echo 'already enabled'
176    fi
177    grep -q 'DUSE_TDB' "${MAKEFILE}"
178    if [ $? -eq 1 ]
179    then
180    echo "Error! Update of ${MAKEFILE} failed."
181    fi
182
183    printf ' * Enabling TDB support in OAI Server receptionist... '
184    # - Makefile.in
185    MAKEFILE="${GSDLHOME}/runtime-src/src/oaiservr/Makefile.in"
186    grep -q 'DUSE_TDB' "${MAKEFILE}"
187    if [ $? -eq 1 ]
188    then
189    grep -q 'EXT_DEFINES' "${MAKEFILE}"
190    if [ $? -eq 1 ]
191    then
192        sed -i 's:CC = @CC@:# Support for adding in extension classes\nEXT_DEFINES = -DUSE_TDB\nEXT_INCLUDES = -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib\nEXT_LDFLAGS = -L$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/lib\nEXT_LIBS = -ltdb\n\n&:' "${MAKEFILE}"
193        sed -i 's:DEFS = @DEFS@:& $(EXT_DEFINES):' "${MAKEFILE}"
194        sed -i 's:INCLUDES = -I$(COMMON_DIR)/src/lib:& $(EXT_INCLUDES):' "${MAKEFILE}"
195        sed -i 's:LDFLAGS = @LDFLAGS@ @ARCH_DEP_FLAGS@:& $(EXT_LDFLAGS):' "${MAKEFILE}"
196        sed -i 's:LIBS = @LIBS@ $(GDBM_LIBS):& $(EXT_LIBS):' "${MAKEFILE}"
197    else
198        sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' "${MAKEFILE}"
199        sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib:' "${MAKEFILE}"
200        sed -i 's:EXT_LDFLAGS =.*:& -L$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/lib:' "${MAKEFILE}"
201        sed -i 's:EXT_LIBS =.*:& -ltdb:' "${MAKEFILE}"
202    fi
203    echo 'Done!'
204    else
205    echo 'already enabled'
206    fi
207    grep -q 'DUSE_TDB' "${MAKEFILE}"
208    if [ $? -eq 1 ]
209    then
210    echo "Error! Update of ${MAKEFILE} failed."
211    fi
212else
213    echo " * Runtime TDB support delegated to Java/JNI/TDB bridge."
214fi
215
216echo
217echo '===================================================='
218echo
219echo 'TDB support has now been merged into Greenstone.'
220echo 'Please return to the main Greenstone directory and '
221echo 'rerun:'
222echo
223if [ "${GSDL3HOME}x" == "x" ]
224then
225    echo ' ./configure <any required arguments>'
226    echo ' make'
227    echo ' make install'
228else
229    echo ' ant install'
230fi
231echo
232echo 'to complete TDB installation.'
233echo
234echo 'Should you later wish to remove TDB support run:'
235echo
236echo ' ./disable_tdb.sh'
237echo
238echo '===================================================='
239echo
240
241exit 0
Note: See TracBrowser for help on using the browser.