LXR Guide: Difference between revisions

From Leo's Notes
This page was last edited on 4 May 2013, at 19:32.
Created page with "LXR, shortened for Linux Cross-Reference, is a perl web application that lets you read linux kernel source code of different versions while having the benefit of having static..."
 
No edit summary
Line 1: Line 1:
LXR, shortened for Linux Cross-Reference, is a perl web application that lets you read linux kernel source code of different versions while having the benefit of having static values and functions 'linked' to each other which makes it a good reference when dealing with kernel source.
LXR, shortened for Linux Cross-Reference, is a perl web application that lets you read linux kernel source code of different versions while having the benefit of having static values and functions 'linked' to each other which makes it a good reference when dealing with kernel source.
== Step by Step Guide ==
=== Prerequisites ===
Install required packages. Unfortunately, there are a few packages that are not available through yum (through default repos), and must be built through CPAN. <code>screen</code> is not a dependency, but it is nice to run the indexer through it as it can take from hours to days depending on your hardware.
<syntaxhighlight lang="bash" line start="1" enclose="div">
yum --nogpgcheck install \
    perl-CGI-Ajax \
    perl-CGI-Simple \
    perl-CPAN \
    perl-DBD-Pg \
    perl-DBI \
    perl-Devel-Size \
    perl-ExtUtils-CBuilder \
    perl-ExtUtils-MakeMaker \
    perl-ExtUtils-Embed \
    perl-PerlIO-gzip \
    perl-HTML-Entities* \
    perl-Term-ProgressBar \
    perl-Template* \
    xapian* \
    postgresql postgresql-server \
    httpd \
    mod_perl \
    mod_perl-devel \
    ctags-etags \
    make gcc gcc-c++ \
    git \
    screen
</syntaxhighlight>
lxr expects it as <code>ctag</code> as <code>ctags-exuberant</code>.
<syntaxhighlight lang="bash" line start="1" enclose="div">
ln -s /usr/bin/ctags /usr/bin/ctags-exuberant
</syntaxhighlight>
Install the missing dependencies through CPAN:
<syntaxhighlight lang="bash" line start="1" enclose="div">
perl -MCPAN -e "install Search::Xapian Apache2::Reload"
</syntaxhighlight>
=== Setting up PostgreSQL ===
With PostgreSQL installed, set it up with a lxrng database. You may want to set up permissions as well, but I will be using the root account.
<syntaxhighlight lang="bash" line start="1" enclose="div">
/etc/init.d/postgresql initdb
/etc/init.d/postgresql start
sudo -u postgres psql
  ALTER USER postgres WITH ENCRYPTED PASSWORD 'lxrng';
  CREATE DATABASE lxrng;
  \q
# Use passwords
sed -i "s/ident$/md5/g" /var/lib/pgsql/data/pg_hba.conf
# Apply changes by restarting
/etc/init.d/postgresql restart
# Make sure postgres starts on startup
chkconfig postgresql on --level 345
</syntaxhighlight>
=== LXRng Setup ===
We will be putting LXRng into <code>/export</code>
<syntaxhighlight lang="bash" line start="1" enclose="div">
mkdir /export
cd /export
# Source is from git. If unavailable, there is a copy at http://pages.cpsc.ucalgary.ca/~leo/support/packages/src/lxrng*.tar.gz
git clone git://lxr.linux.no/git/lxrng.git
Edit LXRng's configuration at lxrng.conf. Make sure the database settings and URL is correct.
<syntaxhighlight lang="bash" line start="1" enclose="div">
cd lxrng
cp lxrng.conf-dist lxrng.conf
sed -i "s/\/var\/lib/\/export/g" /export/lxrng/lxrng.conf
sed -i "s/db_user => \"\"/db_user => \"postgres\"/g" /export/lxrng/lxrng.conf
sed -i "s/db_pass => \"\"/db_pass => \"lxrng\"/g" /export/lxrng/lxrng.conf
sed -i "s/localhost/lxr.lab.cpsc.ucalgary.ca/g" /export/lxrng/lxrng.conf
sed -i "s/'ver_default'\s*=>\s*'[a-z0-9.]*'/'ver_default' => 'v2.6.32'/g" /export/lxrng/lxrng.conf
</syntaxhighlight>
Set up a few directories such as <code>repos</code> which will contain all the source code to be referenced.
<syntaxhighlight lang="bash" line start="1" enclose="div">
mkdir repos
mkdir -p text-db/linux-2.6
mkdir cache
chmod 777 cache
touch lxr-ctags-quirks
</syntaxhighlight>
Get the source code either via git or from an existing tarball.
<syntaxhighlight lang="bash" line start="1" enclose="div">
cd repos
# wget http://pages.cpsc.ucalgary.ca/~leo/support/linux-2.6-source.tar.gz -O - | tar -xzf -
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
</syntaxhighlight>
Start the indexing process:
<syntaxhighlight lang="bash" line start="1" enclose="div">
cd /export/lxrng
./lxr-db-admin linux --init
screen -d -m ./lxr-genxref linux
=== Setting up Apache ===
<syntaxhighlight lang="bash" line start="1" enclose="div">
cd /export/lxrng
cp apache2-site.conf-dist-mod_perl /etc/httpd/conf.d/lxrng.conf
sed -i "s/@@LXRROOT@@/\/export\/lxrng/g" /etc/httpd/conf.d/lxrng.conf
sed -i "s/@@LXRURL@@/lxr/g" /etc/httpd/conf.d/lxrng.conf
sed -i "s/^[\(^#\)]*/# /" /etc/httpd/conf.d/welcome.conf
/etc/init.d/httpd start
chkconfig httpd on --level 345
</syntaxhighlight>
Run 'screen -r' to view the progress of the cross reference generation progress
== Scripted Guide ==


