blob: 6845bc812e78786cb1621aa1d81cbba262c75674 [file] [log] [blame]
Daniel Dunbareaa88c82012-04-06 23:47:34 +00001.. _sphinx_intro:
2
3Sphinx Introduction for LLVM Developers
4=======================================
5
6This document is intended as a short and simple introduction to the Sphinx
7documentation generation system for LLVM developers.
8
9Quickstart
10----------
11
12To get started writing documentation, you will need to:
13
14 1. Have the Sphinx tools :ref:`installed <installing_sphinx>`.
15
16 2. Understand how to :ref:`build the documentation
17 <building_the_documentation>`.
18
19 3. Start :ref:`writing documentation <writing_documentation>`!
20
21.. _installing_sphinx:
22
23Installing Sphinx
24~~~~~~~~~~~~~~~~~
25
26You should be able to install Sphinx using the standard Python package
27installation tool ``easy_install``, as follows::
28
29 $ sudo easy_install sphinx
30 Searching for sphinx
31 Reading http://pypi.python.org/simple/sphinx/
32 Reading http://sphinx.pocoo.org/
33 Best match: Sphinx 1.1.3
34 ... more lines here ..
35
36If you do not have root access (or otherwise want to avoid installing Sphinx in
37system directories) see the section on :ref:`installing_sphinx_in_a_venv` .
38
39If you do not have the ``easy_install`` tool on your system, you should be able
40to install it using:
41
42 Linux
Alex Rosenbergb65e8882013-02-03 07:05:26 +000043 Use your distribution's standard package management tool to install it,
44 i.e., ``apt-get install easy_install`` or ``yum install easy_install``.
Daniel Dunbareaa88c82012-04-06 23:47:34 +000045
46 Mac OS X
47 All modern Mac OS X systems come with ``easy_install`` as part of the base
48 system.
49
50 Windows
51 See the `setuptools <http://pypi.python.org/pypi/setuptools>`_ package web
52 page for instructions.
53
54
55.. _building_the_documentation:
56
57Building the documentation
58~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59
60In order to build the documentation, all you should need to do is change to the
61``docs`` directory and invoke make as follows::
62
63 $ cd path/to/project/docs
64 $ make html
65
Daniel Dunbare84f5ca2012-04-06 23:55:50 +000066Note that on Windows there is a ``make.bat`` command in the docs directory which
67supplies the same interface as the ``Makefile``.
68
69That command will invoke ``sphinx-build`` with the appropriate options for the
70project, and generate the HTML documentation in a ``_build`` subdirectory. You
71can browse it starting from the index page by visiting
72``_build/html/index.html``.
Daniel Dunbareaa88c82012-04-06 23:47:34 +000073
74Sphinx supports a wide variety of generation formats (including LaTeX, man
75pages, and plain text). The ``Makefile`` includes a number of convenience
76targets for invoking ``sphinx-build`` appropriately, the common ones are:
77
78 make html
79 Generate the HTML output.
80
Daniel Dunbare84f5ca2012-04-06 23:55:50 +000081 make latexpdf
Daniel Dunbareaa88c82012-04-06 23:47:34 +000082 Generate LaTeX documentation and convert to a PDF.
83
Daniel Dunbare84f5ca2012-04-06 23:55:50 +000084 make man
Daniel Dunbareaa88c82012-04-06 23:47:34 +000085 Generate man pages.
86
87
88.. _writing_documentation:
89
90Writing documentation
91~~~~~~~~~~~~~~~~~~~~~
92
93The documentation itself is written in the reStructuredText (ReST) format, and Sphinx
94defines additional tags to support features like cross-referencing.
95
96The ReST format itself is organized around documents mostly being readable
97plaintext documents. You should generally be able to write new documentation
98easily just by following the style of the existing documentation.
99
100If you want to understand the formatting of the documents more, the best place
101to start is Sphinx's own `ReST Primer <http://sphinx.pocoo.org/rest.html>`_.
102
103
104Learning More
105-------------
106
107If you want to learn more about the Sphinx system, the best place to start is
108the Sphinx documentation itself, available `here
109<http://sphinx.pocoo.org/contents.html>`_.
110
111
112.. _installing_sphinx_in_a_venv:
113
114Installing Sphinx in a Virtual Environment
115------------------------------------------
116
117Most Python developers prefer to work with tools inside a *virtualenv* (virtual
118environment) instance, which functions as an application sandbox. This avoids
119polluting your system installation with different packages used by various
120projects (and ensures that dependencies for different packages don't conflict
121with one another). Of course, you need to first have the virtualenv software
122itself which generally would be installed at the system level::
123
124 $ sudo easy_install virtualenv
125
126but after that you no longer need to install additional packages in the system
127directories.
128
129Once you have the *virtualenv* tool itself installed, you can create a
130virtualenv for Sphinx using::
131
132 $ virtualenv ~/my-sphinx-install
133 New python executable in /Users/dummy/my-sphinx-install/bin/python
134 Installing setuptools............done.
135 Installing pip...............done.
136
137 $ ~/my-sphinx-install/bin/easy_install sphinx
138 ... install messages here ...
139
140and from now on you can "activate" the *virtualenv* using::
141
142 $ source ~/my-sphinx-install/bin/activate
143
144which will change your PATH to ensure the sphinx-build tool from inside the
145virtual environment will be used. See the `virtualenv website
146<http://www.virtualenv.org/en/latest/index.html>`_ for more information on using
147virtual environments.