Read Source Code the HTML Way

Cross-reference and convert source code to HTML for easy viewing.

The first thing you'll see when you open the file is a definition for a variable called v. As with programming languages, you can define your own variables and use them later in the configuration file. Wherever they occur, they will be replaced by whatever value they have. Variable values are referenced by the configuration file by $/variable-name. Variable definitions follow one of two possible formats:

variable: /variable-identifier, variable-name, 
/(/list-of-values/), /default-value/


variable: /variable-identifier, variable-name,
/[/file-containing-list-of-values/], /default-value/

Here's what the terms stand for:

  • variable-identifier: the name the variable will be known as throughout the configuration file.

  • variable-name: the actual name of the variable that will be displayed to the user.

  • list-of-values: comma-separated list of values to be displayed.

  • file-containing: a file that contains a list of possible values.

  • list-of-values: the list has each entry on a separate line. The user can select any one of them. The absolute path of the file should be provided.

  • default-value: the value that the variable will take on by default. The first value is automatically set if this is not specified.


The baseurl is the URL relative to which all of the scripts required by LXR are placed. It should be accessible via a browser. In my configuration, it's http://my-ip/lxr/http/ <http://localhost/lxr/http/>. Make sure to place the / at the end, or the last directory will be ignored.

HTML Headers and Footers

When the HTML for the source is generated, LXR can add headers and footers to the pages. Sample headers and footers are provided in the $INSTALLPREFIX/http/ directory. They're called template-head and template-tail. In addition, you also can change the way files and directories are displayed by LXR by modifying the template-dir file. The locations of these files can be specified by the htmlhead, htmltail and htmldir options in the lxr.conf file.


This option tells LXR where to look for the actual source code. In my case, it's /var/www/htdocs/lxr/source/glibc-2.3.5. If you want to cross-reference multiple projects, all you have to do is create a variable specifying the location of each of the directories that contain the source code. Then, you can specify the value of the variable as the sourceroot. For example, I set up the sources for glibc-2.3.5 and OpenMOSIX-2.4.26, placing the sources for both of them in /var/www/htdocs/lxr/source in their individual directories with the same names as above. In lxr.conf, I had a line like:

variable: s, Source, (glibc-2.3.5, OpenMOSIX-2.4.26)


sourceroot: /var/www/htdocs/lxr/source/$s

Thus, the appropriate source code is automatically selected based on the value of the source variable.


srcrootname specifies the name of the project whose source code is displayed—for example:

srcrootname: $s


This specifies the locations of the header files that are to be included in the project.


This is the location of the fileidx and xref files generated by genxref. If you have multiple projects, specify a separate location for each, as follows:

dbdir: /var/www/htdocs/lxr/source/$s/

These are the only options you need to set when configuring LXR. Additionally, you can specify the location of the glimpse binary using glimpsebin.


glimpse allows users to search for specific files within the source code and to search for any text within source files. You can obtain the latest version of glimpse from Extract and install it. Once you are done installing glimpse, go to the directory where the source code is installed, such as /var/www/htdocs/lxr/source/glibc-2.3.5, and do the following:

bash# glimpseindex -H . .

The output should look something like this:

This is glimpseindex version 4.18.2, 2006.

Indexing "/var/www/htdocs/lxr/source/glibc-2.3.5" ...

Size of files being indexed = 81711416 B, Total #of files = 10075

Index-directory: "/var/www/htdocs/lxr/source/glibc-2.3.5"

Glimpse-files created here:

-rw-r--r-- 1 root root 676398 2006-09-08 05:51 .glimpse_filenames

-rw-r--r-- 1 root root 40300 2006-09-08 05:51 .glimpse_filenames_index

-rw-r--r-- 1 root root 0 2006-09-08 05:50 .glimpse_filetimes

-rw------- 1 root root 1783314 2006-09-08 05:51 .glimpse_index

-rw-r--r-- 1 root root 686 2006-09-08 05:51 .glimpse_messages

-rw------- 1 root root 836 2006-09-08 05:51 .glimpse_partitions

-rw-r--r-- 1 root root 23888 2006-09-08 05:51 .glimpse_statistics

This creates the required glimpse index files in the current directory. Once they're created, make sure read permission is set for others:

bash# chmod o+r .glimpse-*

Now, set the glimpsebin option in lxr.conf to wherever you installed glimpse. I installed it in /usr/local/bin/glimpse.

That's it; save and close the lxr.conf file. The only thing remaining to do now is configure the Web server to work with LXR.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


Anonymous's picture

change .glimpse-* to .glimpse_*

File search is not working properly for me

Dheeraj Gautam's picture

I tried to install lxr-0.3.1. Almost all things are working fine for me, but file search is not working properly for me. I used "glimpseindex -H /home/source" command to generate the index, then during browsing, I am getting absolute path.

Any solution for this. Please help.


asadouglass's picture

Nice, straightforward article. There were a few typos which I found distracting. (htdcos?). Also, since many of us are running ubuntu nowadays, a little blumb on getting it installed in apache2.conf might have been nice.

I got success install follow

Anonymous's picture

I got success install follow this doc, thx !
btw,another tiny thing: "< File ....." should be "< Files ...."

Its a great article !! But

Anonymous's picture

Its a great article !!

But the one provided on lxr's homepage is good enough too.

Geek Guide
The DevOps Toolbox

Tools and Technologies for Scale and Reliability
by Linux Journal Editor Bill Childers

Get your free copy today

Sponsored by IBM

8 Signs You're Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
On Demand
Moderated by Linux Journal Contributor Mike Diehl

Sign up now

Sponsored by Skybot