The scripted guide is displayed below. It was used and tested on a clean install of ScientificLinux 6.3.  
The scripted guide is displayed below. It was used and tested on a clean install of ScientificLinux 6.3.  
Line 112: Line 246:


</syntaxhighlight>
</syntaxhighlight>
[[Category:Linux]]

Revision as of 19:32, 4 May 2013

LXR, shortened for Linux Cross-Reference, is a perl web application that lets you read linux kernel source code of different versions while having the benefit of having static values and functions 'linked' to each other which makes it a good reference when dealing with kernel source.

Step by Step Guide

Prerequisites

Install required packages. Unfortunately, there are a few packages that are not available through yum (through default repos), and must be built through CPAN. screen is not a dependency, but it is nice to run the indexer through it as it can take from hours to days depending on your hardware.

yum --nogpgcheck install \
    perl-CGI-Ajax \
    perl-CGI-Simple \
    perl-CPAN \
    perl-DBD-Pg \
    perl-DBI \
    perl-Devel-Size \
    perl-ExtUtils-CBuilder \
    perl-ExtUtils-MakeMaker \
    perl-ExtUtils-Embed \
    perl-PerlIO-gzip \
    perl-HTML-Entities* \
    perl-Term-ProgressBar \
    perl-Template* \
    xapian* \
    postgresql postgresql-server \
    httpd \
    mod_perl \
    mod_perl-devel \
    ctags-etags \
    make gcc gcc-c++ \
    git \
    screen

lxr expects it as ctag as ctags-exuberant.

 ln -s /usr/bin/ctags /usr/bin/ctags-exuberant

Install the missing dependencies through CPAN:

 perl -MCPAN -e "install Search::Xapian Apache2::Reload"


Setting up PostgreSQL

With PostgreSQL installed, set it up with a lxrng database. You may want to set up permissions as well, but I will be using the root account.

/etc/init.d/postgresql initdb
/etc/init.d/postgresql start

sudo -u postgres psql
  ALTER USER postgres WITH ENCRYPTED PASSWORD 'lxrng';
  CREATE DATABASE lxrng;
  \q

# Use passwords
sed -i "s/ident$/md5/g" /var/lib/pgsql/data/pg_hba.conf

# Apply changes by restarting
/etc/init.d/postgresql restart

# Make sure postgres starts on startup
chkconfig postgresql on --level 345

LXRng Setup

We will be putting LXRng into /export

mkdir /export
cd /export
# Source is from git. If unavailable, there is a copy at http://pages.cpsc.ucalgary.ca/~leo/support/packages/src/lxrng*.tar.gz
git clone git://lxr.linux.no/git/lxrng.git

Edit LXRng's configuration at lxrng.conf. Make sure the database settings and URL is correct.

<syntaxhighlight lang="bash" line start="1" enclose="div">
cd lxrng
cp lxrng.conf-dist lxrng.conf
sed -i "s/\/var\/lib/\/export/g" /export/lxrng/lxrng.conf
sed -i "s/db_user => \"\"/db_user => \"postgres\"/g" /export/lxrng/lxrng.conf
sed -i "s/db_pass => \"\"/db_pass => \"lxrng\"/g" /export/lxrng/lxrng.conf
sed -i "s/localhost/lxr.lab.cpsc.ucalgary.ca/g" /export/lxrng/lxrng.conf
sed -i "s/'ver_default'\s*=>\s*'[a-z0-9.]*'/'ver_default' => 'v2.6.32'/g" /export/lxrng/lxrng.conf

Set up a few directories such as repos which will contain all the source code to be referenced.

mkdir repos
mkdir -p text-db/linux-2.6
mkdir cache
chmod 777 cache
touch lxr-ctags-quirks

Get the source code either via git or from an existing tarball.

cd repos

# wget http://pages.cpsc.ucalgary.ca/~leo/support/linux-2.6-source.tar.gz -O - | tar -xzf -
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git

Start the indexing process:

