lxr: Linux Cross-Reference
0.31 (stable) for Debian
最近看源码,找到这个工具,不知道对大家是否有用。
本文与README.Debian稍有出入
安装perl
安装Web服务器(apache2)
安装glimpse(可选)
安装目录为
/var/lib/lxr
1) 建立目录
- 源码目录
以2.6.15版本为例
假设源码放在/usr/src/linux-2.6.15中,可以用
# cd /var/lib/lxr/source/
# ln /usr/src/linux-2.6.15 -s linux-2.6.15
当然也可以直接将源码放到此目录中。建立其它版本的源码目录,例
source
|– linux-0.11
|– linux-1.0
|– linux-2.2.25
|– linux-2.4.27
`– linux-2.6.15
创建文件versions,写入版本的列表
代码:linux-0.11
linux-1.0
linux-2.2.25
linux-2.4.27
linux-2.6.15创建文件defversion,写入显示的默认版本
linux-2.6.15
- 索引目录
建立这个目录是为了方便管理文件
# mkdir /var/lib/lxr/databases
# cd /var/lib/lxr/databases
# mkdir linux-0.11
…
2) 配置Web服务器
以apache2为例
创建文件 /etc/apache2/site-available/lxr 写入:
PHP 代码:
# Linux Cross Reference Stuff
# ln /etc/apache2/site-available/lxr -s /etc/apache2/site-enable/lxr
# 以http://hostname/lxr 建立访问
# 允许/var/lib/lxr能被用户访问
Alias /lxr /var/lib/lxr
<Directory /var/lib/lxr>
Options All
AllowOverride All
</Directory>
创建文件 /var/lib/lxr/http/.htaccess 写入:
PHP 代码:
<Files ~ (search|source|ident|diff|find)$>
3) 配置LXR
SetHandler cgi-script
</Files>
修改配置文件 /var/lib/lxr/http/lxr.conf:
PHP 代码:
# Configuration file.
# Define typed variable "v", read valueset from file.
# 版本列表的位置
variable: v, Version, [/var/lib/lxr/source/versions], [/var/lib/lxr/source/defversion]
# Define typed variable "a". First value is default.
# 显示源码的架构版本
variable: a, Architecture, (i386, alpha, m68k, mips, ppc, sparc, sparc64)
# Define the base url for the LXR files.
# 服务器的地址,地址最后必须包括 " / "
baseurl:http://localhost/lxr/
# These are the templates for the HTML heading, directory listing and
# footer, respectively.
# 显示网页的格式
htmlhead: /var/lib/lxr/http/template-head
htmltail: /var/lib/lxr/http/template-tail
htmldir: /var/lib/lxr/http/template-dir
# The source is here.
# 源码目录位置
sourceroot: /var/lib/lxr/source/$v/
# 显示源码的名称
srcrootname: $v
# "#include <foo.h>" is mapped to this directory (in the LXR source
# tree)
incprefix: /include
# The database files go here.
# 放置lxr数据库索引文件的目录
dbdir: /var/lib/lxr/databases/$v/
# Glimpse can be found here.
# glimpse安装位置
glimpsebin: /usr/bin/glimpse
# The power of regexps. This is pretty Linux-specific, but quite
# useful. Tinker with it and see what it does. (How’s that for
# documentation?)
map: /include/asm[^/]/ /include/asm-$a/
map: /arch/[^/]+/ /arch/$a/
4) 生成数据文件
# cd /var/lib/lxr/source
生成lxr的数据库文件
# /var/lib/lxr/bin/genxref linux-2.6.15
# mv fileidx ../databases/linux-2.6.15/
# mv xref ../databases/linux-2.6.15/
生成glimpse数据库(参考glimpse –help生成其它数据)
# glimpseindex -H . linux-2.6.15
# mv .g ../databases/linux-2.6.15
允许数据文件可访问
# chmod +r ../databases/linux-2.6.15/
# chmod +r ../databases/linux-2.6.15/.g
5) 使用
重启Web服务器,访问
http://localhost/lxr/http/blurb.html
** 如果出现错误
- 确保Web访问权限正确;
- 能执行Perl脚本;
- 查看error.log。
如果用diff markup出错,对diff打补丁
// diff.path
PHP 代码:
— diff.old 1998-05-14 20:01:45.000000000 +0800
+++ diff 2006-03-13 22:00:39.000000000 +0800
@@ -130,7 +130,7 @@
}
}
- close(<DIFF>);
+ close(DIFF);
print("<h1>Diff markup</h1>n",
———————————————
0.94-cvs for Debian
版本特性:
- 使用数据库而不再使用数据文件,更新索引时只检查修改过的文件,
而不用重新建立全部索引;
- 目标支持多种编程语言而不只是C,ASM;
- 支持CVS
- 支持swish-e索引
因为此版本用到数据库,如果是从网站上下载的lxr安装文件,要注意的是
mysql 5.0中 ‘release’为保留字,lxr建立的表中恰好有它,如果不改
代码的话,运行会出错;如果不会改代码,最好就用mysql4或postgres。
# apt-get install lxr-cvs
- 安装mod_perl
libapahce2-mod-perl
- 安装数据库
mysql, postgresql
- 安装perl-数据库接口
libdbd-mysql-perl (mysql), libdbd-pg-perl (postgre)
1) 建立目录
- 源码目录
方法同上
这个版本的目录可放在任意位置(stable版的好像也可以)
所以我放在/usr/src中的目录就不改动了
- 索引目录
存放用glimpse或swish生成的索引文件
# cd /var/lib/lxr-cvs
# mkdir databases(存放glimpse生成的索引)
# mkdir index(存放swish生成的索引)
2) 建立数据库
MySQL:
# mysql -u root
执行
==> . /usr/share/doc/lxr-cvs/examples/initdb-mysql
Postgresql:
# su postgres
创建用户 lxr
$ createuser lxr
创建数据库
$ createdb -U lxr lxr
建立数据库
$ psql -U lxr lxr
执行
==> i /usr/share/doc/lxr-cvs/examples/initdb-postgres
3) 配置Web服务器
创建文件 /etc/apache2/site-available/lxr-cvs 写入:
PHP 代码:
Alias /lxr /var/lib/lxr-cvs
如果不用mod_perl,将Alias 改为 ScriptAlias
<Directory /var/lib/lxr-cvs>
AllowOverride All
</Directory>
# ln /etc/apache2/site-available/lxr-cvs -s /etc/apache2/site-enable/lxr-cvs
# cp /usr/share/doc/lxr/cvs/examples/htaccess /var/lib/lxr-cvs/lxr/.htaccess
如果不用mod_perl
# cp /usr/share/doc/lxr/cvs/examples/htaccess_cgi /var/lib/lxr-cvs/lxr/.htaccess
htaccess_cgi
PHP 代码:
Options Indexes ExecCGI FollowSymlinks
order deny,allow
<Files lxr.conf>
deny from all
</Files>
<Files lib>
deny from all
</Files>
<Files ~ (find|search|source|ident|diff|cgi-bin)$>
SetHandler cgi-script
ForceType text/html
</Files>
htaccess
PHP 代码:
Options Indexes ExecCGI FollowSymlinks
order deny,allow
<Files ~ (find|search|source|ident|diff|cgi-bin)$>
SetHandler perl-script
# Apache 2
PerlHandler ModPerl::Registry
# Apache 1.3: uncomment next line and comment the previous line
#PerlHandler Apache::Registry
PerlSetEnv PERL5LIB lib
ForceType text/html
PerlSendHeader On
</Files>
4) 修改 lxr 配置文件. (/etc/lxr-cvs/lxr.conf)
PHP 代码:
服务器的地址要标明,因为这个版本是根据地址来生成访问页面的。
5) 建立交叉索引
’baseurl’ => ‘http://hostname/lxr‘,
如果不加上别名,会用不了localhost来访问
’baseurl_aliases’ => [ ‘http://localhost/lxr‘ ],
根据数据库类型来选择perl接口
# For mysql, the format is dbi:mysql:dbname=<name>
# for Postgres, it is dbi:Pg:dbname=<name>
# for Oracle, it is dbi:Oracle:host=localhost;sid=DEVMMS;port=1521
’dbname’ => ‘dbi:Pg:dbname=lxr’, (postgres)
源码目录
’sourceroot’ => ‘/usr/src’,
显示名称
’sourcerootname’ => ‘LXR $v’,
数据库用户和密码
’dbpass’ => ‘foo’,
’dbuser’ => ‘lxr’,
使用glimpse索引
’glimpsedir’ => ‘/var/lib/lxr-cvs/databases’,
使用swish-e索引
’swishdir’ => ‘/var/lib/lxr-cvs/index/‘,
# genxref –url=http://hostname/lxr –allversions (全部)
或
# genxref –url=http://hostname/lxr –version=linux-2.X.Y
这个时间会很久,大概一个2.X的要2~3小时吧
在浏览器中 http://localhost/lxr/source
如果查看少于两个字符或名称含有’-‘的目录无法打开
对Common.pm打补丁(/usr/share/perl5/LXR/)
PHP 代码:
— Common.pm.old 2005-05-05 07:19:33.000000000 +0800
!$1!;
+++ Common.pm 2006-03-13 22:12:11.000000000 +0800
@@ -539,9 +539,9 @@
if(defined $path) {
# First suppress anything after a dodgy character
- $path =~ s!(^[w_+-,.%^/]+).
+ $path =~ s!(^[w_+-,.%^/]+).*!$1!;
# Clean out /../
- while ($path =~ m!/../!) {
+ while ($path =~ m!/../!) {
$path = s!/../!/!g;
}
}