Bruce Wuu

知足常乐,
享受“登山”的乐趣

ubuntu 12.04上安装LXR 0.11(zz)

https://hi.baidu.com/wstone_h/item/e753015b68dd410de7c4a576

Ps:由于整个过程历时较旧并且很久没写记录,因此过程中可能存在差错。建议看官方文档进行配置。如果你没陪成功,那么是因为ubuntu的快捷害了你。本文仅供参考。


原 来在本地阅读kernel source时常用ctags和vim,或阅读网上lxr搭建的交叉代码(https://lxr.linux.no /+trees)。但是最近kernel的源码版本号飙升,网上依旧是老版本的source。因此想在本地搭建一个使用。记录如下编译和配置过程:

LXR的source主页:https://lxr.sourceforge.net/en/index.shtml
LXR的安装手册:https://lxr.sourceforge.net/en/0-11-InstallSteps/0-11-install.shtml
LXR的source下载地址:https://sourceforge.net/projects/lxr/files/stable/ 

1、安装前检查环境
由于本人使用的是ubuntu 12.04,因此一些软件或环境已经装好,另外使用apt-get方式快速安装一些环境。目前LXR的最新版本是:v0.11.1,安装过程参考了<LXR的安装手册>。

$ perl -v
This is perl 5, version 14, subversion 2 (v5.14.2) ...
ubuntu 12.04 默认已安装了perl,LXR v0.11.1要求perl版本大于v5.8即可。

安装如下的必要软件:
# apt-get install exuberant-ctags
# apt-get install mysql-server mysql-client
# apt-get install apache2
# apt-get install libapache2-mod-perl2-dev 
# apt-get install swish-e 
我选择使用了apache+mysql,当然你可以选择lighttpd等。


若不是使用swish-e,则可选择使用glimpse。ubuntu 12.04的源中没有glimpse的deb安装包,glimpse需自己手动编译。

swish-e和glimpse只需要选择一个。为什么glimpse或swish-e请参考<LXR的安装手册>
glimpse地址:https://webglimpse.net/
安装glimpse前需安装依赖:
$ sudo apt-get install flex
下载glimpse并解压后,直接经典三步走:
$ ./configure 
$ make
$ sudo make install

检查ctags版本
$  ctags --version
Exuberant Ctags 5.9~svn20110310...
LXR v0.11.1要求ctags的版本大于等于v5

检查swish-e的版本
$ swish-e -V
SWISH-E 2.4.7
LXR v0.11.1要求swish-e的版本高于v2.1

安装cpan,以方便安装Perl相关的一些模块,如File::MMagic和Perl DBI(数据库接口)
# apt-get install cpanminus
或使用如下命令进行安装:
# cpan App::cpanminus
有关cpan的文档可参考:https://www.cpan.org/modules/INSTALL.html

安装File::MMagic和Perl DBI
# cpanm DBI
# cpanm File::MMagic
或者使用如下命令安装File::MMagic:
# apt-get install libfile-mmagic-perl

2、下载LXR source并安装
下载LXR最新源码并解压:
$ tar xvf lxr-0.11.1.tgz 
# mv lxr-0.11.1 /usr/local/share/lxr; cd /usr/local/share/lxr
将lxr当成服务使用时,依据官方文档需将lxr安装在/usr/local/share/lxr
# ./genxref --checkonly
No URL specified - Continuing in checking mode
Checking Perl version ... 5.14.2  OK 
Parameter 'ectagsbin' not defined - trying to find ctags
'ectagsbin' temporarily adjusted to /usr/bin/ctags
Manually update lxr.conf for permanent setting
Checking ctags version ... 5.9  OK 
Parameter 'glimpsebin' not defined - trying to find glimpse
'glimpsebin' temporarily adjusted to /usr/local/bin/glimpse
Manually update lxr.conf for permanent setting
Checking glimpse version ... 4.18.5 
Parameter 'glimpseindex' not defined - trying to find glimpseindex
'glimpseindex' temporarily adjusted to /usr/local/bin/glimpseindex
Manually update lxr.conf for permanent setting
Checking glimpseindex version ... 4.18.5 
Parameter 'swishbin' not defined - trying to find swish-e
swish-e not found, `which swish-e` returned a null string
No matching configuration at ./genxref line 275.
其中swish-e和glimpse只需安装一个。

先创建临时文件夹:
# mkdir lxrconf.d/
在使用脚本,生成配置文件:
# ./scripts/initial-config.sh
*** Initial phase configurator for LXR ($Revision: 1.6 $) ***

Configure for single/multiple trees? [S/m] m

Your LXR root directory is: /usr/local/share/lxr

templates directory now protected read-only
File .htaccess written in your LXR root directory
--- List its content with 'more .htaccess'
File apache2-require.pl written in lxrconf.d directory
File apache-lxrserver.conf written in lxrconf.d directory
File lighttpd-lxrserver.conf written in lxrconf.d directory
You need to manually configure lighttpd-lxrserver.conf for multiple trees operation
Prototype lxr.conf written in lxrconf.d directory

*** Configuration directory lxrconf.d now contains: ***
total 44
drwxr-xr-x 2 root   root    4096 May 30 20:02 .
drwxr-xr-x 9 harris harris  4096 May 30 20:02 ..
-rw-r--r-- 1 root   root     155 May 30 20:02 apache2-require.pl
-rw-r--r-- 1 root   root    2410 May 30 20:02 apache-lxrserver.conf
-rw-r--r-- 1 root   root   11958 May 30 20:02 lighttp-lxrserver.conf
-r--r--r-- 1 root   root   14300 May 30 20:02 lxr.conf



根据自己情况选择s或者m,s即单个源码树(S不分大小写),m表示多个源码树。我这边选择了m,请仔细查检查文件.htaccess以及apache-lxrserver.conf等生成。
# ls lxrconf.d/
apache2-require.pl  apache-lxrserver.conf  lighttp-lxrserver.conf  lxr.conf

3、创建数据库文件
我使用了mysql,LXR是可以使用的Postgresql和Oracle。使用其他数据库可参考LXR的官方文档。登录mysql root权限并创建一个账户:
$ mysql -u root -p
mysql> create user 'lxr'@'localhost' identified by 'lxrpassword';
mysql> exit

$ ./scripts/initdb-config.sh
依据默认回答,并在目录lxrconf.d/生成数据初始脚本initdb-mysql-custom.sql,使用该脚本:
$ mysql -u root -p < lxrconf.d/initdb-mysql-custom.sql

文件lxr.conf记录了LXR root目录等重要信息,需做一些修改。

这里是重要的的一步,但是依据文档描述设置即可。
# gedit lxrconf.d/lxr.conf
# cp lxrconf.d/lxr.conf .

# ./genxref --url=https://localhost/lxr --version=v4
Checking Perl version ... 5.14.2  OK 
Checking ctags version ... 5.9  OK 
Checking glimpse version ... 4.18.5 
Checking glimpseindex version ... 4.18.5 
Parameter 'swishbin' not defined - trying to find swish-e
swish-e not found, `which swish-e` returned a null string

This is glimpseindex version 4.18.5, 2006.

permission denied or non-existent: /home/harris/indexed-src/v4

Size of files being indexed = 0 B, Total #of files = 0

Index-directory: "/home/harris/glimpse/databases/v4"
Glimpse-files created here:
-rw------- 1 root root      2 May 27 20:59 .glimpse_filenames
-rw------- 1 root root      0 May 27 20:59 .glimpse_filenames_index
-rw------- 1 root root      0 May 27 20:59 .glimpse_filetimes
-rw------- 1 root root     18 May 27 20:59 .glimpse_index
-rw------- 1 root root    163 May 27 20:59 .glimpse_messages
-rw------- 1 root root      0 May 27 20:59 .glimpse_partitions
-rw------- 1 root root    124 May 27 20:59 .glimpse_statistics
-rw------- 1 root root 262144 May 27 20:59 .glimpse_turbo
*** / v4 
### / v4 
commit ineffective with AutoCommit enabled at lib/LXR/Index/Mysql.pm line 385, <GEN0> line 16.


至此lxr其实完成了大半,但是若不能正常访问,那么就要好好研究apahce的配置和/usr/local/share/lxr/.htaccess文件。拷贝apache2的配置文件:

#cp /usr/local/share/lxr/lxrconf.d/apache-lxrserver.conf  /etc/apache2/conf.d/


ubuntu使用apahce时可能存在以下的报错:
# apache2ctl restart
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
默认情况下,文件httpd.conf是个空文件,修改如下后即可修正错误:
# cat /etc/apache2/httpd.conf
ServerName localhost


访问:https://localhost/lxr/source

若 访问不成功,那么你需要看下报错日志:/var/log/apache2/error.log,若你发现自己的颜色啥的没有启用,那么就去看这个日志文件 /var/log/apache2/error.log,其实是因为lxr.conf时没有设置好。根据error.log的提示,在设置也是可以的。

由于apache使用apt-get安装模式,导致perl_mod没有很好的使用。


在访问:https://localhost/lxr/source不成功时还可以做如下设置:

1、编辑/usr/local/share/lxr/.htaccess文件,仅有如下内容
<Files ~ (search|source|ident|diff|find)$>
 SetHandler cgi-script
</Files> 

2、删除/etc/apache2/conf.d/apache-lxrserver.conf

3、在文件/etc/apache2/conf.d/中添加如下内容:

Alias /lxr /usr/local/share/lxr
<Directory /usr/local/share/lxr>
     Options All
     AllowOverride All
</Directory> 
4、重启apahce2

# apache2ctl restart

评论

© Bruce Wuu | Powered by LOFTER