cd /export/lxrng
./lxr-db-admin linux --init
screen -d -m ./lxr-genxref linux

=== Setting up Apache ===

<syntaxhighlight lang="bash" line start="1" enclose="div">
cd /export/lxrng
cp apache2-site.conf-dist-mod_perl /etc/httpd/conf.d/lxrng.conf
sed -i "s/@@LXRROOT@@/\/export\/lxrng/g" /etc/httpd/conf.d/lxrng.conf
sed -i "s/@@LXRURL@@/lxr/g" /etc/httpd/conf.d/lxrng.conf
sed -i "s/^[\(^#\)]*/# /" /etc/httpd/conf.d/welcome.conf
/etc/init.d/httpd start
chkconfig httpd on --level 345


Run 'screen -r' to view the progress of the cross reference generation progress



Scripted Guide

The scripted guide is displayed below. It was used and tested on a clean install of ScientificLinux 6.3.

I recommend doing everything one step at a time as this was just the list of steps I used to configure/install it.

#!/bin/sh

cd /root

# Installing dependencies.
# Note: Screen isn't a dependency, but it is nice to run the indexer in the background.
yum --nogpgcheck install \
    perl-CGI-Ajax \
    perl-CGI-Simple \
    perl-CPAN \
    perl-DBD-Pg \
    perl-DBI \
    perl-Devel-Size \
    perl-ExtUtils-CBuilder \
    perl-ExtUtils-MakeMaker \
    perl-ExtUtils-Embed \
    perl-PerlIO-gzip \
    perl-HTML-Entities* \
    perl-Term-ProgressBar \
    perl-Template* \
    xapian* \
    postgresql postgresql-server \
    httpd \
    mod_perl \
    mod_perl-devel \
    ctags-etags \
    make gcc gcc-c++ \
    git \
    screen

# Ctags setup. lxr expects it as ctags-exuberant.
ln -s /usr/bin/ctags /usr/bin/ctags-exuberant

# Perl setup
#echo "I need you to init cpan, then run:"
#echo "cpan> install Search::Xapian"
#echo "cpan> install Apache2::Reload"
perl -MCPAN -e "install Search::Xapian Apache2::Reload"

#
# Postgres Setup
#
/etc/init.d/postgresql initdb
/etc/init.d/postgresql start
echo "I need you to enter:"
echo "postgres=# ALTER USER postgres WITH ENCRYPTED PASSWORD 'lxrng';"
echo "postgres=# CREATE DATABASE lxrng;"
echo "postgres=# \q"
sudo -u postgres psql

# Use passwords
sed -i "s/ident$/md5/g" /var/lib/pgsql/data/pg_hba.conf

# Apply - restart required
/etc/init.d/postgresql restart

chkconfig postgresql on --level 345

#
# LXR Setup
#
mkdir /export
cd /export
# Source is from git. If unavailable, there is a copy at http://pages.cpsc.ucalgary.ca/~leo/support/packages/src/lxrng*.tar.gz
git clone git://lxr.linux.no/git/lxrng.git

# Configure lxrng - change the settings here as necessary
cd lxrng
cp lxrng.conf-dist lxrng.conf
sed -i "s/\/var\/lib/\/export/g" /export/lxrng/lxrng.conf
sed -i "s/db_user => \"\"/db_user => \"postgres\"/g" /export/lxrng/lxrng.conf
sed -i "s/db_pass => \"\"/db_pass => \"lxrng\"/g" /export/lxrng/lxrng.conf
sed -i "s/localhost/lxr.lab.cpsc.ucalgary.ca/g" /export/lxrng/lxrng.conf
sed -i "s/'ver_default'\s*=>\s*'[a-z0-9.]*'/'ver_default' => 'v2.6.32'/g" /export/lxrng/lxrng.conf

mkdir repos
mkdir -p text-db/linux-2.6
mkdir cache
chmod 777 cache
touch lxr-ctags-quirks

# Either get everything from git by running:
#  git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
# or get it from an existing source.
cd repos
wget http://pages.cpsc.ucalgary.ca/~leo/support/linux-2.6-source.tar.gz -O - | tar -xzf -

cd /export/lxrng
./lxr-db-admin linux --init
screen -d -m ./lxr-genxref linux

#
# Setup apache
#
cd /export/lxrng
cp apache2-site.conf-dist-mod_perl /etc/httpd/conf.d/lxrng.conf
sed -i "s/@@LXRROOT@@/\/export\/lxrng/g" /etc/httpd/conf.d/lxrng.conf
sed -i "s/@@LXRURL@@/lxr/g" /etc/httpd/conf.d/lxrng.conf
sed -i "s/^[\(^#\)]*/# /" /etc/httpd/conf.d/welcome.conf
/etc/init.d/httpd start
chkconfig httpd on --level 345

echo "Done."
echo "Run 'screen -r' to view the progress of the cross reference generation progress"