Add spec file
[jansson.git] / doc / gettingstarted.rst
1 ***************
2 Getting Started
3 ***************
4
5 .. highlight:: c
6
7 Compiling and Installing Jansson
8 ================================
9
10 The Jansson source is available at
11 http://www.digip.org/jansson/releases/.
12
13 Unix-like systems
14 -----------------
15
16 Unpack the source tarball and change to the source directory:
17
18 .. parsed-literal::
19
20     bunzip2 -c jansson-|release|.tar.bz2 | tar xf -
21     cd jansson-|release|
22
23 The source uses GNU Autotools (autoconf_, automake_, libtool_), so
24 compiling and installing is extremely simple::
25
26     ./configure
27     make
28     make check
29     make install
30
31 To change the destination directory (``/usr/local`` by default), use
32 the ``--prefix=DIR`` argument to ``./configure``. See ``./configure
33 --help`` for the list of all possible installation options. (There are
34 no options to customize the resulting Jansson binary.)
35
36 The command ``make check`` runs the test suite distributed with
37 Jansson. This step is not strictly necessary, but it may find possible
38 problems that Jansson has on your platform. If any problems are found,
39 please report them.
40
41 If you obtained the source from a Git repository (or any other source
42 control system), there's no ``./configure`` script as it's not kept in
43 version control. To create the script, the build system needs to be
44 bootstrapped. There are many ways to do this, but the easiest one is
45 to use ``autoreconf``::
46
47     autoreconf -vi
48
49 This command creates the ``./configure`` script, which can then be
50 used as described above.
51
52 .. _autoconf: http://www.gnu.org/software/autoconf/
53 .. _automake: http://www.gnu.org/software/automake/
54 .. _libtool: http://www.gnu.org/software/libtool/
55
56
57 Other Systems
58 -------------
59
60 On Windows and other non Unix-like systems, you may be unable to run
61 the ``./configure`` script. In this case, follow these steps. All the
62 files mentioned can be found in the ``src/`` directory.
63
64 1. Create ``jansson_config.h``. This file has some platform-specific
65    parameters that are normally filled in by the ``./configure``
66    script:
67
68    - On Windows, rename ``jansson_config.h.win32`` to ``jansson_config.h``.
69
70    - On other systems, edit ``jansson_config.h.in``, replacing all
71      ``@variable@`` placeholders, and rename the file to
72      ``jansson_config.h``.
73
74 2. Make ``jansson.h`` and ``jansson_config.h`` available to the
75    compiler, so that they can be found when compiling programs that
76    use Jansson.
77
78 3. Compile all the ``.c`` files (in the ``src/`` directory) into a
79    library file. Make the library available to the compiler, as in
80    step 2.
81
82
83 Building the Documentation
84 --------------------------
85
86 (This subsection describes how to build the HTML documentation you are
87 currently reading, so it can be safely skipped.)
88
89 Documentation is in the ``doc/`` subdirectory. It's written in
90 reStructuredText_ with Sphinx_ annotations. To generate the HTML
91 documentation, invoke::
92
93    make html
94
95 and point your browser to ``doc/_build/html/index.html``. Sphinx_ 1.0
96 or newer is required to generate the documentation.
97
98 .. _reStructuredText: http://docutils.sourceforge.net/rst.html
99 .. _Sphinx: http://sphinx.pocoo.org/
100
101
102 Compiling Programs that Use Jansson
103 ===================================
104
105 Jansson involves one C header file, :file:`jansson.h`, so it's enough
106 to put the line
107
108 ::
109
110     #include <jansson.h>
111
112 in the beginning of every source file that uses Jansson.
113
114 There's also just one library to link with, ``libjansson``. Compile and
115 link the program as follows::
116
117     cc -o prog prog.c -ljansson
118
119 Starting from version 1.2, there's also support for pkg-config_::
120
121     cc -o prog prog.c `pkg-config --cflags --libs jansson`
122
123 .. _pkg-config: http://pkg-config.freedesktop.org/