LXR(Linux Cross Reference)安装配置心得

LXR的主页上是这样介绍自己的
A general purpose source code indexer and cross-referencer that provides web-based browsing of source code with links to the definition and usage of any identifier. Supports multiple languages.
对于需要阅读源代码的人来说,是一个非常有帮助的工具,所谓工欲善其事,必先利其器。
从配置到成功花了我不少时间,主要是网上的配置方法写的太杂,很多已经过时了,对于现在的情况已经不再适用,所以还是决定自己写一篇东西出来,虽然我知道我写完了过一段时间也会过期,所以尽量写一些这样配置的原因,而不是单纯的步骤,授人以鱼,不如授人以渔。
网上有很多配置好LXR的网站,最有名的当然是http://lxr.linux.no
但是网络上的东西毕竟有其不可靠性。首先是网速没有保证,点一次刷新半天。其次,我们虽然大多数时间能连上网,但总会遇到这样那样的连接问题,说不定某一天它就被GFW和谐掉了,这样的事情太多了,所以还是放在本机的服务器比较保险。
我们配置的环境是在ubuntu 7.04下,当然主要看中的是其安装软件apt的方便性,ubuntu毫无疑问是当今各个linux发行版中最有人气也最好用的一个。

配置步骤:
(1)安装lxr(版本为0.31,stable的版本),apache2,libapache2-mod-perl2,glimpse,perl
注:lxr 0.31版本是不需要有数据库支持的,所以MySQL和PostgreSQL是不需要的,而最新的0.9x的那些版本已经需要数据库支持了,我前面就是在数据库上花费了太多的时间,尤其是它不支持MySQL5,因为有release关键字的问题,非常ft。怎么安装我想ubuntu下大家都会,不用我多说了,apt一下或synaptic一下就可以了。
(2)lxr的安装目录为 /usr/share/lxr/,我们把需要索引的源代码放到/usr/share/lxr/source/下,目录名字为版本号,如2.6.17,然后新建文件/usr/share/lxr/source/versions,文件中写入2.6.17。创建文件/usr/share/lxr/source/defversion,意思为默认版本,我们写入2.6.17
注:我们可以放多个源代码目录在source目录下,名字可以任取,然后写入versions 即可。当然如果源码在其他路径下,也可以做一个软连接过来。
(3)建立索引目录,新建目录/usr/share/lxr/databases,然后在databases目录下创建目录2.6.17
(4)配置apache2,新建文件 /etc/apache2/sites-available/lxr,写入以下代码

[color=blue] Alias /lxr /usr/share/lxr
<Directory /usr/share/lxr>
Options All
AllowOverride All
</Directory> [/color]

注:这是让client访问apache2下http://localhost/linux时直接访问到/usr/share/lxr,以隐藏lxr的真实目录。
然后执行
guzhongshu@guzhongshu-laptop:~$sudo ln /etc/apache2/sites-available/lxr -s /etc/apache2/sites-enabled/lxr
创建文件/usr/share/lxr/http/.htaccess ,写入以下代码:
[color=blue]SetHandler cgi-script [/color]
注:这是为了让perl起作用,让apache2的mod_perl来执行http目录下的perl文件,而不是下载这个文件。
(5)配置LXR,主要修改的文件是/usr/share/lxr/http/lxr.conf,我的配置文件如下所示:

[color=red]# Configuration file.
# Define typed variable "v", read valueset from file. [/color]
variable: v, Version, [/usr/share/lxr/source/versions], [/usr/share/lxr/source/defversion]
[color=red]# Define typed variable "a". First value is default. [/color]
variable: a, Architecture, (i386, alpha, m68k, mips, ppc, sparc, sparc64)
[color=red]# Define the base url for the LXR files.[/color]
baseurl:http://localhost/lxr/http/
[color=red]# These are the templates for the HTML heading, directory listing and # footer, respectively. [/color]
htmlhead: /usr/share/lxr/http/template-head
htmltail: /usr/share/lxr/http/template-tail
htmldir: /usr/share/lxr/http/template-dir
[color=red]# The source is here. [/color]
sourceroot: /usr/share/lxr/source/$v/
srcrootname: Linux
[color=red]# "#include " is mapped to this directory (in the LXR source # tree) [/color]
incprefix: /include
[color=red]# The database files go here. [/color]
dbdir: /usr/share/lxr/databases/$v/
[color=red]# Glimpse can be found here. [/color]
glimpsebin: /usr/bin/glimpse
[color=red]# 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?) [/color]
map: /include/asm[^\/]*/ /include/asm-$a/
map: /arch/[^\/]+/ /arch/$a/
注:大家应该根据自己的系统环境来进行配置lxr.conf

(6) 生成数据文件
[color=blue]guzhongshu@guzhongshu-laptop:~$ cd /usr/share/lxr/source/
guzhongshu@guzhongshu-laptop:/usr/share/lxr/source$ sudo genxref 2.6.17/[/color]
长时间等待,因为要扫描文本处理
[color=blue]guzhongshu@guzhongshu-laptop:/usr/share/lxr/source$ sudo mv fileidx ../databases/2.6.17/
guzhongshu@guzhongshu-laptop:/usr/share/lxr/source$ sudo mv xref ../databases/2.6.17/ [/color]
生成glimpse索引文件
[color=blue]guzhongshu@guzhongshu-laptop:/usr/share/lxr/source$ sudo glimpseindex -H . 2.6.17
guzhongshu@guzhongshu-laptop:/usr/share/lxr/source$ sudo mv .g* ../databases/2.6.17[/color]
允许数据文件可访问
[color=blue]guzhongshu@guzhongshu-laptop:/usr/share/lxr/source$ sudo chmod +r ../databases/2.6.17/*
guzhongshu@guzhongshu-laptop:/usr/share/lxr/source$ sudo chmod +r ../databases/2.6.17/.g*[/color]
(7)重启apache2
[color=blue]guzhongshu@guzhongshu-laptop:/usr/share/lxr/source$ /etc/init.d/apache2 restart[/color]
访问网站http://localhost/lxr/blurb.html
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值