root/gs2-extensions/tdb-edit/trunk/src/enable_tdb.sh @ 25412

Revision 25412, 8.4 KB (checked in by jmt12, 9 years ago)

Adding in required cpp code for TDBServer support (using existing TDB interactions - we don't actually support the runtime in a distributed environment... yet)

  • 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" == "" ] ; then echo 'Error! GSDLHOME not set. Please source setup.bash before running.' ; echo ; exit 0 ; fi
13
14echo ' - enabling TDB support in common function library'
15# - Symlink the source file into place
16ln -f -s $GSDLHOME/ext/tdb-edit/src/lib/tdbclass.h $GSDLHOME/common-src/src/lib/tdbclass.h
17ln -f -s $GSDLHOME/ext/tdb-edit/src/lib/tdbclass.cpp $GSDLHOME/common-src/src/lib/tdbclass.cpp
18# - Makefile.in
19MAKEFILE=$GSDLHOME/common-src/src/lib/Makefile.in
20# - I have no idea why this is commented out in the Makefile
21sed -i 's:#GSDL_DIR = ../../..:GSDL_DIR = ../../..:' ${MAKEFILE}
22grep -q 'DUSE_TDB' ${MAKEFILE}
23if [ $? -eq 1 ]
24then
25  # - Test for extension support in the makefile
26  grep -q 'EXT_DEFINES' ${MAKEFILE}
27  if [ $? -eq 1 ]
28  then
29    # - No Extension variables yet - add them in with TDB parts
30    sed -i 's:AR = ar:# Support for adding in extension classes\nEXT_DEFINES = -DUSE_TDB\nEXT_INCLUDES = -I$(GSDL_DIR)/ext/tdb-edit/linux/include -I$(GSDL_DIR)/ext/tdb-edit/darwin/include -I$(GSDL_DIR)/ext/tdb-edit/src/lib\nEXT_SOURCES = tdbclass.cpp\nEXT_OBJECTS = tdbclass.o\n\n&:' ${MAKEFILE}
31    sed -i 's:DEFS = @DEFS@ .*:& $(EXT_DEFINES):' ${MAKEFILE}
32    sed -i 's:INCLUDES = -I. .*:& $(EXT_INCLUDES):' ${MAKEFILE}
33    sed -i 's:unitool.cpp:& \\\n        $(EXT_SOURCES):' ${MAKEFILE}
34    sed -i 's:unitool.o:& \\\n        $(EXT_OBJECTS):' ${MAKEFILE}
35  else
36    # - Extension support already present - add TDB parts
37    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' ${MAKEFILE}
38    sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/tdb-edit/linux/include -I$(GSDL_DIR)/ext/tdb-edit/darwin/include -I$(GSDL_DIR)/ext/tdb-edit/src/lib:' ${MAKEFILE}
39    sed -i 's:EXT_SOURCES =.*:& tdbclass.cpp:' ${MAKEFILE}
40    sed -i 's:EXT_OBJECTS =.*:& tdbclass.o:' ${MAKEFILE}
41  fi
42fi
43grep -q 'DUSE_TDB' ${MAKEFILE}
44if [ $? -eq 1 ]
45then
46  echo Error! Update of ${MAKEFILE} failed.
47  exit
48fi
49
50echo ' - enabling TDB support in collection server'
51# - Makefile.in
52MAKEFILE=$GSDLHOME/runtime-src/src/colservr/Makefile.in
53grep -q 'DUSE_TDB' ${MAKEFILE}
54if [ $? -eq 1 ]
55then
56  # - Test for extension support in the makefile
57  grep -q 'DUSE_TDB' ${MAKEFILE}
58  if [ $? -eq 1 ]
59  then
60    sed -i 's:AR = ar:# Support for adding in extension classes\nEXT_DEFINES = -DUSE_TDB\nEXT_INCLUDES = -I$(GSDL_DIR)/ext/tdb-edit/linux/include -I$(GSDL_DIR)/ext/tdb-edit/darwin/include -I$(GSDL_DIR)/ext/tdb-edit/src/lib\n\n&:' ${MAKEFILE}
61    sed -i 's:DEFS = @DEFS@:& $(EXT_DEFINES):' ${MAKEFILE}
62    sed -i 's:INCLUDES = -I. -I$(GSDL_DIR):& $(EXT_INCLUDES):' ${MAKEFILE}
63  else
64    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' ${MAKEFILE}
65    sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/tdb-edit/linux/include -I$(GSDL_DIR)/ext/tdb-edit/darwin/include -I$(GSDL_DIR)/ext/tdb-edit/src/lib:' ${MAKEFILE}
66  fi
67fi
68grep -q 'DUSE_TDB' ${MAKEFILE}
69if [ $? -eq 1 ]
70then
71  echo Error! Update of ${MAKEFILE} failed.
72  exit
73fi
74
75# - collectset.cpp
76SRCFILE=$GSDLHOME/runtime-src/src/colservr/collectset.cpp
77grep -q 'tdbclass.h' ${SRCFILE}
78if [ $? -eq 1 ]
79then
80  grep -q '@EXTENSION HEADERS@' ${SRCFILE}
81  if [ $? -eq 1 ]
82  then
83    sed -i 's:collectset\:\:collectset (text_t& gsdlhome, text_t& collecthome):// @EXTENSION HEADERS@\n#include "tdbclass.h //TDB\n\n&:' ${SRCFILE}
84    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}
85  else
86    sed -i 's:// @EXTENSION HEADERS@:&\n#include "tdbclass.h" //TDB:' ${SRCFILE}
87    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}
88  fi
89fi
90grep -q 'tdbclass.h' ${SRCFILE}
91if [ $? -eq 1 ]
92then
93  echo Error! Update of ${SRCFILE} failed.
94  exit
95fi
96
97# - collectserver.cpp
98# There are now sanity tests in collectserver to ensure appropriate indexer and
99# infodbtype are compiled into colservr. While not fatal to leave this as is,
100# it does cause vast amounts of error messages in (Apache) logs
101SRCFILE=$GSDLHOME/runtime-src/src/colservr/collectserver.cpp
102grep -q 'TDB' ${SRCFILE}
103if [ $? -eq 1 ]
104then
105  grep -q '@EXTENSION DATASOURCES@' ${SRCFILE}
106  if [ $? -eq 1 ]
107  then
108    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}
109  else
110    sed -i 's:  // @EXTENSION DATASOURCES@:&\n  if (infodbtype == "tdb") { return; } // TDB Do nothing\n  if (infodbtype == "tdbserver") { return; } // TDBServer Do nothing:' ${SRCFILE}
111  fi
112fi
113grep -q 'TDB' ${SRCFILE}
114if [ $? -eq 1 ]
115then
116  echo Error! Update of ${SRCFILE} failed.
117  exit
118fi
119
120echo ' - enabling TDB support in Greenstone receptionist'
121# - Makefile.in
122MAKEFILE=$GSDLHOME/runtime-src/src/recpt/Makefile.in
123grep -q 'DUSE_TDB' ${MAKEFILE}
124if [ $? -eq 1 ]
125then
126  grep -q 'EXT_DEFINES' ${MAKEFILE}
127  if [ $? -eq 1 ]
128  then
129    sed -i 's:AR = ar:# Support for adding in extension classes\nEXT_DEFINES = -DUSE_TDB\nEXT_INCLUDES = -I$(GSDL_DIR)/ext/tdb-edit/linux/include -I$(GSDL_DIR)/ext/tdb-edit/darwin/include -I$(GSDL_DIR)/ext/tdb-edit/src/lib\nEXT_LDFLAGS = -L$(GSDL_DIR)/ext/tdb-edit/linux/lib -L$(GSDL_DIR)/ext/tdb-edit/darwin/lib\nEXT_LIBS = -ltdb\n\n&:' ${MAKEFILE}
130    sed -i 's:DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DHAVE_CONFIG_H:& $(EXT_DEFINES):' ${MAKEFILE}
131    sed -i 's:INCLUDES = -I. -I$(GSDL_DIR):& $(EXT_INCLUDES):' ${MAKEFILE}
132    sed -i 's:LDFLAGS = @LDFLAGS@ @ARCH_DEP_FLAGS@:& $(EXT_LDFLAGS):' ${MAKEFILE}
133    sed -i 's:LIBS = @LIBS@ $(GDBM_LIBS):& $(EXT_LIBS):' ${MAKEFILE}
134  else
135    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' ${MAKEFILE}
136    sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/tdb-edit/linux/include -I$(GSDL_DIR)/ext/tdb-edit/darwin/include -I$(GSDL_DIR)/ext/tdb-edit/src/lib:' ${MAKEFILE}
137    sed -i 's:EXT_LDFLAGS =.*:& -L$(GSDL_DIR)/ext/tdb-edit/linux/lib -L$(GSDL_DIR)/ext/tdb-edit/darwin/lib:' ${MAKEFILE}
138    sed -i 's:EXT_LIBS =.*:& -ltdb:' ${MAKEFILE}
139  fi
140fi
141grep -q 'DUSE_TDB' ${MAKEFILE}
142if [ $? -eq 1 ]
143then
144  echo Error! Update of ${MAKEFILE} failed.
145fi
146
147
148echo ' - enabling TDB support in OAI Server receptionist'
149# - Makefile.in
150MAKEFILE=$GSDLHOME/runtime-src/src/oaiservr/Makefile.in
151grep -q 'DUSE_TDB' ${MAKEFILE}
152if [ $? -eq 1 ]
153then
154  grep -q 'EXT_DEFINES' ${MAKEFILE}
155  if [ $? -eq 1 ]
156  then
157    sed -i 's:CC = @CC@:# Support for adding in extension classes\nEXT_DEFINES = -DUSE_TDB\nEXT_INCLUDES = -I$(GSDL_DIR)/ext/tdb-edit/linux/include -I$(GSDL_DIR)/ext/tdb-edit/darwin/include -I$(GSDL_DIR)/ext/tdb-edit/src/lib\nEXT_LDFLAGS = -L$(GSDL_DIR)/ext/tdb-edit/linux/lib -L$(GSDL_DIR)/ext/tdb-edit/darwin/lib\nEXT_LIBS = -ltdb\n\n&:' ${MAKEFILE}
158    sed -i 's:DEFS = @DEFS@:& $(EXT_DEFINES):' ${MAKEFILE}
159    sed -i 's:INCLUDES = -I$(COMMON_DIR)/src/lib:& $(EXT_INCLUDES):' ${MAKEFILE}
160    sed -i 's:LDFLAGS = @LDFLAGS@ @ARCH_DEP_FLAGS@:& $(EXT_LDFLAGS):' ${MAKEFILE}
161    sed -i 's:LIBS = @LIBS@ $(GDBM_LIBS):& $(EXT_LIBS):' ${MAKEFILE}
162  else
163    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' ${MAKEFILE}
164    sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/tdb-edit/linux/include -I$(GSDL_DIR)/ext/tdb-edit/darwin/include -I$(GSDL_DIR)/ext/tdb-edit/src/lib:' ${MAKEFILE}
165    sed -i 's:EXT_LDFLAGS =.*:& -L$(GSDL_DIR)/ext/tdb-edit/linux/lib -L$(GSDL_DIR)/ext/tdb-edit/darwin/lib:' ${MAKEFILE}
166    sed -i 's:EXT_LIBS =.*:& -ltdb:' ${MAKEFILE}
167  fi
168fi
169grep -q 'DUSE_TDB' ${MAKEFILE}
170if [ $? -eq 1 ]
171then
172  echo Error! Update of ${MAKEFILE} failed.
173fi
174
175echo
176echo '===================================================='
177echo
178echo 'TDB support has now been merged into Greenstone.'
179echo 'Please return to the main Greenstone directory and '
180echo 'rerun:'
181echo
182echo ' ./configure <any required arguments>'
183echo ' make'
184echo ' make install'
185echo
186echo 'to complete TDB installation.'
187echo
188echo '===================================================='
189echo
190
191exit 0
Note: See TracBrowser for help on using the browser.