Debian Codegraph @

HACKING

raw
1 This HACKING file describes the development environment. -*- org -*-
2
3 Copyright (C) 2008, 2009, 2011 ViewPlus Technologies, Inc. and Abilitiessoft, Inc.
4 Copyright (C) 2012, 2013, 2014,2015 Swiss Library for the Blind, Visually Impaired and Print Disabled
5
6 Copying and distribution of this file, with or without modification,
7 are permitted in any medium without royalty provided the copyright
8 notice and this notice are preserved. This file is offered as-is,
9 without any warranty.
10
11 This file attempts to describe the maintainer-specific notes to follow
12 when hacking liblouis.
13
14 * Table of Contents :TOC:
15 - [[#developing][Developing]]
16 - [[#where-to-get-it][Where to get it]]
17 - [[#build-requirements][Build requirements]]
18 - [[#gnulib][Gnulib]]
19 - [[#how-to-build][How to build]]
20 - [[#build-documentation][Build documentation]]
21 - [[#install-with-homebrew][Install with Homebrew]]
22 - [[#docker][Docker]]
23 - [[#how-to-run-tests][How to run tests]]
24 - [[#how-to-debug][How to debug]]
25 - [[#how-to-find-memory-leaks][How to find memory leaks]]
26 - [[#static-analysis][Static analysis]]
27 - [[#how-to-analyze-performance][How to analyze performance]]
28 - [[#how-to-build-for-windows][How to build for Windows]]
29 - [[#release-procedure][Release Procedure]]
30 - [[#update-the-news-entry][Update the NEWS entry]]
31 - [[#set-the-version-number][Set the version number]]
32 - [[#commit-and-tag][Commit and tag]]
33 - [[#make-the-release][Make the release]]
34 - [[#upload][Upload]]
35 - [[#online-documentation][Online documentation]]
36 - [[#web-site-maintenance][Web site maintenance]]
37 - [[#announce][Announce]]
38
39 * Developing
40 ** Where to get it
41 The development sources are available through git at github.com:
42
43 https://github.com/liblouis/liblouis
44
45 ** Build requirements
46 To build Automake, Autoconf, and Libtool are used. If you are getting
47 the sources from git (or change configure.ac), you'll need to have
48 these tools installed to (re)build. Optionally (if you want to
49 generate man pages) you'll also need ~help2man~. All of these programs
50 are available from ftp://ftp.gnu.org/gnu.
51
52 If you want to run the YAML based test suite you will have to install
53 ~libyaml~.
54
55 On Mac OS, the programs can be optained with Homebrew (http://brew.sh):
56
57 #+BEGIN_SRC shell
58 $ brew install automake libtool pkg-config texinfo
59 #+END_SRC
60
61 Note that if you are using Homebrew to install liblouis (see below),
62 the build dependencies are installed automatically.
63
64 ** Gnulib
65 Gnulib (http://www.gnu.org/software/gnulib) is used to provide
66 portable basic functionality to programs and libraries. We use two
67 instances of gnulib, one to provide portable functions such as
68 ~malloc~, ~strndup~, etc to the library and another one to provide
69 portable functionality such as ~getopt~, ~progname~ or
70 ~version-etc~ to the tools.
71
72 The first time invocation to import gnulib for the library was
73
74 #+BEGIN_SRC shell
75 $ gnulib-tool --add-import --lib=libgnu --source-base=gnulib \
76 --m4-base=gnulib/m4 --aux-dir=build-aux --libtool \
77 --macro-prefix=gl --no-vc-files \
78 malloc-gnu realloc-gnu strndup
79 #+END_SRC
80
81 and for the tools
82
83 #+BEGIN_SRC shell
84 $ gnulib-tool --add-import --lib=libgnutools --source-base=tools/gnulib \
85 --m4-base=tools/gnulib/m4 --aux-dir=build-aux --libtool \
86 --macro-prefix=gl_tools --no-vc-files \
87 getopt-gnu malloc-gnu progname version-etc
88 #+END_SRC
89
90 More modules might have been added since. The currently-used gnulib
91 modules and other gnulib information are recorded in
92 ~gnulib/m4/gnulib-cache.m4~ and ~tools/gnulib/m4/gnulib-cache.m4~.
93
94 If you want to update from the current gnulib, install gnulib, and
95 then run the following commands in the top-level directory.
96
97 #+BEGIN_SRC shell
98 $ gnulib-tool --add-import --lib=libgnu --source-base=gnulib \
99 --m4-base=gnulib/m4 --aux-dir=build-aux --libtool \
100 --macro-prefix=gl --no-vc-files
101 $ gnulib-tool --add-import --lib=libgnutools --source-base=tools/gnulib \
102 --m4-base=tools/gnulib/m4 --aux-dir=build-aux --libtool \
103 --macro-prefix=gl_tools --no-vc-files
104 #+END_SRC
105
106 ** How to build
107 After getting the sources from git, with
108
109 #+BEGIN_SRC shell
110 $ git clone https://github.com/liblouis/liblouis.git
111 #+END_SRC
112
113 and installing the tools above, change to the liblouis directory and
114 and bootstrap the project with the following command
115
116 #+BEGIN_SRC shell
117 $ ./autogen.sh
118 #+END_SRC
119
120 to do a fresh build. Then run configure as usual:
121
122 #+BEGIN_SRC shell
123 $ ./configure
124 #+END_SRC
125
126 You have the choice to compile liblouis for either 16- or 32-bit
127 Unicode. By default it is compiled for the former. To get 32-bit
128 Unicode run configure with ~--enable-ucs4~.
129
130 After running configure run ~make~ and then ~make install~. You must
131 have root privileges for the installation step.
132
133 ** Build documentation
134 As with any project that uses the autotools the documentation can be
135 built using any of the provided make targets:
136
137 - For html documentation type ~make html~
138 - For html documentation in a single file type ~make html MAKEINFOFLAGS="--no-headers --no-split"~
139 - For documentation in the [[https://www.gnu.org/software/texinfo/manual/info-stnd/html_node/index.html#Top][info]] format type ~make info~
140 - For pdf documentation type ~make pdf~
141 - For plain text documentation type ~cd doc; make liblouis.txt~
142
143 ** Install with Homebrew
144 Homebrew (http://brew.sh) is a package manager for Mac OS X that
145 installs software from source. There is nothing special about the
146 installation process in the sense that under the hood it happens
147 exactly as described above, with the only difference that Homebrew
148 automates it completely.
149
150 First, use the ~brew tap~ command to add the repository that includes
151 the liblouis formula:
152
153 #+BEGIN_SRC shell
154 $ brew tap liblouis/liblouis
155 #+END_SRC
156
157 Now you are ready to install liblouis:
158
159 #+BEGIN_SRC shell
160 $ brew install liblouis
161 #+END_SRC
162
163 ** Docker
164 Docker (https://www.docker.com) can be useful both for creating a
165 development environment for liblouis, and for shipping the
166 application.
167
168 Setting up a developer environment can take long and can be
169 problematic especially for Windows. Thanks to Docker we can set up the
170 environment for you, we can easily distribute it as an image, which
171 can be run by anybody and will behave exactly the same for everybody.
172
173 In order to use Docker images of liblouis, first get Docker at
174 http://docs.docker.com/introduction/get-docker. Download the latest
175 liblouis image with:
176
177 #+BEGIN_SRC shell
178 $ docker pull liblouis/liblouis
179 #+END_SRC
180
181 Then, enter the development environment by running the image in a
182 Docker container:
183
184 #+BEGIN_SRC shell
185 $ docker run -it liblouis/liblouis bash
186 #+END_SRC
187
188 Local files and directories can be "mounted" inside the container, in
189 order to make it easier to edit files and to persist changes across
190 runs. For example, to use local table files:
191
192 #+BEGIN_SRC shell
193 $ docker run -it -v $(pwd)/tables:/tmp/liblouis/tables liblouis/liblouis bash
194 #+END_SRC
195
196 See the Docker documentation for more info.
197
198 The same Docker image can be used as a development environment and as
199 the application itself. For example, to run the lou_translate tool
200 from inside a Docker container:
201
202 #+BEGIN_SRC shell
203 $ docker run -it liblouis/liblouis lou_translate en-us-g1.ctb
204 #+END_SRC
205
206 To rebuild the image yourself, run the following command in the root
207 directory of the liblouis source:
208
209 #+BEGIN_SRC shell
210 $ docker build -t liblouis/liblouis .
211 #+END_SRC
212
213 A ~.dockerignore~ file is required if you want to compile the source
214 both on te host and in the Docker container. The ~.dockerignore~ file
215 can be updated from ~.gitignore~ with:
216
217 #+BEGIN_SRC shell
218 $ make .dockerignore
219 #+END_SRC
220
221 ** How to run tests
222 Tests are run with
223
224 #+BEGIN_SRC shell
225 $ make check
226 #+END_SRC
227
228 ** How to debug
229 First you have to build liblouis with debugging info enabled.
230
231 #+BEGIN_SRC shell
232 $ ./configure CFLAGS='-g -O0 -Wall -Wextra'
233 $ make
234 #+END_SRC
235
236 Starting the programs under the tools directory within gdb is a little
237 tricky as they are linked with libtool. See the info page of libtool
238 for more information. To start ~lou_checktable~ for table
239 ~wiskunde.ctb~ for example you'd have to issue the following commands:
240
241 #+BEGIN_SRC shell
242 $ libtool --mode=execute gdb ./tools/lou_checktable
243 (gdb) run tables/wiskunde.ctb
244 #+END_SRC
245
246 ** How to find memory leaks
247 Valgrind is a tool that can be used to find memory errors. It is
248 recommended that you compile liblouis without any optimizations and
249 with all warnings enabled before running it through Valgrind:
250
251 #+BEGIN_SRC shell
252 $ ./configure CFLAGS='-g -O0 -Wall'
253 $ make
254 #+END_SRC
255
256 Then use Valgrind to analyze liblouis. For example you can run
257 ~lou_translate~ trough Valgrind:
258
259 #+BEGIN_SRC shell
260 $ libtool --mode=execute valgrind -v --tool=memcheck \
261 --leak-check=full --leak-resolution=high --log-file=valgrind.log \
262 ./tools/lou_translate en-us-g2.ctb
263 #+END_SRC
264
265 Type a few words at the prompt, check translation and terminate
266 ~lou_translate~. Now open the file ~valgrind.log~ and see if there are
267 any memory leaks reported.
268
269 You can also just run lou_checktable for example:
270
271 #+BEGIN_SRC shell
272 $ libtool --mode=execute valgrind -v --tool=memcheck \
273 --leak-check=full --leak-resolution=high --log-file=valgrind.log \
274 ./tools/lou_checktable tables/nl-BE-g0.utb
275 #+END_SRC
276
277 Again open valgrind.log to see if any memory leaks were reported.
278
279 For the full experience run lou_allround under Valgrind:
280
281 #+BEGIN_SRC shell
282 $ libtool --mode=execute valgrind -v --tool=memcheck \
283 --leak-check=full --show-reachable=yes \
284 --leak-resolution=high --track-origins=yes \
285 --log-file=valgrind.log ./tools/lou_allround
286 #+END_SRC
287
288 *** AddressSanitizer
289 [[https://github.com/google/sanitizers/wiki/AddressSanitizer][AdressSanitizer]] is a memory error detector for C/C++. It is part of
290 both LLVM and gcc. To check liblouis build it as follows:
291
292 #+BEGIN_SRC shell
293 $ ./autogen.sh
294 $ ./configure CFLAGS='-fsanitize=address -O1 -fno-omit-frame-pointer -g'
295 $ make
296 $ ./tools/lou_translate tables/en-ueb-g2.ctb
297 #+END_SRC
298
299 Run a few translations, end the program and marvel at the output of
300 AddressSanitizer. At the time of this writing it complained pretty
301 hard:
302
303 #+BEGIN_EXAMPLE
304 SUMMARY: AddressSanitizer: 12384 byte(s) leaked in 12 allocation(s).
305 #+END_EXAMPLE
306
307 *** Electric Fence
308 Electric Fence is a tool that helps detect memory access that overruns
309 the boundaries of a ~malloc()~ memory allocation, and access to memory
310 that has been released with ~free()~.
311
312 Under Debian the usage is fairly straightforward:
313
314 #+BEGIN_SRC shell
315 $ sudo apt install sudo apt install electric-fence
316 #+END_SRC
317
318 Then compile [[#how-to-debug][as above]] and invoke the debugger [[#how-to-debug][as above]]. Inside ~gdb~
319 set up ~LOUIS_TABLEPATH~ and ~LD_PRELOAD~ as follows:
320
321 #+BEGIN_SRC shell
322 $ libtool --mode=execute gdb ./tools/lou_allround
323 (gdb) set environment LOUIS_TABLEPATH ./tables,./tests/tables,./tests/tables/moreTables,./tests/tablesWithMetadata,./tests/tables/emphclass
324 (gdb) set environment LD_PRELOAD /usr/lib/libefence.so.0.0
325 (gdb) run
326 #+END_SRC
327
328 If there are problems with memory access the program will run into a
329 segmentation fault which you can consequently analyze in the debugger.
330
331 ** Static analysis
332 [[http://clang-analyzer.llvm.org/scan-build.html][scan-build]] is a command line utility to run a static analyzer over the
333 codebase. It helps to find problems such as memory leaks, dereference
334 of null pointer, etc.
335
336 #+BEGIN_SRC shell
337 $ make maintainer-clean
338 $ ./autogen.sh
339 $ scan-build ./configure
340 $ scan-build make
341 ...
342 scan-build: 101 bugs found.
343 scan-build: Run 'scan-view /tmp/scan-build-2019-08-15-141827-5185-1' to examine bug reports.
344 #+END_SRC
345
346 then look at the generated reports and fix (or report) the issues.
347
348 ** How to analyze performance
349 Gprof helps you analyze the performance of programs. You have to
350 compile liblouis as follows:
351
352 #+BEGIN_SRC shell
353 $ ./configure --disable-shared
354 $ make clean all CFLAGS='-g -O0 -pg' LDFLAGS='-all-static'
355 #+END_SRC
356
357 Then translate some stuff with a large table:
358
359 #+BEGIN_SRC shell
360 $ ./tools/lou_translate tests/tables/large.ctb
361 #+END_SRC
362
363 Finally look at the call profile:
364
365 #+BEGIN_SRC shell
366 $ libtool --mode=execute gprof ./tools/lou_translate gmon.out
367 #+END_SRC
368
369 ** How to build for Windows
370 See the ~README.windows~ file and the windows subdirectory.
371
372 *** How to cross-compile for Windows
373 To compile for either win32 or win64 two Dockerfiles are provided
374 which set up the right environment to cross-compile liblouis. There is
375 a Makefile target that will build the Docker images, build liblouis
376 and extract the zip files with the windows build artifacts.
377
378 To build for both win32 and win64 type the following command:
379
380 #+BEGIN_SRC shell
381 $ make distwin
382 #+END_SRC
383
384 This will place ~liblouis-$(VERSION)-win32.zip~ and
385 ~liblouis-$(VERSION)-win64.zip~ in the current directory. The build is
386 compiled with ~--enable-ucs4~ and contains ~lou_checkyaml.exe~.
387
388 *** TODO How to build for Windows using Cygwin
389 (possibly use a Vagrantfile as demonstration + explain that Cygwin
390 binaries can not be used outside the Cygwin environment)
391
392 *** TODO How to build for Windows using MinGW
393 (possibly use a Vagrant file as demonstration)
394
395 * Release Procedure
396 These steps describe what a maintainer does to make a release; they
397 are not needed for ordinary patch submission.
398
399 ** Update the NEWS entry
400 If any new tables were added, renamed or removed please note them with
401 their file name in the NEWS entry. This is usefull for projects like
402 NVDA.
403
404 ** Set the version number
405 Update the version number in ~NEWS~ (with version, date, and release
406 type), ~configure.ac~ and ~windows/include/config.h~.
407
408 Don't forget to update the libtool versioning info in ~configure.ac~,
409 i.e. ~LIBLOUIS_REVISION~ and possibly ~LIBLOUIS_CURRENT~ and
410 ~LIBLOUIS_AGE~. Check the [[https://www.gnu.org/software/libtool/manual/html_node/Interfaces.html#Interfaces][libtool documentation on versioning]] for an
411 explanation of these values.
412
413 ** Commit and tag
414 Commit the changes and tag this version
415
416 #+BEGIN_SRC shell
417 $ git tag -s v2.6.0 -m "Release 2.6.0"
418 $ git push origin v2.6.0
419 #+END_SRC
420
421 If you know the exact version number that needs to be tagged use
422
423 #+BEGIN_SRC shell
424 $ git tag -s v2.6.0 -m "Release 2.6.0" <commit>
425 $ git push origin v2.6.0
426 #+END_SRC
427
428 ** Make the release
429 Check out a clean copy in a different directory, like /tmp. Run
430 autogen.sh and configure with no special prefixes. Run make distcheck.
431 This will make sure that all needed files are present, and do a
432 general sanity check. Run make dist. This will produce a tarball.
433
434 #+BEGIN_SRC shell
435 $ ./autogen.sh && ./configure && make && make distcheck && make dist
436 #+END_SRC
437
438 ** Upload
439 Add the tarball to the github liblouis releases page, i.e. add it
440 under https://github.com/liblouis/liblouis/releases with the specific
441 release and add a link to it in $WEBSITE/downloads/index.md. See below
442 for instructions on how to update the web site.
443
444 ** Online documentation
445 The online documentation is part of the liblouis web site. To add it to the
446 site simply copy doc/liblouis.html to $WEBSITE/documentation/liblouis.html.
447 Make sure you add the proper YAML front matter. Again see below for
448 instructions on how to update the web site.
449
450 ** Web site maintenance
451 The liblouis web site at liblouis.io is maintained with the help of
452 [[https://pages.github.com/][github pages]]. To edit the site just check out the repo at
453 https://github.com/liblouis/liblouis.github.io. You'll need to know a
454 few things about [[http://jekyllrb.com/][Jekyll]] and markdown, the markup that is used to edit
455 the content. In order to update the site simply edit, commit and push.
456
457 For the new release update the project web site.
458
459 - Add a post containing the current NEWS to the _posts directory and
460 - add the download artifacts to the download page
461
462 ** Announce
463 Send an announcement to the liblouis list
464 [email protected]~. See ~ANNOUNCEMENT~ for an
465 example.
466