1 Instructions for hacking on Xapian
2 ==================================
4 This file is aimed to help developers get started with working on
5 Xapian. The Xapian SourceForge project page is at
6 <http://sourceforge.net/projects/xapian/>, and contains various tools
9 Extra options to give to configure:
10 ===================================
12 Note: Non-developer configure options are described in INSTALL
14 You will probably want to use some of these if you're going to be developing
18 This enables compiling of assertion code, to produce warnings if
19 the code gets into an unexpected state, and also compiling into
20 the system of debugging symbols.
22 --enable-debug=partial
23 This option enables debugging symbols, and some assertions. It does
24 not enable verbose debugging messages or very expensive assertions.
26 --enable-debug-verbose
27 This enables compiling into the system of code to generate verbose
28 debugging messages. See "Debugging Messages", below.
31 This is the same as --enable-debug --enable-debug-verbose
36 Lots of places in the code generate debugging messages to tell us what
37 they're up to, and this information can be very useful. However, its got
38 to such a stage that we need to be able to turn it on and off easily: and
39 so I've set up a system for controlling the debugging output by means of
40 environment variables. You can:
42 o) set OM_DEBUG_FILE to be the path to a file that you would like debugging
43 output to be stored in (to override the default of stderr).
45 o) set OM_DEBUG_TYPES to a bitmap to select the types of debugging message
46 you would like to display. Currently, all messages are selected by
47 setting bit 0 (ie, OM_DEBUG_TYPES=1), but they will be differentiated
48 into separate classes in future.
50 Of course, if you didn't compile with --enable-debug=full, these environment
51 variables will have no effect.
53 Debugging memory allocations
54 ============================
56 The testsuite's leak checking has unfortunately proved not to work well with
57 many STL implementations, and it gives spurious reports. For the time being
58 we've removed it, and suggest using a third party product to trap leaks.
60 Building with various profiling and leak-finding tools:
61 =======================================================
63 For use with valgrind, no special build flags are required. You just need to
64 run the program to be checked with valgrind, e.g.:
66 env srcdir=. valgrind ./apitest -v deldoc1
68 To enable profiling for gprof (was --enable-profiling):
70 env CFLAGS=-pg CXXFLAGS=-pg LDFLAGS=-pg ./configure
72 To use Purify (was --enable-purify):
74 env CXXLD='purify c++' CCLD='purify cc' ./configure --disable-shared
76 To use Insure (was --enable-insure):
78 env CXX=insure CC=insure ./configure
83 The CVS repository does not contain any automatically generated files
84 (such as configure and Makefile.in's). Because of this, you need to run
85 several programs to build these files, before you can run the normal
88 At the time of writing, these programs are autoconf, automake, libtool,
89 and GNU bison. Some older versions of these programs may not work correctly:
90 at the time of writing, the versions known to work are:
92 automake (GNU automake) 1.5
93 This is required as automake 1.4 has problems with "make dist"
94 in a VPATH build, and doesn't support AM_CFLAGS/AM_CXXFLAGS.
95 Note that automake 1.6 has a bug which causes it to emit
96 spurious warnings: this is fixed in automake 1.6.1.
99 Needed for many things.
101 ltmain.sh (GNU libtool) 1.3.3
103 GNU Bison version 1.35
104 Bison versions 1.31 to 1.34 don't handle parsequery.yy - for
105 a summary of the gory details, see this (note this isn't a
106 debian specific bug though):
108 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=130914
110 There are apparently some bugs in earlier versions, which
111 might affect us, so we require at least 1.35.
115 Please tell us if you find that older (or newer) versions work or fail to work.
117 We have provided a simple standard script to run these programs for you:
118 simply run ${source-directory}/buildall, in the same way you would normally
119 run configure. Arguments passed to buildall are in turn passed on to configure.
121 You may need to add extra macro directories to the path searched by aclocal
122 (which is part of autoconf) - you may do this by specifying these in the
123 ACLOCAL_FLAGS environment variable.
125 See "buildall --help" for more information. Alternatively, there is a
126 good overview of the GNU autotools at <http://sources.redhat.com/autobook/>.
128 Miscellaneous Portability Issues:
129 =================================
131 open() and <fcntl.h>:
132 ---------------------
134 No C++ file should explicitly "#include <fcntl.h>".
136 When largefile support is enabled, Solaris' fcntl.h will "#define open open64"
137 which breaks C++ code which has methods called open. There's a cunning way
138 to avoid this problem, which is implemented in common/utils.h.
140 Any C++ file which wants to "#include <fcntl.h>" should instead '#include
141 "utils.h"'. For convenience, the open call this defines takes a C++ string,
142 but you can also pass a char* (which will be converted to a C++ string).
144 Warning Free Compilation:
145 -------------------------
147 Compiling without warnings on every platform is our goal, though it's not
148 always possible to achieve. For example, GCC 2.95 produces a few bogus
149 warnings (e.g. about not returning a value from a non-void function).
151 If using GCC 3.0 or newer, you should consider configure-ing with:
153 ./configure CFLAGS=-Werror
155 when doing development work on Xapian. This promotes warnings to errors,
156 and should ensure you don't introduce warnings. If you find out how to
157 do the same with other compilers, please add a note here.
159 Makefile Portability:
160 =====================
162 We don't want to force those building Xapian from the source distribution to
163 have to use GNU make. Requiring GNU make for "make dist" isn't such a problem
164 but it's probably better to use portable constructs everywhere to avoid
165 problems when people move or copy code between targets. If you do make use
166 of non-portable constructs where it's OK, add a comment noting this.
168 Here's an incomplete list of things to avoid:
170 * Don't use "$(RM)" - it's defined by GNU make, but using it actually harms
171 portability as other makes don't define it. Use plain "rm" instead.
173 * Don't use "%" pattern rules - these are GNU make specific. Use an
174 implicit rule (e.g. ".c.o:") if you can. Otherwise, write out each version
177 * Don't use "$<" except in implicit rules. This is an annoying restriction,
178 as using "$<" makes it much easier to make VPATH builds work. But it's only
179 portable in implicit rules. Tips for rewriting - if it's a source file,
182 If it's a generated object file or similar, just write the name as is; if it
183 could be produced by the build, but also goes in the distribution tarball,
184 use this trick to make sure it's found whichever directory it's in:
185 `test -f foo.ext || echo '$(srcdir)/'`foo.ext
187 * Don't use "exit 0" to make a rule fail. Use "false" instead. BSD make
188 doesn't like "exit 0" in a rule.
190 * Don't use make conditionals. Automake offers conditionals which may be
191 of use, and these are implemented to work with any make. See the automake
192 manual for details, and a few caveats.
194 * The list of portable utilities is:
195 cat cmp cp diff echo egrep expr false grep install-info
196 ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true
197 Note that versions of these (GNU versions in particular) support switches
198 which aren't portable - notably, "test -r" isn't portable; neither is
199 "cp -a". And note that "mkdir -p" isn't portable - the semantics vary.
200 See the "Goat Book" for more details and other useful tips:
201 http://sources.redhat.com/autobook/
203 * Don't use "include" - it's not present in BSD make (at least some versions
204 have ".include" instead, but that doesn't really seem to help...) Automake
205 provides a configure-time include, which may provide a replacement for some
208 And lastly a style point - using "@" to suppress outputing of commands being
209 executed removes choice from the user - they may want to see what commands
210 are being executed. And if they don't want to, they can use "make -s" (in
211 many versions of make).
213 Using @echo on a message sent to stdout or stderr is acceptable. Otherwise
214 don't use "@" - it makes it harder to track down problems in the makefiles.
219 Use Asserts to perform internal consistency checks, and to check for invalid
220 arguments to functions and methods (e.g. passing a NULL pointer when this isn't
221 permitted). They should *NOT* be used to check for error conditions such as
222 file read errors, new returning 0, etc (since we want to perform such checks
223 in non-debug builds too).
225 File format errors should also not be tested with Asserts - we want to catch
226 a corrupted database or a malformed input file in a non-debug build too.
228 There are several variants of Assert:
230 Assert(P) -- asserts that expression P is true
231 AssertEq(a,b) -- asserts that expressions a and b are equal [message reports
232 values of a and b, so is more informative than Assert((a)==(b))]
233 AssertNe(a,b) -- asserts a and b are not equal
234 AssertEqDouble(a,b) -- asserts a and b differ by less than DBL_EPSILON
236 AssertParanoid(P) -- a particularly expensive assertion. If you want a build
237 with Asserts enabled, but without a great performance overhead, then
238 passing --enable-debug=partial to configure and AssertParanoids won't
239 be checked, but Asserts will.
244 If you have a patch to fix a problem in Xapian, or to add a new
245 feature, feel free to submit it to us via the SourceForge patch
246 management system. Any major changes should be discussed on the
247 xapian-devel mailing list first:
248 <http://lists.sourceforge.net/mailman/listinfo/xapian-devel>
250 We find patches generated with "diff -puN" easiest to read. If you are
251 working from a CVS copy of the code, you can use "cvs diff -puN" to generate
252 your patch, or put the line "diff -puN" in your ~/.cvsrc file and just use
255 We will however do our best to give proper attribution to you. In
256 particular, if we have used patches from you, or received helpful
257 reports or advice, we will add your name to the AUTHORS file; unless
258 you specifically request us not to. If you see we have forgotten to
259 do this, please draw it to our attention so that we can sort it out.
261 Developers with CVS access:
262 ===========================
264 People who are more seriously involved with the project are likely to
265 have write access to the repository at SourceForge. This section gives
266 the conventions for those developers. In addition to this, obviously
267 you should make sure you update any documentation, especially the
268 inline source code documentation that generates the API docs.
270 1 Make sure the tests are right
271 --------------------------------
273 * If you're adding a feature, also add tests for it.
274 * If you've fixed a bug, make sure there's a regression test which
275 fails on the existing code and succeeds after your changes.
276 * Make sure all existing tests continue to pass.
278 If you don't know how to write tests using the Xapian test rig, then
279 ask. It's reasonably simple once you've done it once. There is a brief
280 introduction to the Xapian test system in docs/tests.txt .
282 2 Make sure the attributions are right
283 ---------------------------------------
285 * If necessary, modify the copyright statement at the top of any
286 files you've altered. If there is no copyright statement, you may
287 add one (there are a couple of Makefile.am's and similar that don't
288 have copyright statements; anything that small doesn't really need
289 one anyway, so it's a judgement call).
290 If you've added files, they should include the GPL boilerplate
292 * If you're not in there, add yourself to the AUTHORS file.
294 3 Create a log entry and commit
295 --------------------------------
297 * Add an entry to the ChangeLog file at the top of the module. The
298 text of this can be identical to the cvs commit message.
299 * Commit to the repository.
301 Then you can update any patch, bug or feature request items in the
302 tracker to indicate that they've been dealt with.